小工具:使用Python自動產生MD風格連結

來源:互聯網
上載者:User

標籤:[]   root   continue   import   格式   https   pre   com   忽略   

很久之前我在Github上搞了一個LeetCode的倉庫,但一直沒怎麼維護。最近發現自己刷了不少LC的題目了,想搬運到這個倉庫上。

玩Github最重要的當然是寫README了,MD的逼格決定了項目牛逼不牛逼。但是讓我一個一個去手寫項目中的連結那是不可能的,這輩子都不可能手寫,只有寫指令碼自動產生才能滿足裝逼的樣子。

import osimport os.path# 根目錄rootdir="E:/gitTest/LeetCode/"list=[]result=[]# 定義連結首碼prefix="https://github.com/rever4433/LeetCode/tree/master/"# 連結中的空格space="%20"for parent,dirnames,filenames in os.walk(rootdir):    for dirname in dirnames:        # 忽略的檔案名稱        if dirname == ".git":            continue        # 檔案夾名放入list        if os.path.isdir(dirname):            list.append(dirname)                    for i in list:    linkSuffix=i.replace(" ",space)    # 產生MD連結,格式:### 1.[Invert Tree]()     i="### "+str(list.index(i)+1)+".["+i+"]("+prefix+linkSuffix+")"    result.append(i)with open(‘test.md‘,‘w‘) as fw:    fw.write(‘%s‘%‘\n‘.join(result))    

小工具:使用Python自動產生MD風格連結

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.