Python Forum
write code that resides in parent directory
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
write code that resides in parent directory
#2
The following will get the absolute paths.
Note that root_dir will get path to the file, including the python file name.
If you just wanted the current path, use root_dir = Path('.')
You would also have to assure that the current path is the the same as __file__ path.
You can still use __file__. but to get previous directory,would need parent_dir = root_dir.parent.parent.absolute()
root_dir = Path(__file__).absolute()
print(root_dir)
parent_dir = root_dir.parent.absolute()
print(parent_dir)
Reply


Messages In This Thread
RE: write code that resides in parent directory - by Larz60+ - Mar-30-2024, 02:46 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Delete file with read-only permission, but write permission to parent folder cubei 6 22,178 Jun-01-2024, 07:22 AM
Last Post: Eleanorreo
  UART write binary code trix 3 445 Apr-28-2024, 04:57 PM
Last Post: deanhystad
  needing some help to write some code for a game calculator rymdaksel 1 526 Jan-02-2024, 09:56 AM
Last Post: deanhystad
  No Module found in other directory than source code [SOLVED] AlphaInc 1 2,160 Nov-10-2021, 04:34 PM
Last Post: AlphaInc
  How to write a code with İF function? Aycaaxx 1 1,904 Nov-03-2020, 05:46 AM
Last Post: deanhystad
  Hi Guys, please help me to write SAS macro parameter equivalent code in Python Manohar9589 2 2,687 Jun-14-2020, 05:07 PM
Last Post: Larz60+
  Getter/Setter : get parent attribute, but no Getter/Setter in parent nboweb 2 3,084 May-11-2020, 07:22 PM
Last Post: nboweb
  Running tests in a sibling directory to code sodhiar 1 2,791 Nov-07-2019, 11:28 PM
Last Post: MckJohan
  How do I read the HTML files in a directory and write the content into a CSV file? glittergirl 1 2,661 Sep-23-2019, 11:01 AM
Last Post: Larz60+
  How do i write tests for this code? hshivaraj 0 2,071 Apr-27-2019, 05:28 PM
Last Post: hshivaraj

Forum Jump:

User Panel Messages

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