I am trying to run a program with two files. file1 contains two classes and one line of code. When I run file1.pyfrom the command line the single line of code runs and calls one of the classes from this file. For file2.py to work it needs to use just one of the classes from file1.py. However no matter what method I use to import this class e.g from file1 import classA all that happens when I try to run file2.py is that it appears to execute all the code in file1.py including the single line, which then runs file1. In short I want access to just a single class from a separate file, not any of the other code. Is this possible?
I am trying to run a program with two files. file1 contains two classes
Share
This code will be executed only if your file was run, but not if your file was imported.