Skip to content Skip to sidebar Skip to footer

Why Does This Python Method Gives An Error Saying Global Name Not Defined?

I have a single code file for my Google App Engine project. This simple file has one class, and inside it a few methods. Why does this python method gives an error saying global na

Solution 1:

It's an instance method, you need to use self.gen_groups(...) and self.gen_albums(...).

Edit: I'm guessing the TypeError you are getting now is because you removed the 'self' argument from gen_groups(). You'll need to put it back in:

defget_groups(self, lines):
    ...

Solution 2:

You have to use it like this:

self.gen_groups(input)

There is not implicit "self" in Python.

Solution 3:

You need to call it explicitly with an instance:

groups = self.gen_groups(input)

Similarly for some of the other calls you're making in there, e.g. gen_album.

Also, see Knowing When to Use self and __init__ for more information.

Post a Comment for "Why Does This Python Method Gives An Error Saying Global Name Not Defined?"