파이썬 cmd 모듈
cmd모듈이란?
Support for line-oriented command interpreters
Cmd.
cmdloop
(intro=None)Repeatedly issue a prompt, accept input, parse an initial prefix off the received input, and dispatch to action methods, passing them the remainder of the line as argument.
The optional argument is a banner or intro string to be issued before the first prompt (this overrides the intro
class attribute) [생략..]
또 사이트의 예제에 보면 아래와 같이 되어있다. self,arg는 기본인자로 아래의 형태가 기본 형태이다.
아주아주 간단하게 코드를 짜봣다 사용방법은 쉬워서 어려운게 없당 ㅎㅎ
import cmd
class my(cmd.Cmd):
intro = " Hello "
prompt = " (mdp) "
file= None
def do_hello(self,arg):
'print Hello~'
self.hello(arg)
def do_name(self,arg):
'print name'
self.name()
def do_job(self,arg):
'print job'
self.job()
def hello(self,arg):
print('Hello~',arg)
def name(self):
print('weejiwon')
def job(self):
print('College student ')
my().cmdloop()
weejw@weejwPC:~/observer$ python3 my.py
Hello
(mdp) ?
Documented commands (type help <topic>):
========================================
hello help job name
(mdp) help hello
print Hello~
(mdp) hello weejiwon
Hello~ weejiwon
(mdp) help job
print job
(mdp) job
College student
(mdp) help name
print name
(mdp) name
weejiwon
(mdp)