matplotlib: Tkagg - resizing window

if isinstance(x, str) and x == 'None':

This is not considered best practice for testing for strings, because
the pythonic philosophy is "if it walks like a duck and talks like a
duck, we'll treat it like a duck", aka "duck-typing"

So matplotlib.cbook provides is_string_like

  from matplotlib.cbook import is_string_like
  if is_string_like(x) and x == 'None':
     something

The implementation is:

def is_string_like(obj):
    if hasattr(obj, 'shape'): return 0 # this is a workaround
                                       # for a bug in numeric<23.1
    try: obj + ''
    except (TypeError, ValueError): return 0
    return 1

This basically tests for the ability to add oneself to a string, which
is a solution suggested by the Python Cookbook.

JDH

John,

Done as recommended, thanks.

Eric

John Hunter wrote:

···

"Eric" == Eric Firing <efiring@...202...> writes:

    > if isinstance(x, str) and x == 'None':

This is not considered best practice for testing for strings, because
the pythonic philosophy is "if it walks like a duck and talks like a
duck, we'll treat it like a duck", aka "duck-typing"

So matplotlib.cbook provides is_string_like

  from matplotlib.cbook import is_string_like
  if is_string_like(x) and x == 'None': something

The implementation is:

def is_string_like(obj):
    if hasattr(obj, 'shape'): return 0 # this is a workaround
                                       # for a bug in numeric<23.1
    try: obj + ''
    except (TypeError, ValueError): return 0
    return 1

This basically tests for the ability to add oneself to a string, which
is a solution suggested by the Python Cookbook.

JDH

Dear John, dear Eric,

thanks for the prompt response!
..any chance you could attach the final patch file for collections.py?

Cheers
Juergen

···

On Monday 27 March 2006 23:38, Eric Firing wrote:

John,

Done as recommended, thanks.

Eric

John Hunter wrote:
>>>>>>"Eric" == Eric Firing <efiring@...202...> writes:
>
> > if isinstance(x, str) and x == 'None':
>
> This is not considered best practice for testing for strings, because
> the pythonic philosophy is "if it walks like a duck and talks like a
> duck, we'll treat it like a duck", aka "duck-typing"
>
> So matplotlib.cbook provides is_string_like
>
> from matplotlib.cbook import is_string_like
> if is_string_like(x) and x == 'None':
> something
>
>
> The implementation is:
>
> def is_string_like(obj):
> if hasattr(obj, 'shape'): return 0 # this is a workaround
> # for a bug in numeric<23.1
> try: obj + ''
> except (TypeError, ValueError): return 0
> return 1
>
>
> This basically tests for the ability to add oneself to a string, which
> is a solution suggested by the Python Cookbook.
>
> JDH

Juergen Haas wrote:

Dear John, dear Eric,

thanks for the prompt response!

You are welcome.

..any chance you could attach the final patch file for collections.py?

Attached.

Eric

collections.patch (1.3 KB)