-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathex22B.py
66 lines (46 loc) · 1.46 KB
/
ex22B.py
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# 17 multiple files
from sys import argv
from os.path import exists
script, fromFile, toFile = argv
print("Copying from file %s to file %s" % (fromFile, toFile))
inFile = open(fromFile)
inData = inFile.read()
print("The input file is %d bytes long! " % (len(inData)))
print("Does output file %s exists ? %r " % (toFile, exists(toFile)))
input()
outFile = open(toFile, 'w')
outFile.write(inData)
print("All Done. Now closing all stuff")
outFile.close()
inFile.close()
# 18 Arguments and Def Functions
def print_two(*args):
arg1, arg2 = args
print("arg1: %r, arg2: %r" % (arg1, arg2))
outFile = open(toFile, 'w')
outFile.write(arg1 + " " + arg2)
outFile.close()
def single():
print("bhi nai hai mere pass")
single()
print_two('I love you', "Twinkle")
# 19 More Functions and variable
def cheese_and_crackers(cheese_count, boxes_of_crackers):
print("You have %d cheeses!" % cheese_count)
print("You have %d boxes of crackers!" % boxes_of_crackers)
print("Man that's enough for a party!")
print("Get a blanket.\n")
print("And we can combine the two, variables and math:")
amount_of_cheese = 10
amount_of_crackers = 50
cheese_and_crackers(amount_of_cheese + 100, amount_of_crackers + 1000)
# 20 Seeking a FIle
def printAll(f):
print(f.read())
def rewind(f):
f.seek(0)
def print_a_Line(linecount, f):
print(linecount, f.readLine())
currentFile = open(toFile)
print("First let's print the whole file: \n")
printAll(currentFile)