What's the elegant way to store_objects ?

Hi All,
I’m trying to store 25 odd datasources via store_objects. This is using streaming plots and a bokeh server.
This code below works fine, however it’s ugly and I’m sure there must be an easier way

cursession().store_objects(light_ds[‘0’], light_ds[‘1’], light_ds[‘2’], light_ds[‘3’], light_ds[‘4’],light_ds[‘5’],temperature_ds[‘0’], temperature_ds[‘1’], temperature_ds[‘2’],temperature_ds[‘3’], temperature_ds[‘4’], temperature_ds[‘5’],humidity_ds[‘0’], humidity_ds[‘1’], humidity_ds[‘2’], humidity_ds[‘3’],humidity_ds[‘4’], humidity_ds[‘5’],gas_ds[‘0’], gas_ds[‘1’], gas_ds[‘2’], gas_ds[‘3’], gas_ds[‘4’], gas_ds[‘5’],pressure_ds[‘0’], pressure_ds[‘1’], pressure_ds[‘2’], pressure_ds[‘3’],pressure_ds[‘4’], pressure_ds[‘5’])

``

``

This code doesn’t work. It throws a AttributeError: ‘list’ object has no attribute ‘references’

cursession().store_objects(light_ds.values(), temperature_ds.values(), humidity_ds.values(), gas_ds.values(), pressure_ds.values())

``

I’m guessing it return a list of values from each ds dict. Is there a way to return each of the values from the dict but not in a list format ?
Is there an elegant way to do this ?
I’m fairly new to python so apologies if I’m missing something simple.
Thanks !

Hi Lachlan,

Is it possible for you to post a bit more of the code? The reason I’m asking is to understand what the *_ds objects and their values are…

Without knowing much and guessing that the *_ds mappings have the the lists of objects to store in the session the reason your code is not working is because store_objects expects the objects to be passed directly as arguments but in your case you are passing the lists of the objects to store as arguments. If you change your code to take use python * magic when passing positional arguments it should work. So your code should become something like this:

cursession().store_objects(*light_ds.values() +
temperature_ds.values() +
humidity_ds.values() +
gas_ds.values() +
pressure_ds.values())

``

Let me know if that helps.

Cheers

···

On Thursday, February 26, 2015 at 10:56:49 AM UTC+1, Lachlan Kidd wrote:

Hi All,
I’m trying to store 25 odd datasources via store_objects. This is using streaming plots and a bokeh server.
This code below works fine, however it’s ugly and I’m sure there must be an easier way

cursession().store_objects(light_ds[‘0’], light_ds[‘1’], light_ds[‘2’], light_ds[‘3’], light_ds[‘4’],light_ds[‘5’],temperature_ds[‘0’], temperature_ds[‘1’], temperature_ds[‘2’],temperature_ds[‘3’], temperature_ds[‘4’], temperature_ds[‘5’],humidity_ds[‘0’], humidity_ds[‘1’], humidity_ds[‘2’], humidity_ds[‘3’],humidity_ds[‘4’], humidity_ds[‘5’],gas_ds[‘0’], gas_ds[‘1’], gas_ds[‘2’], gas_ds[‘3’], gas_ds[‘4’], gas_ds[‘5’],pressure_ds[‘0’], pressure_ds[‘1’], pressure_ds[‘2’], pressure_ds[‘3’],pressure_ds[‘4’], pressure_ds[‘5’])

``

``

This code doesn’t work. It throws a AttributeError: ‘list’ object has no attribute ‘references’

cursession().store_objects(light_ds.values(), temperature_ds.values(), humidity_ds.values(), gas_ds.values(), pressure_ds.values())

``

I’m guessing it return a list of values from each ds dict. Is there a way to return each of the values from the dict but not in a list format ?
Is there an elegant way to do this ?
I’m fairly new to python so apologies if I’m missing something simple.
Thanks !

Thanks Fabio, yes apologies for the cryptic code snippets but your suggestion was spot on…the * magic unpacked the lists and passed them to store_objects (and I’ve learnt what * is good for :-).

Thanks again.

Lachlan

···

On Thu, Feb 26, 2015 at 10:23 PM, Fabio Pliger [email protected] wrote:

Hi Lachlan,

Is it possible for you to post a bit more of the code? The reason I’m asking is to understand what the *_ds objects and their values are…

Without knowing much and guessing that the *_ds mappings have the the lists of objects to store in the session the reason your code is not working is because store_objects expects the objects to be passed directly as arguments but in your case you are passing the lists of the objects to store as arguments. If you change your code to take use python * magic when passing positional arguments it should work. So your code should become something like this:

cursession().store_objects(*light_ds.values() +
temperature_ds.values() +
humidity_ds.values() +
gas_ds.values() +
pressure_ds.values())

``

Let me know if that helps.

Cheers

On Thursday, February 26, 2015 at 10:56:49 AM UTC+1, Lachlan Kidd wrote:

Hi All,
I’m trying to store 25 odd datasources via store_objects. This is using streaming plots and a bokeh server.
This code below works fine, however it’s ugly and I’m sure there must be an easier way

cursession().store_objects(light_ds[‘0’], light_ds[‘1’], light_ds[‘2’], light_ds[‘3’], light_ds[‘4’],light_ds[‘5’],temperature_ds[‘0’], temperature_ds[‘1’], temperature_ds[‘2’],temperature_ds[‘3’], temperature_ds[‘4’], temperature_ds[‘5’],humidity_ds[‘0’], humidity_ds[‘1’], humidity_ds[‘2’], humidity_ds[‘3’],humidity_ds[‘4’], humidity_ds[‘5’],gas_ds[‘0’], gas_ds[‘1’], gas_ds[‘2’], gas_ds[‘3’], gas_ds[‘4’], gas_ds[‘5’],pressure_ds[‘0’], pressure_ds[‘1’], pressure_ds[‘2’], pressure_ds[‘3’],pressure_ds[‘4’], pressure_ds[‘5’])

``

``

This code doesn’t work. It throws a AttributeError: ‘list’ object has no attribute ‘references’

cursession().store_objects(light_ds.values(), temperature_ds.values(), humidity_ds.values(), gas_ds.values(), pressure_ds.values())

``

I’m guessing it return a list of values from each ds dict. Is there a way to return each of the values from the dict but not in a list format ?
Is there an elegant way to do this ?
I’m fairly new to python so apologies if I’m missing something simple.
Thanks !

You received this message because you are subscribed to a topic in the Google Groups “Bokeh Discussion - Public” group.

To unsubscribe from this topic, visit https://groups.google.com/a/continuum.io/d/topic/bokeh/Jz-fyd0WtL8/unsubscribe.

To unsubscribe from this group and all its topics, send an email to [email protected].

To post to this group, send email to [email protected].

To view this discussion on the web visit https://groups.google.com/a/continuum.io/d/msgid/bokeh/b5d955d8-730a-4279-9734-29ccc0e91816%40continuum.io.

For more options, visit https://groups.google.com/a/continuum.io/d/optout.