By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,539 Members | 1,289 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,539 IT Pros & Developers. It's quick & easy.

splitting a long token across lines

P: n/a
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!
Jul 18 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
why can't you just write it like this:

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

"Nakamura" <la******@yahoo.com> wrote in message
news:ef**************************@posting.google.c om...
| 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!
Jul 18 '05 #2

P: n/a
djw
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
Jul 18 '05 #3

P: n/a
djw
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
Jul 18 '05 #4

P: n/a
> 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
Jul 18 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.