Skocz do zawartości

MyNameIsLukas

Członkowie
  • Postów

    2
  • Dołączył

  • Ostatnio

Posty napisane przez MyNameIsLukas

  1. hej,

    chcę monitorować folder pod katem nowo pojawiających się w nim plików csv, problem w tym że program raz działa a innym razem wywala błąd :"PermissionError: [Errno 13] Permission denied: ". Miał ktoś już z tym do czynienia?

     

    import csv
    import time
    from watchdog.observers import Observer
    from watchdog.events import FileSystemEventHandler


     
    class MyHandler(FileSystemEventHandler😞
        def on_created(self, event😞
            if event.is_directory:
                return
            elif event.event_type == 'created':
                process_new_file(event.src_path)
     
    def process_new_file(file_path😞
        with open(file_path) as csv_file:
            reader = csv.DictReader(csv_file)
            desired_key_part = 'AF;PS6 Lastdruck'
     
            for entry in reader:
                value = entry['$$ VALMET AUTOMOTIVE SP. Z O.O.']
     
                if value.startswith(desired_key_part😞
                    parts = value.split(';')
                    num_values = [float(part) for part in parts[3:6]]
                    round_values = [round(values,2) for values in num_values]
                    first_numeric_value, second_numeric_value, third_numeric_value = round_values
                    istwert_values_for_stat = []
                    istwert_values_for_stat.append(first_numeric_value)
     
                    print(istwert_values_for_stat)
                   
     
    if __name__ == "__main__":
        folder_to_monitor = r"C:\Users\User\PycharmProjects\pythonProject114"
     
        event_handler = MyHandler()
        observer = Observer()
        observer.schedule(event_handler, path=folder_to_monitor, recursive=False)
        observer.start()
     
        try:
            while True:
                time.sleep(1)
        except KeyboardInterrupt:
            observer.stop()
     
        observer.join()

     

     

  2. Hej,

    mam problem z tym żeby zapisać losowo wygenerowane wartości w postaci listy do plików .txt które są zapisane w określonej lokalizacji. Nie wiem jak to połączyć z zapisem żeby działało. Może ktoś pomoże🙃?

    Poniżej kod który po wyprintowaniu zwraca randomowe wartości w plikach z tego folderu ale nie chce mi tych wartości do tych plików zapisać.

    folder_patch = r"C:\Users\User\Desktop\Nowy folder"

    for txt_files in os.listdir(folder_patch):
        if txt_files.endswith(".txt"):
            with open(os.path.join(folder_patch,txt_files)) as file:


                lines = file.readlines()
                random_numb = random.uniform(1,2)
                random_numb_a = random.uniform(1,2)
                random_numb_b = random.uniform(1,2)
                coma_def = round(random_numb, 3)
                string = str(coma_def)
                lines[0] = string
                coma_def = round(random_numb_a, 3)
                string = str(coma_def)
                lines[1] = string
                coma_def = round(random_numb_b, 3)
                string = str(coma_def)
                lines[2] = string
                print(lines)


    for txt_files in os.listdir(folder_patch):       # nie działa zapis do plików 
        if txt_files.endswith(".txt"):
            with open(txt_files, "w") as file:
                file.writelines(lines)

     

×
×
  • Utwórz nowe...