Surreal syntax #9841
Replies: 2 comments 1 reply
-
I think the 'w' truncates the file. Try
|
Beta Was this translation helpful? Give feedback.
-
@kjm1102 Not sure what this has to do with syntax (or syntax errors). Syntax errors are specifically when your program cannot be understood by the language. This is distinct to a runtime error (e.g. divide by zero or accessing an attribute that doesn't exist). Both of your snippets have correct syntax. There are three issues here:
f = open('log', 'w')
f.write('test test')
f.close() Or better, have Python do the close automatically using a context manager (i.e. with open('log', 'w') as f:
f.write('test test')
|
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
In my brief upython existence I've had more than my fair share of syntax errors.
Today, while trawling the web for a way to write tuples to files, I spotted a strange looking write syntax. I decide to try it on a rpi pico
No syntax error, but no write either. Thinking that was maybe because it didn't close the file, I tried again
Just curious what's happening here, the cmd is accepted but does'nt seem to do anything?
Beta Was this translation helpful? Give feedback.
All reactions