Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Dyanmically Naming Files
#4
all of the examples I have provided would do. Obviously the os.path functions will require less change in your code.
(Jan-29-2020, 02:28 PM)ovidius Wrote: something that works with string formatting inside the .format(filename)
you can construct the new file name in the open function using os.path functions, but for sake of readability it's better to do it on separate line, e.g. replace line 26
for line in open(('{}_clean.csv').format(filename),'r'):
with
new_name = ''.join((os.path.splitext(filename)[0], '_clean.csv'))
for line in open(new_name, 'r'):
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply


Messages In This Thread
Dyanmically Naming Files - by ovidius - Jan-29-2020, 01:41 PM
RE: Dyanmically Naming Files - by buran - Jan-29-2020, 02:06 PM
RE: Dyanmically Naming Files - by ovidius - Jan-29-2020, 02:28 PM
RE: Dyanmically Naming Files - by buran - Jan-29-2020, 02:44 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  naming entities(city abbreviations) tirumalaramakrishna 1 1,253 May-06-2022, 11:22 AM
Last Post: jefsummers
  Python Style and Naming Variables rsherry8 3 2,230 Jun-07-2021, 09:30 PM
Last Post: deanhystad
  Naming the file as time and date. BettyTurnips 3 3,018 Jan-15-2021, 07:52 AM
Last Post: BettyTurnips
  naming conventions mvolkmann 4 2,171 Sep-28-2020, 05:51 PM
Last Post: Gribouillis
  Question about naming variables in class methods sShadowSerpent 1 2,025 Mar-25-2020, 04:51 PM
Last Post: ndc85430
  naming images adding to number within multiple functions Bmart6969 0 1,935 Oct-09-2019, 10:11 PM
Last Post: Bmart6969
  Sub: Python-3: Better Avoid Naming A Variable As list ? adt 9 4,056 Aug-29-2019, 08:15 AM
Last Post: adt
  Naming convention advice Alfalfa 5 3,361 Jul-21-2018, 11:47 AM
Last Post: Larz60+
  Python Naming Error: List not defined Intelligent_Agent0 1 14,330 Mar-13-2018, 08:34 PM
Last Post: nilamo

Forum Jump:

User Panel Messages

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