Importando clase en GAE (Python)

I know it's a very dumb question. And it's all about the very basics. But unfortunately I'm very very short on time and can't read a Python book right now.

I have this issue. Well in GAE you a root script.

And I have two classes which are stored in: htmlparser/HTMLParser htmlParser/BfsHTMLParser

And I cannot import them into

¿Qué estoy haciendo mal?

Estoy haciendo:

import htmlparser

But I catch:

NameError: global name 'BfsHTMLParser' is not defined

Would appreciate any help. Thank you.

p.s. I would also appreciate any book advice about Python basics like this :)

preguntado el 01 de febrero de 12 a las 14:02

También probé import htmlparser.BfsHTMLParser — i get NameError: global name 'BfsHTMLParser' is not defined -

3 Respuestas

from htmlparser import HTMLParser, BfsHTMLParser

Editar I'm afraid this is really basic Python stuff, and you aren't going to get far without reading a Python tutorial. Python is not Java, and the problem here is that you've imported the modules, but not the classes - in Python they are not the same thing.

If you've got classes named the same as the module files, now that you've imported the modules, you will need to instantiate them via HTMLParser.HTMLParser or BfsHTMLParser.BfsHtmlParser. Of course, really you shouldn't package classes like that, but that's the situation you have.

Respondido 01 Feb 12, 22:02

Thank you!But now I catch TypeError: 'module' object is not callable - momijigari

thanks. But how should a package classes? I'm used to this logical hierarchy from ActionScript and Java, yes. And I have a freedom to package them in other way. - momijigari

Tienes un in the htmlparser directory ??

Respondido 01 Feb 12, 22:02

No-o-o :) But what should it contain? - momijigari

Try just a blank file to start with - Richard Green

I get then line 58, in get parser = BfsHTMLParser() TypeError: 'module' object is not callable - momijigari

Ok, currently I switched to BeautifulSoup Put the BeatifulSoup in the root and it's working.

But still the question of packaging logical code blocks remains open.

Respondido 02 Feb 12, 20:02

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.