Basic Python

sys.path, getcwd

Naranjito 2023. 10. 19. 18:36
  • sys.path

A list of strings that specifies the search path for directory.

In this path, some paths already have been added such as absolute path of .py file directory by default.

sys.path

>>>
['/Users/joohyunyoon/.pyenv/versions/anaconda3-2021.05/envs/sensor_fusion/lib/python37.zip'
 ...

 

  • getcwd

Get the pathname of the Current Working Directory.

os.getcwd()
>>>
'/Users/joohyunyoon/workspace/sensor_fusion/nd013-c2-fusion-exercises'

 

  • sys.path.append()

 If you add some specific path what you want to the list, you can import the .py file from the specific path.

sys.path.append(os.getcwd())

sys.path
>>>
['/Users/joohyunyoon/.pyenv/versions/anaconda3-2021.05/envs/sensor_fusion/lib/python37.zip'
 ...
 '/Users/joohyunyoon/workspace/sensor_fusion/nd013-c2-fusion-exercises'] #added

 

'Basic Python' 카테고리의 다른 글

bytes VS bytearray  (0) 2023.10.30
pickle, dump, load  (0) 2023.10.24
assert  (0) 2022.12.05
return vs yield, yield vs yield from  (0) 2022.11.30
lambda  (0) 2022.11.29