two python questions about function attrib.

Giorgi Lekishvili gleki at gol.ge
Fri Jan 25 22:42:48 CET 2002


sail wrote:

> python-listhello all,
>    I am  reading the "Python ref-Man" after Tutorial , this is I read it
> second. the first time,  I can not understand it all, but I think I must read again in future. so Now , I reading. :), have a bit verbosity.
>    I have two questions about function Special attributes:
>
>    1. what is mean of attrib func_dict or __dict__? I defined a function
>           Afunc()  as follow:
>        def Afunc():
>                         """ A func example"""
>                         print "Afunc"
>
>           why Afunc.__dict__ is {} ??? I do not know.

__dict__ returns something different. E.g., if you have a module foo.py, which defines some functions,  then here' what happens:
>>> import Matrix
>>> Matrix.__dict__
{'identity': <function identity at 00B31C5C>, '__doc__': None, 'matrixmultiply': <function dot at 00B11EEC>, 'asarray': <function asarray at
00B14F84>, '__file__': 'd:\\python20\\numeric\\Matrix.pyc', '__name__': 'Matrix', '__builtins__': {'WindowsError': <class
exceptions.WindowsError at 007FA7AC>, 'OverflowError': <class exceptions.OverflowError at 007FC5BC>, 'AttributeError': <class
exceptions.AttributeError at 007FB1FC>, 'NotImplementedError': <class exceptions.NotImplementedError at 007FACCC>, 'range': <built-in function
range>, 'filter': <built-in function filter>, 'UnboundLocalError': <class exceptions.UnboundLocalError at 007FB04C>, 'KeyboardInterrupt': <class
exceptions.KeyboardInterrupt at 007F9EF4>, 'hash': <built-in function hash>, 'license': Type license() to see the full license text,
'TypeError': <class exceptions.TypeError at 007F9B34>, 'AssertionError': <class exceptions.AssertionError at 007FBA24>, 'apply': <built-in
function apply>, '_': None, 'IndentationError': <class exceptions.IndentationError at 007FB6D4>, '__debug__': 1, 'ord': <built-in function ord>,
'__name__': '__builtin__', 'eval': <built-in function eval>, 'ZeroDivisionError': <class exceptions.ZeroDivisionError at 007FC734>, 'credits':
Python development is led by BeOpen PythonLabs (www.pythonlabs.com)., 'callable': <built-in function callable>, 'len': <built-in function len>,
'max': <built-in function max>, 'buffer': <built-in function buffer>, 'EOFError': <class exceptions.EOFError at 007FA924>, 'None': None, 'map':
<built-in function map>, 'ValueError': <class exceptions.ValueError at 007F572C>, 'slice': <built-in function slice>, 'exit': 'To exit, type
Ctrl-D.', 'abs': <built-in function abs>, 'getattr': <built-in function getattr>, 'complex': <built-in function complex>, 'execfile': <built-in
function execfile>, 'FloatingPointError': <class exceptions.FloatingPointError at 007FC8F4>, 'min': <built-in function min>, 'OSError': <class
exceptions.OSError at 007FA5D4>, 'RuntimeError': <class exceptions.RuntimeError at 007FAAFC>, 'locals': <built-in function locals>, 'id':
<built-in function id>, 'quit': 'To exit, type Ctrl-D.', 'unichr': <built-in function unichr>, 'EnvironmentError': <class
exceptions.EnvironmentError at 007FA284>, 'issubclass': <built-in function issubclass>, 'intern': <built-in function intern>, 'coerce':
<built-in function coerce>, 'KeyError': <class exceptions.KeyError at 007FC224>, 'reduce': <built-in function reduce>, '__import__': <built-in
function __import__>, 'ImportError': <class exceptions.ImportError at 007FA0C4>, 'copyright': Copyright (c) 2000 BeOpen.com.
All Rights Reserved.

Copyright (c) 1995-2000 Corporation for National Research Initiatives.
All Rights Reserved.

Copyright (c) 1991-1995 Stichting Mathematisch Centrum, Amsterdam.
All Rights Reserved., 'oct': <built-in function oct>, 'MemoryError': <class exceptions.MemoryError at 007FD674>, 'cmp': <built-in function cmp>,
'dir': <built-in function dir>, 'round': <built-in function round>, 'str': <built-in function str>, 'reload': <built-in function reload>,
'compile': <built-in function compile>, 'list': <built-in function list>, 'raw_input': <built-in function raw_input>, 'setattr': <built-in
function setattr>, 'IndexError': <class exceptions.IndexError at 007FC0AC>, 'delattr': <built-in function delattr>, 'hasattr': <built-in
function hasattr>, 'ArithmeticError': <class exceptions.ArithmeticError at 007FC3FC>, 'xrange': <built-in function xrange>, 'repr': <built-in
function repr>, 'TabError': <class exceptions.TabError at 007FB85C>, 'tuple': <built-in function tuple>, 'StandardError': <class
exceptions.StandardError at 007F99AC>, 'isinstance': <built-in function isinstance>, 'Exception': <class exceptions.Exception at 007F9694>,
'SystemExit': <class exceptions.SystemExit at 007F9CF4>, '__doc__': "Built-in functions, exceptions, and other objects.\012\012Noteworthy: None
is the `nil' object; Ellipsis represents `...' in slices.", 'type': <built-in function type>, 'input': <built-in function input>, 'IOError':
<class exceptions.IOError at 007FA444>, 'chr': <built-in function chr>, 'NameError': <class exceptions.NameError at 007FAE7C>, 'long': <built-in
function long>, 'hex': <built-in function hex>, 'zip': <built-in function zip>, 'UnicodeError': <class exceptions.UnicodeError at 007F58DC>,
'SystemError': <class exceptions.SystemError at 007F5B2C>, 'open': <built-in function open>, 'LookupError': <class exceptions.LookupError at
007FBBE4>, 'Ellipsis': Ellipsis, 'unicode': <built-in function unicode>, 'divmod': <built-in function divmod>, 'globals': <built-in function
globals>, 'int': <built-in function int>, 'float': <built-in function float>, 'SyntaxError': <class exceptions.SyntaxError at 007FB3AC>, 'pow':
<built-in function pow>, 'vars': <built-in function vars>}, 'string': <module 'string' from 'd:\python20\lib\string.pyc'>, 'inverse': <function
inverse at 00B376C4>, 'UserArray': <class UserArray.UserArray at 00B0ADBC>, 'Matrix': <class Matrix.Matrix at 00B37B54>}
>>>

Note that Matrix is a part of Numeric, which doesn't come wwith the standard distribution. This was true at least for python2.0--

If you want to get the documentation string, use this: Afunc.__doc__

>
>
>    2. like above, I can not know the attrib func_closure. in manual ,
>       this say " free variables", I did not saw it ago at all.

Unfortunately, I have no idea of it, so it#s of interest to me as well.

GRTZ,
Giorgi


>
>
>                 who can help me? thank u.
>
>             sail
>             raise_sail at sina.com




More information about the Python-list mailing list