Re: [Tutor] instantiate and name a class from / with a string

2019-08-10 Thread ingo
On 10-8-2019 05:57, Mats Wichmann wrote:

> Please be more precise.  We're not trying to be argumentative; you have
> to help us know enough before we can help you.
> 

Mats, Bob, sorry for not being clear. I have the string and want to
create the instances.

Bob's

name = # get from data base
setattr(root.channel, name, SSE(name))

is what I was looking for, time to read up on attributes,

Thanks,

Ingo
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] instantiate and name a class from / with a string

2019-08-09 Thread Mats Wichmann
On 8/9/19 11:55 AM, ingo wrote:
> With the available classes Root, Channel and SSE I build the following
> (in CherryPy):
> 
> root = Root()
> root.channel = Channel()
> 
> root.channel.weather = SSE('weather')
> root.channel.energy = SSE('energy')
> root.channel.mail = SSE('mail')
> root.channel.rss = SSE('rss')
> ...
> 
> http://example.com/channel/weather/ will then become the emitter of the
> weather event stream.
> 
> I'd like create the instances of SSE programmatically by pulling the
> string 'weather', 'energy' etc. from a database.

To channel Bob:  what are you actually asking for here? We can't figure
it out. Is there some database that has these strings? If so, what is
it?  Or do you mean "some data structure in your program that maps those
strings to something to do with them" (if so, where do you get that
information from?)

"With the available classes... in CherryPy"

Available from where? Your code? Some external piece of code you're
using? Does CherryPy actually have anything to do with the question
you're not quite asking?

Please be more precise.  We're not trying to be argumentative; you have
to help us know enough before we can help you.

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] instantiate and name a class from / with a string

2019-08-09 Thread bob gailer

On 8/9/2019 1:55 PM, ingo wrote:

With the available classes Root, Channel and SSE I build the following
(in CherryPy):

root = Root()
root.channel = Channel()

root.channel.weather = SSE('weather')
root.channel.energy = SSE('energy')
root.channel.mail = SSE('mail')
root.channel.rss = SSE('rss')
...

http://example.com/channel/weather/ will then become the emitter of the
weather event stream.

I'd like create the instances of SSE programmatically by pulling the
string 'weather', 'energy' etc. from a database.


Are you asking for help in obtaining a value from a database?

Or how to dynamically create instances assigned to root.channel attributes?

Assuming the latter:

name = # get from data base
setattr(root.channel, name, SSE(name))

--
Bob Gailer

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor