Hi, I am fairly new to Python. I am familiar with the concept to pass data accross functions.
In theory,
def c():
r = raw_input("Ask Something? ")
..
return r
def p(x):
...
do something
r = c()
p(r)
The code below works just fine via Terminal ( python filename.py file.txt ), but I want to add workflow where a variable stores the path to the file and passes it to the function ( processFile ). I just cant get the data / value passed to the function.
This is the code I am trying to edit :
def registerException(exc):
exceptions[exc] += 1
def processFile(x):
with open(x, "r") as fh:
currentMatch = None
lastLine = None
addNextLine = False
for line in fh.readlines():
if addNextLine and currentMatch != None:
addNextLine = False
currentMatch += line
continue
match = REGEX.search(line) != None
if match and currentMatch != None:
currentMatch += line
elif match:
currentMatch = lastLine + line
else:
if currentMatch != None:
registerException(currentMatch)
currentMatch = None
lastLine = line
addNextLine = CONT.search(line) != None
# If last line in file was a stack trace
if currentMatch != None:
registerException(currentMatch)
for f in sys.argv[1:]:
processFile(f)
for item in sorted(exceptions.items(), key=lambda e: e[1], reverse=True):
print item[1], ":", item[0]
It doesnt matter if I declare the variable as Global or local. Could someone please help me solve this issue?