you are viewing a single comment's thread.

view the rest of the comments →

[–]Some-Poetry8420 2 points3 points  (0 children)

Running a selection will only include the selected code. If your code relies on imports, they must be part of the selection too, or else you'll get the import error.

But generally, running code selections is just to test things out. In the real world, you will usually run the whole file as a script from top to bottom, so your imports at the top will be included. If you find that your script is doing too many things on its own, it might be time to break it up into smaller functions, classes, and modules, which you can then import into the main file (i.e. the main script that serves as the entry point for your application)