On Thursday, October 27, 2016 at 12:12:15 PM UTC-4, [email protected]
wrote:
>
> Anthony,
>
> From i what i read from you, DAL returns int with type long int
> attached.Ex:9632L.
>
> If i want a string then i must str( row ).
>
> How do i get the int without type description, Ex:
> [2015L, 6249L, 2016L, 9632L],
> [2015, 6249, 2016, 9632]
>
You can always convert to plain integers via the built-in int() function,
but the point is that you will likely not need to bother with that.
However, it is difficult to provide further assistance without knowing what
you are trying to do with these values and in what context you are trying
to display them.
I suggest you look into Python repr() vs str() and __repr__ vs __str__. In
many contexts, when you display a Python object, you get the text
"representation" of the object, which is produced by its __repr__ special
method. Often, the __repr__ method outputs the exact Python code (as a
string) that can be used to reproduce the object. In the case of long
integers, they can be created using the long() built-in function or by
simply appending an "L" to a regular integer -- so:
long(5) == 5L
The __repr__ method of longs therefore produces strings with the "L"
suffix, which can then be used to re-create the original long values:
eval(repr(long(5))) == long(5)
which is the same as:
eval('5L') == long(5)
In other contexts, when you display a Python object, instead of getting a
formal text representation (that potentially could be used to re-create the
object), you get a string intended for display purposes. This is produced
by the object's __str__ method, which is called by the str() built-in
function. For example, when you print an object, you get the output of its
__str__ method. (Note, in some cases, as with regular integers, the __str__
and __repr__ representations are the same).
If you need to work with these integers as numbers, there is no need to
convert them, as they will behave as regular integers. If you need to
display them as text, then use str()/__str__ (depending on the context, the
__str__ method may be applied automatically, such as when the values are
components of web2py HTML helpers rendered in a view). If you are just
seeing the "L" suffixes in some output in a console somewhere, there is no
need to do any conversion, unless the L's really bother you.
Anthony
--
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
---
You received this message because you are subscribed to the Google Groups
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.