Mon, 3 Dec 2001 19:33:11 -0500
On Mon, Dec 03, 2001 at 11:28:26PM +0100, Gregor Lingl wrote:
| Thanks for this argument. I did some considerations
| on this topic for myself.
| My experience is, that my students understand well this
| overloading of /, but they tend to forget it when writing
| some useful programs doing some maths. Especially when
| using the input-statement one often arrives at integers
| unintentionally. So should we type-cast every input with
More of a technicality, but there is no type-casting in python. The
sole purpose of a type cast is to inform the compiler of a statically
typed language (eg C, C++, Java) that you think/want to have something
of a different type that the compiler thinks you have. In python what
you have are conversion functions that actually do a conversion of the
| float or resort only to use raw_input?
For simple programs or where input is assumed to be valid, input() is
functional. In any other situation, use raw_input(). Once you have
the data via raw_input() you can convert it to whatever internal types
you want (eg floats) and also perform proper error checking. A common
example of the pitfalls of using input() is if the user entered
open( "some_file_you_dont_want_to_delete" , "w" )
This would give you back a file object, not a number, and also have
the effect of truncating the file to size 0 if it already existed.
(E)scape (M)eta (A)lt (C)ontrol (S)hift