[Image-SIG] assigning commands to a variable
Chris Cogdon
chris at cogdon.org
Tue Aug 24 17:33:35 CEST 2004
On Aug 24, 2004, at 08:16, francesco wrote:
> Hi,
> is it possible to assign a string to a variable and then make python
> understand that it is not just text but a command?
>
> The actual problem is that I want to use the PIL filters, which are
> called
>
> <myimage>.filter(ImageFilter.<filter_type>)
>
> filter_type can be a number of different filter types, like for
> example "BLUR" or "SMOOTH".
> My user chooses the filter type and then I have to put it in the
> function
>
> a = "BLUR"
> and then
>
> <myimage>.filter(ImageFilter.a)
>
> but of course that does not work, as "a" is not recognized as a
> ImageFilter module and also assigning
>
> a = "ImageFilter.BLUR"
>
> does not work. Is there a trick? (I am obviously not an ace as
> programmer)
try using getattr.
<myimage>.filter( getattr ( ImageFilter, a ) )
--
("`-/")_.-'"``-._ Chris Cogdon <chris at cogdon.org>
. . `; -._ )-;-,_`)
(v_,)' _ )`-.\ ``-'
_.- _..-_/ / ((.'
((,.-' ((,/ fL
More information about the Image-SIG
mailing list