getcwd

How can I find script's directory with Python? [duplicate]

孤人 提交于 2019-11-26 12:37:37
This question already has an answer here: How to properly determine current script directory? 13 answers Consider the following Python code: import os print os.getcwd() I use os.getcwd() to get the script file's directory location . When I run the script from the command line it gives me the correct path whereas when I run it from a script run by code in a Django view it prints / . How can I get the path to the script from within a script run by a Django view? UPDATE: Summing up the answers thus far - os.getcwd() and os.path.abspath() both give the current working directory which may or may

How can I find script's directory with Python? [duplicate]

|▌冷眼眸甩不掉的悲伤 提交于 2019-11-26 03:01:42
问题 This question already has an answer here: How to properly determine current script directory? 11 answers Consider the following Python code: import os print os.getcwd() I use os.getcwd() to get the script file\'s directory location. When I run the script from the command line it gives me the correct path whereas when I run it from a script run by code in a Django view it prints / . How can I get the path to the script from within a script run by a Django view? UPDATE: Summing up the answers