So I'm writing a small Blackjack game and divided a class up into 2 to keep everything tidy but keep getting this little error:
global name 'handle_input' is not defined
The code:
The class being called...

#File: handle_input.py

class handle_input:
...

The file defining the class...

#File: control.py

from card import *
from count import *
from handle_input import *

class control:
    def __init__(self):
        self.card_handle = card()
        self.count_handle = count()
        self.input_handle = handle_input() #<< This is the 'undefined' error

I use similar code else where and it works fine, however its not in a class. I'm thinking that might be contributing to the error but as you can see I'm defining other instances there (which aren't causing errors) so it can't be the problem.

Any comments appreciated,
S.

There doesn't seem to be an error. This kind of errors happen sometimes with IDE like idle when a module like 'handle_input' was previously loaded and then modified, but the modified version is not reloaded by idle.

However, since we don't know the context, I suggest for debugging that you replace from handle_input import * by from handle_input import handle_input . This way we can be sure that the global name handle_input exists.

Hm, now I'm getting
ImportError: cannot import name handle_input

What does that mean? Why can't it import it?

I'm pretty new to python so you'll have to excuse my ignorance :P

It means that there is no class nor function nor variable named 'handle_input' in the handle_input module :)

What? But there is, whats going on? Why doesn't python like me? :(
I have

from handle_input import *

input = handle_input()
input.get_command()

On another page and it works just fine

In fact there is another possibilty, if the handle_input module contains a statement like this

__all__ = [ "hello", "world" ]

then only the symbols "hello" and "world" can be imported

One thing you can try is this:

import handle_input
print handle_input.__file__

It will print you the path from where the handle_input module was imported. Make sure it's the path to your file

It reads handle_input.pyc Is that 'c' supposed to be there?

The rest of the location is as it should be.

ok , you can try to remove the .pyc file (it will reappear automatically)

Same thing is coming up :(

Anything else I can try?

hm, attach your module to a post may be ?

Attatched is the handle_input file, its a .txt because .py aren't accepted.

I think I found it: if control imports handle_input, then handle_input must not import control so remove the

from control import *

Thats it! :)

It had to be something simple :P

Thanks for your help, I greatly appreciate it :)

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.