Apr-03-2020, 08:31 PM
Greetings, I built a script that checks the size of a file upon creation, but the value is definitely inaccurate (the file is not empty and thus should not be 0 bytes).
Here is what happens:
lamidotijjo Week2 $ ls -l
total 24
-rw-rw-r-- 1 lamidotijjo lamidotijjo 31 Apr 3 12:54 newprogram.py
As one can see it should read 31 bytes.
Here is what happens:
import os def create_python_script(filename): comments = "# Start of a new Python Program" #filesize = 0 with open(filename, 'w') as new_file: new_file.write(comments) abspath = os.path.join(os.getcwd(),filename) filesize = os.path.getsize(abspath) return(filesize) print(create_python_script('newprogram.py'))a zero is returned however it should be returning roughly 31 bytes:
lamidotijjo Week2 $ ls -l
total 24
-rw-rw-r-- 1 lamidotijjo lamidotijjo 31 Apr 3 12:54 newprogram.py
As one can see it should read 31 bytes.