Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   Python (http://www.velocityreviews.com/forums/f43-python.html)
-   -   splitting a long token across lines (http://www.velocityreviews.com/forums/t329535-splitting-a-long-token-across-lines.html)

 Nakamura 04-04-2004 07:49 AM

splitting a long token across lines

Hi all,

Say, I have a very long integer constant , how can
I split across lines ?
I tried something like
MODULUS = 7567567567567567567567567567567\
7567507546546986094860986094860\
2345646986598695869548498698989\
...
but it doesn't compile.
Is there another way to write a long numeric constant besides writing
it as a string and then converting to long? I also wouldn't like to put
it all on one very long line.

Thanks!

 Josiah Carlson 04-04-2004 06:45 PM

Re: splitting a long token across lines

> MODULUS = 7567567567567567567567567567567\
> 7567507546546986094860986094860\
> 2345646986598695869548498698989\
> ...

Seems that you cannot use line continuation for integers. Unfortunate.

However, using strings to store the value, then later converting it
doesn't incur a significant overhead, as long as you are only
initializing MODULUS once.

MODULUS = '7567567567567567567567567567567'\
'7567507546546986094860986094860'\
'2345646986598695869548498698989'\
...

MODULUS = int(MODULUS)

- Josiah

 Elaine Jackson 04-04-2004 07:34 PM

Re: splitting a long token across lines

why can't you just write it like this:

MODULUS = A*pow(10,a) + \
B*pow(10,b) + \
C

"Nakamura" <lambajan@yahoo.com> wrote in message
| Hi all,
|
| Say, I have a very long integer constant , how can
| I split across lines ?
| I tried something like
| MODULUS = 7567567567567567567567567567567\
| 7567507546546986094860986094860\
| 2345646986598695869548498698989\
| ...
| but it doesn't compile.
| Is there another way to write a long numeric constant besides writing
| it as a string and then converting to long? I also wouldn't like to put
| it all on one very long line.
|
| Thanks!

 djw 04-04-2004 10:15 PM

Re: splitting a long token across lines

Nakamura wrote:
> Hi all,
>
> Say, I have a very long integer constant , how can
> I split across lines ?
> I tried something like
> MODULUS = 7567567567567567567567567567567\
> 7567507546546986094860986094860\
> 2345646986598695869548498698989\
> ...
> but it doesn't compile.
> Is there another way to write a long numeric constant besides writing
> it as a string and then converting to long? I also wouldn't like to put
> it all on one very long line.
>
> Thanks!

Well, I _suppose_ you could do this:

MODULUS = "7567567567567567567567567567567"\
7567507546546986094860986094860"\
2345646986598695869548498698989"\
...

MODULUS = int(MODULUS)

I'm sure I'm going to have to take some flak for this, though. I
wouldn't do it. What's wrong with really long lines? Anything you do
that I can see is going to obscure your code.

-D

 djw 04-04-2004 10:16 PM

Re: splitting a long token across lines

djw wrote:

> Nakamura wrote:
>
>> Hi all,
>>
>> Say, I have a very long integer constant , how can
>> I split across lines ?
>> I tried something like
>> MODULUS = 7567567567567567567567567567567\
>> 7567507546546986094860986094860\
>> 2345646986598695869548498698989\
>> ...
>> but it doesn't compile.
>> Is there another way to write a long numeric constant besides writing
>> it as a string and then converting to long? I also wouldn't like to put
>> it all on one very long line.
>>
>> Thanks!

>
>
> Well, I _suppose_ you could do this:
>
>
> MODULUS = "7567567567567567567567567567567"\
> 7567507546546986094860986094860"\
> 2345646986598695869548498698989"\
> ...
>
> MODULUS = int(MODULUS)
>
> I'm sure I'm going to have to take some flak for this, though. I
> wouldn't do it. What's wrong with really long lines? Anything you do
> that I can see is going to obscure your code.
>
> -D

Oops, I forgot some quotation marks there, but you get the idea.

-D

 All times are GMT. The time now is 09:44 AM.