-1

I have a.py :

   Class boxfinitestatemachine(models):
   ..... 
       @transistion...
       def hello(self):
           Print happy
       ....
       @transostion..
       def bye(self):
           Print sad
        ....

Normally this would get run as : press F5 & in shell window, give commands as:

        >>>State= boxfinitestatemachine()      #input
        >>> State.hello() #input
        >>> happy         #output
        >>> State.bye()  # input
        >>> Sad           #output

Now I have anothe file b.py, which includes FOR loop function as:

         For I in range 2:

Now I require , if I==0, state.hello have to get executed & happy should be printed.

Similarly for I==1, state.bye should be executed & Sad should be printed.

How to perform this requirement. Any help pls.

  • Can you clarify what you are trying to do, *what you have tried to do that*, and what problem you have encountered? Your descriptions makes it seem like you want to do ``if I == 0: State.hello()``, which you can literally just do. Are you looking for ``import``? – MisterMiyagi Sep 01 '20 at 18:34
  • Does this answer your question? [Call a function from another file in Python](https://stackoverflow.com/questions/20309456/call-a-function-from-another-file-in-python) –  Sep 01 '20 at 18:35
  • a.py actually do finitestatemachine transition function. If I execute in order state.sad first, transition error will be thrown as per defined transistion state in script & as well should be thrown error in my end test application as wel... so in another file b.py, I have permutations list (0,1),(1,0).. so will invoke first list( 0,1) & check the the flow.. – T.D. Nathan Sep 01 '20 at 18:52
  • Suggested link doesn't help. Actually I ahve referred it earlier. But here a.py is finitestatemachine transition.. the defined function will be called in terminal as mentioned above. – T.D. Nathan Sep 01 '20 at 18:53

1 Answers1

0

You can import the boxfinboxfinitestatemachine on the file b, and use as you used on terminal.

from fileA import boxfinboxfinitestatemachine

State = boxfinboxfinitestatemachine()
for i in range 2:
  if(i == 0):
    State.hello()
  if(i == 1):
    State.bye()