02 2020 档案
摘要:打开python自带IDLE编辑器时出的问题 IDLE can't bind to a TCP/IP port, which is necessary tocommunicate with its Python execution server. This might bebecause no ne
阅读全文
摘要:import tkinterwin = tkinter.Tk()win.title("sunck")win.geometry("400x400+200+20")def updata(): message = "" if hobby1.get() == True: message += "money\
阅读全文
摘要:import tkinter#创建主窗口win = tkinter.Tk()#设置标题win.title("sunck")#设置大小和位置#win.geometry("400x400+200+20")'''文本控件,用于显示多行文本'''#创建滚动条scroll = tkinter.Scrollba
阅读全文
摘要:import tkinter#创建主窗口win = tkinter.Tk()#设置标题win.title("sunck")#设置大小和位置win.geometry("400x400+200+20")'''文本控件,用于显示多行文本'''#height显示的行数text = tkinter.Text(
阅读全文
摘要:import tkinter#创建主窗口win = tkinter.Tk()#设置标题win.title("sunck")#设置大小和位置win.geometry("400x400+200+20")def showInfo(): print(entry.get())entry = tkinter.E
阅读全文
摘要:import tkinter#创建主窗口win = tkinter.Tk()#设置标题win.title("sunck")#设置大小和位置win.geometry("400x400+200+20")'''输入控件用于显示简单的文本内容'''#绑定变量e = tkinter.Variable()#sh
阅读全文
摘要:import tkinterdef func(): print("sunck is a good man")win = tkinter.Tk()win.title("sunck")win.geometry("400x400+200+20")#创建按钮button1 = tkinter.Button(
阅读全文
摘要:import tkinterwin = tkinter.Tk()win.title("sunck")win.geometry("400x400+200+20")'''Label:标签控件可以显示文本'''#win 父窗体#text 显示的文本内容#bg 背景色#fg 字体颜色#wraplength
阅读全文
摘要:import tkinter#创建主窗口win = tkinter.Tk()#设置标题win.title("sunck")#设置大小和位置win.geometry("400x400+200+20")#进入消息循环win.mainloop()
阅读全文
摘要:描述: exec 执行储存在字符串或文件中的Python语句,相比于 eval,exec可以执行更复杂的 Python 代码。 需要说明的是在 Python2 中exec不是函数,而是一个内置语句(statement),但是Python 2中有一个 execfile() 函数。可以理解为 Pytho
阅读全文
摘要:#发邮件的库import smtplib#邮件文本from email.mime.text import MIMEText#SMTP服务器SMTPServer = "smtp.163.com"#发邮件的地址sender = "15999999999@163.com"#发送者邮箱的密码passwd =
阅读全文
摘要:# python使用互译无线发送手机短信# 接口类型:互亿无线触发短信接口,支持发送验证码短信、订单通知短信等。# 账户注册:请通过该地址开通账户http://sms.ihuyi.com/register.html# 注意事项:# (1)调试期间,请用默认的模板进行测试,默认模板详见接口文档;# (
阅读全文
摘要:print(1 + 2)print("1" + "2")#不同的类型用加法会有不同的解释class Person(object): def __init__(self, num): self.num = num #运算符重载 def __add__(self, other): return Pers
阅读全文
摘要:class Person(object): def __init__(self, name, age): #属性直接对外暴露 #self.age = age #限制访问 self.__age = age self.__name = name ''' def getAge(self): return
阅读全文
摘要:from types import MethodType#创建一个空类class Person(object): __slots__ = ("name", "age", "speak")per = Person()#动态添加属性,这体现了动态语言的特点(灵活)per.name = "tom"prin
阅读全文
摘要:class Person(object): # 这里的属性实际上属于类属性(用类名来调用) name = "person" def __init__(self, name): pass #对象属性 self.name = nameprint(Person.name)per = Person("tom
阅读全文
摘要:第一类多态:from cat import Catfrom mouse import Mousefrom person import Person'''多态:一种事物的多种形态最终目标:人可以喂任何一种动物'''tom = Cat("tom")jerry = Mouse("jerry")tom.ea
阅读全文
摘要:第一类多继承的实现:from Child import Childdef main(): c = Child(300, 100) print(c.money, c.faceValue) c.play() c.eat() #注意:父类中方法名相同,默认调用的是在括号中排前面的父类中的方法 c.func
阅读全文
摘要:pycharm 不显示代码提示 1、检查是否代码本身有问题。 2、检查代码提示是否成功开启。 setting → Inspections → Spelling 要开启 setting → Inspections → Python 要打开 3、检查IDE省电模式是否关闭状态!!! file → pow
阅读全文
摘要:第一类单继承的实现:from person import Personfrom student import Studentfrom worker import Workerper = Person("aa", 1, 2)stu = Student("tom", 18, 12345, 110)pri
阅读全文
摘要:class Person(object): def run(self): print(self.__money) print("run") def eat(self, food): print("eat " + food) def __init__(self, name, age, height,
阅读全文
摘要:'''重写:将函数重写定义写一遍__str__():在调用print打印对象时自动调用,是给用户用的,是一个描述对象的方法。__repr__():是给机器用的,在Python解释器里面直接敲对象名在回车后调用的方法注意:在没有str时,且有repr,str = repr'''class Person
阅读全文
摘要:'''析构函数:__del__() 释放对象是自动调用'''class Person(object): def run(self): print("run") def eat(self, food): print("eat " + food) def __init__(self, name, age
阅读全文
摘要:'''self代表类的实例,而非类哪个对象调用方法,那么该方法中的self就代表那个对象self.__class__ 代表类名_'''class Person(object): def run(self): print("run") print(self.__class__) p = self.__
阅读全文
摘要:class Person(object): #name = "stu" #age = 10 #height = 160 #weight = 90 def run(self): print("run") def eat(self, food): print("eat " + food) def __i
阅读全文
摘要:class Person(object): name = "stu" age = 10 height = 160 weight = 90 def run(self): print("run") def eat(self, food): print("eat " + food) def openDoo
阅读全文
摘要:class Person(object): name = "" age = 0 height = 0 weight = 0 def run(self): print("run") def eat(self, food): print("eat" + food) def openDoor(self):
阅读全文
摘要:'''设计类类名:见名之意,首字母大写,其他遵循驼峰原则属性:见名之意,其他遵循驼峰原则行为(方法/功能):见名之意,其他遵循驼峰原则类名:Wife属性:sex age height weight faceValue行为:做饭 洗衣服 拖地 揉肩 捶腿类名:Husband属性:sex age hei
阅读全文
摘要:'''Mac:无需安装Linux:无需安装windows:勾选了pip和Add python.exe to Path'''#要安装三方模块,需要知道模块的名字#Pillow 非常强大的处理图像的工具库# pip install Pillow#windows如果报错,则输入pip install --
阅读全文
摘要:1、包import a.sunckimport a.kaigeimport b.sunck思考:如果不同的人编写的模块同名怎么办?解决:为了解决模块命名的冲突,引入了按目录来组织模块的方法,称为包特点:引入了包以后,只要顶层的包不与其他人发生冲突,那么模块都不会与别人的发生冲突注意:目录只有包含一个
阅读全文
摘要:1、模块,命名为sunck.py为例子 #一个.py文件就是一个模块#每一个模块都有一个__name__属性,当其值等于"__main__"时,表明该模块自身在执行。否则被引入其他文件#当前文件如果为程序的入口文件,则__name__属性的值为__main__if __name__ == "__ma
阅读全文
摘要:1、模块,命名为sunck.py为例子#一个.py文件就是一个模块def sayGood(): print("sunck is a very good man!")def sayNice(): print("sunck is a nice man!")def sayHandsome(): print
阅读全文
摘要:1、模块,命名为sunck.py为例子 #一个.py文件就是一个模块def sayGood(): print("sunck is a very good man!")def sayNice(): print("sunck is a nice man!")def sayHandsome(): prin
阅读全文
摘要:1、模块,命名为sunck.py为例子#一个.py文件就是一个模块def sayGood(): print("sunck is a very good man!")def sayNice(): print("sunck is a nice man!")def sayHandsome(): print
阅读全文
摘要:#引入模块import sysimport timeimport datetimeprint(sys.argv)#获取命令行参数的列表for i in sys.argv: print(i)'''name = sys.argv[1]age = sys.argv[2]hoby = sys.argv[3]
阅读全文
摘要:概述:目前代码比较少,写在一个文件中还体现不出什么缺点,但是随着代码量越来越多,代码就越来越难以维护。为了解决难以维护的问题,我们把很多相似功能的函数分组,分别放到不同的文件中取。这样每个文件所包含的内容相对较少,而且对于每一个文件的大致功能可用用文件名来体现。很多编程语言都是这么来组织代码结构。一
阅读全文
摘要:import timetime.clock()sum = 0for i in range(100000000): sum += iprint(time.clock())我的运行结果是10.4179203,有兴趣的可以测测玩
阅读全文
摘要:import calendar'''日历模块'''#使用#返回指定某年某月的日历print(calendar.month(2017, 7))#返回指定年的日历#print(calendar.calendar(2016))#闰年返回True,否则返回False#print(calendar.islea
阅读全文
摘要:import datetime'''datetime比time高级了不少,可以理解为datetime基于time进行了封装,提供了各位使用的函数,datetime模块的接口更直观,更容易调用模块中的类:datetime 同时有时间和日期timedelta 主要用于计算时间的跨度tzinfo 时区相关
阅读全文
摘要:第一种 python -m install pip --upgrade pip 第二种 python -m pip install -u --force-reinstall pip 第三种 pip install --user -- upgrade pip 第四种 python -m pip ins
阅读全文
摘要:import time'''UTC(世界协调时间):格林尼治天文时间,世界标准时间,在中国来说是UTC+8DST(夏令时):是一种节约能源而人为规定时间制度,在夏季调快1个小时时间的表示形式:1、时间戳以整型或浮点型表示时间的一个以秒为单位的时间间隔。这个时间间隔的基础值是从1970年1月1日领带开
阅读全文
摘要:import osimport collectionsdef getAllDirQU(path): queue = collections.deque() #进队 queue.append(path) while len(queue) != 0: #出队数据 dirPath = queue.popl
阅读全文
摘要:import osdef getAllDirDE(path): stack = [] stack.append(path) #处理栈,当栈为空的时候结束循环 while len(stack) != 0: #从栈里取出数据 #[] dirPath = stack.pop() #print(dirPat
阅读全文
摘要:import osdef getAllDirRE(path, sp = ""): #得到当前目录下所有的文件 filesList = os.listdir(path) #处理每一个文件 sp += " " for fileName in filesList: #判断是否是路径(用绝对路径) file
阅读全文
摘要:import collections#创建一个队列queue = collections.deque()print(queue)#进队(存数据)queue.append("A")print(queue)queue.append("B")print(queue)queue.append("C")pri
阅读全文
摘要:#模拟栈结构stack = []#压栈(向栈里存数据)stack.append("A")print(stack)stack.append("B")print(stack)stack.append("C")print(stack)#出栈(在栈里取数据)res1 = stack.pop()print("
阅读全文
摘要:'''递归调用:一个函数,调用了自身,称为递归调用递归函数:一个会调用自身的函数称为递归函数凡是循环能干的事,递归都能干''''''方式:1、写出临界条件2、找这一次和上一次的关系3、假设当前函数已经能用,调用自身计算上一次的结果,再求出本次的结果'''#输入一个数(大于等于1),求1+2+3+……
阅读全文
摘要:from win32com.client import constantsimport osimport win32com.clientimport pythoncomclass SpeechRecognition: def __init__(self, wordsToAdd): self.spea
阅读全文
摘要:import time#系统客户端import win32com.clientdehua = win32com.client.Dispatch("SAPI.SPVOICE")while 1: dehua.Speak("sunck is a handsome man") time.sleep(5)
阅读全文
摘要:#进程模块import win32processimport win32conimport win32guiimport win32apiimport ctypesPROCESS_ALL_ACCESS = (0x000F0000|0x00100000|0xFFF)#找窗体win = win32gui
阅读全文
摘要:import win32conimport win32guiimport timeimport randomQQWin = win32gui.FindWindow("TXGuiFoundation", "QQ")#参数1:控制的窗体#参数2:大致方位,HWND_TOPMOST上方#参数3:位置x#参
阅读全文
摘要:import win32conimport win32guiimport time#找出窗体的编号#QQWin = win32gui.FindWindow("TXGuiFoundation", "QQ")#隐藏窗体#win32gui.ShowWindow(QQWin, win32con.SW_HID
阅读全文
摘要:import os'''os:包含了普遍的操作系统的功能'''#获取操作系统类型 nt->windows posix->Linux、Unix或Mac OS Xprint(os.name)#打印操作系统详细的信息(windows不支持)#print(os.uname())'''posix.uname_
阅读全文
摘要:import pickle #数据持久性模块myList = (1,2,3,4,5,"sunck is a good man")path = r"C:\Users\xlg\Desktop\Python-1704\day08\1-文件读写\file6.txt"f = open(path, "wb")p
阅读全文
摘要:#编码path = r"C:\Users\xlg\Desktop\Python-1704\day08\1-文件读写\file5.txt"with open(path, "wb") as f1: str = "sunck is a good man凯" f1.write(str.encode("utf
阅读全文
摘要:import timepath = r"C:\Users\xlg\Desktop\Python-1704\day08\1-文件读写\file2.txt"f = open(path, "a")#写文件#1、将信息写入缓冲区f.write("sunck in")#2、刷新缓冲区#直接把内部缓冲区的数据立
阅读全文
摘要:'''过程:1、打开文件2、读文件内容3、关闭文件''''''1、打开文件open(path, flag[, encoding][, errors])path:要打开文件的路径flag:打开方式r 以只读的方式打开文件,文件的描述符放在文件的开头rb 以二进制格式打开一个文件用于只读,文件的描述符放
阅读全文
摘要:''''''#print(3 / 0)#需求:当程序遇到问题时不让程序结束,而越过错误继续向下执行'''try……except……else格式:try: 语句texcept 错误码 as e: 语句1except 错误码 as e: 语句2……except 错误码 as e: 语句nelse: 语句
阅读全文
摘要:def func(num, div): assert (div != 0), "div不能为0" return num / divprint(func(10, 0))div不等于0 才能运行成功
阅读全文
摘要:'''try……except……finally格式:try: 语句texcept 错误码 as e: 语句1except 错误码 as e: 语句2……except 错误码 as e: 语句nfinally: 语句f作用:语句t无论是否有错误都讲执行最后的语句f'''try: print(1/1)e
阅读全文
摘要:num = 10print(id(num))def func(): #声明num为全局变量,方便在函数中修改 global num # 修改num num = 20 print(id(num)) #可以使用,但是无法直接修改 #num = 20#相当于在函数内部定义了一个num #print(id(
阅读全文
摘要:第一,两者的功能不同。global关键字修饰变量后标识该变量是全局变量,对该变量进行修改就是修改全局变量,而nonlocal关键字修饰变量后标识该变量是上一级函数中的局部变量,如果上一级函数中不存在该局部变量,nonlocal位置会发生错误(最上层的函数使用nonlocal修饰变量必定会报错)。 第
阅读全文
摘要:'''def outer(): num = 10 def inner(): #修改num nonlocal num num = 20 print("在inner里打印num =", num) inner() print("在outer里打印num =", num)outer()'''def oute
阅读全文
摘要:局部-》函数-》全局-》内建python中只有模块、函数、类才会引入新的的作用域去,其他的(if/if-elif-else/while/for)等不会引入新的作用域的'''if 1: a = 10print(a)#print(num)#体现作用域def func(): b = 20 print("b
阅读全文
摘要:import functools#print(int("1010", base = 2))#偏函数def int2(str, base = 2): return int(str, base)print(int2("1011"))#把一个参数固定住,形成一个新的函数int3 = functools.p
阅读全文
摘要:def outer(func): def inner(*args, **kwargs): #添加修改的功能 print("&&&&&&&&&&&&&") return func(*args, **kwargs) return inner@outer #say = outer(say)def say(
阅读全文
摘要:def outer(func): def inner(age): if age < 0: age = 0 func(age) return inner#使用@符号将装饰器应用到函数#@python2.4支持使用@符号@outer #相当于say = outer(say)def say(age): p
阅读全文
摘要:'''概念:是一个闭包,把一个函数当做参数,返回一个替代版的函数,本质上就是一个返回函数的函数'''#简单的装饰器def func1(): print("sunck is a good man")def outer(func): def inner(): print("***************
阅读全文
摘要:import timemusicLrc = """[00:03.50]传奇[00:19.10]作词:刘兵 作曲:李健[00:20.60]演唱:王菲[00:26.60][04:40.75][02:39.90][00:36.25]只是因为在人群中多看了你一眼[04:49.00][02:47.44][00
阅读全文

浙公网安备 33010602011771号