PDA

View Full Version : starting python



conradin
February 1st, 2012, 08:24 AM
Hi all,
Im just starting python, coming from the bash scripting perspective.
How do I use command line programs like:
clear, seq, date, echo, >> << >, exit, nslookup, grep, and so on from the a python script? Any hints or good reading I should checkout?

ofnuts
February 1st, 2012, 09:31 AM
Hi all,
Im just starting python, coming from the bash scripting perspective.
How do I use command line programs like:
clear, seq, date, echo, >> << >, exit, nslookup, grep, and so on from the a python script? Any hints or good reading I should checkout?
These commands are useless in Python which has its own built-in functions for this (print, range()...); Python isn't a drop-in replacement for bash. In Bash you try to have most things done by commands, you own code being mostly glue. In Python your code includes a lot more logic and in most case you'll deal with files directly (otherwise use Bash).

JDShu
February 1st, 2012, 06:23 PM
Here's a free book to work through:

http://learnpythonthehardway.org/book/

Zed Shaw is highly respected (if abrasive) in the python community.

MadCow108
February 2nd, 2012, 12:32 AM
if you want to use python as a bash shell replacement, there are better shells than the default one available which give direct access to installed executables and their output.
e.g. ipython or bpython

to use it in script there are wrappers to the subprocess module to simplify some things, e.g. pbs:
https://github.com/amoffat/pbs