should i switch to IPYTHON interpreter? What is the killer feature of it?

C

Christian Seberino

I know IPython is another interpreter for Python and was wondering
what people liked about it and if I should switch to it.

If it is so good then why is it not part of the standard Python
tarball?

Chris
 
S

Sean Richards

I know IPython is another interpreter for Python and was wondering
what people liked about it and if I should switch to it.

Some things i like are .....

Typing ? after a function name gives you the function definition and
docstrings for the function. i.e arange? returns

Type: builtin_function_or_method
Base Class: <type 'builtin_function_or_method'>
String Form: <built-in function arange>
Namespace: Interactive
Docstring:
arange(start, stop=None, step=1, typecode=None)

Just like range() except it returns an array whose type can be
specified by the keyword argument typecode.

Normal shell commands like cd & ls are available

Tab completion for keywords and methods etc (you can get this in the
standard python shell as well of course)

Heaps more features but those are the killers for me (YMMV)
If it is so good then why is it not part of the standard Python
tarball?

No idea. It's no big deal for me to download it separately and install
it. You could ask the same question about many other Python packages,
if they were all included the distribution would start getting a bit
big I think.

Anyway give IPython a try I think you will like it.

Sean
 
I

Irmen de Jong

Sean Richards wrote:

Tab completion for keywords and methods etc (you can get this in the
standard python shell as well of course)

You can? How?

--Irmen
 
D

Dang Griffith

I know IPython is another interpreter for Python and was wondering
what people liked about it and if I should switch to it.

If it is so good then why is it not part of the standard Python
tarball?

Chris
I use it on Win32 and like that it provides a simpler/more direct
interface to the file system. I.e., I can do things such as "cd
blahblahblah" and change the directory, rather than importing os and
calling os.chdir("blahblah"), "ls" instead of os.listdir('.'), and
that sort of thing. Also, you can create your own command aliases,
along the lines of cshrc, bash, etc.

Another feature I've used, at least occasionally, is the ability to
save the session history. When I'm exploring a module I've not used
before, I do a lot of schtuff that doesn't work, get it to work, then
move forward (not work, work, not work, work). By the time I've
reached my goal, though, I've become addled and have forgotten which
pieces parts works and which didn't. With IPython, I can save that
history and review what worked and what didn't, delete the chaff and
try the wheat again later.

At least one reason it's not part of the standard tarball is that it's
owned by a different group of people.

--dang
p.s.
One could argue that my approach to learning new modules could use
improvement. And while that may be true, I've found that learning to
recognize error messages, and what causes them, makes it easier to
help others.
 
D

Dang Griffith

Sean Richards wrote:



You can? How?

--Irmen

Press tab after typing part of the keyword/method.

This assumes you're *not* using Win32. The documentation says that
IPython requires the GNU readline function, which I guess isn't
available with Win32. Neither is color highlighting.

--dang
 
I

Irmen de Jong

Dang said:
Press tab after typing part of the keyword/method.

Sean was talking about the 'standard python shell' so I tried
the default python (2.3) on my mandrake 9.2 box.
It doesn't work, it just inserts a tab character.

--Irmen
 
C

Christoph Becker-Freyseng

Irmen said:
Sean was talking about the 'standard python shell' so I tried
the default python (2.3) on my mandrake 9.2 box.
It doesn't work, it just inserts a tab character.

--Irmen


You need an startup-file for python.

(I copied this together out of python-news-mail (thank you once again)
and some own ideas)

..pystartup in your home-dir

# Add auto-completion and a stored history file of commands to your Python
# interactive interpreter. Requires Python 2.0+, readline. Autocomplete is
# bound to the Esc key by default (you can change it - see readline docs).
#
# Store the file in ~/.pystartup, and set an environment variable to point
# to it, e.g. "export PYTHONSTARTUP=/max/home/itamar/.pystartup" in bash.
#
# Note that PYTHONSTARTUP does *not* expand "~", so you have to put in the
# full path to your home directory.

import atexit
import os
import readline
import rlcompleter

historyPath = os.path.expanduser("~/.pyhistory")
historyTmp = os.path.expanduser("~/.pyhisttmp.py")

endMarkerStr= "# # # histDUMP # # #"

saveMacro= "import readline;
readline.write_history_file('"+historyTmp+"'); print '####>>>>>>>>>>';
print ''.join(filter(lambda lineP: not
lineP.strip().endswith('"+endMarkerStr+"'),
open('"+historyTmp+"').readlines())[:])+'####<<<<<<<<<<'"+endMarkerStr

readline.parse_and_bind('tab: complete')
readline.parse_and_bind('\C-w: "'+saveMacro+'"')

def save_history(historyPath=historyPath, endMarkerStr=endMarkerStr):
import readline
readline.write_history_file(historyPath)
# Now filter out those line containing the saveMacro
lines= filter(lambda lineP, endMarkerStr=endMarkerStr: not
lineP.strip().endswith(endMarkerStr), open(historyPath).readlines())
open(historyPath, 'w+').write(''.join(lines))

if os.path.exists(historyPath):
readline.read_history_file(historyPath)

atexit.register(save_history)

del os, atexit, readline, rlcompleter, save_history, historyPath,
historyTmp, endMarkerStr, saveMacro


