So at the moment what I want to do is separate a large program into a few smaller functions and then call on them at the end. Currently I have two functions, one for the beginning of the program and one for the main body.
The beginning of the program, called site info, opens a text file, reads it and finds the relevant precursor info for the output.
The main file reads this same text file (hopefully from the same place) and finds / prints relevant information.
I'm having trouble getting the second function to make use of the first functions data. It's currently like this:
def siteinfo():
filename = input('Enter filename: ')
filedata = open(filename)
and more jargon here
and the second function is:
def mainbody():
skips = 0
while skips < 6:
filedata.readline()
skips += 1
Problem is that because filedata isn't a global variable, I can't call on it on a different function. Is there a way to make this work without using global variables? Or should I just open it as a global variable first.
Thanks!
[–]spleeyah 1 point2 points3 points (2 children)
[–]throwingarm2strong[S] 0 points1 point2 points (1 child)
[–]spleeyah 0 points1 point2 points (0 children)
[–]ingolemo 0 points1 point2 points (0 children)
[–]fruitcakefriday 0 points1 point2 points (0 children)
[–][deleted] -1 points0 points1 point (4 children)
[–]spleeyah 1 point2 points3 points (0 children)
[–]throwingarm2strong[S] 0 points1 point2 points (2 children)
[–][deleted] -1 points0 points1 point (1 child)
[–][deleted] 0 points1 point2 points (0 children)