Come faccio a lanciare un float in long in Python 2.7?
Sto facendo lo stesso in Python 2.3 in questo modo:
from array import*
data = array("L",[12.34])
print data
che stampa:
array("L",[12L])
Come faccio a fare lo stesso in Python 2.7?
risposte:
4 per risposta № 1Forse così?
>>> long(12.34)
12L
3 per risposta № 2
In questi giorni, è molto più comune da vedere numpy
array che array dal array
modulo, tuttavia, l'array può essere costruito come:
>>> from array import *
>>> array("L",map(long,[12.34]))
array("L", [12L])
con numpy, potrebbe essere fatto come:
>>> import numpy as np
>>> np.array([12.34],dtype=long)
Tuttavia, questo in realtà non crea long di Python, ma in realtà crea un array di np.int64
numeri interi (8 byte ints - Precisione non arbitraria come python long).
0 per risposta № 3
lst = [1.1,2.2]
data = map(long,lst)