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’

Related questions

0 votes
asked May 9, 2023 in Python Flask by Robin
+1 vote
asked Feb 15, 2021 in Python by SakshiSharma
...