1

I would like to know how to call one global variable with two different values in a class and call them in the other class (within which behave such as flags).

in SerialP.py

Class SerialP(object):
    def ReceiveFrame (self, data, length):
        global myvariable

        if x:
            myvariable = 1:
        elif y:
            myvariable = 2

in fmMain.py

Class fmMain:
    def OnReadConfig(self, event):
        if SerialP.myvariable = 1:
            #do this task
        if SerialP.myvariable = 2:
            #do another task
3
  • 1
    Equality check is with ==, not with =. Apart from that (and messy indentation), your code looks okay. What problems are you experiencing? Of course you need to call that method to create the variable first... Commented Feb 25, 2016 at 17:09
  • Possible duplicate of Python - How to make a local variable (inside a function) global Commented Feb 25, 2016 at 17:09
  • The indentation of your code is incorrect. Commented Feb 25, 2016 at 17:10

1 Answer 1

1

There are a few issues with your code.
First, comparison is done with == and not with = which is used for assignment. Also, you have not included the import statement which might be misleading.

In fmMain.py

import SerialP  # and not from SerialP import SerialP

Class fmMain:
    def OnReadConfig(self, event):
      if SerialP.myvariable == 1:  # changed to ==
          #do this task
      if SerialP.myvariable == 2:  # changed to ==
          #do another task
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.