0

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)

2 Answers 2

1
 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().)

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks, Tripleee, but still doesn't work for me. I have tried that before, but no luck.
I have also heard of os.popen. Does that have to do with something, or am I missing something here?
0
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!

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.