[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.python

Re: Class context execution problems

Gabriel Genellina

3/6/2008 7:46:00 PM

En Thu, 06 Mar 2008 11:04:26 -0200, Marcelo de Moraes Serpa
<celoserpa@gmail.com> escribi�:

> I'm using a class in a conext other than the subpackage in which it is
> located and I'm getting template lookup errors.
>
> This class expects to find a .pt file in a directory relative to its
> package. However, this class is normally used by other classes in the
> same
> namespace.
>
> class ObjectWidget:
> template = "templates/objectwidget.pt"
>
> However, I needed to import this class (ObjectWidget) from a class
> outside
> its namespace(package). Now, I think the class is running in the context
> of
> the file that is using it and so, the
> the class not finding the .pt file (I think becouse the class file is
> being
> contextualized to the currently running one which is outside the browser
> subpackage)

No, it's not. The globals() (i.e., the "context") are of the imported
module itself, not of the caller. The error probably lies on how that
template attribute is converted into a full path; post that code.
As an example, this is a rather safe way, even if the program uses
os.chdir():

basepath = os.path.abspath(os.path.dirname(__file__))

class ObjectWidget:
template = "templates/objectwidget.pt"

def open(self):
fn = os.path.join(basepath, template)
print fn

--
Gabriel Genellina

1 Answer

pmwolf

2/17/2011 10:37:00 PM

0

Black Rose isn't a BAD game....but this one isn't close.

Shadow is a far, far better game.