-1

sample_box.py

gr=0

class SampBoxLayout(BoxLayout):

    def input_rpm(self, instance, value):
        if value is True:
            global gr
            gr=22

pyth.py

from sample_box import gr

while(True):
    if(gr== '22'):
Ahmad Khan
  • 2,655
  • 19
  • 25
  • You're trying to pass a variable from one file to another. And? – Ahmad Khan Oct 29 '18 at 07:48
  • when i run pyth.py file then whole sample_box.py file run because i imported that file,i want to pass gr variable without running the sample_box file – Shailesh Pawar Oct 29 '18 at 07:54
  • Possible duplicate of [Pass variable between python scripts](https://stackoverflow.com/questions/16048237/pass-variable-between-python-scripts) – Boris Sokolov Oct 29 '18 at 07:58

1 Answers1

0

Try creating a constant instead of a normal variable:

GR = 0

and then import it:

import sample_box

To get the constant, use the syntax:

sample_box.GR

Add this to your code to prevent the import statement to run sample_box.py:

GR = 0
if __name__ == "__main__":
    # all your code that you don't want to run here
HUAN5235
  • 13
  • 4
  • im actually creating gui using kivy and for communication purpose i want some variable like gr and my app file is sample_box.py , so when i import sample_box into the pyth.py file it launches that because of the import i don't want that i want to just pass gr variable – Shailesh Pawar Oct 29 '18 at 08:04