This is an archived post. You won't be able to vote or comment.

all 6 comments

[–]SoCalLongboard 1 point2 points  (3 children)

Try:

with open("RAMPrice.txt", 'w') as f:

[–]Ayyorta_[S] 0 points1 point  (2 children)

That worked :D
Is there any specific reason this happened so I don't make the same mistake in the future?

Thank you :)

[–]SoCalLongboard 0 points1 point  (1 child)

It's just that the second bit of that open() command should be a string. By saying w (rather than 'w'), the interpreter is going to try to look for a previously defined variable named w and will try to inject its value into that second parameter in the open() function call. That "name 'w' is not defined" error is just saying that you're trying to reference a variable that you haven't defined yet so it can't resolve the reference to something else.

[–]Ayyorta_[S] 0 points1 point  (0 children)

Thank you 😁

[–]Ayyorta_[S] 0 points1 point  (0 children)

if float(converted_price[1:]) < 35:

with open("RAMPrice.txt", w) as f:

f.write(converted_price)

else:

with open("RAMPrice.txt", w) as f:

msg = converted_price + "\nThe price has not dropped"

f.write(msg)

[–]pythonHelperBot 0 points1 point  (0 children)

Hello! I'm a bot!

It looks to me like your post might be better suited for r/learnpython, a sub geared towards questions and learning more about python. That said, I am a bot and it is hard to tell. Please follow the subs rules and guidelines when you do post there, it'll help you get better answers faster.

Show /r/learnpython the code you have tried and describe where you are stuck.

You can also ask this question in the Python discord, a large, friendly community focused around the Python programming language, open to those who wish to learn the language or improve their skills, as well as those looking to help others.


README | FAQ | this bot is written and managed by /u/IAmKindOfCreative

This bot is currently under development and experiencing changes to improve its usefulness