目录

  • (一) 今日进展及明日计划
  • (二) 具体进展情况
    • (14) 文件操作
    • (15) 类的基本定义
    • (16) 类的属性操作
    • (17) 时间操作

(一) 今日进展及明日计划

今日进展:
1.到今天为止总算把python的全部语法过完了.

存在的问题:
1.为防止遗忘,接下来几天得想办法把学到的python语法用起来.

明日计划:
1.可以放心去修改python上位机的bug了;
2.读英文文章,争取这周把摘要和引言部分先写完.

(二) 具体进展情况

(14) 文件操作

这里是引用:https://zhidao.baidu.com/question/176982986770397124.html

这里是引用:https://blog.csdn.net/qq_26442553/article/details/81626442

# 高级:pandas、numpy
#!/usr/bin/python
# -*- coding:utf-8 -*-
txt =open('C:/Users/张志远/Desktop/python_Qt/A/abc.txt','r')
print(txt.read())

> 有bug,根本行不通

txt = open('C:/Users/张志远/Desktop/python_Qt/A/abc.txt')
# txt_read = txt.read()
# print(txt_read)
# 按行读
lines = txt.readlines()  # read()和readlines()不能同时出现
print(type(lines))
print(lines)
print('----------------------------------------------------')
for line in lines:print('cur_line',line)
# 关闭文件
# txt.close()


txt = open('C:/Users/张志远/Desktop/python_Qt/A/abc.txt','w') # 写文件(覆盖原内容)
txt.write('利威尔.阿克曼\n')
txt.write('莎夏.布劳斯\n')
txt.write('希斯特利亚.雷斯')
txt.close()

txt = open('C:/Users/张志远/Desktop/python_Qt/A/abc.txt','a')  # 追加内容
txt.write('\n进击的巨人\n')
txt.write('始祖巨人\n')
txt.write('坐标の力')
txt.close()

txt = open('C:/Users/张志远/Desktop/python_Qt/A/abc.txt','w')
for i in range(10):# txt.write(str(i)+'\n')txt.write(str(i)+'\n')
txt2 = open('C:/Users/张志远/Desktop/python_Qt/A/abc.txt','r') #这里并没有打印出来
print(txt2.read())

txt = open('C:/Users/张志远/Desktop/python_Qt/A/abc.txt','w')
for i in range(10):# txt.write(str(i)+'\n')txt.write(str(i)+'\n')
txt.close() # 加上这句就能打印出来了
txt2 = open('C:/Users/张志远/Desktop/python_Qt/A/abc.txt','r')
print(txt2.read())

txt = open('C:/Users/张志远/Desktop/python_Qt/A/abc.txt','w')
try:for i in range(11):10/(i-10)txt.write(str(i)+'\n')
except Exception:print('error',i)
finally:txt.close()


# with可以自动完成try、except、finally,遇到错误也会自动关闭文件,不用加close
with open('C:/Users/张志远/Desktop/python_Qt/A/abc.txt','w') as f: # f是别名f.write('莱纳,你坐啊')

(15) 类的基本定义

class people:'帮助信息:XXXXX'number = 100def __init__(self,name,age): # 初始化方法self.name = nameself.age = agedef display(self):print('number =',people.number) # number是在people这个类下的,只写number可不行def display_name(self):print(self.name)p1 = people('zzy',30)
p2 = people('luffy','40')print('------------从类中打印属性---------------')
print(people.__doc__)
print(p1.name)  # 打印属性不用加()
print(p2.name)
print(p1.display())
print(p2.display())# 改名字
print('----------------改名字-------------------')
print(p1.name)
p1.name = '艾伦.耶格尔'
print(p1.name)
# 删除属性
print('---------------删除属性-----------------')
# del p2.name
print(p2.name)
# 看下有没有某个属性
print('------------看某属性是否存在--------------')
print(hasattr(p1,'name'))
print(hasattr(p1,'sex'))
# 先has下看有没有某个属性,有的话就get出来
print('--------------get出某个属性--------------')
print(getattr(p1,'name'))
# set改名
print('---------------set改名------------------')
print(p1.name)
setattr(p1,'name','尤弥尔')
print(getattr(p1,'name'))
# 删除属性
print('-------------del删除属性-----------------')
# delattr(p1,'name')
print(getattr(p1,'name'))
# 打印类中的一些信息
print('----------打印类中的一些信息--------------')
print(people.__doc__) # 帮助文档
print(people.__name__) # 类的名字
print(people.__module__) # 类的定义
print(people.__bases__) # 类的副类
print(people.__dict__) # 类的结构




(16) 类的属性操作

# # 子类继承父类属性,就不必重复定义了,如狗是动物,就应该具备动物的共有属性
class parent: # 定义父类number = 100def __init__(self):print('调用父类构造函数')def parentM(self):print('调用父类方法')# def setattr(self.attr):  # 应当是‘,’,而我却看成‘.’了#     parent.parentattr = attrdef setattr(self,attr):parent.parentattr = attrdef getattr(self):print('父类属性:',parent.parentattr)
class child(parent): # 定义子类def __init__(self):print('调用子类构造函数')def childM(self):print('调用子类方法')# 子类实例化,调用子类
c = child()
c.childM()
c.parentM()
c.setattr(100)
c.getattr()

