splitting a long token across lines

N

Nakamura

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!
 
J

Josiah Carlson

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
 
E

Elaine Jackson

why can't you just write it like this:

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

| 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!
 
D

djw

Nakamura said:
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
 
D

djw

djw said:
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,768
Messages
2,569,575
Members
45,053
Latest member
billing-software

Latest Threads

Top