-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4c04bc9
commit e8ed336
Showing
7 changed files
with
165 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
/.quarto/ | ||
/*cache/ | ||
/data/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,6 +7,7 @@ number-sections: true | |
code-fold: show | ||
code-link: true | ||
code-tools: true | ||
format: html | ||
--- | ||
|
||
# 基本数据类型 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -41,6 +41,8 @@ book: | |
- control_structure.qmd | ||
- function.qmd | ||
- class.qmd | ||
- file_RW.qmd | ||
- visualization.qmd | ||
|
||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
--- | ||
knitr: | ||
opts_chunk: | ||
comment: "#>>>" | ||
collapse: TRUE | ||
number-sections: true | ||
code-fold: show | ||
code-link: true | ||
code-tools: true | ||
--- | ||
|
||
# 文件处理 | ||
|
||
## 读取文件 | ||
|
||
```{python} | ||
f = open("data/pi_digits.txt",mode="r") | ||
contents = f.read() | ||
print(contents) | ||
contents = contents.rstrip() | ||
print(contents) | ||
f.close() | ||
``` | ||
|
||
```{python} | ||
with open("data/pi_digits.txt",mode="r") as g: | ||
for i in g: | ||
print(i) | ||
``` | ||
|
||
```{python} | ||
from pathlib import Path | ||
path = Path("data/pi_digits.txt") | ||
f = path.read_text() | ||
f = f.splitlines() | ||
for i in f: | ||
print(i) | ||
``` | ||
|
||
## 写入文件 | ||
|
||
```{python} | ||
with open("data/write.txt",mode="a") as w: | ||
w.write("Π是无限不循环小数。") | ||
with open("data/write.txt",mode="a") as w: | ||
w.write("fafhaofhaohfo") | ||
``` | ||
|
||
## 异常处理 | ||
|
||
exception | ||
|
||
```{python} | ||
def division(dividend,divisor): | ||
answer = dividend/divisor | ||
return(answer) | ||
division(4,2) | ||
division(4,0) | ||
|
||
def division_(dividend,divisor): | ||
try: | ||
answer = dividend/divisor | ||
except ZeroDivisionError: | ||
print("You can't divide by 0!") | ||
else: | ||
return(answer) | ||
finally: | ||
print("OK") | ||
division_(4,2) | ||
division_(4,0) | ||
``` | ||
|
||
## 存储数据 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
--- | ||
title: "visualization.qmd" | ||
knitr: | ||
opts_chunk: | ||
comment: "#>>>" | ||
collapse: TRUE | ||
number-sections: true | ||
code-fold: show | ||
code-link: true | ||
code-tools: true | ||
format: html | ||
editor: visual | ||
--- | ||
|
||
# 数据可视化 | ||
|
||
Matplotlib |