0

I create a python function in a file and filename is ifunc.py

def func():
    print('print something')

I have my main program in another file like this:

import ifunc

inputFlag = input('input something:')

if inputFlag == 1:
    ifunc.func()

and this produce nothing, but when I try to import the function outside the if statement like:

import ifunc
ifunc.func()

the print message print something will show up.

So how could I make the print message show up when the called function inside the if statement?

Please give me some advice. Thanks in advance!

Community
  • 1
  • 1
weeshin
  • 25
  • 1
  • 5
  • Cannot reproduce your issue. If you have created a minimal example of your problem, pleases add some additional detail that reflects your actual problem. And please verify that the simplified example you have posted *does indeed* cause the issue you describe – sshashank124 Jan 14 '20 at 04:54
  • @sshashank124 sorry for the misleading example, I found the problem is actually caused by the `input()` function, I have edited my post. – weeshin Jan 14 '20 at 05:04
  • @XinWang Check out the solution :-) – Vaibhav Jadhav Jan 14 '20 at 05:05

1 Answers1

1

You should change the below statement in main code:

The input you are taking is as a string. And if statement checks value of inputFlag to be 1 which is int and not string.

inputFlag = int(input('input something:'))
Vaibhav Jadhav
  • 2,000
  • 1
  • 5
  • 19