-
-
Notifications
You must be signed in to change notification settings - Fork 8.2k
Micropython file truncate doesn't exist #4775
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Hello, |
I would use this if it was available |
I finally defined my own truncate function: def Truncate(self, Num): |
I'd appreciate having a log = open("log", "w")
blank_kb = "\n" * 1024
for i in range(16): log.write(blank_kb)
log.seek(0, 0)
print("\n", file=log)
...
# log.truncate() would be nice here
log.close() |
Both the FatFS and LittleFS drivers provide a file truncate function, so this would be straight forward to implement (and of course make it match CPython). |
…truncate() Micropython does not support file truncations. This new implementation instead reads and writes each line into a new file, skipping the last line. See micropython/micropython#4775 for more information
I could also really use this for a mpy project that I'm working on |
Is there any alternative in MicroPython to truncate a file at the current seek position? I don't want to just empty the file, I want to truncate it at a position.
The truncate function doesn't exist ( https://docs.micropython.org/en/latest/esp8266/tutorial/filesystem.html?highlight=open#creating-and-reading-files https://docs.micropython.org/en/latest/library/builtins.html?highlight=open#open )
Any alternatives?
I thought about copying the whole contents to a new file, but I wanted to avoid that since I'm limited to memory and storage(working on a LoPy4)
The text was updated successfully, but these errors were encountered: