-4

The following two python runs don't print the same output. Does anybody know why there is a difference? Thanks.

$ pwd
/tmp
$ cat main.py 
import sys
print("\n".join(sys.path))
$ python3 -c 'import sys; print("\n".join(sys.path))' | head -n 1

$ python3 ./main.py | head -n 1
/private/tmp
user1424739
  • 11,937
  • 17
  • 63
  • 152

1 Answers1

0

Sys does not only print your current path, It slso prints your libs and their corresponding paths.

Run the below code and it will give you an understanding of what you're doing and what you need to do in order to get current working directory.

import sys
print(sys.path)

import os
print(os.getcwd())
High-Octane
  • 1,104
  • 5
  • 19