From D

mensanator at aol.com mensanator at aol.com
Thu Jul 26 07:01:06 CEST 2007


On Jul 25, 9:04?pm, Steven D'Aprano
<st... at REMOVE.THIS.cybersource.com.au> wrote:
> On Wed, 25 Jul 2007 18:17:19 -0700, mensana... at aol.com wrote:
> > On Jul 25, 8:00 pm, Ben Finney <bignose+hates-s... at benfinney.id.au>
> > wrote:
> >> "mensana... at aol.com" <mensana... at aol.com> writes:
> >> > On Jul 24, 6:08 pm, Steven D'Aprano
> >> > <st... at REMOVE.THIS.cybersource.com.au> wrote:
> >> > > Python already does:
> >> > > "hello-" "world" => "hello-world"
>
> >> > > Propose:
> >> > > 123 456 789 => 123456789
> >> > > 123.456 789 => 123.456789
>
> >> > So, spaces will no longer be delimiters?
>
> >> I don't see how you get that conclusion from Steven's proposal.
>
> > IDLE 1.2c1
> >>>> s = '123 456'
> >>>> s.split()
> > ['123', '456']
>
> > The only way to get '123 456' would be to treat a space as a
> > non-delimiter. But what if those actually WERE two different numbers?
>
> That makes no sense at all. Your example is about splitting a _string_.

Why does it make no sense? Have you never had to
scrape a web page or read a CSV file?

> You can construct and split the string any way you like:
>
> >>> s = '123SURPRISE456'
> >>> s.split('SURPRISE')
>
> ['123', '456']
>
> Notice that the results aren't ints, they are strings.

Duh. I took for granted you knew how to convert
an string to an integer.

>
> To get an int literal, you currently type something like 123456. 123 456
> is currently not valid in Python, it raises an SyntaxError. Try it for
> yourself:

So this proposal would only apply to string literals
at compile time, not running programs?

>
> >>> 123 456
>
>   File "<stdin>", line 1
>     123 456
>           ^
> SyntaxError: invalid syntax

And I want the same error to occur if my CSV parser
tries to convert '123 456' into a single number.
I don't want it to assume the number is '123456'.

>
> If you want two numbers, you would do exactly the same thing you would now:
>
> >>> x, y = 123, 456
> >>> print "x is %d and y is %d" % (x, y)
>
> x is 123 and y is 456
>
> --
> Steven




More information about the Python-list mailing list