Newbie - Stuck

Paddy paddy3118 at netscape.net
Sun Oct 8 14:51:24 CEST 2006


r3bol at yahoo.com wrote:
> The perl version of this code works but not the python version. What am
> I doing wrong?
>
> message = "abc"
> password = "z12"
>
> scrambled = message ^ password
>
> I also wondered why this errored as well...
>
> int(messege)
>
> Is it not meant to convert a string to a number?
Hmm,
Looks like you need to learn more elementary Python before we can even
attempt to help you more, but here goes anyway...

Python has strict typing compared to Perl (a good thing)!
The string "abc" is not a valid representation of an integer in Python,
 and, unlike Perl, Python will complain about its use when an integer
is expected:

$ perl -e 'print "abc" ^ 123, "\n"'
123

$ python -c 'print "abc" ^ 123'
Traceback (most recent call last):
  File "<string>", line 1, in ?
TypeError: unsupported operand type(s) for ^: 'str' and 'int'

$

Please don't give up on Python. It *is* different to Perl. 

- Paddy.




More information about the Python-list mailing list