7c977cb5f370d2e8a8ceda762f8d22a3c668e8f0,fileinfo.py,,,#,20

Before Change


t_char = 0
try:
    with open(file_name) as f:
        line = f.readline()
        t_char += len(line)
        while line:
            count += 1
            line = f.readline()
            t_char += len(line)
except FileNotFoundError as e:
    print(e)
    sys.exit()

After Change


        // Source: https://stackoverflow.com/a/1019572
        count = (sum(1 for line in f))
        f.seek(0)
        t_char = (sum([len(line) for line in f]))
except FileNotFoundError as e:
    print(e)
    sys.exit(1)
// When open item is a directory (python2)
except IOError:
    pass
// When open item is a directory (python3)
except IsADirectoryError:
    pass

file_stats = os.stat(file_name)
// create a dictionary to hold file info
file_info = {
    "fname": file_name,
    "fsize": file_stats[stat.ST_SIZE],
    "f_lm": time.strftime("%d/%m/%Y %I:%M:%S %p",
                          time.localtime(file_stats[stat.ST_MTIME])),
    "f_la": time.strftime("%d/%m/%Y %I:%M:%S %p",
                          time.localtime(file_stats[stat.ST_ATIME])),
    "f_ct": time.strftime("%d/%m/%Y %I:%M:%S %p",
                          time.localtime(file_stats[stat.ST_CTIME])),
    "no_of_lines": count,
    "t_char": t_char
}

file_info_fmt = ("\nfile name = {}\nfile size = {}\nlast modified = {}\n"
                 "last accessed = {}\ncreation time = {}\n"
                 "Total number of lines are = {}\n"
                 "Total number of characters are = {}")
print(
    file_info_fmt.format(file_info["fname"],
                         str(file_info["fsize"]) + " bytes", file_info["f_lm"],
                         file_info["f_la"], file_info["f_ct"],
                         file_info["no_of_lines"], file_info["t_char"]))
Italian Trulli
In pattern: SUPERPATTERN

Frequency: 3

Non-data size: 5

Instances


Project Name: geekcomputers/Python
Commit Name: 7c977cb5f370d2e8a8ceda762f8d22a3c668e8f0
Time: 2020-03-22
Author: alopex4@163.com
File Name: fileinfo.py
Class Name:
Method Name:


Project Name: sassoftware/python-dlpy
Commit Name: 8afa7fb5dc0ef8bb6f2eb98e97d64821624b4e3c
Time: 2019-08-02
Author: Xiaozhuo.Cheng@sas.com
File Name: dlpy/speech_utils.py
Class Name:
Method Name: segment_audio


Project Name: geekcomputers/Python
Commit Name: 7c977cb5f370d2e8a8ceda762f8d22a3c668e8f0
Time: 2020-03-22
Author: alopex4@163.com
File Name: fileinfo.py
Class Name:
Method Name:


Project Name: flow-project/flow
Commit Name: 3f5718f8e40fa7207c7b547f3875f0076813e2b4
Time: 2019-01-09
Author: akreidieh@gmail.com
File Name: flow/utils/aimsun/run.py
Class Name:
Method Name: threaded_client