上一页 1 ··· 32 33 34 35 36 37 38 39 40 ··· 48 下一页
摘要: try-except 可以应用所有错误,同时也可以指定错误的类型进行过滤。除非特殊需求,对于我来说就不需要特定的了。。。#!/usr/bin/pythonimport systry: s=raw_input('Enter:')except: sys.exit()下面这个案例是简明教程的,但是一般来说,上面的够用了。特定的错误有的时候无法估计,除非你很懂。。 #!/usr/bin/python# Filename: try_except.pyimport systry: s = raw_input('Enter something --> ')except 阅读全文
posted @ 2013-03-07 12:18 墨迹哥's 阅读(191) 评论(0) 推荐(0) 编辑
摘要: 存储数组/持久的方式。#!/usr/bin/pythonimport cPickle as pshoplist_file='shoplist.data'shoplist=['dede','dede2','dede3']f=file(shoplist_file,'w')p.dump(shoplist,f)f.close()del shoplistf=file(shoplist_file)print p.load(f) 阅读全文
posted @ 2013-03-06 22:57 墨迹哥's 阅读(176) 评论(0) 推荐(0) 编辑
摘要: 一个简单的小练习,后面还要改成输入的。。#!/usr/bin/python#coding=gbkclass User: def __init__(self,username,password,age,sex): self.username=username self.password=password self.age=age self.sex=sex def tell(self): print 'UserContext:Name:%s,Pass:%s,Age:%s,Sex:%s' % (self.usernam... 阅读全文
posted @ 2013-03-06 13:27 墨迹哥's 阅读(412) 评论(0) 推荐(0) 编辑
摘要: Python当中的继承有点类似于JAVA。感觉特别像~可能学过JAVA以后对这个比较好理解吧。不过Python更加清晰一点,比起Perl面对对象,PYTHON看起来舒服,并且让人感觉一看就懂~下面这个实例是简明教程里面的,我初步理解了一下,一会再自己写个练习,熟练下。。。#!/usr/bin/python#coding=gbk#创建父类,该类会被下面的子类所继承class SchoolMember: #在父类里面有两个变量,当继承以后,子类同样有效 def __init__(self,name,age): self.name=name self.age=... 阅读全文
posted @ 2013-03-06 13:00 墨迹哥's 阅读(585) 评论(0) 推荐(0) 编辑
摘要: 发现一个无比诡异的现象。当创建对象为JACK的时候。就会出现很奇怪的错误。。到现在未明白,百度了下说是变量到某个地方没有传递成功。。蛋疼。。难道Python封杀了JACK?。。Exception AttributeError: "'NoneType' object has no attribute 'population'" in <bound method Person.__del__ of <__main__.Person instance at 0x7f42b2b596c8>> ignored就是这上面的错误,比 阅读全文
posted @ 2013-03-06 12:17 墨迹哥's 阅读(207) 评论(0) 推荐(0) 编辑
上一页 1 ··· 32 33 34 35 36 37 38 39 40 ··· 48 下一页