How to get absolute path in python?

0 votes

I am trying to get a file path using python. I am using the following script:

import os
filename = os.path.dirname(<filename>)

But this is returning relative path. How to get absolute path?

Feb 3 in Python by Khush
435 views

1 answer to this question.

0 votes

Instead of using os.path.dirname method which returns the relative path, you os.path.abspath method:

import os
os.path.abspath("<filename>")
answered Feb 3 by Omkar
• 67,660 points

Related Questions In Python

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 ariaholic
• 7,340 points
110 views
0 votes
3 answers

How to get the current time in Python

FOLLOWING WAY TO FIND CURRENT TIME IN ...READ MORE

answered Apr 8 in Python by rajesh
• 1,210 points
82 views
0 votes
1 answer

How to add to the python path in Windows?

You know what has worked for me ...READ MORE

answered Jul 25, 2018 in Python by Frankie
• 9,810 points
129 views
0 votes
1 answer

How to get the current time in Python

>>> import datetime >>> datetime.datetime.now() datetime(2018, 25, ...READ MORE

answered Jul 25, 2018 in Python by Frankie
• 9,810 points
54 views
+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 in Python by Neha
• 330 points

edited Jul 8 by Kalgi 349 views
+4 votes
6 answers
0 votes
1 answer

How to get path with filename in python?

There is no direct way to get ...READ MORE

answered Feb 3 in Python by Omkar
• 67,660 points
136 views
+3 votes
2 answers

how to print array integer without [] bracket in python like result = 1,2,3,4,5

Hey @abhijmr.143, you can print array integers ...READ MORE

answered Aug 4, 2018 in Python by Omkar
• 67,660 points

edited Aug 8, 2018 by Omkar 1,183 views