Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
change to home directory
#1
what is the "best", most pythonic, way to change to the home directory so that all file operations are now relative to the home directory and any program that get run by any means will see the current working directory and the HOME environment variable referring to the current working directory.  this is not trying to change the working directory of the shell.
Tradition is peer pressure from dead people

What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.
Reply
#2
Regular way:
os.chdir(os.path.expanduser('~'))
Or more abstract with pathlib:
home_directory = pathlib.Path.home()
os.chdir(home_directory)
Almost dead, but too lazy to die: https://sourceserver.info
All humans together. We don't need politicians!
Reply
#3
that's what i was going to use.  but i was wondering if there was something better like maybe sys.ch_home().
Tradition is peer pressure from dead people

What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  change directory of save of python files akbarza 3 3,521 Jul-23-2023, 08:30 AM
Last Post: Gribouillis
  home automation using python barryjo 1 1,946 Jul-24-2022, 09:09 PM
Last Post: Larz60+
  Key Error: os.environ["HOME"] Anldra12 12 21,038 Jun-18-2021, 04:11 PM
Last Post: Axel_Erfurt
  /home/pi/.local/bin is not on PATH hcccs 3 14,644 Feb-08-2021, 10:12 PM
Last Post: Gribouillis
  Home Directory pgoosen 9 8,614 Oct-15-2020, 12:37 PM
Last Post: DeaD_EyE
  How to change directory to any folder where python is not installed ? firashelou 4 3,773 Apr-03-2020, 02:43 PM
Last Post: firashelou
  simple code: change to home directory Skaperen 5 4,525 Sep-10-2018, 10:29 AM
Last Post: buran
  change to home directory Skaperen 4 13,099 Apr-20-2017, 05:54 AM
Last Post: Skaperen

Forum Jump:

User Panel Messages

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