本文整理匯總了Python中types.FloatType方法的典型用法代碼示例。如果您正苦於以下問題:Python types.FloatType方法的具體用法?Python types.FloatType怎麽用?Python types.FloatType使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類types
的用法示例。
在下文中一共展示了types.FloatType方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: assertEquals
# 需要導入模塊: import types [as 別名]
# 或者: from types import FloatType [as 別名]
def assertEquals( exp, got ):
"""assertEquals(exp, got)
Two objects test as "equal" if:
* they are the same object as tested by the 'is' operator.
* either object is a float or complex number and the absolute
value of the difference between the two is less than 1e-8.
* applying the equals operator ('==') returns True.
"""
from types import FloatType, ComplexType
if exp is got:
r = True
elif ( type( exp ) in ( FloatType, ComplexType ) or
type( got ) in ( FloatType, ComplexType ) ):
r = abs( exp - got ) < 1e-8
else:
r = ( exp == got )
if not r:
print >>sys.stderr, "Error: expected <%s> but got <%s>" % ( repr( exp ), repr( got ) )
traceback.print_stack()
示例2: assertEquals
# 需要導入模塊: import types [as 別名]
# 或者: from types import FloatType [as 別名]
def assertEquals( exp, got, msg = None ):
"""assertEquals( exp, got[, message] )
Two objects test as "equal" if:
* they are the same object as tested by the 'is' operator.
* either object is a float or complex number and the absolute
value of the difference between the two is less than 1e-8.
* applying the equals operator ('==') returns True.
"""
if exp is got:
r = True
elif ( type( exp ) in ( FloatType, ComplexType ) or
type( got ) in ( FloatType, ComplexType ) ):
r = abs( exp - got ) < 1e-8
else:
r = ( exp == got )
if not r:
print >>sys.stderr, "Error: expected <%s> but got <%s>%s" % ( repr( exp ), repr( got ), colon( msg ) )
traceback.print_stack()
示例3: assertNotEquals
# 需要導入模塊: import types [as 別名]
# 或者: from types import FloatType [as 別名]
def assertNotEquals( exp, got, msg = None ):
"""assertNotEquals( exp, got[, message] )
Two objects test as "equal" if:
* they are the same object as tested by the 'is' operator.
* either object is a float or complex number and the absolute
value of the difference between the two is less than 1e-8.
* applying the equals operator ('==') returns True.
"""
if exp is got:
r = False
elif ( type( exp ) in ( FloatType, ComplexType ) or
type( got ) in ( FloatType, ComplexType ) ):
r = abs( exp - got ) >= 1e-8
else:
r = ( exp != got )
if not r:
print >>sys.stderr, "Error: expected different values but both are equal to <%s>%s" % ( repr( exp ), colon( msg ) )
traceback.print_stack()
示例4: realEncode
# 需要導入模塊: import types [as 別名]
# 或者: from types import FloatType [as 別名]
def realEncode(self, data):
"""Convert number to string.
If no formatString was specified in class constructor data type is
dynamically determined and converted using a default formatString of
"%d", "%f", or "%d" for Int, Float, and Long respectively.
"""
if self._formatString is None:
retType = type(data)
if retType is IntType:
return "%d" % data
elif retType is FloatType:
return "%f" % data
elif retType is LongType:
return "%d" % data
else:
return data
return self._formatString % data
示例5: radius
# 需要導入模塊: import types [as 別名]
# 或者: from types import FloatType [as 別名]
def radius(self, z):
'''
sets the height of the point constraining the plate, returns
the radius at this point
'''
if isinstance(z, types.FloatType):
self.pnt.SetX(z)
else:
self.pnt.SetX(float(z[0]))
self.build_surface()
uv = uv_from_projected_point_on_face(self.plate, self.pnt)
print(uv)
radius = radius_at_uv(self.plate, uv.X(), uv.Y())
print('z: %f radius: %f ' % (z, radius))
self.curr_radius = radius
return self.targetRadius-abs(radius)
示例6: init_info
# 需要導入模塊: import types [as 別名]
# 或者: from types import FloatType [as 別名]
def init_info(self):
scalar_converter.init_info(self)
# Not sure this is really that safe...
self.type_name = 'float'
self.check_func = 'PyFloat_Check'
self.c_type = 'double'
self.return_type = 'double'
self.to_c_return = "PyFloat_AsDouble(py_obj)"
self.matching_types = [types.FloatType]
示例7: mysql_escape
# 需要導入模塊: import types [as 別名]
# 或者: from types import FloatType [as 別名]
def mysql_escape(f):
@wraps(f)
def decorated_function(*args, **kwargs):
newargs = []
#先轉義參數,再執行方法
for arg in args:
#字符串,包括中文
if type(arg) is types.StringType or type(arg) is types.UnicodeType:
newargs.append(MySQLdb.escape_string(arg))
#字典
elif isinstance(arg, dict):
newargs.append(MySQLdb.escape_dict(arg, {
types.StringType: _str_escape,
types.UnicodeType: _str_escape,
types.IntType: _no_escape,
types.FloatType: _no_escape
}))
#其他類型不轉義
else:
newargs.append(arg)
newargs = tuple(newargs)
func = f(*newargs, **kwargs)
return func
return decorated_function
示例8: to_sec
# 需要導入模塊: import types [as 別名]
# 或者: from types import FloatType [as 別名]
def to_sec(v):
"""
Convert millisecond, microsecond or nanosecond to second.
ms_to_ts, us_to_ts, ns_to_ts are then deprecated.
"""
v = float(str(v))
if (type(v) != types.FloatType
or v < 0):
raise ValueError('invalid time to convert to second: {v}'.format(v=v))
l = len(str(int(v)))
if l == 10:
return int(v)
elif l == 13:
return int(v / 1000)
elif l == 16:
return int(v / (1000**2))
elif l == 19:
return int(v / (1000**3))
else:
raise ValueError(
'invalid time length, not 10, 13, 16 or 19: {v}'.format(v=v))
示例9: valueTreeToString
# 需要導入模塊: import types [as 別名]
# 或者: from types import FloatType [as 別名]
def valueTreeToString(fout, value, path = '.'):
ty = type(value)
if ty is types.DictType:
fout.write('%s={}\n' % path)
suffix = path[-1] != '.' and '.' or ''
names = value.keys()
names.sort()
for name in names:
valueTreeToString(fout, value[name], path + suffix + name)
elif ty is types.ListType:
fout.write('%s=[]\n' % path)
for index, childValue in zip(xrange(0,len(value)), value):
valueTreeToString(fout, childValue, path + '[%d]' % index)
elif ty is types.StringType:
fout.write('%s="%s"\n' % (path,value))
elif ty is types.IntType:
fout.write('%s=%d\n' % (path,value))
elif ty is types.FloatType:
fout.write('%s=%.16g\n' % (path,value))
elif value is True:
fout.write('%s=true\n' % path)
elif value is False:
fout.write('%s=false\n' % path)
elif value is None:
fout.write('%s=null\n' % path)
else:
assert False and "Unexpected value type"
示例10: set_hp
# 需要導入模塊: import types [as 別名]
# 或者: from types import FloatType [as 別名]
def set_hp(self, hp):
if type(hp) in [types.IntType, types.FloatType]:
self.__hp = hp
else:
self.__hp = 0
示例11: set_maxHp
# 需要導入模塊: import types [as 別名]
# 或者: from types import FloatType [as 別名]
def set_maxHp(self, maxHp):
if type(maxHp) in [types.IntType, types.FloatType]:
self.__maxHp = maxHp
else:
self.__maxHp = 1
示例12: set_hp
# 需要導入模塊: import types [as 別名]
# 或者: from types import FloatType [as 別名]
def set_hp(self, hp):
if type(hp) in [types.IntType, types.FloatType]:
self.__hp = hp
else:
self.__hp = 1
開發者ID:PiratesOnlineRewritten,項目名稱:Pirates-Online-Rewritten,代碼行數:7,代碼來源:DistributedInteractiveProp.py
示例13: __init__
# 需要導入模塊: import types [as 別名]
# 或者: from types import FloatType [as 別名]
def __init__(self, name, host='ip-address', port=9955):
Instrument.__init__(self, name, tags=['physical'])
self.add_parameter('condenser_pressure',
type=types.FloatType,
flags=Instrument.FLAG_GET, units='mbar')
self.add_parameter('still_pressure',
type=types.FloatType,
flags=Instrument.FLAG_GET, units='mbar')
self.HOST, self.PORT = host, port
示例14: parinfo
# 需要導入模塊: import types [as 別名]
# 或者: from types import FloatType [as 別名]
def parinfo(self, parinfo=None, key='a', default=None, n=0):
if self.debug:
print 'Entering parinfo...'
if (n == 0) and (parinfo is not None):
n = len(parinfo)
if n == 0:
values = default
return values
values = []
for i in range(n):
if (parinfo is not None) and (parinfo[i].has_key(key)):
values.append(parinfo[i][key])
else:
values.append(default)
# Convert to numeric arrays if possible
test = default
if type(default) == types.ListType:
test=default[0]
if isinstance(test, types.IntType):
values = numpy.asarray(values, int)
elif isinstance(test, types.FloatType):
values = numpy.asarray(values, float)
return values
# Call user function or procedure, with _EXTRA or not, with
# derivatives or not.
示例15: _convert_to
# 需要導入模塊: import types [as 別名]
# 或者: from types import FloatType [as 別名]
def _convert_to(l, dest_unit="m"):
if type(l) in (types.IntType, types.LongType, types.FloatType):
return l * _m[_default_unit] * scale['u'] / _m[dest_unit]
elif not isinstance(l, length):
l = length(l) # convert to length instance if necessary
return (l.t + l.u*scale['u'] + l.v*scale['v'] + l.w*scale['w'] + l.x*scale['x']) / _m[dest_unit]