简体   繁体   中英

How can I get the python script path from a python interpreter command line?

related: Python: Find `sys.argv` before the `sys` module is loaded

I have a similar use case to that described in the question - I need to get the python script name from within the usercustomize hook

however, sys.argv isn't populated at this time, and there's no documented way to get the script that is going to be executed.

using psutil allows getting the original command line

I'm looking for a reliable way to parse it the same way python does (preferably using the same code that does the parsing for the python interpreter)

Does the __file__ variable give you what you want?

PS - sorry, not enough rep to comment

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM