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
#2
With the text file, I would have test something like :

import datetime
 
 
now = datetime.datetime.now()
readFileName = now.strftime("%d-%m-%y.txt")

dirName = "dataLogging"

readFileFullPath = ('E:/' + dirName + '/' + readFileName)

writeFileName = 'parsed_' + readFileName
writeFileFullPath = ('C:/' + 'parsed_' + dirName + '/' + writeFileName)


with open(readFileFullPath, 'r') as readFile, open(writeFileFullPath, 'w') as writeFile:

    lines = readFile.readlines()
    errorCount = 0
    
    for line in lines:
        line = line.strip()
        if line.find("ERROR") != -1:  
        # if "ERROR" in line.upper():   # another way
            errorCount +=1
        else:
            writeFile.write(line)
     
    writeFile.write(f"Errors:{errorCount}") 
Reply


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

Possibly Related Threads…
Thread Author Replies Views Last Post
  Error on open of file created with tempfile.TemporaryDirectory() Brian177 4 6,487 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,921 Dec-06-2020, 04:14 PM
Last Post: Divya577
  SyntaxError: positional argument follows keyword argument syd_jat 3 5,960 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,383 Oct-12-2019, 08:02 PM
Last Post: mrhopeedu
  Incorrect code output (File not being created) Hass 4 3,014 Jan-01-2019, 04:10 AM
Last Post: ichabod801
  Opening txt file created in python in excel fabipc 1 2,605 Aug-05-2018, 11:59 PM
Last Post: ichabod801
  CSV file created is huge in size. How to reduce the size? pramoddsrb 0 10,560 Apr-26-2018, 12:38 AM
Last Post: pramoddsrb
  Accept Multiple Lines of Input into a User Created File Bragger 0 2,682 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,737 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