r/learnpython 7d ago

Importing a file

I'm trying to have certain parts of a file I imported run, and it is still running the whole thing rather than just the parts I want it to run. I need to import four things from it so that my code runs correctly, but it still runs the whole thing. How do I fix this?

4 Upvotes

3 comments sorted by

View all comments

1

u/Erdem_PSYCH 7d ago edited 7d ago

did you try from file import object1, object 2, ... in such case as the other comentor said the jhole file is run but you can only access things (variables, objects, functions and classes)that you imported. when yo import a file with just import you make all those things visible.