tkFileDialog question
Gabriel Genellina
gagsl-py2 at yahoo.com.ar
Sun Nov 15 21:56:18 EST 2009
En Fri, 13 Nov 2009 11:32:37 -0300, Matt Mitchell
<mmitchell at transparent.com> escribió:
> answer = tkFileDialog.askdirectory()
>
> if answer is not '':
> #do stuff
Although it "reads well", this is *wrong*. You want != here, not the `is
not` operator.
if answer != '': ...
If you want to compare the *values* of two objects, to see if they are
equal or not, use == or !=.
If you want to compare *identity*, to see if two results refer to the very
same object or not, use `is` or `is not`
(In your example, it *may* appear to work, because CPython optimizes very
short strings like 'a' or '', but you should not rely on this optimization)
--
Gabriel Genellina
More information about the Python-list
mailing list