Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

first time in vip-github-project #63

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions vip/wingsdouble/python快速入门/day1_面向对象编程.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
title: 面向对象编程
tag:
- python
- coding
---

Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
异常的继承关系是这样的:

![img](https://vip.fxxkpython.com/wp-content/uploads/2019/10/Screenshot-from-2019-10-10-17-44-23.png)
127 changes: 127 additions & 0 deletions vip/wingsdouble/python快速入门/note/文件操作.md
Original file line number Diff line number Diff line change
@@ -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)
3 changes: 3 additions & 0 deletions vip/wingsdouble/python快速入门/note/自定义异常.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
![img](https://vip.fxxkpython.com/wp-content/uploads/2019/10/Screenshot-from-2019-10-12-18-19-08.png)

其中value不一定通过初始化函数进行传递,也可直接初始化。
Original file line number Diff line number Diff line change
@@ -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__)
19 changes: 19 additions & 0 deletions vip/wingsdouble/readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# ***Introduction***

从公众号过来的,写了很久的java代码,目前从事建模语言构建的工作。

### 从哪里来:

从公众号过来的,没办法,人帅就够了,话还骚,关键教程是真的推敲和实践过的,每一行都能够复现,真的让人很难拒绝。

### 到哪里去:

1. 希望能够了解python的细节,真正掌握一门编程语言。目前工作中主要用的Java(eclipse的EMF框架),但是因为非软件工程科班出身,很多编程上面的细节并不清楚,很需要系统性的全面的学习一门编程语言。

2. 从python开始进行NLP方面的项目实践,作为未来研究方向的交叉工具,目前几乎所有的AI相关的工程都采用python,不得不学。

3. 实在是帅B说话好听,学习真的就当日常娱乐了(比游戏好玩多了)。

***ps***

独学而无友,则孤陋而寡闻 ------一起进步成长,以此共勉