Python: Difference between revisions
Jump to navigation
Jump to search
(→Shell: magic) |
|||
Line 7: | Line 7: | ||
== Shell == |
== Shell == |
||
Use '''[http://ipython.org/ iPy]''' (ipython) to get an interactive shell with auto-completion, instant help... |
Use '''[http://ipython.org/ iPy]''' (ipython) to get an interactive shell with auto-completion, instant help... |
||
<source lang=python> |
|||
%magic # Get help on %magic commands (%run,...) |
|||
?run # Get help on %run magic |
|||
%run script.py # Run given script |
|||
%run -i script.py # ... with inspect mode on |
|||
%run -i -e script.py # ... ... and ignore sys.exit() call |
|||
</source> |
|||
== Reference == |
== Reference == |
Revision as of 21:38, 2 April 2014
Links
- Nice example of generating / testing regex in Python (with nice / small test framework) [1]
Shell
Use iPy (ipython) to get an interactive shell with auto-completion, instant help...
%magic # Get help on %magic commands (%run,...)
?run # Get help on %run magic
%run script.py # Run given script
%run -i script.py # ... with inspect mode on
%run -i -e script.py # ... ... and ignore sys.exit() call
Reference
Basic
for i in range(10):
print i # carriage return
for i in range(10):
print i, # no carriage return
Tips
Simple HTTP Server
It's very easy to setup an ad-hoc HTTP server with Python. Just open a shell in a folder with some contents to share, and type:
python -m SimpleHTTPServer
More available at http://docs.python.org/2/library/internet.html (see BaseHTTPServer and CGIHTTPServer).