From pahome.chen at mirlab.org Mon Feb 12 04:36:46 2018 From: pahome.chen at mirlab.org (lampahome) Date: Mon, 12 Feb 2018 17:36:46 +0800 Subject: [Python-compilers] abspath returns different results when py_compile input path is different in Python? Message-ID: I want to know abspath of python script followed by steps below. 1. *built it to byte code by py_compile.* 2. *execute it to check abspath.* But I got *2 results* when I execute it.I found the *results based on the path of script* followed by py_compile. Here is my script test.py : import osimport inspect print os.path.dirname(os.path.abspath(inspect.getfile(inspect.currentframe()))) Build it with py_compile, then got 2 results when I enter *different path of test.py*: *enter the folder and compile with only script name.* [~]cd /usr/local/bin/[/usr/local/bin/]python -m py_compile test.py[/usr/local/bin/]cd ~[~]python /usr/local/bin/test.pyc/home/UserXX *In other folder and compile with absolute script name.* [~]python -m py_compile /usr/local/bin/test.py[~]python /usr/local/bin/test.pyc/usr/local/bin how come got 2 different results? -------------- next part -------------- An HTML attachment was scrubbed... URL: From brett at python.org Tue Feb 13 00:31:36 2018 From: brett at python.org (Brett Cannon) Date: Tue, 13 Feb 2018 05:31:36 +0000 Subject: [Python-compilers] abspath returns different results when py_compile input path is different in Python? In-Reply-To: References: Message-ID: I would also print out __file__ and see what that says. On Mon, Feb 12, 2018, 15:07 lampahome, wrote: > I want to know abspath of python script followed by steps below. > > 1. *built it to byte code by py_compile.* > 2. *execute it to check abspath.* > > But I got *2 results* when I execute it.I found the *results based on the > path of script* followed by py_compile. > > Here is my script test.py : > > import osimport inspect > print os.path.dirname(os.path.abspath(inspect.getfile(inspect.currentframe()))) > > Build it with py_compile, then got 2 results when I enter *different path > of test.py*: > > *enter the folder and compile with only script name.* > > [~]cd /usr/local/bin/[/usr/local/bin/]python -m py_compile test.py[/usr/local/bin/]cd ~[~]python /usr/local/bin/test.pyc/home/UserXX > > *In other folder and compile with absolute script name.* > > [~]python -m py_compile /usr/local/bin/test.py[~]python /usr/local/bin/test.pyc/usr/local/bin > > how come got 2 different results? > > _______________________________________________ > Python-compilers mailing list > Python-compilers at python.org > https://mail.python.org/mailman/listinfo/python-compilers > -------------- next part -------------- An HTML attachment was scrubbed... URL: