Jython

Message3149

Author pjenvey
Recipients pjenvey
Date 2008年04月12日.19:42:42
SpamBayes Score 0.0042740684
Marked as misclassified No
Message-id <1208029363.32.0.624799667939.issue1022@psf.upfronthosting.co.za>
In-reply-to
Content
CPython will define a __module__ attribute at the beginning of a class 
definition based on the __name__ global.
Jython 2.3a0 on java1.5.0_13
Type "copyright", "credits" or "license" for more information.
>>> class Foo(object):
... print __module__
... 
Traceback (most recent call last):
 File "<stdin>", line 1, in <module>
 File "<stdin>", line 2, in Foo
NameError: name '__module__' is not defined
Python 2.5.1 (r251:54863, Aug 19 2007, 21:02:30) 
[GCC 4.0.1 (Apple Computer, Inc. build 5367)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> class Foo(object):
... print __module__
... 
__main__
>>> 
CPython actually does this in the class's code object, so this is a 
compiler bug:
>>> c = compile("""\
... class Foo(object):
... print __module__
... 
... """, 'foo', 'exec')
>>> c.co_consts[1]
<code object Foo at 0x54d4e8, file "foo", line 1>
>>> dis.dis(c.co_consts[1])
 1 0 LOAD_NAME 0 (__name__)
 3 STORE_NAME 1 (__module__)
 2 6 LOAD_NAME 1 (__module__)
 9 PRINT_ITEM 
 10 PRINT_NEWLINE 
 11 LOAD_LOCALS 
 12 RETURN_VALUE
History
Date User Action Args
2008年04月12日 19:42:43pjenveysetspambayes_score: 0.00427407 -> 0.0042740684
recipients: + pjenvey
2008年04月12日 19:42:43pjenveysetspambayes_score: 0.00427407 -> 0.00427407
messageid: <1208029363.32.0.624799667939.issue1022@psf.upfronthosting.co.za>
2008年04月12日 19:42:43pjenveylinkissue1022 messages
2008年04月12日 19:42:42pjenveycreate

Supported by Python Software Foundation,
Powered by Roundup

AltStyle によって変換されたページ (->オリジナル) /