import numbers
class base62(numbers.Number):
digits='0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'
def __init__(self,value):
if isinstance(value,int):
self.value=value
if value==0:
self.string='0'
else:
self.string='' if value>0 else '-'
while value!=0:
value,d=divmod(value,62)
self.string=self.digits[d]+self.string
elif isinstance(value,(str,bytes)):
assert(value.isalnum())
self.string=str(value)
self.value=0
for d in value:
self.value=self.value*62+self.digits.index(d)
def __int__(self):
return self.value
def __str__(self):
return self.string
def __repr__(self):
return self.string
Python 2.6.6 (r266:84292, Sep 15 2010, 15:52:39)
[GCC 4.4.5] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import base62
>>> b = base62(3)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: 'module' object is not callable
>>>
最佳答案
base62
似乎是您的模块名称以及该模块中函数的名称。尝试:
>>> import base62
>>> b = base62.base62(3)
关于python - 有人可以帮我解决为什么无法运行此python脚本吗?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/4352311/