Pregunta

I am working on an API made using Python called Cobra, and it does exactly what Python does. Here is my code:

import os

x = 1

print("Cobra Programming Language 3.3.2")
print("\n\nThe new version of Python programming, but with an all new editor!")

while x == 1:
     code = input("\n\nEnter your code below:\n\n")

     f = open("C:/temp-cobra-code.py", "w")

     m = code

     f.write(m)

     f.close()

     os.system("cd\\")

     os.system("python temp-cobra-code.py")

     print("\n\n\n**********RELAUNCHING...**********\n\n")

My problem is that I can't seem to launch the CMD on Windows to display the outcome of the user's code. Am I doing something wrong? (I am using Python 3.3.2)

¿Fue útil?

Solución 2

import time
import os

localtime = time.asctime(time.localtime(time.time()))

x = 1

print("Cobra Language 3.3.3 (v3.3.3:h3js89sj9fs, February 18 2014, 20:33:34) [MSC v.1600 32/64 bit (Intel) Raihaanium Code] on win32/64")
print("\nA Replica of Python programming, but with an all new editor! The Cobra Editor Version 3.3.3!")

while x == 1:

    code = input("\n\nEnter your Cobra Code below:\n\n")

    f = open("C:\\Cobra Code Temp. File.py", "w+")

    m = code

    f.write(m)

    f.write("\n\n")

    f.write("input(\"Press ENTER to Re-launch: \")")

    f.write("\n\n\n")

    f.write("#Cobra Code 3.3.3 \n\
#Code Generated on: ")

    f.write(localtime)

    f.close()

    os.system("python C:\\Cobra Code Temp. File.py")

    print("\n**********RELAUNCHING...**********")

I have added some extra features, and repaired the bug! See for yourself!

Otros consejos

 os.system("cd\\")
 os.system("python temp-cobra-code.py")

This creates one process which changes to a different directory, then exits, and another which attempts to run Python in the current directory.

The fix is easy; don't cd at all, just use an absolute file name instead.

 os.system("python C:\\temp-cobra-code.py")

(If you do want to change directories for other reasons, do it with os.chdir().)

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top