[Zope] Re: Re: [Zope] Problem with _[xyz]

2000-07-12 Thread Jason Byron

In response to:

> 
> 

Martijn Pieters wrote:

> You want to split this name up at the dots, 
> and ask the namespace for each part 
> individually, like 
> _['top']['German']['ActualPages'].
> 
> Now, using a variable, this is going to be 
> a bit more tricky.

I can't get this to work using a variable. 
Can you give an example of this where the 
variable is a string? 

Also, I'd like to use PARENTS[].  Will that 
be a problem too?

Thanks, 
Jason









__
Do You Yahoo!?
Get Yahoo! Mail – Free email you can access from anywhere!
http://mail.yahoo.com/

___
Zope maillist  -  [EMAIL PROTECTED]
http://lists.zope.org/mailman/listinfo/zope
**   No cross posts or HTML encoding!  **
(Related lists - 
 http://lists.zope.org/mailman/listinfo/zope-announce
 http://lists.zope.org/mailman/listinfo/zope-dev )




Re: [Zope] Problem with _[xyz]

2000-07-07 Thread Martijn Pieters

On Fri, Jul 07, 2000 at 07:12:26PM +0200, Christian Zagrodnick wrote:
> shouldn't  and  return the same result?
> 
> Well - I don't know why but only the 1st is working.
> (top.German.ActualPages is a folder; tThisIs... is a dtml-method)
> 
> 1:
> 
> 
> 
> 
> 
> 2:
> 
> 
> 
> 
> 
> Of course I want to replace the 'top.German.ActualPages' with a variable...
> but since it doesn't work with a hardcoded string it'll not work with a
> variable.

Two things wrong here:

1.  is not the same as  if xyz is
   callable!  (or ) however is. 
   
   _[] will call the identified object if it can be. You can use
   _.getitem('xyz', 0) (or just plain _.getitem('xyz')) to get an item without
   calling it. Calling _.getitem('xyz', 1) (second argument 'true') is the
   same as _['xyz'] and  again.

2. top.German.ActualPages is a Python expression meaning "The 'ActualPages'
   object in the 'German' object inside the 'top' object. The '.' operator
   signifies containment or membership.

   _['top.German.ActualPages'] however, means "The 'top.German.ActualPages'
   object", where the dots are part of the identifier. You want to split this
   name up at the dots, and ask the namespace for each part individually, like
   _['top']['German']['ActualPages'].

Now, using a variable, this is going to be a bit more tricky. If it is all the
same to you, you may want to change such an object pointer to use '/' instead
of '.' as an object delimiter, and use the new Zope 2.2.0 Traversal interface
for this. If you have to, you use _.string.replace to replace all dots with
slashes on the spot. For this interface, see:

  http://www.zope.org/Members/michel/Projects/Interfaces/Traversal

Note that this interface is restricted to Product and External Method access
only! You will have to create yourself a Eternal Method in this case:

import string

getObject(self, id):
if string.find(id, '.'): id = string.split(id, '.')
return self.restrictedTraverse(id)

The above method will support id's with both dots and slashes, but not id's
that have a '.' in them (like 'image.gif').

Use this method then like this:

  

  

-- 
Martijn Pieters
| Software Engineermailto:[EMAIL PROTECTED]
| Digital Creations  http://www.digicool.com/
| Creators of Zope   http://www.zope.org/
| ZopeStudio: http://www.zope.org/Products/ZopeStudio
-

___
Zope maillist  -  [EMAIL PROTECTED]
http://lists.zope.org/mailman/listinfo/zope
**   No cross posts or HTML encoding!  **
(Related lists - 
 http://lists.zope.org/mailman/listinfo/zope-announce
 http://lists.zope.org/mailman/listinfo/zope-dev )




Re: [Zope] Problem with _[xyz]

2000-07-07 Thread Jim Washington

Hi, Christian

Christian Zagrodnick wrote:
> 
> Hi all,
> 
> shouldn't  and  return the same result?

if xyz is a simple variable, yes.
 
> Well - I don't know why but only the 1st is working.
> (top.German.ActualPages is a folder; tThisIs... is a dtml-method)
> 
> 1:
> 
> 
> 
> 
> 2:
> 
> 
> 

I may be wrong on this, but if the dots indicate subobjects, you may
want to do this

as Python sequence syntax: "_['top']['German']['ActualPages']"

or as "_['top'][aLanguage]['ActualPages']" assuming aLanguage is a
variable which may be e.g., 'German'

I hope this is a helpful hint.

-- Jim Washington
 
> Of course I want to replace the 'top.German.ActualPages' with a variable...
> but since it doesn't work with a hardcoded string it'll not work with a
> variable.
> 
> Any hint?
> 
> Thanks

___
Zope maillist  -  [EMAIL PROTECTED]
http://lists.zope.org/mailman/listinfo/zope
**   No cross posts or HTML encoding!  **
(Related lists - 
 http://lists.zope.org/mailman/listinfo/zope-announce
 http://lists.zope.org/mailman/listinfo/zope-dev )




[Zope] Problem with _[xyz]

2000-07-07 Thread Christian Zagrodnick

Hi all,


shouldn't  and  return the same result?

Well - I don't know why but only the 1st is working.
(top.German.ActualPages is a folder; tThisIs... is a dtml-method)

1:





2:





Of course I want to replace the 'top.German.ActualPages' with a variable...
but since it doesn't work with a hardcoded string it'll not work with a
variable.

Any hint?

Thanks


-- 
Christian Zagrodnick - Progressive Media Production
http://www.promp.de/   

Die Haftung ist auf das Gesellschaftsvermoegen beschraenkt.

___
Zope maillist  -  [EMAIL PROTECTED]
http://lists.zope.org/mailman/listinfo/zope
**   No cross posts or HTML encoding!  **
(Related lists - 
 http://lists.zope.org/mailman/listinfo/zope-announce
 http://lists.zope.org/mailman/listinfo/zope-dev )