• 大小: 7.15MB
    文件类型: .zip
    金币: 1
    下载: 0 次
    发布日期: 2023-11-18
  • 语言: Python
  • 标签: python  

资源简介

挺不错的挺不错的

资源截图

代码片段和文件信息


# coding: utf-8

# # 将笔记转化为不同的文件格式

# In[1]:

import os
import os.path
import nbconvert
import glob


# 检查路径是否存在,删除旧的文件:

# In[2]:

if not os.path.exists(‘static-files‘):
    os.mkdir(‘static-files‘)
    
for n in glob.glob(‘static-files/*/*/*‘):
    os.remove(n)


# 文件夹:

# In[3]:

folders = [‘01-python-tools‘ 
           ‘02-python-essentials‘
           ‘03-numpy‘
           ‘04-scipy‘
           ‘05-advanced-python‘
           ‘06-matplotlib‘
           ‘07-interfacing-with-other-languages‘
           ‘08-object-oriented-programming‘
           ‘09-theano‘
           ‘10-something-interesting‘
           ‘11-useful-tools‘
           ‘12-pandas‘
          ]


# 遍历文件夹得到所有的文件名:

# In[4]:

file_names = []

for folder in folders:
    files = sorted(os.listdir(folder))
    file_names += [os.path.join(folder file_name) for file_name in files if file_name.endswith(‘.ipynb‘)]


# In[5]:

def convert_to_files(names to_format):
    target_dir = os.path.join(“static-files“ to_format)
    for folder in folders:
        if not os.path.exists(os.path.join(target_dir folder)):
            os.makedirs(os.path.join(target_dir folder))
    converter = {
        “html“: nbconvert.export_html
        “python“: nbconvert.export_python
        }
    
    for file_name in names:
        p = converter[to_format](file_name)
        with open(os.path.join(target_dir file_name[:-6] + p[1][“output_extension“]) ‘w‘) as f:
            f.write(p[0].encode(“utf-8“))
        print file_name


# 转化 HTML 文件:

# In[6]:

convert_to_files(file_names “html“)


# 产生新目录:

# In[7]:

with open(‘index.md‘) as f:
    text = f.read()
    with open(os.path.join(“static-files“ “html“ “README.md“) “w“) as g:
        g.write(text.replace(“.ipynb“ “.html“))


 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----
     目录           0  2019-05-10 19:19  python入门笔记(强烈推荐)\
     文件          17  2017-04-16 23:49  python入门笔记(强烈推荐)\.gitattibutes
     文件         131  2017-04-16 23:49  python入门笔记(强烈推荐)\.gitignore
     目录           0  2019-05-10 19:19  python入门笔记(强烈推荐)\.ipynb_checkpoints\
     文件       17006  2017-04-20 19:02  python入门笔记(强烈推荐)\.ipynb_checkpoints\index-checkpoint.ipynb
     目录           0  2019-05-10 19:19  python入门笔记(强烈推荐)\01-python-tools\
     文件        7403  2017-04-16 23:49  python入门笔记(强烈推荐)\01-python-tools\01.01-python-overview.ipynb
     文件       19567  2017-04-16 23:49  python入门笔记(强烈推荐)\01-python-tools\01.02-ipython-interpreter.ipynb
     文件         958  2017-04-16 23:49  python入门笔记(强烈推荐)\01-python-tools\01.03-ipython-notebook.ipynb
     文件       15044  2017-04-16 23:49  python入门笔记(强烈推荐)\01-python-tools\01.04-use-anaconda.ipynb
     目录           0  2019-05-10 19:19  python入门笔记(强烈推荐)\02-python-essentials\
     文件       55190  2017-04-16 23:49  python入门笔记(强烈推荐)\02-python-essentials\02.01-a-tour-of-python.ipynb
     文件        1500  2017-04-16 23:49  python入门笔记(强烈推荐)\02-python-essentials\02.02-python-data-types.ipynb
     文件       26095  2017-04-16 23:49  python入门笔记(强烈推荐)\02-python-essentials\02.03-numbers.ipynb
     文件       22959  2017-04-16 23:49  python入门笔记(强烈推荐)\02-python-essentials\02.04-strings.ipynb
     文件        9749  2017-04-16 23:49  python入门笔记(强烈推荐)\02-python-essentials\02.05-indexing-and-slicing.ipynb
     文件       23262  2017-04-16 23:49  python入门笔记(强烈推荐)\02-python-essentials\02.06-lists.ipynb
     文件        6869  2017-04-16 23:49  python入门笔记(强烈推荐)\02-python-essentials\02.07-mutable-and-immutable-data-types.ipynb
     文件        5899  2017-04-16 23:49  python入门笔记(强烈推荐)\02-python-essentials\02.08-tuples.ipynb
     文件        4117  2017-04-16 23:49  python入门笔记(强烈推荐)\02-python-essentials\02.09-speed-comparison-between-list-&-tuple.ipynb
     文件       24323  2017-04-16 23:49  python入门笔记(强烈推荐)\02-python-essentials\02.10-dictionaries.ipynb
     文件       20447  2017-04-16 23:49  python入门笔记(强烈推荐)\02-python-essentials\02.11-sets.ipynb
     文件        3175  2017-04-16 23:49  python入门笔记(强烈推荐)\02-python-essentials\02.12-frozen-sets.ipynb
     文件       12198  2017-04-16 23:49  python入门笔记(强烈推荐)\02-python-essentials\02.13-how-python-assignment-works.ipynb
     文件        8460  2017-04-16 23:49  python入门笔记(强烈推荐)\02-python-essentials\02.14-if-statement.ipynb
     文件        8998  2017-04-16 23:49  python入门笔记(强烈推荐)\02-python-essentials\02.15-loops.ipynb
     文件        5110  2017-04-16 23:49  python入门笔记(强烈推荐)\02-python-essentials\02.16-list-comprehension.ipynb
     文件       17508  2017-04-16 23:49  python入门笔记(强烈推荐)\02-python-essentials\02.17-functions.ipynb
     文件       11989  2017-04-16 23:49  python入门笔记(强烈推荐)\02-python-essentials\02.18-modules-and-packages.ipynb
     文件       22764  2017-04-16 23:49  python入门笔记(强烈推荐)\02-python-essentials\02.19-exceptions.ipynb
     文件        2316  2017-04-16 23:49  python入门笔记(强烈推荐)\02-python-essentials\02.20-warnings.ipynb
............此处省略160个文件信息

评论

共有 条评论