#!/ usr / bin / env python> 2.4? [英] #!/usr/bin/env python > 2.4?

查看:86
本文介绍了#!/ usr / bin / env python> 2.4?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨伙计,


好​​的我喜欢日志记录模块。我到处都用它。我很高兴

放在我的每个剧本的顶部


------< snip> ------

#!/ usr / bin / env python2.4

导入日志

LOGLEVEL = logging.INFO


#设置'基本记录器

logging.basicConfig(level = LOGLEVEL,format ="%(asctime)s%(name)s%

(levelname)-8s%(消息)s",

datefmt =''%d%b%Y%H:%M:%S'',流= sys.stderr)


试试:

module = os.path.basename(traceback.extract_stack(limit = 2)[1]

[0])。split(" .py")[0] +"。"

除了:

module = os.path。 basename(traceback.extract_stack(limit = 2)[0]

[0])。split(" .py")[0] +"。"

def main(loglevel = False):

""" """

#设置记录

log = logging.getLogger(module + sys._getframe()。f_code.co _name)

如果loglevel不是False:log.setLevel(loglevel)

else:log.setLevel(logging.WARN)


log.debug("我爱登录)


if __name__ ==''__ main__'':

sys.exit(main(loglevel = LOGLEVEL))

------< snip> ------


但现在你们继续制作这种很酷的语言,2.5来了

out。好现在我怎么把/ usr / bin / env python> 2.4?


或者你能建议一个更好的方法来给这只猫上皮吗?


再次感谢!!

Hi Folks,

OK I love the logging module. I use it everywhere. I was happily
putting at the top of each of my scripts

------<snip>------
#!/usr/bin/env python2.4

import logging

LOGLEVEL=logging.INFO

# Set''s up a basic logger
logging.basicConfig(level=LOGLEVEL, format="%(asctime)s %(name)s %
(levelname)-8s %(message)s",
datefmt=''%d %b %Y %H:%M:%S'', stream=sys.stderr)

try:
module= os.path.basename(traceback.extract_stack(limit=2)[1]
[0]).split(".py")[0]+"."
except:
module = os.path.basename(traceback.extract_stack(limit=2)[0]
[0]).split(".py")[0]+"."

def main(loglevel=False):
""" """
# Setup Logging
log = logging.getLogger(module+sys._getframe().f_code.co _name )
if loglevel is not False: log.setLevel(loglevel)
else:log.setLevel(logging.WARN)

log.debug("I LOVE LOGGING")

if __name__ == ''__main__'':
sys.exit(main(loglevel=LOGLEVEL))
------<snip>------

But now you guys continued to make this cool language and 2.5 came
out. Great now how do I put /usr/bin/env python>2.4?

Or can you suggest a better way to skin this cat?

Thanks again!!

推荐答案

rh0dium写道:
rh0dium wrote:

嗨伙计,


好​​的我喜欢日志记录模块。我到处都用它。我很高兴

放在我的每个剧本的顶部


------< snip> ------

#!/ usr / bin / env python2.4
Hi Folks,

OK I love the logging module. I use it everywhere. I was happily
putting at the top of each of my scripts

------<snip>------
#!/usr/bin/env python2.4



[...]

[...]


>

但现在你们继续制作这种很酷的语言,2.5来了

out。好现在我怎么把/ usr / bin / env python> 2.4?


或者你能建议一个更好的方法来给这只猫上皮吗?


再次感谢!!
>
But now you guys continued to make this cool language and 2.5 came
out. Great now how do I put /usr/bin/env python>2.4?

Or can you suggest a better way to skin this cat?

Thanks again!!



通常的方式是


#!/ usr / bin / env python


Python通常会安装,因此最新版本链接为

/ usr / bin / python。 HTere'不需要将你的脚本绑定到特定的

版本。


问候

Steve

-

Steve Holden +44 150 684 7255 +1 800 494 3119

Holden Web LLC / Ltd http://www.holdenweb.com

Skype:holdenweb http://del.icio.us/steve.holden

最近的Ramblings http://holdenweb.blogspot.com

The usual way is something like

#!/usr/bin/env python

Python usually installs so the latest version gets linked as
/usr/bin/python. HTere''s no need to bind your scripts to a particular
version.

regards
Steve
--
Steve Holden +44 150 684 7255 +1 800 494 3119
Holden Web LLC/Ltd http://www.holdenweb.com
Skype: holdenweb http://del.icio.us/steve.holden
Recent Ramblings http://holdenweb.blogspot.com



Python通常安装,因此最新版本链接为

/ usr / bin / python。 HTere'不需要将你的脚本绑定到特定的

版本。


关于
Python usually installs so the latest version gets linked as
/usr/bin/python. HTere''s no need to bind your scripts to a particular
version.

regards



True - 但这完全取决于你的道路。示例:


Redhat(RHEL3)在/ usr / bin中附带python2.3

将2.5版本添加到/ usr / local / bin


设置PATH = / usr / local / bin:/ usr / bin


" python" - 将使用2.5


相反,如果您:

设置PATH = / usr / bin:/ usr / local / bin


" python" - 将使用2.3

但如果我想确保我使用的是2.5,我只需键入

python2.5我想确保python版本我我正在使用的是

租约

True - but that entirely depends on your path. Example:

Redhat (RHEL3) ships with python2.3 in /usr/bin
Adding an 2.5 version to /usr/local/bin

set PATH=/usr/local/bin:/usr/bin

"python" - will use 2.5

Conversely if you:
set PATH=/usr/bin:/usr/local/bin

"python" - will use 2.3

but if I wanted to ensure I was using 2.5 I would simply type
python2.5 I want to ensure that the python version I am using is at
lease 2.4


rh0dium schrieb:
rh0dium schrieb:

>> Python通常安装,因此最新版本链接为
/ usr / bin / python。 HTere'不需要将脚本绑定到特定的
版本。

问候
>>Python usually installs so the latest version gets linked as
/usr/bin/python. HTere''s no need to bind your scripts to a particular
version.

regards




True - 但这完全取决于你的道路。示例:


Redhat(RHEL3)在/ usr / bin中附带python2.3

将2.5版本添加到/ usr / local / bin


设置PATH = / usr / local / bin:/ usr / bin


" python" - 将使用2.5


相反,如果您:

设置PATH = / usr / bin:/ usr / local / bin


" python" - 将使用2.3

但如果我想确保我使用的是2.5,我只需键入

python2.5我想确保python版本我我正在使用的是

租赁2.4



True - but that entirely depends on your path. Example:

Redhat (RHEL3) ships with python2.3 in /usr/bin
Adding an 2.5 version to /usr/local/bin

set PATH=/usr/local/bin:/usr/bin

"python" - will use 2.5

Conversely if you:
set PATH=/usr/bin:/usr/local/bin

"python" - will use 2.3

but if I wanted to ensure I was using 2.5 I would simply type
python2.5 I want to ensure that the python version I am using is at
lease 2.4



#!/ usr / bin / env python





来自sys import version_info

如果version_info [0]< 2或version_info [1]< 4:

引发RuntimeError(你至少需要python2.4才能运行这个脚本)


IMO你也不应该为之奋斗硬。如果用户的python

版本不合适,不要破解其翻译机制来完成你需要的工作。无论如何,你不应该检查特定的python

版本,但是对于modules / APIs / builtins无论如何*然后*你可以提出

异常指向用户的事实是python版本确实

不符合您的需求。


HTH,

Stargaming

#!/usr/bin/env python

and

from sys import version_info
if version_info[0] < 2 or version_info[1] < 4:
raise RuntimeError("You need at least python2.4 to run this script")

IMO you shouldn''t struggle with it too hard. If the user''s python
version is not appropriate, don''t hack its interpreter mechanism to do
the work you need. Anyways, you should not check for specific python
versions but for modules/APIs/builtins whatever and *then* you may raise
an exception pointing the user to the fact that is python version does
not fit your needs.

HTH,
Stargaming


这篇关于#!/ usr / bin / env python&gt; 2.4?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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