Thanks Miki and Jason. I knew it could be done :-)
--
http://mail.python.org/mailman/listinfo/python-list
On Jan 6, 8:38 am, Steven D'Aprano wrote:
> On Wed, 06 Jan 2010 06:53:40 -0800, m...@infoserv.dk wrote:
> > I'm looking for a way to make a list of string literals in a class.
>
> > Example:
>
> > class A:
> > def method(self):
> > print 'A','BC'
>
> ExtractLiterals(A)
> > ['A','BC'
On Wed, 06 Jan 2010 06:53:40 -0800, m...@infoserv.dk wrote:
> I'm looking for a way to make a list of string literals in a class.
>
> Example:
>
> class A:
>def method(self):
>print 'A','BC'
>
ExtractLiterals(A)
> ['A','BC']
>
> Is this possible? Can anyone point me in the rig
Hello Martin,
> I'm looking for a way to make a list of string literals in a class.
from inspect import getsourcelines
from tokenize import generate_tokens, STRING, NUMBER
def is_literal(t):
return t[0] in (STRING, NUMBER)
def get_lieterals(obj):
lines, _ = getsourcelines(obj)
readli
In article <4a0d2e07$0$9422$426a7...@news.free.fr>,
Bruno Desthuilliers wrote:
>Aahz a écrit :
>> In article <4a0c6e42$0$12031$426a7...@news.free.fr>,
>> Bruno Desthuilliers wrote:
>>> Marco Mariani a écrit :
Bruno Desthuilliers wrote:
> Oh, you meant the "return type" ? Nope, no way.
Aahz a écrit :
In article <4a0c6e42$0$12031$426a7...@news.free.fr>,
Bruno Desthuilliers wrote:
Marco Mariani a écrit :
Bruno Desthuilliers wrote:
Oh, you meant the "return type" ? Nope, no way. It just doesn't make
sense given Python's dynamic typing.
Unless he's really trying to write in N
On May 14, 3:55 pm, a...@pythoncraft.com (Aahz) wrote:
> In article <4a0c6e42$0$12031$426a7...@news.free.fr>,
> Bruno Desthuilliers wrote:
>
> >Marco Mariani a écrit :
> >> Bruno Desthuilliers wrote:
>
> >>> Oh, you meant the "return type" ? Nope, no way. It just doesn't make
> >>> sense given Py
Aahz wrote:
In article <4a0c6e42$0$12031$426a7...@news.free.fr>,
Bruno Desthuilliers wrote:
Marco Mariani a �crit :
Bruno Desthuilliers wrote:
Oh, you meant the "return type" ? Nope, no way. It just doesn't make
sense given Python's dynamic typing.
Unless he's really trying to write in Noht
In article <4a0c6e42$0$12031$426a7...@news.free.fr>,
Bruno Desthuilliers wrote:
>Marco Mariani a écrit :
>> Bruno Desthuilliers wrote:
>>>
>>> Oh, you meant the "return type" ? Nope, no way. It just doesn't make
>>> sense given Python's dynamic typing.
>>
>> Unless he's really trying to write i
Marco Mariani a écrit :
Bruno Desthuilliers wrote:
Oh, you meant the "return type" ? Nope, no way. It just doesn't make
sense given Python's dynamic typing.
I thought that the OP was writing a tool to document not-very-dynamic code.
Unless he's really trying to write in Nohtyp,
You mean
Bruno Desthuilliers wrote:
Oh, you meant the "return type" ? Nope, no way. It just doesn't make
sense given Python's dynamic typing.
I thought that the OP was writing a tool to document not-very-dynamic code.
Unless he's really trying to write in Nohtyp, the language where value
types are mo
On the other hand, generally good programming practice suggests you to
write functions that have a constant return type. And in most programs
most functions are like this. This is why ShedSkin can indeed infer
the return type of functions in "good behaved" programs. To do this
ShedSkin uses a quite
flam...@gmail.com a écrit :
Hello,
I am wondering if it's possible to get the return value of a method
*without* calling it
Getting the return *value* without calling the function ? heck, that
would be really helpful - we'd save quiet a lot on function call
overhead and function execution tim
Diez B. Roggisch wrote:
> flam...@gmail.com wrote:
>
>> Hello,
>> I am wondering if it's possible to get the return value of a method
>> *without* calling it using introspection?
>
> Nope. All that's possible to see if there is a implicit or explicit return
> through dis.disassemble - if you fin
flam...@gmail.com:
> I am wondering if it's possible to get the return value of a method
> *without* calling it using introspection?
Python is dynamically typed, so you can create a function like this:
>>> foo = lambda x: "x" if x else 1
>>> foo(1)
'x'
>>> foo(0)
1
The return type of foo() chang
flam...@gmail.com wrote:
> Hello,
> I am wondering if it's possible to get the return value of a method
> *without* calling it using introspection?
Nope. All that's possible to see if there is a implicit or explicit return
through dis.disassemble - if you find "LOAD_CONST None" before any
return-
Alex K wrote:
Please don't top-post.
> On 07/01/2008, Peter Otten <[EMAIL PROTECTED]> wrote:
>> Alex K wrote:
>>
>> > What would be the simplest way of enumerating all methods and members
>> > (including inherited) of a given object? Thank you.
>>
>> inspect.getmembers()
> Nice thank you. But an
2008/1/7, Alex K <[EMAIL PROTECTED]>:
> Nice thank you. But anyway to make it look pretty?
>
pprint.pprint(inspect.getmembers(someobject))
> On 07/01/2008, Peter Otten <[EMAIL PROTECTED]> wrote:
> > Alex K wrote:
> >
> > > What would be the simplest way of enumerating all methods and members
> >
Nice thank you. But anyway to make it look pretty?
On 07/01/2008, Peter Otten <[EMAIL PROTECTED]> wrote:
> Alex K wrote:
>
> > What would be the simplest way of enumerating all methods and members
> > (including inherited) of a given object? Thank you.
>
> inspect.getmembers()
>
> Peter
> --
> htt
Alex K wrote:
> What would be the simplest way of enumerating all methods and members
> (including inherited) of a given object? Thank you.
inspect.getmembers()
Peter
--
http://mail.python.org/mailman/listinfo/python-list
2008/1/7, Alex K <[EMAIL PROTECTED]>:
> Hi Guys,
>
> What would be the simplest way of enumerating all methods and members
> (including inherited) of a given object? Thank you.
>
> Alex
> --
> http://mail.python.org/mailman/listinfo/python-list
>
import inspect
inspect.getmembers(yourobject)
--
Ricardo Aráoz wrote:
> Ayaz Ahmed Khan wrote:
>
>> "James Stroud" typed:
>>
>>> py> def doit(a, b, c, x=14):
>>> ... pass
>>> ...
>>> py> doit.func_code.co_argcount
>>> 4
>>> py> doit.func_code.co_varnames
>>> ('a', 'b', 'c', 'x')
>>> py> doit.func_defaults
>>> (14,)
>>>
>> Neat.
>
Ayaz Ahmed Khan wrote:
> "James Stroud" typed:
>> py> def doit(a, b, c, x=14):
>> ... pass
>> ...
>> py> doit.func_code.co_argcount
>> 4
>> py> doit.func_code.co_varnames
>> ('a', 'b', 'c', 'x')
>> py> doit.func_defaults
>> (14,)
>
> Neat.
>
How do you know the 14 corresponds to x ?
--
http
"James Stroud" typed:
> py> def doit(a, b, c, x=14):
> ... pass
> ...
> py> doit.func_code.co_argcount
> 4
> py> doit.func_code.co_varnames
> ('a', 'b', 'c', 'x')
> py> doit.func_defaults
> (14,)
Neat.
--
Ayaz Ahmed Khan
I have not yet begun to byte!
--
http://mail.python.org/mailman/listinf
yagyala wrote:
> Hi. I would like to be able to tell, at run time, how many parameters
> a function requires. Ideally I would like to be able to tell which are
> optional as well. I've tried looking at the functions attributes, but
> haven't found one that helps in this. How can I do this?
>
> Tha
yagyala a écrit :
> Hi. I would like to be able to tell, at run time, how many parameters
> a function requires. Ideally I would like to be able to tell which are
> optional as well. I've tried looking at the functions attributes, but
> haven't found one that helps in this. How can I do this?
>>>
yagyala wrote:
> Hi. I would like to be able to tell, at run time, how many parameters
> a function requires. Ideally I would like to be able to tell which are
> optional as well. I've tried looking at the functions attributes, but
> haven't found one that helps in this. How can I do this?
>
> Tha
yagyala wrote:
> Hi. I would like to be able to tell, at run time, how many parameters
> a function requires. Ideally I would like to be able to tell which are
> optional as well. I've tried looking at the functions attributes, but
> haven't found one that helps in this. How can I do this?
>
I'v
Fredrik Lundh wrote:
> brad tilley wrote:
>
>> How do I import a module and then ask it to show me its methods or
>> other aspects about itself during execution? I'd like to do something
>> such as this:
>>
>> import win32api
>
> dir(win32api)
> help(win32api)
>
> and also
>
> import inspect
brad tilley wrote:
> How do I import a module and then ask it to show me its methods or other
> aspects about itself during execution? I'd like to do something such as
> this:
>
> import win32api
dir(win32api)
help(win32api)
and also
import inspect
help(inspect)
--
http://mail.python.org
brad tilley <[EMAIL PROTECTED]> writes:
> How do I import a module and then ask it to show me its methods or other
> aspects about itself during execution? I'd like to do something such as
> this:
>
> import win32api
>
> print win32api.methods()
>
> I'd like to write some test scripts that load
brad tilley wrote:
> How do I import a module and then ask it to show me its methods or other
> aspects about itself during execution? I'd like to do something such as
> this:
>
> import win32api
>
> print win32api.methods()
>
> I'd like to write some test scripts that load modules and probe them
*binarystar* wrote:
> Hello there,
>
> what method would you use to return the name of the class and/or
> instance introspectively eg.
>
> class Bollocks:
>
> def __init__( self ):
>
> print self.__method_that_returns_class_name__()
> print self.__method_that_ret
*binarystar* wrote:
> class Bollocks:
>
> def __init__( self ):
>
> print self.__method_that_returns_class_name__()
> print self.__method_that_returns_instance_name__()
>
>
> instance_of_bollocks = Bollocks()
>
> # Which outputs
>
> 'Bollocks'
> 'i
What about:
py> class A:
py. def __init__(self):
py. print self.__class__.__name__
py. print str(self)
py. def __str__(self):
py. return 'instance of %s' % self.__class__.__name__
py.
py> a = A()
A
instance of A
py>
--
http://mail.python.org/mailman/l
*binarystar* wrote:
> Hello there,
>
> what method would you use to return the name of the class and/or
> instance introspectively eg.
>
> class Bollocks:
>
> def __init__( self ):
>
> print self.__method_that_returns_class_name__()
> print self.__method_that_ret
Robin Becker wrote:
import inspect
class A:
_class_name=inspect.currentframe().f_code.co_name
def __init__(self,text,_defining_class_name=_class_name):
print 'text=',text,'_defining_class_name=',_defining_class_name
class B(A):
pass
b=B('aaa')
That won't work, if you, say, wanted to print
Michael Hoffman wrote:
Robin Becker wrote:
self.__class__.__name__
Unless I misunderstood the question, that won't work. That will
give you the name of the class the object is an instance is of.
I think he wants the name of the class the method was defined in.
Here's a way to do that using metacla
John Roth wrote:
If that's the case, then the inspect module should give
the tools to do it without a great deal of angst. Unfortunately,
it doesn't give you the class that defined the method, just
the class that invoked it.
Are you saying that the inspect module *should* give you the
tools to do i
Diez B. Roggisch wrote:
>[Michael Hoffman]:
Unless I misunderstood the question, that won't work. That will
give you the name of the class the object is an instance is of.
I think he wants the name of the class the method was defined in.
Where is the difference? The method is defined in a class - a
"Michael Hoffman" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
Robin Becker wrote:
self.__class__.__name__
Unless I misunderstood the question, that won't work. That will
give you the name of the class the object is an instance is of.
I think he wants the name of the class the metho
> Unless I misunderstood the question, that won't work. That will
> give you the name of the class the object is an instance is of.
> I think he wants the name of the class the method was defined in.
Where is the difference? The method is defined in a class - and an instance
is created from that c
Robin Becker wrote:
self.__class__.__name__
Unless I misunderstood the question, that won't work. That will
give you the name of the class the object is an instance is of.
I think he wants the name of the class the method was defined in.
Here's a way to do that using metaclasses and Python's magic
[EMAIL PROTECTED] wrote:
...
My question is this: what can be substituted for that will
make the example above work?
self.__class__.__name__
--
Robin Becker
--
http://mail.python.org/mailman/listinfo/python-list
44 matches
Mail list logo