0 votes
in Python Flask by
With Python, how do you find out which directory you are currently in?

1 Answer

0 votes
by
To find this, we use the function/method getcwd(). We import it from the module os.

>>> import os
>>> os.getcwd()
‘C:\\Users\\lifei\\AppData\\Local\\Programs\\Python\\Python36-32’

>>> type(os.getcwd)
<class ‘builtin_function_or_method’>

We can also change the current working directory with chdir().

>>> os.chdir('C:\\Users\\lifei\\Desktop')
>>> os.getcwd()
‘C:\\Users\\lifei\\Desktop’
...