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

StackOverflow https://stackoverflow.com/questions/21419427

  •  04-10-2022
  •  | 
  •  

Question

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%! I have no clue what I'm doing wrong and any help would be greatly appreciated!

Was it helpful?

Solution

You have conflicting definitions of x:

import DefaultX as x

x = raw_input (">>>")

Change one of them.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top