Home » Python

How to get current working directory in Python?

Python | getcwd() Function: Here, we are going to learn how to get the path to the current working directory in Python?
Submitted by IncludeHelp, on April 24, 2020

To get the current working directory in Python, there is a library function getcwd() in the os module.

getcwd() function does not accept any parameter and returns the path of the current working directory as string i.e. it’s return type is <class str>.

Syntax:

    # import statement
    import os

    # function call
    os. getcwd()

Python code to get current working directory

# Python code to get 
# current working directory

# importing the module
import os

# getting the current path
current_path = os.getcwd()

print("Current working directory is:", current_path)

# printing the type of getcwd() function
print("Type of \'getcwd()\' function is:", type(os.getcwd()))

Output

Current working directory is: /home/runner/FrenchBrightDaemon
Type of 'getcwd()' function is: <class 'str'>






Comments and Discussions

Ad: Are you a blogger? Join our Blogging forum.





Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates


© https://www.includehelp.com some rights reserved.