----- Mensaje original ----
> De: Eric Firing <efir...@hawaii.edu>
> 
> import matplotlib.cbook as cbook
> 
> def to_sequence(arg):
>     if cbook.is_iterable(arg):
>         return arg
>     return [arg]
> 
> Above is an example of how one can turn a scalar into a sequence (a list, in 
> this case) if necessary.

When I enter this into ipython, I get:

In [67]: to_sequence(1)
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)

/home/jscandal/sw/python/myimports.py in <module>()
----> 1 
      2 
      3 
      4 
      5 

/home/jscandal/sw/python/myimports.py in to_sequence(arg)
      1 
----> 2 
      3 
      4 
      5 

AttributeError: 'module' object has no attribute 'is_iterable'

I have matplotlib 0.98.5.2, and it seems is_iterable is not there.


> Different types of sequence have different advantages and disadvantages. 
> Tuples 
> are immutable.  Lists are much more flexible, and can be extended.  ndarrays 
> are 
> fixed-size, but facilitate efficient computation.
> 
> If a function or method accepts any kind of sequence for a given argument, 
> then 
> probably the thing to do is give it whatever you have already, or whatever is 
> most convenient to generate.  Lists are a good default if the sequence has 
> only 
> a few elements and you are writing them out, rather than calculating them 
> from 
> some other sequence.  In other words, if a function is flexible, then trust 
> the 
> function to do whatever conversions it needs internally; there is no 
> particular 
> advantage in doing the conversion yourself when you specify the argument.
> 

Thanks for the hints, I guess I get a bit frustrated or lost sometimes. Trying 
to get work done while being at the bottom of the learning curve might not be 
the best situation. I have the feeling, though, that I had to switch this way 
or else I would never really do it at all. I've been wanting to play with 
python for a long time now, but never did anything more than hello world 
examples. Until now ;)

Jorge


      

------------------------------------------------------------------------------
Crystal Reports - New Free Runtime and 30 Day Trial
Check out the new simplified licensing option that enables unlimited
royalty-free distribution of the report engine for externally facing 
server and web deployment.
http://p.sf.net/sfu/businessobjects
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users

Reply via email to