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

Mats Wichmann mats at wichmann.us
Fri Aug 9 23:57:26 EDT 2019


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.



More information about the Tutor mailing list