The example in this article describes how Python obtains the running directory and the current script directory. Share to everyone for your reference. The implementation method is as follows:
Import osimport sys# Run directory Currentpath = OS.GETCWD () print currentpath# current script directory print "#################################### ############## "Print Os.pathprint sys.argv[0]print os.path.split (Os.path.realpath (sys.argv[0))) print" ############ ###################################### "ScriptPath = Os.path.split (Os.path.realpath (sys.argv[0])) [0]print ScriptPath
The results of the operation are as follows:
c:\pythondemo##################################################
c:/pythondemo/1.py (' C:\\ Pythondemo ', ' 1.py ') ################################################# #C: \pythondemo
Hopefully this article will help you with Python programming.