I must not understand retrning a value from a function! os.file_size. Resolved #15660
Replies: 7 comments 5 replies
-
We would need to see a complete working example to check into this. import os
println(os.file_size('foo.v')) Then check the size with ls:
Then run the code:
... which is the exact correct size. |
Beta Was this translation helpful? Give feedback.
-
I agree os.file_size returns the right value. It is when it is wrapped in my file utils file_size wrapper (see below and the println there always shows the correct value). It is only when my file utils file_size wrapper is called in a loop that I get the issue. I will try and build a small test program later today and see if I can get the issues to occur as well there.
|
Beta Was this translation helpful? Give feedback.
-
Ok this example shows the error: Output is
And the example code that causes the problem - copy into a file, change test_path to point at a folder with files, compile and run. The issue is then displayed as the file sizes are printed.
|
Beta Was this translation helpful? Give feedback.
-
works for me. i notice file_size returns u64, but with an error tries return -1? |
Beta Was this translation helpful? Give feedback.
-
Try using |
Beta Was this translation helpful? Give feedback.
-
Good spot splace and spytheman that issue needs raising! Obvious oversight on my behalf but it still does not completely fix the error I changed file size to
And get this result:
Given I have written a stack of V lately and it has been working I was tending to the view that calling println in the loop was in error. And this test run still suggests this to me as I am not seeing an obvious error in my code. |
Beta Was this translation helpful? Give feedback.
-
Thank you Carl for catching my obvious dumb mistake - dunce cap for me please, perhaps I should return my Masters in comp sci! Code below works and produces correct output - println is innocent!
Result with fixed code
|
Beta Was this translation helpful? Give feedback.
-
OK,
I have done some V and it works great in general but this has me stumped....in one V file I have this function
In another V file I call it like so: Note this is stripped down!
Now in my test harness I call it like so:
And I expected the file size to be printed correctly but I get:
File is /home/david/Pictures/test/IPTC-PhotometadataRef-Std2017.1.jpg Size is 18446744073709551615 : 91435
aimg_file_size = 18446744073709551615 (incorrect with the file_utils.file_size call in get properties )
img_file_size = 91435 (correct with the os.file_size call in get_properties )
Note on the last call of the loop it produces the correct value!
File is /home/david/Pictures/test/20200208_114235.jpg Size is 3867705 : 3867705
The println call in file_utils.file_size prints the correct size as expected.
Am I doing something obviously wrong? Or is this confusing and I have to bail this down to a small test program to seek help? It looks like an uninitialized variable or address value to me...
V doctor output - Before you start laughing I am on vacation using an ancient computer! And I have a feeling this works correctly on the modern computer at home...
Beta Was this translation helpful? Give feedback.
All reactions