diff --git "a/vip/wingsdouble/python\345\277\253\351\200\237\345\205\245\351\227\250/day1_\351\235\242\345\220\221\345\257\271\350\261\241\347\274\226\347\250\213.md" "b/vip/wingsdouble/python\345\277\253\351\200\237\345\205\245\351\227\250/day1_\351\235\242\345\220\221\345\257\271\350\261\241\347\274\226\347\250\213.md" new file mode 100644 index 0000000..69ee9ba --- /dev/null +++ "b/vip/wingsdouble/python\345\277\253\351\200\237\345\205\245\351\227\250/day1_\351\235\242\345\220\221\345\257\271\350\261\241\347\274\226\347\250\213.md" @@ -0,0 +1,7 @@ +--- +title: 面向对象编程 +tag: + - python + - coding +--- + diff --git "a/vip/wingsdouble/python\345\277\253\351\200\237\345\205\245\351\227\250/note/\345\274\202\345\270\270\347\232\204\347\273\247\346\211\277\345\205\263\347\263\273.md" "b/vip/wingsdouble/python\345\277\253\351\200\237\345\205\245\351\227\250/note/\345\274\202\345\270\270\347\232\204\347\273\247\346\211\277\345\205\263\347\263\273.md" new file mode 100644 index 0000000..34e19ed --- /dev/null +++ "b/vip/wingsdouble/python\345\277\253\351\200\237\345\205\245\351\227\250/note/\345\274\202\345\270\270\347\232\204\347\273\247\346\211\277\345\205\263\347\263\273.md" @@ -0,0 +1,3 @@ +异常的继承关系是这样的: + +![img](https://vip.fxxkpython.com/wp-content/uploads/2019/10/Screenshot-from-2019-10-10-17-44-23.png) \ No newline at end of file diff --git "a/vip/wingsdouble/python\345\277\253\351\200\237\345\205\245\351\227\250/note/\346\226\207\344\273\266\346\223\215\344\275\234.md" "b/vip/wingsdouble/python\345\277\253\351\200\237\345\205\245\351\227\250/note/\346\226\207\344\273\266\346\223\215\344\275\234.md" new file mode 100644 index 0000000..681386f --- /dev/null +++ "b/vip/wingsdouble/python\345\277\253\351\200\237\345\205\245\351\227\250/note/\346\226\207\344\273\266\346\223\215\344\275\234.md" @@ -0,0 +1,127 @@ +建一个目录可以这样: + +![img](https://vip.fxxkpython.com/wp-content/uploads/2019/10/Screenshot-from-2019-10-14-18-29-12.png) + +这样就创建了一个新目录了: + +![img](https://vip.fxxkpython.com/wp-content/uploads/2019/10/Screenshot-from-2019-10-14-18-30-46.png) + +## 修改目录名 + +这里只是为了演示,一般情况下,目录的名称不建议使用中文,用英文会好一些,那么我们可以使用 Python 来修改一下目录的名称: + +![img](https://vip.fxxkpython.com/wp-content/uploads/2019/10/Screenshot-from-2019-10-14-18-35-02.png) + +这时候目录名就修改了: + +![img](https://vip.fxxkpython.com/wp-content/uploads/2019/10/Screenshot-from-2019-10-14-18-34-47.png) + +## 获取目录路径 + +接着,你可以使用 getcwd() 来获取你现在所处的路径: + +![img](https://vip.fxxkpython.com/wp-content/uploads/2019/10/Screenshot-from-2019-10-14-18-36-35.png) + +比如这里,我是处于 ‘/home/wistbean’ 这个路劲下。 + +## 切换目录 + +那么我们要进入我们刚刚创建的文件夹怎么搞呢?这样: + +![img](https://vip.fxxkpython.com/wp-content/uploads/2019/10/Screenshot-from-2019-10-14-18-37-54.png) + +也就是说, os 的 chdir 方法,就相当于切换目录的意思。 + +## 删除目录 + +我们想把这个目录删除掉的话,也很简单: + +![img](https://vip.fxxkpython.com/wp-content/uploads/2019/10/Screenshot-from-2019-10-14-18-41-26.png) + +这样,文件就消失了: + +![img](https://vip.fxxkpython.com/wp-content/uploads/2019/10/Screenshot-from-2019-10-14-18-41-38.png) + +ok,接着我们再来使用 Python 操作文件。 + +## 打开文件 + +Python 中有一个内置的方法—— open(), 使用它我们就可以打开指定的文件了,我们先创建一个 txt 文件: + +![img](https://vip.fxxkpython.com/wp-content/uploads/2019/10/Screenshot-from-2019-10-14-20-42-13.png) + +然后用 Python 来打开这个文件: + +![img](https://vip.fxxkpython.com/wp-content/uploads/2019/10/Screenshot-from-2019-10-14-20-42-50.png) + +## **读取文件** + +通过 read 方法就可以读取到文件中的内容了: + +![img](https://vip.fxxkpython.com/wp-content/uploads/2019/10/Screenshot-from-2019-10-14-20-43-25.png) + +当然,你也可以逐行读取: + +![img](https://vip.fxxkpython.com/wp-content/uploads/2019/10/Screenshot-from-2019-10-14-20-44-04.png) + +## 文件操作模式 + +在使用 open 方法的时候,你还可以指定文件的模式,比如只读,还是要写入,追加等模式,比如默认的只读模式: + +![img](https://vip.fxxkpython.com/wp-content/uploads/2019/10/Screenshot-from-2019-10-14-20-47-00.png) + +常见的文件模式要以下几种 + +``` + =============================================================== +Character Meaning +--------- --------------------------------------------------------------- +'r' 只读模式 +'w' 写入模式 +'x' 创建一个新的可写文件 +'a' 追加内容 +'b' 字节模式 +'t' 文本模式 +'+' 打开磁盘文件进行读写 + =============================================================== +``` + +这些模式可以组合使用,比如你想要这个文件以字节的模式读取文件可以这样: + +![img](https://vip.fxxkpython.com/wp-content/uploads/2019/10/Screenshot-from-2019-10-14-20-59-47.png) + +那么要写入文件内容就可以使用 w 模式: + +![img](https://vip.fxxkpython.com/wp-content/uploads/2019/10/Screenshot-from-2019-10-14-21-01-45.png) + +这时候你打开文件会发现之前的内容被直接都替换了: + +![img](https://vip.fxxkpython.com/wp-content/uploads/2019/10/Screenshot-from-2019-10-14-21-02-12.png) + +那么如果你仅仅是想要追加内容呢?一样的道理,使用 a 模式: + +![img](https://vip.fxxkpython.com/wp-content/uploads/2019/10/Screenshot-from-2019-10-14-21-03-27.png) + +这样你的内容就追加到文件了: + +![img](https://vip.fxxkpython.com/wp-content/uploads/2019/10/Screenshot-from-2019-10-14-21-04-10.png) + +## 关闭文件 + +当你操作完文件的时候,需要关闭这个文件,这样 Python 才不会一直引用它,不会浪费资源,关闭文件很简单,调用 close 方法即可: + +![img](https://vip.fxxkpython.com/wp-content/uploads/2019/10/Screenshot-from-2019-10-14-21-08-59.png) + +## **文件的**重**命名和删除** + +关于文件的重命名和删除可以使用 os 模块的 rename 方法和 remove 方法。 + +重命名文件: + +![img](https://vip.fxxkpython.com/wp-content/uploads/2019/10/Screenshot-from-2019-10-14-21-12-00.png) + +删除文件: + +![img](https://vip.fxxkpython.com/wp-content/uploads/2019/10/Screenshot-from-2019-10-14-21-12-35.png) + +如果你想读取一个目录下的所有文件,可以使用 os.listdir(“路径”) 来获取该目录下的所有文件名,再通过 open 打开文件就可以了。当然,关于文件的 open ,还可以使用我们之前说的 with 语句更加方便操作: [牛逼的 with 语句 ](https://vip.fxxkpython.com/?p=525) \ No newline at end of file diff --git "a/vip/wingsdouble/python\345\277\253\351\200\237\345\205\245\351\227\250/note/\350\207\252\345\256\232\344\271\211\345\274\202\345\270\270.md" "b/vip/wingsdouble/python\345\277\253\351\200\237\345\205\245\351\227\250/note/\350\207\252\345\256\232\344\271\211\345\274\202\345\270\270.md" new file mode 100644 index 0000000..afb7d6f --- /dev/null +++ "b/vip/wingsdouble/python\345\277\253\351\200\237\345\205\245\351\227\250/note/\350\207\252\345\256\232\344\271\211\345\274\202\345\270\270.md" @@ -0,0 +1,3 @@ +![img](https://vip.fxxkpython.com/wp-content/uploads/2019/10/Screenshot-from-2019-10-12-18-19-08.png) + +其中value不一定通过初始化函数进行传递,也可直接初始化。 \ No newline at end of file diff --git "a/vip/wingsdouble/python\345\277\253\351\200\237\345\205\245\351\227\250/source_code/class_multi_super.py" "b/vip/wingsdouble/python\345\277\253\351\200\237\345\205\245\351\227\250/source_code/class_multi_super.py" new file mode 100644 index 0000000..e17a415 --- /dev/null +++ "b/vip/wingsdouble/python\345\277\253\351\200\237\345\205\245\351\227\250/source_code/class_multi_super.py" @@ -0,0 +1,25 @@ +class Person: + + def __init__(self,name,age): + self.name = name + self.age = age + + def eat(self, food): + print(self.name,' 正在吃{}'.format(food)) + +class YellowPeopleFather(Person): + def eat(self,food): + print("黄种人的eat方法") + +class WhitePeopleMother(Person): + def eat(self,food): + print("白种人的eat方法") + +class Son(YellowPeopleFather, WhitePeopleMother): + def eat(self, food): + super(WhitePeopleMother,self).eat(food) + +he = Son('hey', 90) + +he.eat("水果沙拉") +print(Son.__mro__) diff --git a/vip/wingsdouble/readme.md b/vip/wingsdouble/readme.md new file mode 100644 index 0000000..4f63811 --- /dev/null +++ b/vip/wingsdouble/readme.md @@ -0,0 +1,19 @@ +# ***Introduction*** + +从公众号过来的,写了很久的java代码,目前从事建模语言构建的工作。 + +### 从哪里来: + +从公众号过来的,没办法,人帅就够了,话还骚,关键教程是真的推敲和实践过的,每一行都能够复现,真的让人很难拒绝。 + +### 到哪里去: + +1. 希望能够了解python的细节,真正掌握一门编程语言。目前工作中主要用的Java(eclipse的EMF框架),但是因为非软件工程科班出身,很多编程上面的细节并不清楚,很需要系统性的全面的学习一门编程语言。 + +2. 从python开始进行NLP方面的项目实践,作为未来研究方向的交叉工具,目前几乎所有的AI相关的工程都采用python,不得不学。 + +3. 实在是帅B说话好听,学习真的就当日常娱乐了(比游戏好玩多了)。 + +***ps*** + + 独学而无友,则孤陋而寡闻 ------一起进步成长,以此共勉 \ No newline at end of file