0

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

3
Contributors
2
Replies
3
Views
8 Years
Discussion Span
Last Post by jlm699
0

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.

0

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

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.