简体   繁体   English

有人可以向我解释此Python代码中我在做什么错,并帮我弄清楚吗?

[英]Could someone explain to me what I'm doing wrong in this Python Code and help me figure it out?

Here is the error: 这是错误:

    Traceback (most recent call last):
      File "/home/endergreen/PyOS/SHOE/C.pyx", line 24, in <module>
        x.execute()
    AttributeError: 'str' object has no attribute 'execute'

Here is the set of code: 这是代码集:

    #!/usr/bin/env python
    import os as os
    import sys as sys
    import time as time
    import DefaultX as x

    def setup():
        execfile ("Setup.pyx")
        print ("Running...")
    def start():
        execfile ("/HDD/BOOT.pyrx")
        print ("Running...")
    def end():
        print ("Stopping...")
        time.sleep (3)

    x.machine_start
    x = raw_input (">>>")
    if x == 'setup':
        x.setup()
    if x == 'start':
        x.start()
    if x == 'execute':
        x.execute()
    if x == 'chkfile':
        x.chkfile()
    if x == 'chkinstall':
        x.chkdisk()
    if x == 'commands':
        x.cmds()
    else:
        print ("Unsupported Command")
        raw_input ("Press [Enter] to continue...")
        execfile ("C.pyx")

The error appears to be saying that the 'execute' function has not been defined in DefaultX.py, but I've used the SAME EXACT CODE (a literal copy-paste situation) in another project and it worked 100%! 错误似乎是在“ DefaultX.py”中尚未定义“执行”功能,但是我在另一个项目中使用了“相同的精确代码”(按字面意思复制粘贴的情况),它的工作效率为100%! I have no clue what I'm doing wrong and any help would be greatly appreciated! 我不知道我在做什么错,任何帮助将不胜感激!

You have conflicting definitions of x : 您对x定义有冲突:

import DefaultX as x

x = raw_input (">>>")

Change one of them. 更改其中之一。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 有人可以告诉我我做错了什么[暂停] - Can someone tell me what I'm doing wrong [on hold] 有人可以为我解释此代码吗? - Could someone explain this code for me? 有人可以帮我将 **for 循环** 替换为 **while 循环** 我正在努力弄清楚吗? - Can someone help me replace the **for loop** to **while loop** I'm struggling to figure it out? 有人可以向我解释python-twisted就像我五岁一样? - Could someone explain to me python-twisted like I'm five? 有人可以帮我弄清楚如何在我的 python 刽子手代码上更新我的破折号 - May someone help me figure out how to update my dashes on my python hangman code 有人可以向我解释为什么我的代码有效吗? (异步蟒蛇) - Could someone explain to me why my code works? (Asyncio python) 有人可以通过这个Python代码并向我解释 - Could someone go through this Python code and explain it to me 有人可以帮我理解什么.index 在这段代码中做了什么吗? - Can someone help me understand what .index is doing in this code? 有人可以向我解释我做错了什么吗? - can someone explain to me what I did wrong? 我不知道如何解决这个问题,有人可以帮助我吗? Pirple作业python - I cannot figure out how to fix this problem, can someone help me ? Pirple homework python
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM