Hey I'm new here registered today.
I've been trying to import some definitions from other .py files in the same folder, but for some reason IDLE wont recognize/ import them and keeps telling me they arent defined.
I have tried From file import *
and was wondering if my syntax is wrong?
Its been a while since ive used python but im pretty sure thats what I used last and it worked fine.

any help would be greatly appreciated

Recommended Answers

All 2 Replies

What exactly is the filename of the file you're trying to import? It shouldn't be "file" because that's already a reserved word in Python, so it'll cause problems. And you wrote "From", yet it should be all lowercase ("from"). Drop the .py extension of whatever file you're importing too, so if I wanted to import "otherfile.py", I'd do it like so:

# keeps all aspects of otherfile accessible only by calling them through otherfile, such as: otherfile.myvariable
import otherfile
# OR
# imports everything from otherfile directly into the current file
from otherfile import *

Hope that cleared it up.

Also keep in mind that idle may not be running in the same working directory as your script. Check that wish os.getcwd()

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.