A couple of things i found on Python

Used to clear and history on the terminal and on the iPython console, i feel frustrated working on the native python interpreter on a terminal.
So while looking for solutions, i found these - 

import os

clear = lambda: os.system('clear')
clear()

will do what clear will does on the terminal.

We can just replace clear in os.system('clear') with ls, pwd or other common unix commands. It was useful for me because i was going through checking through multiple files and defining ls() in python was easier than changing between two tabs on the terminal.


import readline

for i in xrange(readline.get_current_history_length()):
      readline.get_history_item(i)

will do what history does on the terminal.

Further, you one could append the output to a log file.

Just saying...

EDIT:

Instead of

pwd = lambda: os.system('pwd') 

you could use the already defined

os.getcwd().

And note, cd = lambda:os.system('cd') doesn't work.

Instead, use os.chdir('')

Popular posts from this blog

Farewell to Enthought

Arxiv author affiliations using Python

Elementary (particle physics), my dear Watson