* Bug: verbatim export of python code block with numpy array returns wrong value [8.2.1 (8.2.1-10-g9c1ef6-elpaplus @ /Users/sbagley/Dropbox/emacsd/elpa/org-plus-contrib-20131014/)]
@ 2013-10-21 3:24 Steven Bagley
2013-10-22 2:31 ` Eric Schulte
0 siblings, 1 reply; 3+ messages in thread
From: Steven Bagley @ 2013-10-21 3:24 UTC (permalink / raw)
To: emacs-orgmode
The following file contents, when exported (to HTML or pdf), produce
incorrect output:
#+PROPERTY: header-args:python :session "*Python*"
#+PROPERTY: exports both
#+PROPERTY: results value verbatim
#+BEGIN_SRC python
import numpy as np
np.array([1, 2, 3])
#+END_SRC
The resulting value block contains [1 2 3], which is not the print
representation of that numpy array. I suspect the problem arises in
ob-python.el from the use of str() instead of repr(). Thanks.
--Steve
Remember to cover the basics, that is, what you expected to happen and
what in fact did happen. You don't know how to make a good report? See
http://orgmode.org/manual/Feedback.html#Feedback
Your bug report will be posted to the Org-mode mailing list.
------------------------------------------------------------------------
Emacs : GNU Emacs 24.3.1 (x86_64-apple-darwin11.4.2, Carbon Version
1.6.0 AppKit 1138.51)
of 2013-09-24 on Yukikaze.local
Package: Org-mode version 8.2.1 (8.2.1-10-g9c1ef6-elpaplus @
/Users/sbagley/Dropbox/emacsd/elpa/org-plus-contrib-20131014/)
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: Bug: verbatim export of python code block with numpy array returns wrong value [8.2.1 (8.2.1-10-g9c1ef6-elpaplus @ /Users/sbagley/Dropbox/emacsd/elpa/org-plus-contrib-20131014/)]
2013-10-21 3:24 Bug: verbatim export of python code block with numpy array returns wrong value [8.2.1 (8.2.1-10-g9c1ef6-elpaplus @ /Users/sbagley/Dropbox/emacsd/elpa/org-plus-contrib-20131014/)] Steven Bagley
@ 2013-10-22 2:31 ` Eric Schulte
2013-10-22 8:09 ` Rasmus
0 siblings, 1 reply; 3+ messages in thread
From: Eric Schulte @ 2013-10-22 2:31 UTC (permalink / raw)
To: Steven Bagley; +Cc: emacs-orgmode
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?
Thanks,
Steven Bagley <stevenbagley@fastmail.fm> writes:
> The following file contents, when exported (to HTML or pdf), produce
> incorrect output:
> #+PROPERTY: header-args:python :session "*Python*"
> #+PROPERTY: exports both
> #+PROPERTY: results value verbatim
> #+BEGIN_SRC python
> import numpy as np
> np.array([1, 2, 3])
> #+END_SRC
>
> The resulting value block contains [1 2 3], which is not the print
> representation of that numpy array. I suspect the problem arises in
> ob-python.el from the use of str() instead of repr(). Thanks.
> --Steve
>
> Remember to cover the basics, that is, what you expected to happen and
> what in fact did happen. You don't know how to make a good report? See
>
> http://orgmode.org/manual/Feedback.html#Feedback
>
> Your bug report will be posted to the Org-mode mailing list.
> ------------------------------------------------------------------------
>
>
>
> Emacs : GNU Emacs 24.3.1 (x86_64-apple-darwin11.4.2, Carbon Version
> 1.6.0 AppKit 1138.51)
> of 2013-09-24 on Yukikaze.local
> Package: Org-mode version 8.2.1 (8.2.1-10-g9c1ef6-elpaplus @
> /Users/sbagley/Dropbox/emacsd/elpa/org-plus-contrib-20131014/)
>
--
Eric Schulte
https://cs.unm.edu/~eschulte
PGP: 0x614CA05D
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: Bug: verbatim export of python code block with numpy array returns wrong value [8.2.1 (8.2.1-10-g9c1ef6-elpaplus @ /Users/sbagley/Dropbox/emacsd/elpa/org-plus-contrib-20131014/)]
2013-10-22 2:31 ` Eric Schulte
@ 2013-10-22 8:09 ` Rasmus
0 siblings, 0 replies; 3+ messages in thread
From: Rasmus @ 2013-10-22 8:09 UTC (permalink / raw)
To: emacs-orgmode
Eric Schulte <schulte.eric@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
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2013-10-22 8:07 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-10-21 3:24 Bug: verbatim export of python code block with numpy array returns wrong value [8.2.1 (8.2.1-10-g9c1ef6-elpaplus @ /Users/sbagley/Dropbox/emacsd/elpa/org-plus-contrib-20131014/)] Steven Bagley
2013-10-22 2:31 ` Eric Schulte
2013-10-22 8:09 ` Rasmus
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.