Global Variable in Python

前端 未结 2 1231
说谎
说谎 2020-12-21 06:30

I am very new to Python. Not learnt classes yet. Using Python 3.2.2. Tried implement some procedural C logic. My code is spread over 2 files as follows.

this file i

2条回答
  •  臣服心动
    2020-12-21 07:15

    Your date.isValidDate function does not operate on the globalvariables dd, mm, yy - it rather operates on (function) local variables with the same names.

    In order for date.isValidDate to change the (module) global values of the variables you want, you have to declare them as global at the top of the function - like this:

    def isValidDate(d,m,y):
        global dd, mm, yy
        ...
    

提交回复
热议问题