Class not loading properly in CGI

T

Tom Chance

Hullo,

I've got a very, very odd problem here which I can't seem to solve. I'm
creating a class instance in a CGI script, but that instance isn't
inheriting all of the methods associated with that file. Confused? Here's
what I mean:

the commands to check:
import db
mydb = db.mySQL()
print str(dir(mydb))

done in a python shell on my machine:
"['__doc__', '__init__', '__module__', 'connectTime', 'cursor', 'delete',
'fetchRow', 'fetchRows', 'info', 'insert', 'mysql', 'update']"

in the cgi script online:
['connectTime', 'cursor', 'mysql']

What on earth is going on?

Tom
 
J

Jp Calderone

Hullo,

I've got a very, very odd problem here which I can't seem to solve. I'm
creating a class instance in a CGI script, but that instance isn't
inheriting all of the methods associated with that file. Confused? Here's
what I mean:

the commands to check:
import db
mydb = db.mySQL()
print str(dir(mydb))

done in a python shell on my machine:
"['__doc__', '__init__', '__module__', 'connectTime', 'cursor', 'delete',
'fetchRow', 'fetchRows', 'info', 'insert', 'mysql', 'update']"

in the cgi script online:
['connectTime', 'cursor', 'mysql']

What on earth is going on?

Try printing db.__file__

Jp
 
T

Tom Chance

Jp said:
I've got a very, very odd problem here which I can't seem to solve. I'm
creating a class instance in a CGI script, but that instance isn't
inheriting all of the methods associated with that file. Confused? Here's
what I mean:

the commands to check:
import db
mydb = db.mySQL()
print str(dir(mydb))

done in a python shell on my machine:
"['__doc__', '__init__', '__module__', 'connectTime', 'cursor', 'delete',
'fetchRow', 'fetchRows', 'info', 'insert', 'mysql', 'update']"

in the cgi script online:
['connectTime', 'cursor', 'mysql']

What on earth is going on?

Try printing db.__file__

That shows the correct .py file. Doing a dir() operation on the imported
class itself looks fine though:

db.mySQL (class) : ['__doc__', '__init__', '__module__', 'delete',
'fetchRow', 'fetchRows', 'info', 'insert', 'update']

mydb (class instance) : ['connectTime', 'cursor', 'mysql']

Tom
 
J

Jp Calderone

One further note of interest:

Python version: 1.5.2

Ah. This explains it. In 1.5.2, dir() did not return class attributes,
only instance attributes. The missing methods are still usable, you just
won't see them without examining mydb.__class__.

Jp
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,171
Messages
2,570,933
Members
47,472
Latest member
KarissaBor

Latest Threads

Top