将__filename__预定义属性添加到2.5? [英] Adding a __filename__ predefined attribute to 2.5?

查看:89
本文介绍了将__filename__预定义属性添加到2.5?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以将新的__filename__预定义属性包含在

2.5中,以便__file__包含模块的完整路径,并且

__filename__只包含名称模块?

例如,在脚本用法()部分中包含对

文件名的非静态引用是很有用的提取

文件名或执行模块导入只是为了解析它很麻烦。

Is it an idea to include a new __filename__ predefined attribute to
2.5, so that __file__ contains the entire path to the module, and
__filename__ only the name of the module?

For instance it''s useful to include a not-static reference to the
filename in a scripts usage() section and it''s cumbersome to extract
the filename or to do module imports just to parse it.

推荐答案

Rune Strand写道:
Rune Strand wrote:
是否包含了一个新的__filename__预定义属性到
2.5,以便__file__包含模块的完整路径,而
__ filenamename只有名称该模块?

例如,在脚本用法()部分中包含对
文件名的非静态引用是有用的,并且提取文件名或执行模块导入只是为了解析它。
Is it an idea to include a new __filename__ predefined attribute to
2.5, so that __file__ contains the entire path to the module, and
__filename__ only the name of the module?

For instance it''s useful to include a not-static reference to the
filename in a scripts usage() section and it''s cumbersome to extract
the filename or to do module imports just to parse it.



No. 不是通常一个好主意,把它加(其中大部分时间它从你的程序

消除复杂性是没有必要的)底层

系统。这里有一个关于如何在没有__file__的情况下完成任务的线索:


sholden @ bigboy~ / Projects / Python


No. It''s not usually a good idea to remove complexity from your program
by adding it (where most of the time it''s not needed) to the underlying
system. Here''s a clue as to how you might do without __file__ altogether:

sholden@bigboy ~/Projects/Python


cat test78.py

import sys

print sys.argv

sholden @ bigboy~ / Projects / Python
cat test78.py
import sys
print sys.argv

sholden@bigboy ~/Projects/Python


python test78.py我们可以说与它一起生活吗?

[''test78.py'',''可以'',''我们'' ,'''',''直播'',''带'',''它?''']


问候

Steve

-

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

Holden Web LLC www.holdenweb.com

PyCon TX 2006 www.python.org/pycon/

python test78.py can we say live with it?
[''test78.py'', ''can'', ''we'', ''say'', ''live'', ''with'', ''it?'']

regards
Steve
--
Steve Holden +44 150 684 7255 +1 800 494 3119
Holden Web LLC www.holdenweb.com
PyCon TX 2006 www.python.org/pycon/


这篇关于将__filename__预定义属性添加到2.5?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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