Reputation: 21
The purpose of the code is to put the output into a text file the problem i have is it says i have a syntax error and would like to know what i am missing
def save():
with open(os.path.join('C:\Users\test\Documents\test', 'directory.txt','w+'))#syntax error in this line
directoryScan.write(outPut) #file
directoryScan.close()
the w+ is used for - if the file does not exist create a .txt file and insert the output there
Upvotes: 0
Views: 288
Reputation: 309
Go through Section 7.2 here, Python Input output Documentation
Your with is incomplete, hence the syntax issue.
Also the format for opening should be open('file','w+')
and in your case 'file'
is replaced with os.path.join()
, but you seem to be treating it as open(os.path.join())
.
When you are done, your code should be something like :
with open (os.path.join(<path>,<filename>), 'w+') as directoryScan:
Upvotes: 1