Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

I made this http://defcraft.org/hacks/pycmds/pii.py to help define "commands" in the interactive interpreter. Commands like "ls" and "h os".

"ls" is a simple command -- invokes the Unix command "ls -l". A more complicated one: "h os" -- run help on the os module (just like "help(os)"). This is kinda tricky because "h os" is actually a syntax error in Python. When interactive, I catch syntax errors and see if they are user defined commands, in which case I execute the desired command. This works for Python 2.5, but shouldn't be too hard to port to Python 3.0.

I briefly looked at IPython, but that seemed to complicated for my needs.

(Also, http://defcraft.org/hacks/pycmds/strftime_helper.py uses the above file to help the user with strftime spec usage. I can never remember all the special characters.)



Nice!

We use similar technic with hpy - you type in Hebrew Python http://nirs.freeshell.org/code/hpy/ , then each line is translated to Python and executed.

How do create more fancy links here?




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: