Python Forum
n00b help with referencing files
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
n00b help with referencing files
#3
Quote:I have a script that basically modifies a file. In a nutshell, fileA contains some text, and the script reads fileA and uses the text to modify fileB. fileA is in a different directory than fileB, and I have multiple iterations of this. So I've hardcoded the paths in the script to fileA and fileB, but basically I need the script to iterate over multiple paths that contain fileA and fileB. Hopefully this makes sense.

Maybe you post some content of fileA and of fileB and your script.
My line of thinking: paths in fileA and fileB should be relative. Then you should have a absolute base directory stores inside your script or as env variable or in a config file. Then joining them together os.path.join(base_path, path_from_text_file). This prevents you from manipulating the path with string interpolation and it is os independent. But when the files are already done and have for example 16k lines, you must handle it like ichabod801 has shown. My suggestion is always, don't use absolute paths in files, which you want to process later. If you want to move the files to a different place and all paths are absolute, you'll have to handle this in your script also or doing the trick with a symlink.
Almost dead, but too lazy to die: https://sourceserver.info
All humans together. We don't need politicians!
Reply


Messages In This Thread
n00b help with referencing files - by theturd - Jul-11-2017, 03:58 PM
RE: n00b help with referencing files - by DeaD_EyE - Jul-11-2017, 05:14 PM
RE: n00b help with referencing files - by theturd - Jul-19-2017, 02:16 PM
RE: n00b help with referencing files - by nilamo - Jul-19-2017, 03:19 PM
RE: n00b help with referencing files - by theturd - Jul-19-2017, 03:54 PM
RE: n00b help with referencing files - by nilamo - Jul-19-2017, 04:09 PM
RE: n00b help with referencing files - by theturd - Jul-21-2017, 03:17 PM
RE: n00b help with referencing files - by nilamo - Jul-21-2017, 04:16 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  name 'lblstatus' is not defined when referencing a label KatManDEW 4 1,665 Apr-21-2022, 12:33 PM
Last Post: KatManDEW
  Dictionary Referencing nickdavis2017 1 1,667 Nov-20-2021, 06:24 PM
Last Post: deanhystad
  Referencing string names in df to outside variables illmattic 1 1,429 Nov-16-2021, 12:47 PM
Last Post: jefsummers
  Referencing a fixed cell Mark17 2 2,160 Dec-17-2020, 07:14 PM
Last Post: Mark17
Sad need help in referencing a list n00bdev 2 1,908 Nov-01-2020, 12:06 PM
Last Post: buran
  Issue referencing new instance from other class nanok66 3 2,313 Jul-31-2020, 02:07 AM
Last Post: nanok66
  referencing another method in a class Skaperen 6 2,784 Jul-02-2020, 04:30 AM
Last Post: Skaperen
  Theory behind referencing a dictionary rather than copying it to a list sShadowSerpent 2 2,168 Mar-24-2020, 07:18 PM
Last Post: sShadowSerpent
  n00b question millpond 6 3,488 Jul-13-2019, 06:41 AM
Last Post: Gribouillis
  "not defined" error in function referencing a class Exsul 2 3,764 Mar-27-2019, 11:59 PM
Last Post: Exsul

Forum Jump:

User Panel Messages

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