Python Forum
How to rename a CSV file by adding MODIFIED in the filename?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to rename a CSV file by adding MODIFIED in the filename?
#25
Python_User Wrote:I can't find the variable parts defined in the code anyway...
parts is an attribute pathlib that Larz60+ use here.
That Pylint complain about can you just ignore,as it's not error just that Pylint struggle whit pathlib.

Also is not necessary to split it up parts as done here,can just read filename
from tkinter.filedialog import askopenfilename
from pathlib import Path
import csv
 
def get_filename():
    filename = Path(askopenfilename(filetypes=[("CSV files", "*.csv")])) 
    return filename
 
def read_csv_file(filename):
    # parts = list(filename.parts)
    with open(filename) as fp:    
        crdr = csv.reader(fp, delimiter=',') 
        for row in crdr:
            print(row)    

if __name__ == '__main__':          
   read_csv_file(get_filename())
Output:
['name', 'origin', 'dest'] ['xxx', 'uk', 'france'] ['yyyy', 'norway', 'finland'] ['zzzz', 'denmark', 'canada']
Reply


Messages In This Thread
RE: How to rename a CSV file by adding MODIFIED in the filename? - by snippsat - Dec-13-2020, 12:20 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  rename same file names in different directories elnk 5 2,398 Jul-12-2024, 01:43 PM
Last Post: snippsat
  Extract and rename a file from an Archive tester_V 4 3,632 Jul-08-2024, 07:54 AM
Last Post: tester_V
  Rename first row in a CSV file James_S 3 1,579 Dec-17-2023, 05:20 AM
Last Post: James_S
  PDF properties doesn't show created or modified date Pedroski55 4 2,545 Jun-19-2023, 08:09 AM
Last Post: Pedroski55
  rename file RolanRoll 0 1,073 May-18-2023, 02:17 PM
Last Post: RolanRoll
  File path by adding various variables Mishal0488 2 3,808 Apr-28-2023, 07:17 PM
Last Post: deanhystad
  '' FTP '' File upload with a specified string and rename midomarc 1 2,205 Apr-17-2023, 03:04 AM
Last Post: bowlofred
  output provide the filename along with the input file processed. arjunaram 1 1,496 Apr-13-2023, 08:15 PM
Last Post: menator01
  rename and add desire "_date" to end of file name before extention RolanRoll 1 1,947 Jun-13-2022, 11:16 AM
Last Post: gruntfutuk
  Rename part of filename in multiple files atomxkai 7 10,659 Feb-18-2022, 10:03 PM
Last Post: atomxkai

Forum Jump:

User Panel Messages

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