Eric Schulte <schulte.e...@gmail.com> writes:

> Hi Steve,
>
> Is this a Python problem or is it numpy specific?
>
> Is repr() a numpy or a Python function i.e., could it replace str() in
> every Python code block or only when numpy is loaded?

repr is a Python-thing and it's main feature, I guess, is
eval(repr(object)) == object cf. below.  So e.g. 

In [1]: import numpy as np
In [2]: repr(np.array([1,2,3]))
Out[2]: 'array([1, 2, 3])'
In [3]: str(np.array([1,2,3]))
Out[3]: '[1 2 3]'

I'm not sure convinced that repr is necessarily better, tho.

Here's the docstrings.

In [4]: str?
Type:       type
String Form:<class 'str'>
Namespace:  Python builtin
Docstring:
str(object='') -> str
str(bytes_or_buffer[, encoding[, errors]]) -> str

Create a new string object from the given object. If encoding or
errors is specified, then the object must expose a data buffer
that will be decoded using the given encoding and error handler.
Otherwise, returns the result of object.__str__() (if defined)
or repr(object).
encoding defaults to sys.getdefaultencoding().
errors defaults to 'strict'.

In [5]: ?repr
Type:       builtin_function_or_method
String Form:<built-in function repr>
Namespace:  Python builtin
Docstring:
repr(object) -> string

Return the canonical string representation of the object.
For most object types, eval(repr(object)) == object.



–Rasmus

-- 
Got mashed potatoes. Ain't got no T-Bone. No T-Bone


Reply via email to