Python Forum
Copy and append data from .dat file
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Copy and append data from .dat file
#16
I managed to add some code below to have a seperate csv file.

import time
import schedule    
import csv

#starttime=time.time()
  
def task():  
  
#Input_file: "C:\\Campbellsci\\LoggerNet\\CR1000_Table1.dat"
#Output_file: "C:\\Users\\Makada\\Desktop\\CR1000_Table1 - kopie.dat"
  
 while True:
    """ Not to append duplicate data to output file"""
    existingLines = set(line.strip() for line in open("C:\\Users\\Makada\\Desktop\\CR1000_Table1 - kopie.dat"))
    outfile = open("C:\\Users\\Makada\\Desktop\\CR1000_Table1 - kopie.dat", "a+")
    for content in open("C:\\Campbellsci\\LoggerNet\\CR1000_Table1.dat", "r"):
        if content.strip() not in existingLines: # to void duplicate lines
            outfile.write(content)
            existingLines.add(content)
    outfile.close()

    with open("C:\\Users\\Makada\\Desktop\\CR1000_Table1 - kopie.dat", "r") as f:
        with open("C:\\Users\\Makada\\Desktop\\CR1000_Table1 - kopie.csv", "a+") as f1:
            for line in f:
                f1.write(line)

    
schedule.every().minute.at(":01").do(task)
while True:
    schedule.run_pending()
    time.sleep(1)
refresh()
The CSV file is getting the data but after that, i get a error:

Traceback (most recent call last):
  File "F:\Software\python definitief\copieer bron naar copie alleen nieuw data deze werkt op de minuut precies kopie.py", line 31, in <module>
    schedule.run_pending()
  File "C:\Python\lib\site-packages\schedule\__init__.py", line 563, in run_pending
    default_scheduler.run_pending()
  File "C:\Python\lib\site-packages\schedule\__init__.py", line 94, in run_pending
    self._run_job(job)
  File "C:\Python\lib\site-packages\schedule\__init__.py", line 147, in _run_job
    ret = job.run()
  File "C:\Python\lib\site-packages\schedule\__init__.py", line 466, in run
    ret = self.job_func()
  File "F:\Software\python definitief\copieer bron naar copie alleen nieuw data deze werkt op de minuut precies kopie.py", line 23, in task
    with open("C:\\Users\\Makada\\Desktop\\CR1000_Table1 - kopie.csv", "a+") as f1:
PermissionError: [Errno 13] Permission denied: 'C:\\Users\\Makada\\Desktop\\CR1000_Table1 - kopie.csv'
>>> 
And the csv file isnt displayed the comma seperated data in Excel in columns.
How can i achieve that?

Thanks Smile
Reply


Messages In This Thread
Copy and append data from .dat file - by Makada - Jan-16-2020, 09:00 PM
RE: Copy and append data from .dat file - by Makada - Jan-17-2020, 08:04 AM
RE: Copy and append data from .dat file - by Makada - Jan-17-2020, 11:13 AM
RE: Copy and append data from .dat file - by Makada - Jan-17-2020, 12:56 PM
RE: Copy and append data from .dat file - by Makada - Jan-17-2020, 01:36 PM
RE: Copy and append data from .dat file - by Makada - Jan-17-2020, 04:45 PM
RE: Copy and append data from .dat file - by Makada - Jan-17-2020, 08:27 PM
RE: Copy and append data from .dat file - by Makada - Jan-17-2020, 09:42 PM
RE: Copy and append data from .dat file - by Makada - Jan-18-2020, 10:06 AM
RE: Copy and append data from .dat file - by Makada - Jan-19-2020, 03:35 PM
RE: Copy and append data from .dat file - by Makada - Jan-19-2020, 04:45 PM
RE: Copy and append data from .dat file - by Makada - Jan-20-2020, 08:33 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Why is the copy method name in python list copy and not `__copy__`? YouHoGeon 2 388 Apr-04-2024, 01:18 AM
Last Post: YouHoGeon
  Copy Paste excel files based on the first letters of the file name Viento 2 560 Feb-07-2024, 12:24 PM
Last Post: Viento
  How to copy work sheet data one workbook to other? sayyedkamran 2 787 Nov-03-2023, 09:10 AM
Last Post: Larz60+
  Copy data from Excel and paste into Discord (Midjourney) Joe_Wright 4 2,284 Jun-06-2023, 05:49 PM
Last Post: rajeshgk
Question How to append integers from file to list? Milan 8 1,617 Mar-11-2023, 10:59 PM
Last Post: DeaD_EyE
  is it possible to copy image from email and place into excel file? cubangt 3 1,352 Nov-30-2022, 05:11 PM
Last Post: snippsat
  Please help me [copy and paste file from src to dst] midomarc 2 1,091 Nov-24-2022, 10:13 PM
Last Post: midomarc
  read a text file, find all integers, append to list oldtrafford 12 3,936 Aug-11-2022, 08:23 AM
Last Post: Pedroski55
  How to modify python script to append data on file using sql server 2019? ahmedbarbary 1 1,288 Aug-03-2022, 06:03 AM
Last Post: Pedroski55
  Append data to Yaml section tbaror 0 7,166 Feb-09-2022, 06:56 PM
Last Post: tbaror

Forum Jump:

User Panel Messages

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