How do I get the full path of the current file’s directory?
Stack How?
Stackorigin – The Community of Question and Answers Latest Articles
Read More About Python List Comprehension with examples
Python List Comprehension: Python List comprehension provides a much more short syntax for creating a new list based on the values of an existing list. Advantages of List Comprehension in Python: Time Efficient than loop Space Efficient than loop Needs ...
Do not accept an offer letter from companies.
Do not accept an offer letter from companies without verifying the following points. Designation Salary Details & CTC Distribution Leave Policies Working Hours & Days Medical Coverage/Insurance Probation Period Notice Period Benefits and Perks Bonus F&F Policy
How to call API using Ajax
AJAX stands for Asynchronous JavaScript and XML and its used for to make calls to the server to fetch some data. In this article, we will learn how to implement a simple API call using AJAX technology. How to use GET ...
How do I get the full path of the current file’s directory?
Python 3
For the directory of the script being run:
For the current working directory:
Python 2 and 3
For the directory of the script being run:
If you mean the current working directory:
In Python 3.x I do:
Explanation:
Path(__file__)
is the path to the current file..parent
gives you the directory the file is in..absolute()
gives you the full absolute path to it.Using
pathlib
is the modern way to work with paths. If you need it as a string later for some reason, just dostr(path)
.