Okay, all I want to do for now, is create a rather simple python interpreter. I have already created a simple command prompt for windows, utilizing the os module, the script's code is here:

import os
os.system("title Command Prompt")
while True:
    osc = raw_input(os.getcwd()+">> ")
    if osc == "exit" or osc == "quit" or osc == "exit()" or osc == "quit()":
        quit()
    try:
        os.system(osc)
    except:
        print "Not a valid shell command"
    print ""

I want to do the same, but have it evaluate python commands instead. Any help would be appreciated! :D
Also, I've already tried setting a variable to raw_input, then doing eval(variable). That doesn't work.

Okay, all I want to do for now, is create a rather simple python interpreter. I have already created a simple command prompt for windows, utilizing the os module, the script's code is here:

You missed one point that Python interpreter already exists and is not simple but rather a complex coding by Guido and PSF team! So calling your interpreter Python will get you in trouble with PSF trademark/whatever it is called in US. Just curious, do you want to take Python out of business using Python?

import os
os.system("title Command Prompt")
while True:
    osc = raw_input(os.getcwd()+">> ")
    if osc == "exit" or osc == "quit" or osc == "exit()" or osc == "quit()":
        quit()
    try:
        os.system(osc)
    except:
        print "Not a valid shell command"
    print ""

Okay, you are calling system calls right? It does the job. The problem is, the commandline windows vanishes quickly. Try command like (in windows) ping x.x.x.x -t

I want to do the same, but have it evaluate python commands instead. Any help would be appreciated! :D
Also, I've already tried setting a variable to raw_input, then doing eval(variable). That doesn't work.

you should list your own keywords and syntax .....etc. It is not simple job. It is like creating your own language which is not english, swahili or any other. Just new one!

Check out the "code" module. It has functions to emulate a Python interpreter.

The standard module code contains classes to help you write your own interpreter. Basically, you need to subclass InteractiveConsole and call its push method with lines of input.

Thank you for giving me that info. I'll try to look into that. It's not that I want to create my own language, just an application that will do whatever you type. I don't like the setup of the current python interpreter, so I want to create my own, the way I did with Windows' Command Prompt.

Thank you for giving me that info. I'll try to look into that. It's not that I want to create my own language, just an application that will do whatever you type. I don't like the setup of the current python interpreter, so I want to create my own, the way I did with Windows' Command Prompt.

Cool! I think those above mentioned class will do the job though personally haven't test it. Sorry for misunderstanding your questio, I though you are like one guy who planned to code his own OS

There is more than one Python interpreter. There is the command line interpreter that starts when you open the command prompt, navigate to the Python root folder, and type python.exe and hit return.

There is also the IDLE interpreter, the GUI interpreter that starts from the IDLE toolkit.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.