随笔分类 - ptython
摘要:去服务器执行ssh-keygen,生成对应的公钥和私钥。目录用户/.ssh/,id_rsa叫私钥,也就是钥匙,id_rsa.pub叫公钥。 import paramiko private_key = paramiko.RSAKey.from_private_key_file('id_rsa31.tx
阅读全文
摘要:执行ssh命令import paramiko# 创建SSH对象ssh = paramiko.SSHClient()# 允许连接不在know_hosts文件中的主机ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())# 连接服务器ssh.c
阅读全文
摘要:#client import socketimport os,jsonclass FTPClient(object): def __init__(self): self.client = socket.socket() def help(self): msg =''' is pwd cd .. cd
阅读全文
摘要:server: import socket,osserver = socket.socket()server.bind(("localhost",9999))server.listen()while True: conn, addr = server.accept() while True: dat
阅读全文
摘要:#server import socket,osserver = socket.socket()server.bind(('localhost',9999))server.listen()while True: conn,addr=server.accept() while True: data =
阅读全文
摘要:#断言a ='testing'if type(a) is int: print('error')assert type(a) is str#为True assert type(a) is int#为False。错误信息:AssertionError print('test1')
阅读全文
摘要:__import__('import_lib.metaclass') #这是解释器自己内部用的,导入到import_lib模块 import importlib #importlib.import_module('import_lib.metaclass') #与上面这句效果一样,官方建议用这个。导
阅读全文
摘要:#服务器端import socketserver = socket.socket()server.bind(('localhost',6969))#绑定要监听端口server.listen()#监听conn, addr = server.accept() # 等电话打进来# conn就是客户端连过来
阅读全文
摘要:name = ["test","测试"]data = {}try: # open("oooo.txt") # name[3] # data["name"] a = 1 print(a)except (KeyError,IndexError) as e: print("没有这个key", e)exce
阅读全文
摘要:def bulk(self): print('%s is barking'%self.name)class Dog(object): def __init__(self,name): self.name = name def eat(self,food): print('%s is eating %
阅读全文
摘要:type:使用type来创建一个类 def func(self): print('%s hello world'%self.name)def __init__(self,name ,age): self.name = name self.age = ageFoo = type('Foo', (obj
阅读全文
摘要:class Dog(object): ''' 这个类是描述狗这个对象的''' def __init__(self,name): self.name = name @staticmethod#实际上跟类没有什么关系了。eat和类的关系截断了,只是类下面函数 #静态方法:只是名义上归类管理,实际上在静态
阅读全文
摘要:'''class Dog(object): def __init__(self,name): self.name = name @staticmethod#实际上跟类没有什么关系了。eat和类的关系截断了,只是类下面函数 #静态方法:只是名义上归类管理,实际上在静态方法里访问不了类或实例中的任何属性
阅读全文
摘要:多态性(polymorphisn)是允许你将父对象设置成为和一个或更多的他的子对象相等的技术,赋值之后,父对象就可以根据当前赋值给它的子对象的特性以不同的方式运作。简单的说,就是一句话:允许将子类类型的指针赋值给父类类型的指针。 那么,多态的作用是什么呢?我们知道,封装可以隐藏实现细节,使得代码模块
阅读全文
摘要:# class People:#经典类#父类class People(object): #新式类 # 父类 def __init__(self,name,age): self.name = name self.age = age def __del__(self): pass def eat(sel
阅读全文
摘要:class Role(object): def __init__(self, name, role, weapon, life_value=100, money=15000):#内置函数,程序启动自动调用 self.name = name self.role = role self.weapon =
阅读全文
摘要:'.' 默认匹配除\n之外的任意一个字符,若指定flag DOTALL,则匹配任意字符,包括换行'^' 匹配字符开头,若指定flags MULTILINE,这种也可以匹配上(r"^a","\nabc\neee",flags=re.MULTILINE)'$' 匹配字符结尾,或e.search("foo
阅读全文
摘要:import hashlib,hmac#散列消息鉴别码,简称HMAC,是一种基于消息鉴别码MAC(Message Authentication Code)的鉴别机制。使用HMAC时,消息通讯的双方,通过验证消息中加入的鉴别密钥K来鉴别消息的真伪;# m = hashlib.md5()# m.upda
阅读全文
摘要:import configparser#write'''config = configparser.ConfigParser()config["DEFAULT"] = {'ServerAliveInterval': '45', 'Compression': 'yes', 'CompressionLe
阅读全文
摘要:import xml.etree.ElementTree as ET# tree = ET.parse("xmltest.xml")#操作的文件# root = tree.getroot()#获取一个内存地址# print(root.tag)#标签名## # 遍历xml文档# for child i
阅读全文

浙公网安备 33010602011771号