LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   Python: bash-shell-like less functionality in the python shell (https://www.linuxquestions.org/questions/programming-9/python-bash-shell-like-less-functionality-in-the-python-shell-816389/)

narnie 06-25-2010 01:11 PM

Python: bash-shell-like less functionality in the python shell
 
Hello,

Is there some type of functional way to read things in the Python shell interpreter similar to less or more in the bash (and other) command line shells?

Example:
Code:

>>> import subprocess
>>> help(subprocess)
...
[pages of stuff to read]
...

I'm hoping so as I hate scrolling and love how less works with simple keystrokes for page-up/page-down/searching etc.

With thanks,
Narnie

robotsari 06-25-2010 01:50 PM

Hi Narnie,

When I do this I do get the help page in a less-type viewer. I'm running

~$ python -V
Python 2.6.5

on ubuntu 10.04.

narnie 06-26-2010 07:29 AM

Quote:

Originally Posted by robotsari (Post 4015043)
Hi Narnie,

When I do this I do get the help page in a less-type viewer. I'm running

~$ python -V
Python 2.6.5

on ubuntu 10.04.

I should have mentioned that I'm using the IDLE IDE for my messing around (I'm just learning programming and starting with Python, but I'm quite facile with bash scripting).

I get less-type functionality in the bash shell, but not in the IDLE python shell.

However, I'll check IDLE to see if there is a command line option to start it with python -V. That's a great tip :)

Thank you,
Narnie

robotsari 06-28-2010 12:09 PM

Hmm. python -V simply displays the version of Python that you're running; I was thinking perhaps you were running an older version of Python.

I somewhat suspect that the IDLE shell doesn't actually enable what you're looking to do 8/

Try using ipython (in the universe; sudo apt-get install ipython). It combines some of the best aspects of the bash shell, python interpreter, and IDLE - for example you can navigate directories with commands such as cd and ls, and you can enter in Python code and run scripts (using the "run" command, eg > run test.py). And, it displays "help" as you want it to! Basically, they simply implemented the python interpreter on top of a normal shell.

Another option I haven't tried before is bpython, which looks really interesting; it also supplies syntax highlighting (I thought ipython provided syntax highlighting, but I just installed it here on my work computer and it apparently doesn't have it).

narnie 06-29-2010 12:25 PM

Quote:

Originally Posted by robotsari (Post 4017345)
Hmm. python -V simply displays the version of Python that you're running; I was thinking perhaps you were running an older version of Python.

I somewhat suspect that the IDLE shell doesn't actually enable what you're looking to do 8/

Try using ipython (in the universe; sudo apt-get install ipython). It combines some of the best aspects of the bash shell, python interpreter, and IDLE - for example you can navigate directories with commands such as cd and ls, and you can enter in Python code and run scripts (using the "run" command, eg > run test.py). And, it displays "help" as you want it to! Basically, they simply implemented the python interpreter on top of a normal shell.

Another option I haven't tried before is bpython, which looks really interesting; it also supplies syntax highlighting (I thought ipython provided syntax highlighting, but I just installed it here on my work computer and it apparently doesn't have it).

Sarina,

You are very kind to provide me so much followup.

I have done some reading and it is in fact that the IDLE shell isn't a "proper" shell. I will look into you solution when I get home. I'm always interested in trying in out and it's being in the repos will make it even easier.

Thanks very much for the suggestion.

Yours,
Narnie

PS
Hoping it does code completion!!!

PPS
Loving how it sound like it makes it easier to change working directory, etc.


All times are GMT -5. The time now is 03:42 PM.