views:

930

answers:

2
+3  A: 
>>> i = 1240832864000L
>>> i
1240832864000L
>>> print i
1240832864000
>>> 
>>> '<script type="text/javascript"> var num = %s; </script>' % i
'<script type="text/javascript"> var num = 1240832864000; </script>'

The L only shows up when you trigger the object's __repr__

When and how are you sending this data to JavaScript? If you send it as JSON, you shouldn't have to worry about long literals or how Python displays its objects within Python.

apphacker
He is calling `str(created_on_timestamp)`, so `__str__` will be the magic method involved, right?
Joe Koberg
He's not getting the L in that case, but the quotes. But yes when str() is called __str__ is the magic method called.
apphacker
+2  A: 

With the line:

created_on_timestamp = str(created_on_timestamp)

You are converting something into a string. The python console represents strings with single-quotes (is this what you mean by tick marks?) The string data, of course, does not include the quotes.

When you use int() to re-convert it to a number, int() knows it's long because it's too big, and returns a long integer.

The python console represents this long number with a trailing L. but the numeric content, of course, does not include the L.

>>> l = 42000000000
>>> str(l)
'42000000000'
>>> l
42000000000L
>>> int(str(l))
42000000000L
>>> type( int(str(l)) )
<type 'long'>

Although the python console is representing numbers and strings this way (in python syntax), you should be able to use them normally. Are you anticipating a problem or have you actually run into one at this point?

Joe Koberg