# # 子类继承父类属性,就不必重复定义了,如狗是动物,就应该具备动物的共有属性
# 父类的方法对子类不适用,就要进行方法的重写
class parent: # 定义父类number = 100def __init__(self):print('调用父类构造函数')def parentM(self):print('调用父类方法')# def setattr(self.attr):  # 应当是‘,’,而我却看成‘.’了#     parent.parentattr = attrdef setattr(self,attr):parent.parentattr = attrdef getattr(self):print('父类属性:',parent.parentattr)def newM(self):   # 父类的方法不满足于子类,进行方法的重写,此方法在子类中要重写一遍print('父类要按重新的方法')class child(parent): # 定义子类def __init__(self):print('调用子类构造函数')def childM(self):print('调用子类方法')def newM(self):  # 和父类中那个是一样的print('子类给他改掉了')# 子类实例化,调用子类
c = child()
c.childM()
c.parentM()
c.setattr(100)
c.getattr()
c.newM()   # 打印的是子类的方法

(17) 时间操作

import time
print(time.time()) # 从1970开始经历了多少时间
print(time.localtime(time.time()))
print(time.asctime(time.localtime(time.time())))
print(time.strftime('%Y-%m-%d %H:%M:%S',time.localtime()))
print(time.strftime('%y-%m-%d %H:%M:%S',time.localtime()))print('----------------------------------------------')import calendar
print(calendar.month(2019,8))
# help(time)

2019年 8月7日 日报相关推荐

  1. 2019年 8月9日 日报

    目录 (一) 今日进展及明日计划 (二) 具体进展情况 1. 关于华为预测2025十大趋势的启示 2. 关于华为鸿蒙操作系统的一些看法 3.谷歌自动重建果蝇完整大脑:40万亿像素图像首公开 (一) 今 ...

  2. 2019年 8月8日 日报

    目录 (一) 今日进展及明日计划 (二) 具体进展情况 1. 北京航天航空大学 2. 北京理工大学 3. 北京邮电大学 4.北京科技大学 5. 武汉大学 6. 北京师范大学 7. 中科院自动化研究所 ...

  3. D2 日报 2019年6月11日

    ? 开源项目 ➡️ sfyc23/EverydayWechat watch 34 star 1690 fork 317 每日自动给女朋友发微信暖心话. github.com ➡️ YMFE/yapi ...

  4. D2 日报 2019年1月2日

    官网阅读获得更好的体验,传送门<日报 2019年1月2日> 你有一个苹果,我有一个苹果,交换之后我们还是各自有一个苹果. 你有一份知识,我有一份知识,我们互相分享一下就都有了两份知识. 开 ...

  5. D2 日报 2019年4月17日

    ? 新闻 ➡️ Is React Translated Yet? ¡Sí! Sim! はい! react 文档翻译了多种语言 reactjs.org ? 开源项目 ➡️ formal/packages ...

  6. D2 日报 2019年5月20日

    ? 新闻 ➡️ Faster smarter JavaScript debugging in Firefox DevTools - Mozilla Hacks - the Web developer ...

  7. D2 日报 2019年1月3日

    官网阅读获得更好的体验,传送门<日报 2019年1月3日> 你有一个苹果,我有一个苹果,交换之后我们还是各自有一个苹果. 你有一份知识,我有一份知识,我们互相分享一下就都有了两份知识. 开 ...

  8. D2 日报 第152期 2019年7月22日

    ? 开源项目 ➡️ yehuio/Coot watch 4 star 58 fork 9 玩转 IFTTT 体验极客生活,互联网自动化神器 github.com ➡️ xiaolai/regular- ...

  9. D2 日报 2019年5月15日

    ? 开源项目 ➡️ zenghongtu/Mob watch 5 star 387 fork 31 Mob - 一个高颜值的喜马拉雅 FM 桌面客户端,支持 Mac.Win 和 Linux githu ...

  10. D2 日报 2019年6月3日

    ? 开源项目 ➡️ Simonwep/pickr 非中文 watch 13 star 1514 fork 65 一个简单,无依赖的颜色选择器组件 github.com ➡️ scrumpy/tipta ...

最新文章

  1. SpringMVC上传文件
  2. gcc for Windows 开发环境介绍
  3. android-仿QQtab
  4. java rest 图_SpringMVC视图及REST风格
  5. 管理学中的知名定律之阿尔巴德定理
  6. InputStream 转 String
  7. xyCMS框架的webshell
  8. npm aes 加密(js aes 加密)
  9. 赵雅智_Swift(2)_swift常量和变量
  10. 无限网盘,36个T,360网盘无限空间的申请方法www.credream.com
  11. 让你成为高效的Web开发者的10个步骤
  12. Google发布超难问答数据集「自然问题」:30万对问答,BERT都达不到70分
  13. 为什么勒索软件的预防如此重要?
  14. android 电源管理驱动
  15. 有一个会做饭的男朋友幸福么?
  16. 投资组合管理-风险分散与马科维茨均值方差模型
  17. sci论文、ei论文和ieee论文三者之间有什么区别?
  18. oracle的固定值
  19. 论文解读:CRBPDL:使用集成神经网络方法识别 circRNA-RBP 相互作用位点
  20. C语言中的fprintf函数

热门文章

  1. IE报证书错误提示页面,如何屏蔽?
  2. 有哪些PDF分割工具?建议收藏这些工具
  3. 机器学习笔记之基础概念
  4. 苹果系统简易音乐播放器
  5. 物无定味适口者珍,Python3并发场景(CPU密集/IO密集)任务的并发方式的场景抉择(多线程threading/多进程multiprocessing/协程asyncio)
  6. 虚拟服务器怎么选操作系统,虚拟主机怎样选择合适的操作系统
  7. 电商项目需求分析 七月实习总结
  8. Kattle Spoon同步工具
  9. 固态硬盘和机械硬盘区别 固态硬盘和机械硬盘的优缺点
  10. Miracle密码算法开源库(四)分析 :mrarth2.c