首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >从Cmd import cmd (不使用类MyPrompt)

从Cmd import cmd (不使用类MyPrompt)
EN

Stack Overflow用户
提问于 2018-08-04 01:18:33
回答 1查看 551关注 0票数 3

这是python中的助手命令行,我希望为自己添加自定义内容,并添加了一个IP搜索器。我已经得到这个错误有一段时间了,似乎找不到它,关键是开始我的提示符。感谢您的建议,祝您愉快。

代码语言:javascript
运行
复制
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:\Users\David\eclipse-workspace\CMD\src\L2.py")

    @staticmethod
    def do_ip(self):
        """IP"""
        print("Switching to IP stuff.... ")
        os.system(r"python C:\Users\David\eclipse-workspace\CMD\src\Play.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)\Google\Chrome\Application\chrome --app=https://genvideos.org")
        if num == 2:
            print("https://www3.gomovies.sc")
            os.system("C:\Program Files (x86)\Google\Chrome\Application\chrome --app=https://www3.gomovies.sc")
        if num == 3:
            print("https://vioozgo.org/")
            os.system("C:\Program Files (x86)\Google\Chrome\Application\chrome --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)\Google\Chrome\Application\chrome --app=google.com")


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

我的错误:

代码语言:javascript
运行
复制
Traceback (most recent call last):
  File "C:\Users\David\eclipse-workspace\CMD\src\Cmdd.py", line 1, in <module>
    from cmd import Cmd
ImportError: cannot import name 'Cmd'

这是以前的工作,必须改变一些东西。我哪里错了?

EN

Stack Overflow用户

发布于 2018-08-04 01:57:26

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

为此,我在问题发生的位置附近添加了import pdb; pdb.set_trace(),在本例中是在文件的顶部。一旦进入调试模式,我就开始查看导致问题的对象。我可能会从修改导入语句开始,导入完整的cmd模块,然后再导入dir模块。您可以打印cmd.__file__以查看其来源

代码语言:javascript
运行
复制
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:\Users\David\eclipse-workspace\CMD\src\L2.py")

    @staticmethod
    def do_ip(self):
        """IP"""
        print("Switching to IP stuff.... ")
        os.system(r"python C:\Users\David\eclipse-workspace\CMD\src\Play.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)\Google\Chrome\Application\chrome --app=https://genvideos.org")
        if num == 2:
            print("https://www3.gomovies.sc")
            os.system("C:\Program Files (x86)\Google\Chrome\Application\chrome --app=https://www3.gomovies.sc")
        if num == 3:
            print("https://vioozgo.org/")
            os.system("C:\Program Files (x86)\Google\Chrome\Application\chrome --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)\Google\Chrome\Application\chrome --app=google.com")


if __name__ == '__main__':
    clear()
    prompt = MyPrompt()
    prompt.prompt = '> '
    prompt.cmdloop(cprint(figlet_format('--------\nHelper\n--------', font='smslant'), "yellow"))
票数 1
EN
查看全部 1 条回答
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/51677378

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档