TIME NOW
World current time now,
CALENDAR
Calendar monthly, yearly
login CONVERT LENGTH
login CONVERT TEMPERATURE
login DICTIONARIES, LISTS
login SCIENCE EDUCATION RELIGION
login WORK CALCULATOR
login CALCULATE LIFE

Python 3 programming language, learn python, tutorial

Previous articlePage bottomNext article  ALL TOPICS

Python 3. Sys module examples

 Sys module examples:
http://www.pythonforbeginners.com/system/python-sys-argv
import sys
print ("This is the name of the script: ", sys.argv[0])
print ("Number of arguments: ", len(sys.argv))
print ("The arguments are: " , str(sys.argv))

# sys.argv[0] yra visada script pavadinimas. Visi kiti žodžiai per tarpa yra traktuojami kaip kiti argumentai.

usage:
cat about.txt | python soinput.py
import sys

def read_in():
    lines = sys.stdin.readlines()
    for i in range(len(lines)):
        lines[i] = lines[i].replace('\n','')
    #print lines
    return lines

def main():
    lines = read_in()
    print (lines)   

if __name__ == '__main__':
    main()

2.

Usage in Linux:
cat about.txt | python soinput.py

Python code:
import sys

def read_in():
    lines = sys.stdin.readlines()
    for i in range(len(lines)):
        lines[i] = lines[i].replace('\n','')
    #print lines
    return lines

def main():
    lines = read_in()
    print lines

if __name__ == '__main__':
    main()
--
 
Previous articlePage topNext article  ALL TOPICS



 Use username: Guest, Anonymous, Programmer






QUOTES:
That is happiness to be dissolved into something complete and great.
Willa Sibert Cather
As a general thing, when the woman wears the pants in the family, she has a good right to them.
Josh Billings
When humor can be made to alternate with melancholy, one has a success, but when the same things are funny and melancholic at the same time, it's just wonderful.
FrantOis Truffaut