From: inhahe on
Python 2.6.4 (r264:75708, Oct 26 2009, 08:23:19) [MSC v.1500 32 bit (Intel)] on
win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import inspect
>>> def a(b=1): pass
....
>>> inspect.getargvalues(a)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Python26\lib\inspect.py", line 816, in getargvalues
args, varargs, varkw = getargs(frame.f_code)
AttributeError: 'function' object has no attribute 'f_code'
>>> dir(a)
['__call__', '__class__', '__closure__', '__code__', '__defaults__', '__delattr_
_', '__dict__', '__doc__', '__format__', '__get__', '__getattribute__', '__globa
ls__', '__hash__', '__init__', '__module__', '__name__', '__new__', '__reduce__'
, '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', '__subcla
sshook__', 'func_closure', 'func_code', 'func_defaults', 'func_dict', 'func_doc'
, 'func_globals', 'func_name']
>>>

So i'm guessing that the attribute has been changed from func_code to
f_code but the inspect module wasn't updated to reflect that.
From: inhahe on
On Tue, Dec 29, 2009 at 5:10 PM, inhahe <inhahe(a)gmail.com> wrote:
>
> So i'm guessing that the attribute has been changed from func_code to
> f_code but the inspect module wasn't updated to reflect that.
>

er i mean from f_code to func_code
From: inhahe on
On Tue, Dec 29, 2009 at 5:11 PM, inhahe <inhahe(a)gmail.com> wrote:
> On Tue, Dec 29, 2009 at 5:10 PM, inhahe <inhahe(a)gmail.com> wrote:
>>
>> So i'm guessing that the attribute has been changed from func_code to
>> f_code but the inspect module wasn't updated to reflect that.
>>
>
> er i mean from f_code to func_code
>

f_locals doesn't even seem to exist at all.

Traceback (most recent call last):
File "E:\jsterm\specs\test.py", line 6, in <module>
print inspect.getargvalues(a)
File "E:\Python26\lib\inspect.py", line 817, in getargvalues
return ArgInfo(args, varargs, varkw, frame.f_locals)
AttributeError: 'function' object has no attribute 'f_locals
>>> dir(a)
['__call__', '__class__', '__closure__', '__code__', '__defaults__',
'__delattr__', '__dict__', '__doc__', '__format__', '__get__',
'__getattribute__', '__globals__', '__
hash__', '__init__', '__module__', '__name__', '__new__',
'__reduce__', '__reduce_ex__', '__repr__', '__setattr__',
'__sizeof__', '__str__', '__subclasshook__', 'func_clo
sure', 'func_code', 'func_defaults', 'func_dict', 'func_doc',
'func_globals', 'func_name']
From: Daniel Fetchinson on
On 12/29/09, inhahe <inhahe(a)gmail.com> wrote:
> Python 2.6.4 (r264:75708, Oct 26 2009, 08:23:19) [MSC v.1500 32 bit (Intel)]
> on
> win32
> Type "help", "copyright", "credits" or "license" for more information.
>>>> import inspect
>>>> def a(b=1): pass
> ...
>>>> inspect.getargvalues(a)
> Traceback (most recent call last):
> File "<stdin>", line 1, in <module>
> File "C:\Python26\lib\inspect.py", line 816, in getargvalues
> args, varargs, varkw = getargs(frame.f_code)
> AttributeError: 'function' object has no attribute 'f_code'
>>>> dir(a)
> ['__call__', '__class__', '__closure__', '__code__', '__defaults__',
> '__delattr_
> _', '__dict__', '__doc__', '__format__', '__get__', '__getattribute__',
> '__globa
> ls__', '__hash__', '__init__', '__module__', '__name__', '__new__',
> '__reduce__'
> , '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__',
> '__subcla
> sshook__', 'func_closure', 'func_code', 'func_defaults', 'func_dict',
> 'func_doc'
> , 'func_globals', 'func_name']
>>>>
>
> So i'm guessing that the attribute has been changed from func_code to
> f_code but the inspect module wasn't updated to reflect that.



Please read the documentation for inspect.getargvalues:

"""
inspect.getargvalues(frame)

Get information about arguments passed into a particular frame. A
tuple of four things is returned: (args, varargs, varkw, locals). args
is a list of the argument names (it may contain nested lists). varargs
and varkw are the names of the * and ** arguments or None. locals is
the locals dictionary of the given frame.

Changed in version 2.6: Returns a named tuple ArgInfo(args,
varargs, keywords, locals).
"""

HTH,
Daniel


--
Psss, psss, put it down! - http://www.cafepress.com/putitdown
From: Irmen de Jong on
On 29-12-2009 23:22, inhahe wrote:
> On Tue, Dec 29, 2009 at 5:11 PM, inhahe<inhahe(a)gmail.com> wrote:
>> On Tue, Dec 29, 2009 at 5:10 PM, inhahe<inhahe(a)gmail.com> wrote:
>>>
>>> So i'm guessing that the attribute has been changed from func_code to
>>> f_code but the inspect module wasn't updated to reflect that.
>>>
>>
>> er i mean from f_code to func_code
>>
>
> f_locals doesn't even seem to exist at all.

[...]

I think there are 2 different things :
f_code : 'the code object being executed in this frame'
func_code : 'The code object representing the compiled function'

That is, one is valid in the context of execution stack frames,
while the other is valid in the context of compiled byte code objects
that are generated for functions and so on.

inspect.getargvalues is used on frames, not on regular code objects.
Maybe you were looking for inspect.getargspec?

-irmen