Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from sys import argv
- from os.path import exists
- script, arg1, arg2 = argv
- def copy(a,b):
- open(b,'w').write(open(a).read())
- def read(a):
- return int(open(a).readline())
- def write(a,b):
- open(a,'w').write(b)
- def add(a,b):
- return a+b
- file1 = open(arg1)
- file2 = open(arg2)
- print 'This program\'ll take whatever number you write in a file,'
- print 'and add it with a number in another file...atleast I hope.'
- num1 = int(raw_input('Let\'s get a first number: '))
- num2 = int(raw_input('and the second number: '))
- print 'Ok, they were %s and %s' % (num1,num2)
- print 'Alright, let\'s open up \'%s\', and write %s to it, then %s to \'%s\'' % (arg1,num1,num2,arg2)
- print add(num1,num2)
- #turn to string to write to file
- f = str(num1)
- s = str(num2)
- write(arg1,f)
- write(arg2,s)
- #close files
- file1.close()
- file2.close()
- print 'alright, they\'re written..and closed to make sure they\'re not still in buffer'
- print 'so now we\'ll reopen them and print out the result of whatever was in the file'
- print 'Does the file exist? %s' % exists(arg1)
- print 'And the other one? %s' % exists(arg2)
- result = raw_input('Where do you want the result saved to?: ')
- file3 = open(result,'w')
- print 'Ok, lets add\'em up'
- #read files, turn to string then write to result
- new_r = str(add(read(arg1),read(arg2)))
- write(result,new_r)
- print 'Alright, we\'ll copy the result to a new file then read it, to see if it all worked.'
- #write to new file then read answer
- new_f = raw_input('New file is called what? ')
- file4 = open(new_f,'w')
- copy(result,new_f)
- print 'And the result is~~~~ %s ' % open(new_f).readline()
- file1.close()
- file2.close()
- file3.close()
- file4.close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement