# Extracting values from text file

Mirco Wahab wahab at chemie.uni-halle.de
Sun Jun 18 11:46:43 EDT 2006

```Thus spoke Preben Randhol (on 2006-06-18 13:34):
> On Sun, 18 Jun 2006 10:54:01 +0200
> Mirco Wahab <wahab at chemie.uni-halle.de> wrote:
>> - no DWIM-ism (do what I mean) on 'value' addition
>
> But you don't add two values. you add two strings. If you
> want numbers you must convert the strings.

Why? At least - if its obvious, what I want.

> Yes, but how can Python know that you want to add to
> numbers and not concate two strings?

The programming language should make some
rules regarding its operators and their
meaning.

Compare:

#      want to add NUMBERS ('1' + '1.1111'/1.1111 = 2.1111)
#
#      in python                         in perl
#
a1  = int( '1' )                       \$a1  = '1';
a1 += float( '1.1111' )                \$a1 += '1.1111';
print a1                               print \$a1;

a2  = int( '1' )                       \$a2  = '1';
a2 += 1.1111                           \$a2 += 1.1111;
print a2                               print \$a2;

#      want to add strings ('1' . '1.1111'/1.1111 = 11.1111)
#
b1  = '1'                              \$b1  = '1';
b1 += '1.1111';                        \$b1 .= '1.1111';
print b1                               print \$b1;

b2  = '1'                              \$b2  = '1';
b2 += str( 1.1111 )                    \$b2 .= 1.1111;
print b2                               print \$b2;

You see the picture? Pythons designer made the
same mistake as the Java/Javascript designer -
they use the _same_ operator (+) for number _addition_
and string _concatenation_, which is, imho, cumbersome.

If you have an operator with meaning "add numbers" (+)
and one for "add strings" (.), the language could then
do the obvious for you.

Why would one go from C/C++ to "dynamical typed"
things, if he has to be so explicit on easy
things?

Of course, you will get along with it, you
'learn' the corresponding 'python-phrases'
that do specific things, you get used to it.
But if you come, like me, from elsewhere,
there is sometimes something to rant on ;-)

I really try to get into it (Python), but
I'm, in such cases, more or less shocked -
and try express that , but I'm not interested
in 'language supremacy' discussions and the like.

BTW.: what exactly did you try to solve?
What would be a 'complete example' where
the parser has to chew on?

Regards

Mirco

```