Assume I have a file of the following format:
a,1
b,2
c,3
d,4
Here is my code:
def junk(f):
d1 = {}
d2 = {}
for line in f:
columns = line.split(":")
letters = columns[1]
numbers = columns[2]
d1[letters] = numbers
d2[numbers] = letters
return (d1, d2)
def something():
print d1
print d2
if __name__ == "__main__":
f = open("filename.txt")
d1 = junk(f)[0]
d2 = junk(f)[1]
Assume I want to call function something. It cannot print d1 and d2 unless I add them to the main block. As soon as I add d1 and d2 to the "main" block and call either of the two functions, both return two empty dictionaries. Why does this happen? How can I fix it? Please help!