Skip to content

Instantly share code, notes, and snippets.

@dalaing
Created February 5, 2018 08:34
Show Gist options
  • Save dalaing/3ebda19719ad3e701df1f10bf7c18363 to your computer and use it in GitHub Desktop.
Save dalaing/3ebda19719ad3e701df1f10bf7c18363 to your computer and use it in GitHub Desktop.
def writeFile(filename, contents):
with open(filename, "w") as f:
f.write(contents)
def readFile(filename):
contents = ""
with open(filename, "r") as f:
contents = f.read()
return contents
def p1():
file = "/tmp/file"
writeFile(file, "abcdef")
x = readFile(file)
print(x)
writeFile(file, "ghijkl")
y = readFile(file)
print (x + y)
def p2():
file = "/tmp/file"
expr = readFile(file)
writeFile(file, "abcdef")
x = expr
print(x)
writeFile(file, "ghijkl")
y = expr
print (x + y)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment