#Ex 7 not done and does not work at all #The user should write a filename #Improve 4.2 and 4.3 (old programs) by adding a command line interface #This means you can write ProgramName<FileName> (or something like that on the command line #and your program should use the argument that you have supplied on the command line #It should only ask for filename if no argument was specified #Improved Ex 4.2 #Create a new file that contains two integers. #Used nedit <name> & (in this case nedit integers.txt) #The numbers choosen to be in the new file are 2 and 6 #Saved the file #The numbers are read from STDIN import sys filename = input('Please, enter a filename: ') try: infile = open(filename, 'r') except IOError as error print('Can not open file, reason: ', str(error)) sys.stdout.exit(1) if len(sys.argv) == 1: first = int(sys.stdin.readline()) second = int(sys.stdin.readline()) else: first = sys.argv[1] second = sys.argv [2] print(first) print(second) infil.close()
Run
Reset
Share
Import
Link
Embed
Language▼
English
中文
Python Fiddle
Python Cloud IDE
Follow @python_fiddle
Browser Version Not Supported
Due to Python Fiddle's reliance on advanced JavaScript techniques, older browsers might have problems running it correctly. Please download the latest version of your favourite browser.
Chrome 10+
Firefox 4+
Safari 5+
IE 10+
Let me try anyway!
url:
Go
Python Snippet
Stackoverflow Question