[Tutor] classes & required method not working

Roeland Rengelink roeland.rengelink at chello.nl
Wed Jun 23 19:40:51 EDT 2004


Dave S wrote:
> I have a class problem. I have a script, ggScanStock.py which defines a 
> class ScanData :
> 
> #!/usr/bin/env python
> 
> """
> AnalizeClass
> """
> 
> import os,ggdatacore3
> 
> class ScanData:

<snip code>

> ggpcprofit.py
> 
> #!/usr/bin/env python
> 
> import os,ggScanStock
> 
> class pcprofit(ScanData):

<snip more code>


> However when I try & execute ggpcprofit.py I get :
> 
> bash-2.05b$ ./ggpcprofit.py
> Traceback (most recent call last):
>  File "./ggpcprofit.py", line 5, in ?
>    class pcprofit(ScanData):
> NameError: name 'ScanData' is not defined
> bash-2.05b$
> 
> Can anyone explain where I am going wrong - I imported ggScanStock so 
> why cant my class pcprofit
> find class ScanData ?
> 

You should use:

class pcprofit(ggScanStock.ScanData):
     ...

i.e.: the object ScanData from the module ggScanStock

import amodule, does not import the objects defined in 'amodule' in your 
module. It creates them in 'amodule' and you can access them using the 
dot-notation

Hope this help,

Roeland
--
Author of PyORQ (http://pyorq.sourceforge.net), an Object-Relational 
binding that lets you write queries as Python expression

'half of what I say is nonsense, unfortunately I don't know which half'



More information about the Tutor mailing list