#๐ help with saving a file
27 messages ยท Page 1 of 1 (latest)
@olive spade
Remember to:
- Ask your Python question, not if you can ask or if there's an expert who can help.
- Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
- Explain what you expect to happen and what actually happens.
:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.
add py behind the backticks then it looks like this
elif opts == 10:
print("Filename: ")
filename = input("$| ")
print("Contents: ")
contents = input("$| ")
if not filename.endswith(".txt"):
filename += ".txt"
file_path = os.path.abspath(filename)
with open(filename, 'w') as file:
file.write(contents)
print(f"Text successfully saved to {file_path}")
which is much more readably
it didnt work, but for some reason VSCode doesnt let me run scripts so i couldnt see what the error was
but why do you use abspath? it would automatically be stored in the same folder when you just use the filename. and the os module is part of the standard library you do not need to install it, it comes with python
yes i know i put "import os" at the far beggening of my code
but nevertheless, the code works for me
happens if you don't save the file
and i mean ur python file
i save it a lot
it tells me error in line 1 invalid sytax
this is line 1
```import time````
are you sure that the opts == 10 condition is true? because the storing logic works
what is the error message
is there a ready squiggly line under it? if there is hover over it, should give more details
no
there is a & before your path
how do i remove that?
i do not know how it gets there since i do not have your code
This help channel has been closed. Feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.