My job currently utilizes python 2.7 for scripting. However, I'm currently working on script with python 3.7. Normally, when we need to write to a log file the code looks like this:
log = file(r'\\server\blah\result.log', 'w')
print >>log, 'BEGIN DAILY REPORT ' + strftime("%m/%d/%y %H:%M:%S", localtime()) + '\n
However, in 3.7 I'm getting this error: "NameError: name 'file' is not defined". Is this the result of syntax changes? Forgive me as I'm new to python.
To open a file in Python 3.x, you need to use open(filename, mode)
.
Look here for more information and examples.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.