-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathArgvReading.py
More file actions
48 lines (36 loc) · 1.08 KB
/
ArgvReading.py
File metadata and controls
48 lines (36 loc) · 1.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import sys
# the following prints one system argument
def arg1():
print(sys.argv[1])
#The following prints 2 system arguments
def arg2():
print(sys.argv[1],sys.argv[2])
# the following reads 3 arguments and assigns them to variables.
def arg3():
first=sys.argv[1]
second=sys.argv[2]
third=sys.argv[3]
print("First argument is",first,"! The second argument is", second, " ! The third argument is", third)
# the following reads a file as an argument
def readfilearg():
ValidFile=False
while ValidFile==False:
try:
file = sys.argv[1] # get the file from the argument
print(file)
f = open(file, "r") # opens the file essay.txt
print(file)
apple=f.read()
ValidFile=True
except:
print("File not found")
print("This is the name of the script: ")
print("Number of arguments: ",)
print("The arguments are: ",)
break
print(apple)
#uncomment whichever function call you want to run
#arg1()
#arg2()
#arg3()
readfilearg()