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 907 Jul-23-2023, 08:30 AM
Last Post: Gribouillis
  Home Directory pgoosen 9 6,416 Oct-15-2020, 12:37 PM
Last Post: DeaD_EyE
  How to change directory to any folder where python is not installed ? firashelou 4 2,639 Apr-03-2020, 02:43 PM
Last Post: firashelou
  simple code: change to home directory Skaperen 5 3,518 Sep-10-2018, 10:29 AM
Last Post: buran
  change to home directory Skaperen 4 11,510 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