"Unknown" wrote:
> >> Well, I would normally do what you suggest, using parameters, but in
> >> the example at hand I have to have the method names as variables and
> >> the reason is that the whole thing will be run by apache using
> >> mod_python and the publisher handler. There a URL
> >> http:
Magnus Lycka wrote:
> Daniel Nogradi wrote:
>
>> Well, I would normally do what you suggest, using parameters, but in
>> the example at hand I have to have the method names as variables and
>> the reason is that the whole thing will be run by apache using
>> mod_python and the publisher handler. T
> *>* I don't get it, why is it more safe to accept GET variables than
> *>* method names? Concretely, why is the URL
> *>* http://something.com/script?q=parameter safer than
> *>* http://something.com/script/parameter if in both cases exactly the
> *>* same things are happening with 'parameter'?
>
Daniel Nogradi wrote:
>>Ouch! This certainly seems like a possible security hole!
>>
>>As someone else said, use rewrite rules to get this passed
>>in as a parameter.
>
> I don't get it, why is it more safe to accept GET variables than
> method names? Concretely, why is the URL
> http://something.
> Ouch! This certainly seems like a possible security hole!
>
> As someone else said, use rewrite rules to get this passed
> in as a parameter.
I don't get it, why is it more safe to accept GET variables than
method names? Concretely, why is the URL
http://something.com/script?q=parameter safer th
Daniel Nogradi wrote:
> Well, I would normally do what you suggest, using parameters, but in
> the example at hand I have to have the method names as variables and
> the reason is that the whole thing will be run by apache using
> mod_python and the publisher handler. There a URL
> http://something
Daniel Nogradi wrote:
>>Here you go:
>>
>> >>> database = {
>> ... "Alice": 24,
>> ... "Bob":25}
>> ...
>> >>> class Lookup(object):
>> ... def __catcher(self, name):
>> ... try:
>> ... print "Hello my name is %s and I'm %s" % (name,
>>database[name])
>> ...
On Fri, 27 Jan 2006 01:20:52 +0100, Daniel Nogradi <[EMAIL PROTECTED]> wrote:
>> > Is it possible to have method names of a class generated somehow
>> dynamically?
>> >
>> > More precisely, at the time of writing a program that contains a class
>> > definition I don't know what the names of its ca
Daniel Nogradi wrote:
> Is it possible to have method names of a class generated somehow dynamically?
>>> class Dummy(object):
... pass
...
>>> def mymethod(self, *args, **kw):
... pass
...
>>> setattr(Dummy, 'a_dynamically_generated_method_name', mymethod)
>>>
>>> Dummy.a_dynamically_generate
Daniel Nogradi wrote:
> Well, I would normally do what you suggest, using parameters, but in
> the example at hand I have to have the method names as variables and
> the reason is that the whole thing will be run by apache using
> mod_python and the publisher handler. There a URL
> http://something
> Here you go:
>
> >>> database = {
> ... "Alice": 24,
> ... "Bob":25}
> ...
> >>> class Lookup(object):
> ... def __catcher(self, name):
> ... try:
> ... print "Hello my name is %s and I'm %s" % (name,
> database[name])
> ... except KeyErro
Daniel Nogradi wrote:
...
> - database content ---
>
> Alice 25
> Bob 24
>
> - program1.py -
>
> class klass:
...
>
> inst = klass()
>
> - program2.py ---
>
> import program1
>
> # The code in klass above should be such that the following
> > My database has 1 table with 2 fields, one called 'name' and the other
> > one called 'age', let's suppose it has the following content, but this
> > content keeps changing:
> >
> > Alice 25
> > Bob 24
> >
> > --- program1.py
> >
> > class klass:
> >
> > # do the
Daniel Nogradi wrote:
> Thanks for all the replies, it became clear that I need to look into
> getattr, __getattr__ and __call__. I'll do that, but since you asked,
> here is the thing I would like to do in a little more detail:
>
> My database has 1 table with 2 fields, one called 'name' and the
> > Is it possible to have method names of a class generated somehow
> dynamically?
> >
> > More precisely, at the time of writing a program that contains a class
> > definition I don't know what the names of its callable methods should
> > be. I have entries stored in a database that are changing
x.__class__.__dict__[mname](x,*args,**kwargs)
here
x is an instance of a class FOO
FOO has a method "bar" (if the value of mname is "bar")
args is a tuple whose length is the number of positional arguments
accepted by bar
kwargs is a dictionary corresponding to the keyword arguments accepted
by ba
Daniel Nogradi wrote:
> Is it possible to have method names of a class generated somehow dynamically?
>
> More precisely, at the time of writing a program that contains a class
> definition I don't know what the names of its callable methods should
> be. I have entries stored in a database that ar
import inspect
x = ABC() # create an instance of class ABC
print inspect.getmembers(x,inspect.ismethod)
Most of any introspection stuff can be done using the module "inspect".
--
http://mail.python.org/mailman/listinfo/python-list
> Is it possible to have method names of a class generated somehow dynamically?
If you don't know the name of the method ahead of time, how do you write
the code for it? Do you use some dummy name? If so, once you have the
name determined then you could use setattr to set the method name.
Here'
Is it possible to have method names of a class generated somehow dynamically?
More precisely, at the time of writing a program that contains a class
definition I don't know what the names of its callable methods should
be. I have entries stored in a database that are changing from time to
time and
20 matches
Mail list logo