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,420 points
162 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,560 points
120 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,560 points
4,247 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,420 points
375 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 6, 2019 in Python by Neha
• 330 points

edited Jul 8, 2019 by Kalgi 1,842 views
0 votes
0 answers
+4 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,810 points
1,419 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,420 points
53,074 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
412 views