-4

I have several function writen, and when i want to call it, i get problem like (something in first function) is not defined

def func1():

def func2():

def func3():

main()
    print("something")
    def func1():
    def func2():
    def func3():
    print("something")

if __name__ == '__main__':
    main()

func1: reading file and give him variables ( reading mode)
func2: new inputs
func3: opening file for writing, write old variable from func1 and write new inputs from fun2.

Problem is variable (from func1) is not defined.

It works until need to write new inputs and old variable. File are cleared after last inputs popup.

NameError: name 'oldNamestaj' is not defined

oldNamestaj is that variable in func1.

CristiC
  • 22,068
  • 12
  • 57
  • 89
XpreSS
  • 57
  • 5
  • 3
    Please try an introductory Python tutorial. Most of your code has syntax (crucial, Python cannot even interpret the file) errors. All of this is explained if you learn how to write Python functions through a tutorial, such as here: https://docs.python.org/2/tutorial/ – Alex Huszagh Dec 05 '15 at 18:54
  • Possible duplicate of [Using global variables in a function other than the one that created them](http://stackoverflow.com/questions/423379/using-global-variables-in-a-function-other-than-the-one-that-created-them) – Jim K Dec 05 '15 at 20:14
  • If I understand correctly, the error occurs in func2. I flagged as duplicate based on this assumption. It would be helpful to see the line that causes the error. Maybe it looks like `x = oldNamestaj`. – Jim K Dec 05 '15 at 20:21

1 Answers1

0

There are a few syntax problems with your code. First, you need to define main. Second, when executing functions, you do not need to include the colon. Also, your functions were empty, so I put a simple print command in them so I could see if the code was working properly. Below, you will see the edited code:

     ***
     def func1():
         print("something")
     def func2():
         print("something")
     def func3():
         print("something")
     def main():
         print("something")
         func1()
         func2()
         func3()
         print("something")

     if __name__ == '__main__':
         main()

Which gives the following output:

     ***
     something
     something
     something
     something
     something
     ***

This is because the function main will print "something" once. Then function 1, then 2, then 3, and then there is one final print statement in main, which results in 5 "somethings" printed to the console.

I hope this helps.