Edward Elliott wrote:
> Peter Otten wrote:
[snip]
>
> Now that is absolutely lovely. Looks like it's time to join the ranks of
> Perl and C with an Obfuscated Python Contest. ;)
>
yes, please! and you get special points for programs that seem to do one
thing but do something totally entirely
Peter Otten wrote:
class Int(object):
[snip]
> ... def __pos__(self):
> ... if self.half:
> ... self.value += 1
> ... self.half = not self.half
> ... return self
[snip]
i = Int()
which leads us to:
i
> 0
+i
> 0
[EMAIL PROTECTED] wrote:
> but when I input:
++i
> and the interpreter replies
> 0
>
> Don't you think it is misleading when you expect a variable to
> increment?
You have been warned...
$ cat pp.py
i = 42
++i
print i
--i
$ pychecker pp.py
Processing pp...
42
Warnings...
pp.py:2: Operato
>++i
>>
>>and the interpreter replies
>>0
>>
>>Don't you think it is misleading when you expect a variable to
>>increment?
>>
>
> Terribly. So stop expecting it to increment :)
>
> Seriously, --i is also valid Python. Both expressions apply two unary
> operators to a name. Would you have the
[EMAIL PROTECTED] wrote:
> Don't you think it is misleading when you expect a variable to
> increment?
no. and in my experience, most people know that they cannot just type
random stuff into a computer and expect it to do what they want.
(have you figured out *why* this is valid syntax, and wh
[EMAIL PROTECTED] wrote:
> given i = 0,
> I know i = i + 1 and i += 1 are all correct
> but when I type:
>
i++
>
> the interpreter replies:
> File "", line 1
> i++
> ^
> SyntaxError: invalid syntax
>
> so I get the idea that suffix ++ is invalid in python
> but when I input:
>
>
given i = 0,
I know i = i + 1 and i += 1 are all correct
but when I type:
>>> i++
the interpreter replies:
File "", line 1
i++
^
SyntaxError: invalid syntax
so I get the idea that suffix ++ is invalid in python
but when I input:
>>> ++i
and the interpreter replies
0
Don't you think it