[Zope] FQ Path Names in container
J Cameron Cooper
jccooper@jcameroncooper.com
Wed Aug 6 00:35:23 EDT 2003
>
>
>Then if we're accessing /D/script and returning 'container['C.pdf']' we'll
>return C.pdf(3); if we return 'container['A/B/C.pdf'] then we'll return
>C.pdf(2) (acquisition is a beautiful thing).
>
>However, returning 'container['A/B/C.pdf'] gives me a key error. This makes
>it rather difficult to access C.pdf(1).
>
>
Naturally. You're trying to access a thing called
ay-slash-be-slash-see-dot-pee-dee-eff. And it's not there.
If you want to get substructures in Python, you can do one of these things:
container.A.B.C # can't go to something with a dot in the name
container.A.B['C.pdf']
container['A']['B']['C.pdf']
container.restrictedTraverse('A/B/C.pdf')
Restricted traverse is probably the best way to deal with a variable
path, as you seem to have.
See also:
http://www.zopelabs.com/cookbook/1001104105
http://www.zopelabs.com/cookbook/1032051886
--jcc
More information about the Zope
mailing list