-1

I have a list of followers, I'd like to follow. The one problem that I'm having is that it appears the user_id has to be an int, not a string, and can't have the trailing L. I have some large numbers as id. For example

user_id = 900000000000000L 

I tried changing using a few suggestions like

format(user_id, 'd')

but it returns a string.

I looked at:

Python Trailing L Problem

However hexadecimal isn't an option for me. I understand in C after a certain point an int can't be expressed, and you need a long or double long. however is there a way to override the L in python?

user2723240
  • 803
  • 1
  • 13
  • 23

1 Answers1

3

900000000000000L is of type long which is an int-like class. When integers get too big to represent, the automatically convert to long... e.g.:

>>> import sys
>>> sys.maxint
9223372036854775807
>>> sys.maxint + 1
9223372036854775808L

Most of the time, int and long can be used interchangeably and you shouldn't need to worry about it. However, if having long integers really is a problem, for small enough numbers, you can probably just call int on it:

>>> user_id = 900000000000000L
>>> int(user_id)
900000000000000

But if the numbers get bigger than sys.maxint, you need to figure out how to make those numbers smaller as it isn't possible to represent them as an int any longer1...

>>> int(sys.maxint + 1)  # still a long.
9223372036854775808L

1pun intended

mgilson
  • 300,191
  • 65
  • 633
  • 696
  • So basically I'm stuck with using a program for apis that require an int for int large than sys.maxint? – user2723240 Jul 01 '16 at 19:39
  • just adding this comment here for future users. Python 2. has this problem, however I was told it changes in Python 3. – user2723240 Jul 01 '16 at 19:48
  • @user2723240 -- Well ... Sort of. In python3 there is no difference between `int` and `long`. However, if your API expects an int in an appropriate range, you still might have troubles... – mgilson Jul 01 '16 at 20:12