来自cmd import cmd(不适用于MyPrompt类)



这是python中的一个助手命令行,我当然想为自己添加自定义内容,并在IP搜索器中添加。我已经收到这个错误有一段时间了,似乎无法解决它,启动我的提示至关重要。感谢任何提示,祝您愉快。

from cmd import Cmd
import pyautogui as pag #Future#
import time #Debugging/Future#
import sys,os
clear = lambda : os.system('cls')
#############################################
from colorama import init
from ctypes.test.test_pickling import name
init(strip=not sys.stdout.isatty()) # strip colors if stdout is redirected
from termcolor import cprint 
from pyfiglet import figlet_format
##############################################
class MyPrompt(Cmd):
@staticmethod
def do_lineage(self):
"""Switch to Lineage 2 Helper"""
print("Switching to Lineage 2 Helper....")
os.system(r"python C:UsersDavideclipse-workspaceCMDsrcL2.py")
@staticmethod
def do_ip(self):
"""IP"""
print("Switching to IP stuff.... ")
os.system(r"python C:UsersDavideclipse-workspaceCMDsrcPlay.py")    
@staticmethod
def do_quit(self):
"""Quits the program."""
print("Quitting...")
raise SystemExit
@staticmethod
def do_Movies(self,num):
"""1-3 different sites, or all for """
if num == 1:
print("https://genvideos.org")
os.system("C:Program Files (x86)GoogleChromeApplicationchrome --app=https://genvideos.org")
if num == 2:
print("https://www3.gomovies.sc")
os.system("C:Program Files (x86)GoogleChromeApplicationchrome --app=https://www3.gomovies.sc")
if num == 3:
print("https://vioozgo.org/")
os.system("C:Program Files (x86)GoogleChromeApplicationchrome --app=google.com")
if num == "all":
print("https://genvideos.org")
print("https://www3.gomovies.sc")
print("https://vioozgo.org/")
os.system("C:Program Files (x86)GoogleChromeApplicationchrome --app=google.com")

if __name__ == '__main__':
clear()
prompt = MyPrompt()
prompt.prompt = '> '
prompt.cmdloop(cprint(figlet_format('--------nHelpern--------', font='smslant'), "yellow"))

我的错误:

Traceback (most recent call last):
File "C:UsersDavideclipse-workspaceCMDsrcCmdd.py", line 1, in <module>
from cmd import Cmd
ImportError: cannot import name 'Cmd'

这以前是有效的,一定改变了一些东西。我哪里错了?

当我遇到这样的问题时,我喜欢在命令行中将自己放入调试器中,并开始四处查找。

要做到这一点,我在问题发生的地方附近添加import pdb; pdb.set_trace(),在本例中是在文件的顶部。一旦进入调试模式,我就开始查看导致问题的对象。我可能会从更改import语句开始,导入完整的cmd模块,然后我会dir所说的模块。您可以打印cmd.__file__以查看它来自的位置

import cmd
import pdb; pdb.set_trace()
# code stops here so you can start digging
# dir(cmd) will tell you what properties the module has
# cmd.__file__ will tell you the file path
from cmd import Cmd
import pyautogui as pag #Future#
import time #Debugging/Future#
import sys,os
clear = lambda : os.system('cls')
#############################################
from colorama import init
from ctypes.test.test_pickling import name
init(strip=not sys.stdout.isatty()) # strip colors if stdout is redirected
from termcolor import cprint 
from pyfiglet import figlet_format
##############################################
class MyPrompt(Cmd):
@staticmethod
def do_lineage(self):
"""Switch to Lineage 2 Helper"""
print("Switching to Lineage 2 Helper....")
os.system(r"python C:UsersDavideclipse-workspaceCMDsrcL2.py")
@staticmethod
def do_ip(self):
"""IP"""
print("Switching to IP stuff.... ")
os.system(r"python C:UsersDavideclipse-workspaceCMDsrcPlay.py")    
@staticmethod
def do_quit(self):
"""Quits the program."""
print("Quitting...")
raise SystemExit
@staticmethod
def do_Movies(self,num):
"""1-3 different sites, or all for """
if num == 1:
print("https://genvideos.org")
os.system("C:Program Files (x86)GoogleChromeApplicationchrome --app=https://genvideos.org")
if num == 2:
print("https://www3.gomovies.sc")
os.system("C:Program Files (x86)GoogleChromeApplicationchrome --app=https://www3.gomovies.sc")
if num == 3:
print("https://vioozgo.org/")
os.system("C:Program Files (x86)GoogleChromeApplicationchrome --app=google.com")
if num == "all":
print("https://genvideos.org")
print("https://www3.gomovies.sc")
print("https://vioozgo.org/")
os.system("C:Program Files (x86)GoogleChromeApplicationchrome --app=google.com")

if __name__ == '__main__':
clear()
prompt = MyPrompt()
prompt.prompt = '> '
prompt.cmdloop(cprint(figlet_format('--------nHelpern--------', font='smslant'), "yellow"))

最新更新