Warning: Creating default object from empty value in /home/patricknevindwyer/digilutionary.com/wp-includes/functions.php on line 292
digilutionary.com
Patrick Dwyer

Echo :: Python

in News, Comparative Programming, Python by patrick


Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/patricknevindwyer/digilutionary.com/wp-includes/functions-formatting.php on line 76

This program is part of the Comparative Programming :: Echo set of examples.

Our Python example seems very familiar; many of the scripting languages have eerily similar syntax for an example this basic. The one major difference here is the use of Slices to pull our arguments out of the list of command line arguments. Python’s sys.argv (provided for us after importing the sys module) includes the name of the program script as it’s first element. We need to trim this item off and print only the remaining items on the argument list. Our ’slice’ gives us every element from the index 1 to the end of the list (remember, our list is indexed from 0).

Python
#!/usr/bin/python

import sys

print " ".join(sys.argv[1:])

Program Source: echo.py

Running the example

From the command line:

python echo.py Hello World