I am trying to create a small program to parse a text file that outputs data from a datalogger, but from what I have looked up online, using 'w' as an argument in the open parameter should be enough. I only started coding in python yesterday so a bit of help would be appreciated. This is my code:
import datetime now = datetime.datetime.now() readFileName = now.strftime("%d-%m-%y.txt") dirName = "dataLogging" readFileFullPath = ('E:/' + dirName + '/' + readFileName) readFile = open(readFileFullPath, 'r') writeFileName = 'parsed_' + readFileName writeFileFullPath = ('C:/' + 'parsed_' + dirName + '/' + writeFileName) writeFile = open(writeFileFullPath, 'w') lines = readFile.readlines() errorCount = 0 for line in lines: line = line.strip() if line.find("ERROR") != -1: errorCount +=1 else: writeFile file.write(line) file.close() writeFile("Errors:", errorCount)and this is the traceback I get:
Error: Traceback (most recent call last):
File "C:\Users\christopher.donnelly\PycharmProjects\HelloWorld\pythonProject\readWriteDataLogging.py", line 11, in <module>
writeFile = open(writeFileFullPath, 'w')
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
FileNotFoundError: [Errno 2] No such file or directory: 'C:/parsed_dataLogging/parsed_13-03-24.txt'
Process finished with exit code 1
Edit: never mind, I solved it, it was just the directory and a bit of syntax. The directory will already be created so all it needs to create is the text file.