On Tue, Oct 2, 2012 at 8:39 PM, Steven D'Aprano wrote:
> On 03/10/12 04:20, Tino Dai wrote:
>
>> and the get_class class works sometime for finding modules within a
certain directory. If the get_class
doesn't work, it throws an AttributeError.
>>>
>>> I don't really understand what
On 03/10/12 04:20, Tino Dai wrote:
and the get_class class works sometime for finding modules within a
certain directory. If the get_class
doesn't work, it throws an AttributeError.
I don't really understand what you mean by this. Can you copy and
paste the actual error message (all of it)?
On 03/10/12 03:44, Tino Dai wrote:
Hi All,
I'm using the get_class from:
http://stackoverflow.com/questions/452969/does-python-have-an-equivalent-to-java-class-forname
Do you mean this function?
def get_class( kls ):
parts = kls.split('.')
module = ".".join(parts[:-1])
m
On 2 October 2012 19:27, Tino Dai wrote:
> On Tue, Oct 2, 2012 at 2:20 PM, Tino Dai wrote:
and the get_class class works sometime for finding modules within a
certain directory. If the get_class
doesn't work, it throws an AttributeError.
>>>
>>> I don't really understand what you m
On Tue, Oct 2, 2012 at 2:20 PM, Tino Dai wrote:
>>> and the get_class class works sometime for finding modules within a
>>> certain directory. If the get_class
>>> doesn't work, it throws an AttributeError.
>>
>> I don't really understand what you mean by this. Can you copy and
>> paste the actual
>> and the get_class class works sometime for finding modules within a
>> certain directory. If the get_class
>> doesn't work, it throws an AttributeError.
>
> I don't really understand what you mean by this. Can you copy and
> paste the actual error message (all of it)?
>
>>
>> The module exists i
On 2 October 2012 18:44, Tino Dai wrote:
> Hi All,
Hi Tino
>
> I'm using the get_class from:
>
> http://stackoverflow.com/questions/452969/does-python-have-an-equivalent-to-java-class-forname
Can you show the relevant portion of your code please?
>
> and the get_class class works sometim
Hi All,
I'm using the get_class from:
http://stackoverflow.com/questions/452969/does-python-have-an-equivalent-to-java-class-forname
and the get_class class works sometime for finding modules within a
certain directory. If the get_class
doesn't work, it throws an AttributeError.
The modul
mjole...@gmail.com wrote:
> What is the purpose of getattr? Why not just use help or am I completely
> misunderstanding this?
>
>>From what I read, getattr allows you to get a reference to a function
>>without knowing its name until runtime.
>
> However, the example provided is:
>
> li = ['larr
What is the purpose of getattr? Why not just use help or am I completely
misunderstanding this?
>From what I read, getattr allows you to get a reference to a function without
>knowing its name until runtime.
However, the example provided is:
li = ['larry', 'curly]
getattr(li, 'pop')
It seems
On 8/4/2010 4:32 PM, Huy Ton That wrote:
I have a side question,
I am using python 2.7.
Why do you use class A: instead of class A(object): ?
My example does not depend on old / new style classes.
--
Bob Gailer
919-636-4239
Chapel Hill NC
___
Tuto
class A:
def call_by_name(self, func, data):
f = A.__dict__.get(func, self.output_text)
return f(data)
def output_text(self, data):return data
def output_hex(self, data):return '\\x' + data
a = A()
data = 'bar'
print a.call_by_name('output_text', data)
print a.call_by_name('output_he
I have a side question,
I am using python 2.7.
Why do you use class A: instead of class A(object): ?
-Huy
On Wed, Aug 4, 2010 at 4:08 PM, bob gailer wrote:
> On 8/4/2010 4:04 PM, bob gailer wrote:
>
>> On 8/4/2010 3:44 PM, Huy Ton That wrote:
>>
>>> Oh, that's right, I should have tried to ex
On 8/4/2010 4:04 PM, bob gailer wrote:
On 8/4/2010 3:44 PM, Huy Ton That wrote:
Oh, that's right, I should have tried to example in the interpreter
instead of in my head:P
Say Bob,
Is that the preferred method over something like:
I would prefer to create a class and make these functions cl
On 8/4/2010 3:44 PM, Huy Ton That wrote:
Oh, that's right, I should have tried to example in the interpreter
instead of in my head:P
Say Bob,
Is that the preferred method over something like:
I would prefer to create a class and make these functions class methods.
class A:
def output_text
Oh, that's right, I should have tried to example in the interpreter instead
of in my head:P
Say Bob,
Is that the preferred method over something like:
>>> import __main__ as main
On Wed, Aug 4, 2010 at 3:32 PM, bob gailer wrote:
> On 8/4/2010 1:23 PM, Pete wrote:
>
> Hi,
>
> I'm trying to u
On 8/4/2010 1:23 PM, Pete wrote:
Hi,
I'm trying to understand the syntax for reflection in python. I was
wondering about this.
From the example on diveintopython:
http://diveintopython.org/power_of_introspection/index.html
import statsout
def output(data, format="text"):
output_func
*You can do like below Pete. Where globals has a reference to all
functions in this space.*
def output(data, format="text"):
output_function = getattr(globals()['FUNCTION'], "output_%s" %
format, statsout.output_text)
return output_function(data)
On Wed, Aug 4, 2010 at 3:18 PM, Pete wr
Hey Huy,
thanks. But what is the first parameter in this case? (Note there is nothing
here I'm trying to accomplish except understand).
In the original example, 'statsout' is the name of the module. In this case
there is no module so why can you substitute 'output_text'?
thanks,
Pete
On 2010
Hi,
I'm trying to understand the syntax for reflection in python. I was wondering
about this.
From the example on diveintopython:
http://diveintopython.org/power_of_introspection/index.html
import statsout
def output(data, format="text"):
output_function = getattr(statsout, "output_%s"
Janos,
I'm confused...
#
#This should be the complete file
def OnMenuFindMe():
print 'You found me'
f = getattr(What_Should_It_Be???, 'OnMenuFindMe')
f()
#
You are trying to get a reference to a function in the same
file and whose name you know? So why not
Tony Cappellini wrote:
> From: Kent Johnson <[EMAIL PROTECTED]>
>
>
>>> or you can import __main__, which is the top-level module
> Do you mean __main__ is the top level module for every python
> program/script?
>
Yes, at least in the standard Python runtime, I'm not sure what happens
when r
Dear Kent,
>>You can look up the function in the globals()
dict, or you can import
>>__main__, which is the top-level module, and use getattr() on it.
Or you
>>could wrap your functions in a class...
>>
>>def OnMenuFindMe():
>> print 'You found me'
>>
>>f = globals()['OnMenuFindMe']
>>
>>f()
János Juhász wrote:
>
> Dear All,
>
> I want to use getattr() to collect a list with all the functions on my
> simple script those has got some functionname like 'On'.
>
> #This should be the complete file
> def OnMenuFindMe():
> print 'You found me'
>
> f = getattr(What_Should_It_Be???, '
Dear All,
I want to use getattr() to collect
a list with all the functions on my simple script those has got some functionname
like 'On'.
#This should be the complete file
def OnMenuFindMe():
print 'You found me'
f = getattr(What_Should_It_Be???, 'OnMenuFindMe')
f()
#Till here
It can
Negroup - wrote:
> Hi all! I'm here again with a question about introspection.
>
> My module stores a set of functions. I need to know, from another
> script, if a particular function of this module "is enabled" (it
> means, if it shall be executed by the caller script). I looked for
> some intros
2005/11/24, Liam Clarke <[EMAIL PROTECTED]>:
> What do you mean enabled?
>
> If it's imported into the namespace you can call it...
>
> Err, can you clarify on the enabling, what context are you using it
> in, and what are you trying to achieve?
Hi, sorry. I'll try to present the actors omitting t
What do you mean enabled?
If it's imported into the namespace you can call it...
Err, can you clarify on the enabling, what context are you using it
in, and what are you trying to achieve?
On 11/25/05, Negroup - <[EMAIL PROTECTED]> wrote:
> Hi all! I'm here again with a question about introspec
Hi all! I'm here again with a question about introspection.
My module stores a set of functions. I need to know, from another
script, if a particular function of this module "is enabled" (it
means, if it shall be executed by the caller script). I looked for
some introspective builtin/function, but
29 matches
Mail list logo