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).
print " ".join(sys.argv[1:])
Program Source: echo.py
Running the example
From the command line:
python echo.py Hello World