python类的问题
import os,sys
import hashlib
def sha1():
files=raw_input("Drag the file into here:")
f=open('sha1.txt','w')
if os.path.isfile(files):
f1=open(files,'rb')
sha1obj=hashlib.sha1()
sha1obj.update(f1.read())
hashs=sha1obj.hexdigest()
print hashs
f.write(hashs+'\n')
f.close()
else:
for x,y,z in os.walk(files):
for a in z:
h=os.path.join(x,a)
f1=open(h,'rb')
sha1obj=hashlib.sha1()
sha1obj.update(f1.read())
hashs=sha1obj.hexdigest()
print hashs
f.write(hashs+'\n')
f.close()
def md5():
files=raw_input("Drag the file into here:")
f=open('md5.txt','w')
if os.path.isfile(files):
f1=open(files,'rb')
md5obj=hashlib.md5()
md5obj.update(f1.read())
md5s=md5obj.hexdigest()
print md5s
f.write(md5s+'\n')
f.close()
else:
for x,y,z in os.walk(files):
for a in z:
h=os.path.join(x,a)
f1=open(h,'rb')
md5obj=hashlib.md5()
md5obj.update(f1.read())
md5s=md5obj.hexdigest()
print md5s
f.write(md5s+'\n')
f.close()
def main():
r=raw_input("please input 'sha1' or 'md5':")
if r=='sha1':
sha1()
elif r=='md5':
md5()
else:
print "error"
if __name__=='__main__':
main()
[/code]
这是个求md5值和sha1值的程序,怎么放在类中写啊?(我是想把这段代码用类的方式写出来,但本人对类和对象一直很模糊,所以希望有人能帮我转换成有含类的代码)
相关推荐
python类的实例化问题解决
类的实例化问题解决 运行结果: line 21, in <module> s=speaker('ken',10,'aaa') TypeError: __init__() missing 1 required positional argument: 'h' 错误要点:定义类的时候是四个参数,在实例化的时候也必须是四个,不能因为用不到而不写。 这是因为:类定义了 __init__() 方法,类的实例化操作会自动调用 __init__() 方法。实例化和定义的不匹配,当然报错了。 您可能感兴趣的文章:Python面向对象程序设计中类的定义、实
Python类的多重继承问题深入分析
正文 首先得说明的是,Python的类分为经典类 和 新式类 经典类是python2.2之前的东西,但是在2.7还在兼容,但是在3之后的版本就只承认新式类了 新式类在python2.2之后的版本中都可以使用 经典类和新式类的区别在于: 经典类是默认没有派生自某个基类的,而新式类是默认派生自object这个基类的: 复制代码 代码如下: # old style class A():pass # new style class A(obejct):pass 2.经典类在类多重继承的时候是采用从左到右深度优先原则匹配方法的..而新式类是采用C3算法(不同于广度优先)进行匹配的 3.经典类是没有__
解决Python中导入自己写的类,被划红线,但不影响执行的问题
主要介绍了解决Python中导入自己写的类,被划红线,但不影响执行的问题,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧
Introduction_to_Python_Programming:我第二个sem Python类中给出的python问题的存储库
Introduction_to_Python_Programming 我的第二学期Python类The Very Basics中给出的python问题的存储库
基于Python实现的2023年全国大学生数学建模竞赛C题源代码,用数学建模方法解决商超果蔬类商品的价格预测、补货预测等问题
本项目为2023年全国大学生数学建模竞赛C题的代码实现。C题主要围绕商超果蔬类商品的定价与补货,要求参赛队伍通过数学建模方法解决一系列与价格预测、补货预测等相关的实际问题。


