[Zope] Composing variables
    Jo Meder 
    jo at meder.de
       
    Fri Jul 29 12:10:45 EDT 2005
    
    
  
Am 29.07.2005, 18:02 Uhr
	schryb Cristi Barladeanu <kristache at gmail.com>:
> An example written in PHP:
> 
> $alternative = "bar";
> $foo_bar = "content based on bar";
> echo ${"foo_".$alternative} 
same in a Python-Skript:
------------------------------------------------------------------
foo = {"bar": "content based on bar",
       "baz": "content based on baz",
      }
alternative = "bar"
print foo[alternative]
------------------------------------------------------------------
or, if foo_bar and foo_baz are attributes in your current context:
------------------------------------------------------------------
alternative = "bar"
print getattr(context, "foo_%s"%alternative)
------------------------------------------------------------------
HTH
	Jo.
-- 
internetmanufaktur jo----------------------------- Berlin, Germany
  |||||||||||||||meder-------------------fon: ++49-30-417 17 63 33
http://www.meder.de/ ------------------- fax: ++49-30-417 17 63 45
Kollwitzstr. 75 ------------------------ mob: ++49-170- 2 98 89 97
10435 Berlin ---------------http://www.meder.de/keys/jo-pubkey.txt
    
    
More information about the Zope
mailing list