Python学习手册epub是一本用于帮助初学者学习Python编程的电子书,其中包含了Python基础知识、Python脚本编写、Python编程技巧等内容。代码如下:
Python学习手册epub是一本用于帮助初学者学习Python编程的电子书,其中包含了Python基础知识、Python脚本编写、Python编程技巧等内容。代码如下:
import epub
book = epub.EpubBook()
# set metadata
book.set_identifier('python_learning_manual')
book.set_title('Python Learning Manual')
book.set_language('en')
# add chapters
chapter1 = epub.EpubHtml(title='Introduction to Python', file_name='chapter1.xhtml', lang='en')
chapter1.content=u'
Introduction to Python
This chapter will introduce you to the basics of Python programming.
'book.add_item(chapter1)
# define Table Of Contents
book.toc = (epub.Link('chapter1.xhtml', 'Introduction to Python', 'intro'),
(epub.Section('Python Scripting'),
(epub.Link('chapter2.xhtml','Writing Your First Python Script','scripting'),
epub.Link('chapter3.xhtml','Advanced Python Scripting','advancedscripting')),
(epub.Section('Python Programming Tips'),
(epub.Link('chapter4.xhtml','Debugging Your Code','debugging'),
epub.Link('chapter5.xhtml','Optimizing Your Code','optimizing')))
)
# add default NCX and Nav file
book.add_item(epub.EpubNcx())
book.add_item(epub.EpubNav())
# define CSS style
style = 'BODY {color: white;}'
nav_css = epub.EpubItem(uid="style_nav", file_name="style/nav.css", media_type="text/css", content=style)
# add CSS file
book.add_item(nav_css)
# basic spine
book.spine = ['nav', chapter1]
# write to the file
epub.write_epub('python_learning_manual.epub', book, {})
本站系公益性非盈利分享网址,本文来自用户投稿,不代表边看边学立场,如若转载,请注明出处
评论列表(21条)