pickle实例2-不写文件直接传

摘要:>>> import pickle>>> a={'a':123,'b':456}>>> a{'a': 123, 'b': 456}>>> b=pickle.dumps(a)      #写入>>> b"(dp0\nS'a'\np1\nI123\nsS'b'\np2\nI456\ns.">>> pickle.loads(b)     #导出{'a': 123, 'b': 456} 

 pickle实例1-写文件

摘要: 将字典写入文件( 序列化):>>> import pickle>>> account_info={...  '134134134':['alex31234',15000,15000]...  }>>> f=file('account.pkl','wb')>>> pickle.dump(account_info,f)>>> account_info['134134134'][0]='Fiona'>>> pickle.dump(account_info,f)>>> f.close() [root@n

 面向对象编程-类的属性-getattr

摘要:vim modify_attri.py#!/usr/bin/env pythonclass person:  deftell(self,name):    print 'hi myname is',name class student(person):  def study(self):    print 'I amstudying py right now'  s=student()s.tell('rsc')s.study() s1=student()s1.tell('gmy')s1.study()s1.age=30print s1.age p=student(

 面向对象编程-类的继承-person

摘要:#!/usr/bin/env pythonclass Person:  def__init__(self,Type,Sex,Age,Name):    self.race =Type    self.sex = Sex     self.age = Age     self.name =Name  deftalk(self,msg=0):    self.msg = msg     if self.msg !=0:      printself.

 面向对象编程-类的继承-inherit

摘要:vim  inherit.py #!/usr/bin/env pythonclass SchoolMember:             #申明一个基类  def__init__(self,name,gender,nationality='CN'):   #初始化基类    self.name =name     #定义类的属性    self.gender =gender  &nb

 面向对象编程-实例1-类变量通信

摘要:不同的方法可以通过类变量进行通信:#!/usr/bin/env pythonclass dog:  def sayHi(self):    print 'Himaster,I am your little dog,who do you want me to bite...'    favorate_food = 'bone'                    #函数内部变量,其它方

 socket-FTP-client

摘要:#!/usr/bin/env pythonimport socketimport sysimport os HOST,PORT="192.168.2.110",90c = socket.socket(socket.AF_INET,socket.SOCK_STREAM)c.connect((HOST,PORT)) def recv_all(obj,msg_length):  raw_result = ''  while True:    if msg_length<=4096:      data =obj.recv(msg_length) 

 socket-FTP-server

摘要:#!/usr/bin/env pythonimport commandsimport timeimport SocketServerclass MyTCPHandler(SocketServer.BaseRequestHandler):  defrecv_all(self,obj,msg_length,des_file):    while msg_length!=0:      if msg_length<=4096:        data =obj.recv(msg_length)   &nb

 socket-SSH模拟-client

摘要:#!/usr/bin/env pythonimport socketimport sys HOST,PORT="192.168.2.110",90sock = socket.socket(socket.AF_INET,socket.SOCK_STREAM)sock.connect((HOST,PORT)) def recv_all(obj,msg_length):  raw_result = ''  while True:    if msg_length<=4096:      data =obj.recv(msg_length) &n

 socket-SSH模拟-server

摘要:#!/usr/bin/env pythonimport commandsimport timeimport SocketServerclass MyTCPHandler(SocketServer.BaseRequestHandler):   def handle(self):    print 'Got anew connection from',self.client_address    while True:      cmd  = self.request.recv(1024).strip()    &nb
分页:« 1 2 3 4 5 6 7 8 9 »
Powered by AKCMS