摘要: 存储数组/持久的方式。#!/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 阅读(410) 评论(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) 编辑
摘要: 对这个本来有点小模糊,稍微练习一下就明白它的意思了。还是得练习,实践出真知。。#!/usr/bin/pythonclass Persion: def __init__(self,username,passwd): self.username=username self.passwd=passwd def print_u(self): print 'username:%s , password:%s' % (self.username,self.passwd)user=Persion('jack','123456')user.print_u(... 阅读全文
posted @ 2013-03-06 11:35 墨迹哥's 阅读(245) 评论(0) 推荐(0) 编辑
摘要: 这个有点难理解,需要时间看看。。#!/usr/bin/python#coding=gbk#__init__代表初始化的意思,当对象被建立,马上运行。class Person: #创建初始化函数(self是自身调用,还有就是name被初始化) def __init__(self,name): self.name=name def sayHi(self): print 'hello,my name is',self.namep=Person('jack')p.sayHi() 阅读全文
posted @ 2013-03-06 11:29 墨迹哥's 阅读(424) 评论(0) 推荐(0) 编辑
摘要: 在这里有个比较模糊的地方,就是这个self,表示自身的意思。说明这个程序在调用的时候,调用了自身的函数,应该就是这个意思。。#!/usr/bin/python#coding=gbk#创建一个Person类class Person: #在里面创建一个sayhi函数 def sayHi(self): #调用的时候打印输出 print 'hello,how are you!?'#将类实例化p=Person()#执行类里面定义的函数p.sayHi() 阅读全文
posted @ 2013-03-06 11:23 墨迹哥's 阅读(4840) 评论(0) 推荐(0) 编辑
摘要: #!/usr/bin/python#coding=gbk#创建一个类class Person: pass#创建对象实例p=Person()#打印输出print p 阅读全文
posted @ 2013-03-06 11:16 墨迹哥's 阅读(261) 评论(0) 推荐(0) 编辑