Re: [Zope3-Users] Convert from string to class

2006-01-18 Thread Adam Groszer
Hello Florian,

There is a full-blow method for that in
src\zope\configuration\config.py in the class ConfigurationContext
called resolve.

Tuesday, January 17, 2006, 11:10:12 PM, you wrote:

 Hello,
 I've a string like zope.app.folder.Folder and I want to get the class
 zope.app.folder.Folder from this string. How can I do that?
 It's probably more a python problem that Zope... but I hope you excuse.


 Thanks,

 Florian
 ___
 Zope3-users mailing list
 Zope3-users@zope.org
 http://mail.zope.org/mailman/listinfo/zope3-users 


-- 
Best regards,
 Adammailto:[EMAIL PROTECTED]
--
Quote of the day:
Only a Christ could have conceived a Christ. 
- Joseph Parker 

___
Zope3-users mailing list
Zope3-users@zope.org
http://mail.zope.org/mailman/listinfo/zope3-users


Re: [Zope3-Users] Convert from string to class

2006-01-18 Thread Dominik Huber

Florian Lindner wrote:


Hello,
I've a string like zope.app.folder.Folder and I want to get the class 
zope.app.folder.Folder from this string. How can I do that?

It's probably more a python problem that Zope... but I hope you excuse.


another implementation ;)
zope.dottedname.resolve.resolve

regards,
dominik

___
Zope3-users mailing list
Zope3-users@zope.org
http://mail.zope.org/mailman/listinfo/zope3-users


[Zope3-Users] Convert from string to class

2006-01-17 Thread Florian Lindner
Hello,
I've a string like zope.app.folder.Folder and I want to get the class 
zope.app.folder.Folder from this string. How can I do that?
It's probably more a python problem that Zope... but I hope you excuse.


Thanks,

Florian
___
Zope3-users mailing list
Zope3-users@zope.org
http://mail.zope.org/mailman/listinfo/zope3-users


Re: [Zope3-Users] Convert from string to class

2006-01-17 Thread Marc Rijken

Hi Florian,

This function will do the job:

def translateDottedName(i):
   names = i.split('.')
  
   module = __import__('.'.join(names[:-1]), {}, {}, ['*'])

   return getattr(module, names[-1])

Marc


Florian Lindner wrote:


Hello,
I've a string like zope.app.folder.Folder and I want to get the class 
zope.app.folder.Folder from this string. How can I do that?

It's probably more a python problem that Zope... but I hope you excuse.


Thanks,

Florian
___
Zope3-users mailing list
Zope3-users@zope.org
http://mail.zope.org/mailman/listinfo/zope3-users

 



___
Zope3-users mailing list
Zope3-users@zope.org
http://mail.zope.org/mailman/listinfo/zope3-users


Re: [Zope3-Users] Convert from string to class

2006-01-17 Thread Gary Poster


On Jan 17, 2006, at 5:10 PM, Florian Lindner wrote:


Hello,
I've a string like zope.app.folder.Folder and I want to get the  
class

zope.app.folder.Folder from this string. How can I do that?
It's probably more a python problem that Zope... but I hope you  
excuse.


Was just rewriting this for myself, as a matter of fact--something I  
need now and then.  This is today's spelling:


 def getImport(s):
... try:
... return __import__(s, globals(), {}, ['ignored'])
... except ImportError:
... elements = s.split('.')
... last = elements.pop()
... mod = '.'.join(elements)
... mod_obj = __import__(mod, globals(), {}, [last])
... return getattr(mod_obj, last)
...
 getImport('xml.sax.saxutils.unescape')
function unescape at 0x28b630
 getImport('xml.sax.saxutils')
module 'xml.sax.saxutils' from '/Library/Frameworks/Python.framework/ 
Versions/2.4/lib/python2.4/xml/sax/saxutils.pyc'


Could be refined a bit, but that's the idea.

Gary
___
Zope3-users mailing list
Zope3-users@zope.org
http://mail.zope.org/mailman/listinfo/zope3-users


Re: [Zope3-Users] Convert from string to class

2006-01-17 Thread Markus Leist
Hello,
what about:
http://www.talkaboutprogramming.com/group/comp.lang.python/messages/318370.html

Markus


17.01.2006 23:10, Florian Lindner:
 Hello,
 I've a string like zope.app.folder.Folder and I want to get the class
 zope.app.folder.Folder from this string. How can I do that?
 It's probably more a python problem that Zope... but I hope you excuse.


 Thanks,

 Florian
 ___
 Zope3-users mailing list
 Zope3-users@zope.org
 http://mail.zope.org/mailman/listinfo/zope3-users
___
Zope3-users mailing list
Zope3-users@zope.org
http://mail.zope.org/mailman/listinfo/zope3-users