Path python ---- get files (in various ways)

# Get the current file to the file folder directory 
ABSPATH = os.path.abspath with (the os.path.realpath (os.path.dirname (__ file__)))

# obtain a relative path
FRONTEND = os.path.abspath (os .path.join (ABSPATH, the sys.argv [0]))
Print ABSPATH
Print FRONTEND

# obtain a relative path
print sys.argv [0]


results:

/Users/lucky/PycharmProjects/lucky_L/test_02
/Users/lucky/PycharmProjects/lucky_L/test_02/test.py
/Users/lucky/PycharmProjects/lucky_L/test_02/test.py

 

Guess you like

Origin www.cnblogs.com/syw20170419/p/11002963.html