You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hey, nice github tutorial for python... But all your code is on Python 2!
Can i start update to python 3? And make some changes, here is one example:
# from sys module import a member called 'argv'
from sys import argv
#unpack
script, filename = argv
fp = open(filename, "w")
print "Writing to file %r " % fp
fp.write("Hello World")
fp.close()
This example is from python_write.py, but here is the problem, when you are working with files if you open you need to close it.
The way to do it more "easily" is yo use context manager with statement.
So:
# from sys module import a member called 'argv'
from sys import argv
#unpack
script, filename = argv
with open(filename, "w") as f:
print("Writing to file".format(f)) # As python 3+
f.write("Hello World")
More clean, and modern python.
The text was updated successfully, but these errors were encountered:
Hey, nice github tutorial for python... But all your code is on Python 2!
Can i start update to python 3? And make some changes, here is one example:
This example is from python_write.py, but here is the problem, when you are working with files if you open you need to close it.
The way to do it more "easily" is yo use context manager with statement.
So:
More clean, and modern python.
The text was updated successfully, but these errors were encountered: