Ignore leading '>>>' and ellipsis?

R

Reckoner

Hi,

I am studying some examples in a tutorial where there are a lot of
leading >>> characters and ellipsis in the text. This makes it hard to
cut and paste into the IPython interpreter since it doesn't like these
strings.

Is there another interpreter I could use that will appropriately
ignore and interpret these leading terms?

For example, I cannot paste the following directly into the
interpreter:
d = dict(x.__array_interface__)
d['shape'] = (3, 2, 5)
d['strides'] = (20, 20, 4)
class Arr:
.... __array_interface__ = d
.... base = x
 
J

Javier Collado

Hello,

I think that's exactly what the cpaste magic function does. Type
'cpaste?' in your IPython session for more information.

Best regards,
Javier

2010/1/14 Reckoner said:
Hi,

I am studying some examples in a tutorial where there are a lot of
leading >>> characters and ellipsis in the text. This makes it hard to
cut and paste into the IPython interpreter since it doesn't like these
strings.

Is there another interpreter I could use that will appropriately
ignore and interpret these leading terms?

For example, I cannot paste the following directly into the
interpreter:
d = dict(x.__array_interface__)
d['shape'] = (3, 2, 5)
d['strides'] = (20, 20, 4)
class Arr:
...     __array_interface__ = d
...     base = x
 
R

r0g

Javier said:
Hello,

I think that's exactly what the cpaste magic function does. Type
'cpaste?' in your IPython session for more information.

Best regards,
Javier

2010/1/14 Reckoner said:
Hi,

I am studying some examples in a tutorial where there are a lot of
leading >>> characters and ellipsis in the text. This makes it hard to
cut and paste into the IPython interpreter since it doesn't like these
strings.

Is there another interpreter I could use that will appropriately
ignore and interpret these leading terms?

For example, I cannot paste the following directly into the
interpreter:
d = dict(x.__array_interface__)
d['shape'] = (3, 2, 5)
d['strides'] = (20, 20, 4)
class Arr:
... __array_interface__ = d
... base = x



Or, as a man with a shiny new hammer, you could roll your own processor
in python as a learning exercise...

#!/usr/bin/python
import sys
lines = []
try:
while 1:
l1 = sys.stdin.readline()
l2 = l1.lstrip(">")
if l1<>l2: l2 = l2[1:]
lines.append( l2 )
except KeyboardInterrupt:
print "\n--8<--------8<--------8<--------8<--------8<--------"
print ''.join(lines)


10 points for modding it so it automatically recopies the data to the
clipboard

20 points for using a timer to automatically issue a keyboard interrupt
if the buffer has data and no input has been received for half a second

:)

Roger.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top