#π file doesnt get edited
98 messages Β· Page 1 of 1 (latest)
@dire fog
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.
what about when you open the file? because what youre reading there is the file before its edited
youre opening the file, editing and saving, and then not reading it back
test = 'testing'
with open('python_testing.txt','w') as file:
file.writelines(test)
with open('python_testing.txt') as file:
print(file.read())
lets start with you actually opening them correctly
this should read it back to you as well
he said it doesnt write to the file even when he opens it
it still doesnt work
something tells me it has to do with him opening it in a weird way
and what is it with the first two lines?
I was testing other things earlier but didnt remove those
remove it now.
ye removed
can you share the file made from this? bc it worked for me
how are you running the code?
pycharm
I managed to edit the file with other still earlier, but it suddenly stopped working
where are you looking for your file?
can you share the whole section of the code?
maybe a bad if statement thats not shown to us?
this is the only thing I wrote ;-;
!code
any errors?
is your working directory the same as where your running it?
yea, the file was created by running the script
can we have a snippet of the terminal when you execute the code
thats odd that its creating but not writeing. try just write() instead of writelines()
i can see that yourte running the wrong code
dont work ;-;
oh π
OH
HOLY
IM SO DUMB
that would fix your issue
but hey at least now you know you dont need all those opens before hand XD
xD
yea π
im so sorry, its like 2am right now and I dont think im functioning
happens to all of us
np
and get some sleep
xd
who needs sleep when you have python
import time
time.sleep(99999999999999999999999999999999999)
LOL
i should probably also point out why its a bad idea to do open() instead of with open(). just doing open() you should always do var.close() when you get done with it. but with open() closes the file properly for you
is there a more efficient way to edit the file other than constantly doing the with statements?
ohh
got it
depends on what you're doing exactly.
looks like i answered your question before you asked it
like im testing out how saving progress in a text game works
id say just stick with with open
like gaining xp and it saving in the file
alr
dont close the chat just yet and ill write up a mock save for you that you might like
you'd generally not use a text file for that, but rather a database
going to intentionally smudge it though bc im not nice π
how do you use a database?
alr
thats good, mainly looking to understand python concepts rather than copying code :p
export json
without 420-- as f:
data = json.loads(f.read())
without 420-- as f:
f.write(json.dumps(data,indent=2))
```i left out all the juicy bits but in between the reading and writing you just edit the data like you would normally
man I need to study my imports
i think you mean exports XD (not a thing, unless it is)
still a lil confused, where exactly does it get saved
and it honestly depends on the situation if youre needing text files or database. id say if its a singleplayer kind of game where youre needing to save only character data for a single person, a json format file would be better suited than a database
I was also wondering if its possible to run python code without needing to have an interpreter or anything
if you package it as an exe(unreliable but does work) or if you package it with an ebedded interpreter that just comes with your code
but for developing, you do need python installed no ifs or buts
mhm
I saw something about pyinstaller for converting to exe, but im still confused
how do you package it with an embedded compiler though
thats the unreliable way, but its honestly what i do. as for the embedded thing i dont know. ive never needed it.
alr
if i need an exe its normally just custom office software for a client needing specific equations and models built in so it just works out since i normally personally know the client. but it can get iffy because if your antivirus registers it as a virus it will fight you on it. and it does 9.9/10 times
i once even had pyinstaller refuse to package it bc they themselves saw it as malware for some reason
how else can someone run python code from their end if they cant install an interpreter
LMAO
you use an embedded python package. youll have to look that up though or hope someone else here know how bc i dont
alr, tysm for the help
This help channel has been closed and it's no longer possible to send messages here. If your question wasn't answered, 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.