2

I've searched around other threads with similar questions, but I'm not finding the answer. Basically, I have a class:

import Android_Class

class Android_Revision(object):

    def __init__(self):
        # dict for storing the classes in this revision
        # (format {name : classObject}):
        self.Classes = {}
        self.WorkingClass = Android_Class()
        self.RevisionNumber = ''

    def __call__(self):  
        print "Called"

    def make_Class(self, name):
        newClass = Android_Class(name)
        self.Classes.update({name : newClass})
        self.WorkingClass = newClass

    def set_Class(self, name):
        if not(self.Classes.has_key(name)):
            newClass = Android_Class(name)
            self.Classes.update({name : newClass})
        self.WorkingClass = self.Classes.get(name)

I'm trying to make an instance of this class:

Revision = Android_Revision()

and that's when I'm getting the error. I'm confused because I have another situation where I'm doing almost the exact same thing, and it's working fine. I can't figure out what differences between the two would lead to this error. Thanks.

2
  • Android_Class is the name of a module. Are you sure you didn't mean to write from Android_Class import Android_Class or something similar? Commented Oct 8, 2012 at 3:30
  • What is the exact content (message) of the error? Which line does it reference? What does the "almost the exact same thing" look like? Commented Oct 8, 2012 at 3:30

1 Answer 1

3

I second the comments, this question lacks important information, and if this error wasn't insanely common and had rather distinctive symptoms, I wouldn't be able to provide anything resembling an answer.

Python's view on {files,modules} and classes is quite different from Java's. A module is a higher-level unit of organization than classes. Specifically, a module may contain any number of classes (among numerous other things). import deals with modules, not with classes. import foo gives you the module of that name, regardless of any classes of that name. If you must have a class in a module of the same name (quite often, this is a sign of overusing classes or ignoring modules as unit of organization), you either access it as Foo.Foo or you do from Foo import Foo.

By the way, module names should be lower_case while class names should be PascalCase. Don't mix the two. Also read PEP 8 for other conventions.

Sign up to request clarification or add additional context in comments.

1 Comment

Ah, I'm sorry for asking such a stupid question. My problems definitely came from thinking of classes/modules in a Java context, and your simple explanation was super helpful. I fixed the issue.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.