I used this code to append a string to a file, but it wrote the string to the beginning of the file. Can anyone help?
import os
fn main() raises:
var f = open("file", "w")
_ = f.seek(0, os.SEEK_END)
f.write("a string")
f.close()
I used this code to append a string to a file, but it wrote the string to the beginning of the file. Can anyone help?
import os
fn main() raises:
var f = open("file", "w")
_ = f.seek(0, os.SEEK_END)
f.write("a string")
f.close()
This might be a bug. I agree that what you have should work, and checked it as well and didn’t get it to work.
Would you be up for making a bugticket for it?
I do not know how to make a bug ticket.
I think what is maybe happening is that opening with “w” is just overwriting the whole thing to start with, there needs to be an “append” mode, which there is not. If nobody else drops in with a solution I’ll make a github issue for it.
Nevermind, there is an issue for this already: [BUG] File open does not have the append flag · Issue #3849 · modular/modular · GitHub
Github can be a bit scary and arcane (at least to me).
To file a bugticket/issue/bug report, go to the appropriate repository on github.
Modular repo for mojo+MAX issues
Then click on issues
Alternatively: Issues
You can search through the issues at this point to see if something similar has occurred. If so, you can track that issue to see when it gets fixed. If not, then you can open a new issue.
Then, upper right, click “New issue”
Note: you will need a github account to file an issue and be logged in
Choose what you think is the most appropriate category. The title and category can all be changed later.
The bug report templates are important. They will likely trigger thought, action, and additional work but that is intended. Vague phrasing and complex code create drag on developers to understand and fix bugs. You aren’t expected to be an expert or even know what’s wrong; however, the “expected behavior” and “actual behavior” parts are essential. What you or I might think is wrong may be an unknown bug, a known bug, an unimplemented feature, a feature that is implemented but our code is incorrect, and many more possibilities. Put another way, it’s the beginning of a conversation so it’s important to attend to your ticket once it’s opened.
Here’s the github official documentation on issues LINK