Skip to content

Commit

Permalink
ex18.py
Browse files Browse the repository at this point in the history
  • Loading branch information
tianyicui committed Oct 28, 2010
1 parent 4c66f2d commit 6dd7bd8
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 0 deletions.
23 changes: 23 additions & 0 deletions ex17.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
from sys import argv
from os.path import exists

script, from_file, to_file = argv

print "Copying from %s to %s" % (from_file, to_file)

# we could do these two on one line too, how?
input = open(from_file)
indata = input.read()

print "The input file is %d bytes long" % len(indata)

print "Does the output file exist? %r" % exists(to_file)
print "Ready, hit RETURN to continue, CTRL-C to abort."
raw_input()

output = open(to_file, 'w')
output.write(indata)

print "Alright, all done."

output.close()
23 changes: 23 additions & 0 deletions ex18.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# this one is like your scriptss with argv

def print_two(*args):
arg1, arg2 = args
print "arg1: %r, arg2: %r" % (arg1, arg2)

# of, that *args is actually pointless, we can just do this
def print_two_again(arg1, arg2):
print "arg1: %r, arg2: %r" % (arg1, arg2)

# this just takes one argument
def print_one(arg1):
print "arg1: %r" % arg1

# this one takes no arguments
def print_none():
print "I got nothin'."


print_two("Zed","Shaw")
print_two_again("Zed","Shaw")
print_one("First!")
print_none()

0 comments on commit 6dd7bd8

Please sign in to comment.