examples format

12 views
Skip to first unread message

mb

unread,
Jan 25, 2008, 12:14:48 AM1/25/08
to sage-forum
Hello,

Here is a suggestion. The default way to post examples is like so:

sage: s=0
sage: for i in range(100):
....: s=s+i
....:
sage: print s
4950


I would propose a format that makes it easier to cut and paste (into a
file), without having to do it line by line, namely

s=0
for i in range(100):
s=s+i
print s


--mb

Jason Grout

unread,
Jan 25, 2008, 12:20:54 AM1/25/08
to sage-...@googlegroups.com

How do you propose separating input and output?

I think it should be pretty easy to write a function that converts the
former form to the latter form. Maybe you can make it a trac ticket?

Jason

mabshoff

unread,
Jan 25, 2008, 12:24:49 AM1/25/08
to sage-forum


On Jan 25, 6:20 am, Jason Grout <jason-s...@creativetrax.com> wrote:
> mb wrote:
> > Hello,
>
> > Here is a suggestion. The default way to post examples is like so:
>
> > sage: s=0
> > sage: for i in range(100):
> > ....: s=s+i
> > ....:
> > sage: print s
> > 4950
>
> > I would propose a format that makes it easier to cut and paste (into a
> > file), without having to do it line by line, namely
>
> > s=0
> > for i in range(100):
> > s=s+i
> > print s
>
> How do you propose separating input and output?

Well, I guess it would only be input ;)

> I think it should be pretty easy to write a function that converts the
> former form to the latter form. Maybe you can make it a trac ticket?

Don't. "sage:" is already eaten by the preparser (you can try that)
and the already is a ticket for "....:".

> Jason

Cheers,

Michael

Jason Grout

unread,
Jan 25, 2008, 12:56:02 AM1/25/08
to sage-...@googlegroups.com

What about the situation the poster describes, where you want to strip
the example down to something you can stick into the file? A function
would be nice to do that:

strip_example("""


sage: s=0
sage: for i in range(100):
....: s=s+i
....:
sage: print s
4950

""")

prints

s=0
for i in range(100):
s=s+i

print s


and then it's easy to copy and paste the example into a file.

-Jason

William Stein

unread,
Jan 25, 2008, 1:02:24 AM1/25/08
to sage-...@googlegroups.com, Fernando Perez

Some comments about this thread:

(1) We're not changing the docstring format for two reasons:
(a) There are now over 40,000 lines of just *input* docstrings in the
main sage library!
teragon:plot was$ sage -grep "sage:" |wc -l
40353
(b) The current format is imposed by Python; it's already the
standard Python docstring
format, and hence we should stick with it.

(2) It is annoying that ipython formats input with a stupid ....:
instead of the ... format like
in Python. Fernando -- why does Ipython do that?
teragon:plot was$ sage -python
Python 2.5.1 (r251:54863, Jan 18 2008, 16:10:52)
[GCC 4.0.1 (Apple Inc. build 5465)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> for n in range(10):
... print n
...
0
1...

(3) In the Sage notebook, if you make a worksheet, then click "Text"
in the top right area,
you'll get plain text formated for inclusion in docstrings.

--- William

Reply all
Reply to author
Forward
0 new messages