Python:在加载`sys`模块之前查找`sys.argv` [英] Python: Find `sys.argv` before the `sys` module is loaded

查看:48
本文介绍了Python:在加载`sys`模块之前查找`sys.argv`的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想找到调用我的程序的命令行参数,即 sys.argv,但我想在 Python 使 sys.argv 可用之前做到这一点.这是因为我在 usercustomize.py 中运行代码,该代码由 site 模块导入,该模块在 Python 填充 sys.argv 之前导入.(如果你很好奇,我这样做的原因是在不更改程序代码的情况下启动我的调试器.)

I want to find the command line arguments that my program was called with, i.e. sys.argv, but I want to do that before Python makes sys.argv available. This is because I'm running code in usercustomize.py which is imported by the site module, which is imported before Python populates sys.argv. (If you're curious, the reason I'm doing this is to start my debugger without changing my program code.)

有没有办法在没有 sys.argv 的情况下找到命令行参数?

Is there any way to find the command line arguments without sys.argv?

另外:该解决方案需要适用于 Python 2.6 :(

Also: The solution needs to work for Python 2.6 :(

推荐答案

不.Python 使用 sys、os 等库来访问系统变量和 os 函数.仅靠核心功能是做不到的.所以,无论如何,你都需要导入sys.

Nope. Python uses such libraries as sys, os, and etc to get access to system variables and os functional. It can't do it with just core functions. So, in any case, you need to import sys.

这篇关于Python:在加载`sys`模块之前查找`sys.argv`的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