[Tutor] Misc question about scoping
Emile van Sebille
emile at fenx.com
Fri Jun 4 00:21:45 CEST 2010
On 6/3/2010 8:50 AM Tino Dai said...
> Hi All,
>
> Is there a way to express this:
> isThumbnail = False
> if size == "thumbnail":
> isThumbnail = True
>
> like this:
> [ isThumbnail = True if size == "thumbnail" isThumbnail = False ]
> and the scoping extending to one level above without resorting to the
> global keyword?
If by 'extending one level above' you mean 'outside the current scope',
then yes if isThumbnail is mutable. ie, something like:
isThumbnail = [False]
# create scope
def inner(size):
isThumbnail[0] = bool(size == "thumbnail")
inner('not thumbnail')
print isThumbnail
inner('thumbnail')
print isThumbnail
More information about the Tutor
mailing list