(I hope spaces will survive mailing)

Additionaly you need to
~# export PYTHONSTARTUP=/root/.pystartup

You can do this e.g. in .profile


Pressing tab completes the input like common unix-shells.
Pressing CTRL-w gives You an python code to print the history-file (or
parts of it -- there's a [:] in the command that You can replace by
[-50:]; which will give you the last 50 lines)


cu cbf
 
P

Paul McGuire

One could argue that my approach to learning new modules could use
improvement. And while that may be true, I've found that learning to
recognize error messages, and what causes them, makes it easier to
help others.
I would say you have nothing to apologize for, this approach to learning new
modules sounds strikingly similar to my own. It's part of what I think is a
big advantage to Python (and similar scripting languages), that you can
engage in a highly efficient, quick turnaround, exploratory process, without
the overhead and delay of compile/correct-syntax-errors/compile/link/run.
The immediate feedback (and sometimes, gratification) allows you to stay in
that high-intensity mental zone, without the distractions of awkward
meta-tasks, for hours at a time (or days or weeks!).

-- Paul
 
D

Diez B. Roggisch

Sean was talking about the 'standard python shell' so I tried
the default python (2.3) on my mandrake 9.2 box.
It doesn't work, it just inserts a tab character.

I use rlcompleter2 for this - in the standard shell. Very nice - but I think
I've got to take a look at IPython, too.

Diez
 
G

Guest

Sean was talking about the 'standard python shell' so I tried
the default python (2.3) on my mandrake 9.2 box.
It doesn't work, it just inserts a tab character.

Put this in ~/.pythonrc, and setup the PYTHONSTARTUP environment variable to
point to it: export PYTHONSTARTUP=~/.pythonrc


# ~/.pythonrc
# enable syntax completion
try:
import readline
except ImportError:
print "Module readline not available."
else:
import rlcompleter
readline.parse_and_bind("tab: complete")
 
I

Irmen de Jong

дамјан г. wrote:

Put this in ~/.pythonrc, and setup the PYTHONSTARTUP environment variable to
point to it: export PYTHONSTARTUP=~/.pythonrc


# ~/.pythonrc
# enable syntax completion
try:
import readline
except ImportError:
print "Module readline not available."
else:
import rlcompleter
readline.parse_and_bind("tab: complete")

I say thank you ! This works like a charm.
Somehow I've never discovered rlcompleter... :)

--Irmen
 
S

Sean Richards

Dang Griffith said:
Press tab after typing part of the keyword/method.

This assumes you're *not* using Win32. The documentation says that
IPython requires the GNU readline function, which I guess isn't
available with Win32. Neither is color highlighting.

--dang

Actually you can get all this on win32 if you use the cvs version of
IPython and Gary Bishop's Python readline module. There is a URL
and instructions on how to set it up here.
http://www.scipy.net/pipermail/ipython-dev/2003-December/000094.html
The Python readline module needs ctypes so get that as well.
Works with Python 22 and 23 and gives you readline functionality and
colour highlighting when using IPython under win32.

Sean
 
G

Gary Bishop

?????? ?. said:
# ~/.pythonrc
# enable syntax completion
try:
import readline
except ImportError:
print "Module readline not available."
else:
import rlcompleter
readline.parse_and_bind("tab: complete")

This will work on win32 as well if you download ctypes and then my
python implementation of gnu readline from

http://prdownloads.sourceforge.net/uncpythontools/readline-1.1.zip?download

It also includes the ability to translate ascii color escapes into
colors on windows for use with iPython.

gb
 
F

Fernando Perez

Christian said:
I know IPython is another interpreter for Python and was wondering
what people liked about it and if I should switch to it.

As the ipython developer, you could say that I'm biased :) But you could
simply try it and see if you like it. It's a simple python package with no C
dependencies (under *nix), so getting it going is pretty straightforward.

I personally can't stand using the standard python shell anymore, which to me
feels like a crippled toy. But YMMV.

As Sean pointed, some of its nicer features (readline and color support) are
finally available to Windows XP/2k users, but only with CVS code. I'll be
making a new release soon-ish, but I want to clean some other outstanding
small bugs before that.
If it is so good then why is it not part of the standard Python
tarball?

I'd like it to, but I haven't even considered proposing such an idea. Right
now the ipython internals are a heinous mess, and nobody in their sane mind
would accept to maintain such a codebase. But there's hope for a rewrite with
the help of some dedicated users (I have very limited time for its
development). If we manage to clean it up completely, it might be conceivable
to propose it for the standard distribuition (not as a replacement, but as an
alternative: it's still slower to load and more complex code).

Regards,

Fernando.
 
T

Tim Golden

Gary Bishop said:
This will work on win32 as well if you download ctypes and then my
python implementation of gnu readline from

http://prdownloads.sourceforge.net/uncpythontools/readline-1.1.zip?download

Brilliant! Thank you very much indeed.

I would add a warning for those Windows users who aren't also Linux
users: by default you'll need to use Ctrl-D to exit the interpreter
rather than Ctrl-Z. (I imagine this could be changed; I've given the
source no more than a cursory glance).

TJG
 

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

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,009
Latest member
GidgetGamb

Latest Threads

Top