[Zope] Convert URL to object

Phil Harris phil@wigwamweb.net
Mon, 1 Nov 1999 10:43:34 -0000


OK try this,

def urlToObject(self,url=None):
	from string import replace 
	url=replace(url,'/','.')
	return eval("self.%s()" %url)

which should be called by something like this:

<dtml-var "urlToObject(url='tt_xml/index_html')">

However, this doesn't seem to work quite as you might expect.

There must be a better way.

Hmmm

Phil
phil@WigWamWeb.net

-----Original Message-----
From: itamar@localhost.localdomain
[mailto:itamar@localhost.localdomain]On Behalf Of Itamar Shtull-Trauring
Sent: Monday, November 01, 1999 10:17 AM
Cc: zope@zope.org
Subject: Re: [Zope] Convert URL to object


Phil Harris wrote:

> Well I have done this with an external method.

Okay, I have an external method:

def urlToobject(url=None):
	from string import replace 
	replace(url,'/','.')
	return eval(url)

I get a Error Type: NameError
        Error Value: QuickStart

when I give QuickStart as the url (urlToobject('QuickStart')) where my dtml
method is at the top level.  And QuickStart does exist, of course.

_______________________________________________
Zope maillist  -  Zope@zope.org
http://www.zope.org/mailman/listinfo/zope

(Related lists - please, no cross posts or HTML encoding!

To receive general Zope announcements, see:
http://www.zope.org/mailman/listinfo/zope-announce

For developer-specific issues, zope-dev@zope.org -
http://www.zope.org/mailman/listinfo/zope-dev )