Python Forum
File is not being created with 'w' argument
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
File is not being created with 'w' argument
#1
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.
Reply


Messages In This Thread
File is not being created with 'w' argument - by CAD79 - Mar-13-2024, 08:19 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Error on open of file created with tempfile.TemporaryDirectory() Brian177 4 6,375 Apr-05-2021, 07:12 PM
Last Post: Brian177
  code to read files in folders and transfer the file name, type, date created to excel Divya577 0 1,886 Dec-06-2020, 04:14 PM
Last Post: Divya577
  SyntaxError: positional argument follows keyword argument syd_jat 3 5,883 Mar-03-2020, 08:34 AM
Last Post: buran
  I created a function that generate a list but the list is empty in a new .py file mrhopeedu 2 2,348 Oct-12-2019, 08:02 PM
Last Post: mrhopeedu
  Incorrect code output (File not being created) Hass 4 2,981 Jan-01-2019, 04:10 AM
Last Post: ichabod801
  Opening txt file created in python in excel fabipc 1 2,574 Aug-05-2018, 11:59 PM
Last Post: ichabod801
  CSV file created is huge in size. How to reduce the size? pramoddsrb 0 10,517 Apr-26-2018, 12:38 AM
Last Post: pramoddsrb
  Accept Multiple Lines of Input into a User Created File Bragger 0 2,647 Oct-29-2017, 04:15 PM
Last Post: Bragger
  Calling a C Func though Pyhon Script using DLL file which is created for C file. CMMouli 4 4,694 Feb-18-2017, 05:06 AM
Last Post: Skaperen

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020