[Python-Dev] Re: Passing floats to "i" parser marker
Guido van Rossum
guido@python.org
Wed, 05 Feb 2003 16:48:56 -0500
> for my personal extension code, i actually benefit from the features
> of automatic float-to-int conversion.
Can you explain the situation more? What's your application? Where
do the floats come from?
> in the same context, i'm wondering if the "s" formatting should change
> also? currently you can pass unicode or string objects and they get
> properly converted. i use so little of unicode my input may be totally
> invalid, but it seems float->int is approximate to unicode->string ?
No, when the unicode->string conversion would lose information, an
exception is raised.
> lastly, as a contrived example. to insert an item in the middle of a
> list is pretty simple,
> mylist.insert(len(mylist)/2, myval)
> with the new integer division, this would pass a float into an integer
> argment(?). just food for thought, wondering what the expected behaviour
> of this would be?
You should be writing len(mylist)//2.
--Guido van Rossum (home page: http://www.python.org/~guido/)