Skip to content

MindyTai/python-notebook

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 

Repository files navigation

PythonProject : ChaCha's NoteBook

tags: python

來點介紹

這是一個python的練習專題,是一個command line的記事本。 這個記事本只能透由terminal執行。 之後會有GUI版本釋出。

如何使用

這個記事本有4個功能。分別為1.Add 2.List 3.Read 4.Remove 使用者在執行完這個程式後,需要輸入這4個功能中其中一個。

Add : insert the title and the body

List: print all notes (title and body)

Read:search the title and print the note (title and body)

Remove: search the title and remove the note

- 輸入Add:

新建的Sam.txt & Dora.txt 就會在這支程式的資料夾裡。listName記錄每個新建檔案名字。

- 輸入List:

顯示各個檔案名字及內容

- 輸入Read:

讀取Sam.txt,顯示其內容

- 輸入Remove:

移除資料夾裡的Dora.txt,且刪除listName裡的Dora.txt

檔案的各種事

讀檔、創檔、寫檔

使用open( )打開檔案

語法為

var = open('fileName','mode')

mode:

r - 讀取已存在的file

w - 新建檔案寫入(file存在與否皆沒關係,若存在則清空原本的file,即會覆蓋原本file)

a - 資料附加到舊檔案後面(直接接在原本資料後面,無空格)

讀檔:

var = open('fileName','r')

創檔&寫檔:

var = open('fileName','w')
fileContent = input( )
var.write(fileContent)

從一個file裡刪除資料

1. open the file

f = open("file.txt","r")

2. get lines from the file

lines = f.readlines()

3. close the file

f.close()

4. reopen it in w mode

f = open("file.txt","w")

5. write the lines back, and don't write the line which you want to delete. Add the "\n" to whatever line ending your file uses.

for line in lines:
      if line!="The_thing_to_delete"+"\n":
        f.write(line)

從一個file裡新增資料

1. Open the file and set it to a mode

f = open('yourfile.txt', 'a', encoding = 'UTF-8') 

2. Write the content in it

FileContent = f.write(the content you want to write)   

License

MIT © MindyTai

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages