# daily tasks have to be done habits have to be developed # some things are better when done at night # procrastination and think for ten minutes # enjoy the boredom struggle hard persistence is triumph # 2022/9/5 13:18 import time # sj=time.localtime() # print(sj) # print(time.time()) 当前时间的时间戳 #print(time.strftime('%Y %m %d %H %M %S',time.localtime())) print(time.strftime('%H %M')) #s t r f t i m e应该是string format(格式化)time的缩写 import datetime # print(datetime.date.today()) #返回当天日期 # print(datetime.date.fromtimestamp(time.time()))#根据时间戳来返回当天时间 # print(datetime.date.min) #0001-01-01 max:9999-12-31 #print(datetime.date.today().timetuple()) # t=datetime.time(10,9,8) # print(t.isoformat()) # print('------------------') # print(t.strftime('%I %M %S %p')) # print('------------------') # print(t.replace(hour=2,minute=3)) # print('------------------') # print(t.hour) #import calendar from calendar import Calendar #print(calendar.isleap(2022)) # c=Calendar() # print(list(c.iterweekdays())) # for i in c.itermonthdates(2020,2): # print(i) # from calendar import HTMLCalendar # hc=HTMLCalendar() # print(hc.formatmonth(2019,2)) # print(hc.formatyearpage(2022)) # class cat: # def __init__(self,name): # self.name=name # def eat(self, food): # self.food=food # print(self.name, '正在吃'+food) # color='black' # c=cat('tom') # c.eat('yu') # print(cat.color) # class cat: # breed='garfield' # def __eun(self,temperament): # print(self.breed+'猫的性情'+temperament) # def temper(self,temperament): # self.__eun(temperament) # sc=cat() # sc.temper('懒') # class persiancat(cat): # breed='persian' # def __init__(self,color): # print(self.breed + '是' + color + '的') # def colors(self,color): # self.color=color # class garfieldcat(cat): # def __init__(self,speed): # self.speed=speed # def run(self,speed): # print(self.breed+'的速度'+speed+'迈') # p=persiancat('黑白') # g=garfieldcat('50') # p.colors('黑') # g.run('70') # class singcat(garfieldcat): # pass # class multicat(garfieldcat,persiancat): # pass # sc=singcat('波斯猫1') # sc.run('20') # mc=multicat('渣中') # mc.run('30') # mc.colors('白') # open('D:\\code\\day1\\asdf.txt',mode='r',buffering=-1,newline=None,errors=None,closefd=True,opener=None) # wf=open('D:\\code\\day1\\asdf.txt','w',encoding='utf-8') # wf.write('shengzi') # wf.writelines(['learn python\n','i am happy']) # wf.close() # with open('D:\\code\\day1\\asdf.txt','w',encoding='utf-8') as wf: # wf.write('come on') # wf.writelines(['persistance\n','you can do it']) # with open('D:\\code\\day1\\asdf.txt','r',encoding='utf-8') as rf: # print('readline---->',rf.readline()) # print('read---->',rf.read(6)) # print('readlines---->',rf.readlines()) # with open('D:\\code\\day1\\asdf.txt','rb+') as f: # f.write(b'123456789') # print(f.tell()) # f.seek(3) # print(f.read(1)) # print(f.tell()) # f.seek(-2,2) # print(f.tell()) # print(f.read(1)) # with open('D:\\code\\day1\\asdf.txt','r+') as f: # print(f.isatty()) # f.truncate(2) # print(f.read( )) import os #print(os.listdir('D:/')) #os.mkdir('D:/pythonfile') #os.makedirs('D:/test1/test2') 创建多级目录 #print(os.system('ping www.baidu.com')) from enum import Enum # class weekday(Enum): # monday=0 # tuesday=1 # wednesday=2 # thursday=3 # friday=4 # saturday=5 # sunday=6 # print(weekday.monday) # print(weekday.monday.name) # print(weekday.monday.value) # for day in weekday: # print(day) # print(day.name) # print(day.value) # print(list(weekday)) # #枚举成员只能比较==是否相等,不能比较大小 # print(weekday.monday==weekday.tuesday) # from enum import Enum,unique # @unique # class Weekday(Enum): # monday=0 # tuesday=1 # 定义枚举时,成员名称是不可以重复的, # 但成员值是可以重复的,如果想要保证成员值不可重复, # 可以通过装饰器 @unique 来实现 # for i in 'hello': # print(i) #过程即迭代 from collections.abc import Iterable #print(isinstance(abc,Iterable)) #报错NameError: name 'abc' is not defined. Did you mean: 'abs'? # # print(isinstance('abc',Iterable)) True # print(isinstance({1,3,4},Iterable))True # print(isinstance(1002,Iterable))False #迭代器对象本质是一个数据流, # 它通过不断调用 __next__() 方法或被内置的 next() 方法 # 调用返回下一项数据,当没有下一项数据时抛出 StopIteration # 异常迭代结束。上面我们说的 for 循环语句的实现便是利用了迭代器 # class MYiterator:#迭代器 # # def __init__(self): #init initialize 初始化 # self.s = '程序之间' #初始化 # self.i = 0 # def __iter__(self): # return self #返回自身 # def __next__(self): # if self.i<4: #循环 # n=self.s[self.i] # self.i+=1 # return n # else: # raise StopIteration #注意大写和raise # mi=iter(MYiterator()) # for i in mi: # print(i) class MyIterator: def __init__(self): self.s = '程序之间' self.i = 0 def __iter__(self): return self def __next__(self): if self.i < 4: n = self.s[self.i] self.i += 1 return n else: raise StopIteration mi = iter(MyIterator()) for i in mi: print(i)