How to get the home directory using in Python

+1 vote

Hi,

Can anyone explain what’s the process to get the home directory using ‘~’ in Python?

Jun 26, 2020 in Python by Roshni
• 10,500 points
303 views

1 answer to this question.

0 votes

Hello, @Roshni,

You need to import the os module, and then just a single line would do the rest.

import os
print (os.path.expanduser('~'))

Output:

/home/runner
answered Jun 26, 2020 by Gitika
• 65,870 points

Related Questions In Python

0 votes
1 answer

How to get the home directory in Python?

Hello, You need to use os.path.expanduser. This will ensure it works ...READ MORE

answered Nov 19, 2020 in Python by Niroj
• 82,740 points
744 views
0 votes
1 answer

How to get the latest file in a folder using python?

Hello @kartik,  would suggest using glob.iglob() instead of the glob.glob(), as ...READ MORE

answered May 27, 2020 in Python by Niroj
• 82,740 points
9,089 views
0 votes
1 answer

How to get the size of a string in Python?

If you are talking about the length ...READ MORE

answered Jun 4, 2018 in Python by aryya
• 7,440 points
607 views
0 votes
2 answers
+1 vote
2 answers

how can i count the items in a list?

Syntax :            list. count(value) Code: colors = ['red', 'green', ...READ MORE

answered Jul 7, 2019 in Python by Neha
• 330 points

edited Jul 8, 2019 by Kalgi 2,904 views
0 votes
1 answer
+5 votes
6 answers

Lowercase in Python

You can simply the built-in function in ...READ MORE

answered Apr 11, 2018 in Python by hemant
• 5,790 points
2,135 views
0 votes
3 answers

How to get the return value from a thread using python?

FWIW, the multiprocessing module has a nice interface for ...READ MORE

answered Dec 15, 2020 in Python by Roshni
• 10,500 points
95,189 views
0 votes
1 answer

How to save an image locally using Python in which we already know the URL address?

Hi, @Roshni, The following code is used to ...READ MORE

answered Jun 26, 2020 in Python by Gitika
• 65,870 points
821 views
webinar REGISTER FOR FREE WEBINAR X
Send OTP
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP