Sanky Cse
Sanky Cse

Reputation: 171

how to call a python script inside another python script where both in the same directory?

i have two script--script1.py and script2.py. Now i want to call script1.py with in script2.py. algo will be like this--

IF condition: run script1.py #through command line ELSE : exit

Upvotes: 3

Views: 320

Answers (1)

alecxe
alecxe

Reputation: 473803

In script1.py place this:

def main():
    do something

if __name__ == "__main__":
    main()

In script2.py:

import script1

if condition:
    script1.main()

Upvotes: 2

Related Questions