Skip to Content
Python 技術手冊 第三版
book

Python 技術手冊 第三版

by lex Martelli, Anna Martelli Ravenscroft, Steve Holden
January 2018
Intermediate to advanced content levelIntermediate to advanced
856 pages
17h 17m
Chinese
GoTop Information, Inc.
Content preview from Python 技術手冊 第三版
372
|
10 章 檔案與文字作業
一個 Cmd 範例
下列的範例展示如何使用
cmd.Cmd
來提供動詞
print
(輸出文字行其餘部
分)和
stop
(結束迴圈):
import cmd
class X(cmd.Cmd):
def do_print(self, rest):
print(rest)
def help_print(self):
print('print (any string): outputs (any string)')
def do_stop(self, rest):
return True
def help_stop(self):
print('stop: terminates the command loop')
if __name__ == '_ _main_ _':
X().cmdloop()
使用這個範例的工作階段可能會像這樣:
C:\>python examples/chapter10/cmdex.py
(Cmd) help
Documented commands (type help <topic>):
= == == == == == == == == == == == == == == == == == == == =
print stop
Undocumented commands:
= == == == == == == == == == == =
help
(Cmd) help print
print (any string): outputs (any string) ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

測試驅動開發|使用 Python

測試驅動開發|使用 Python

Harry J.W. Percival
Linux 内核观测技术BPF

Linux 内核观测技术BPF

David Calavera, Lorenzo Fontana

Publisher Resources

ISBN: 9789864766819