简体   繁体   中英

How to configure python interpretor in sublime text 2 to make it function as IDLE python shell

I believe other people might have asked similar questions, I don't know if I'm cross posting this, if so, I apologize and will be very appreciated for some hints or links that can guide me through this.

I'm new to sublime text2 but have being using IDLE for python scripting for a while.

The question here is quite simple. so here is the thing.

In IDLE, after I wrote a script and run it with F5 , the script will run in a python shell like this: 在此处输入图片说明

and I was able to retrieve some of the avriables I defined in my script that was running after the shell finish running the script like this: adm_pop is a dict type I defined in my script. 在此处输入图片说明

this is very handy since every time I ran the script I was able to check whether one or two variables were declared correct and value assigned to it is correct. But in sublime text I wasn't able to do this since after the script finished running it just finished. like this: 在此处输入图片说明 I wasn't able to do any other input with the console like I can do with IDLE. It's just bugging me a lot so hopely you guys can give me some hints. Thanks in advance!!!!

Go to your Packages folder by selecting Preferences -> Browse Packages... . Go to the User folder and create a SublimeREPL folder containing a config folder containing a Python folder. Then, within that final folder save the following as Main.sublime-menu :

[
     {
        "id": "tools",
        "children":
        [{
            "caption": "SublimeREPL",
            "mnemonic": "r",
            "id": "SublimeREPL",
            "children":
            [
                {"caption": "Python",
                "id": "Python",

                 "children":[
                    {"command": "repl_open",
                     "caption": "Python",
                     "id": "repl_python3",
                     "mnemonic": "p",
                     "args": {
                        "type": "subprocess",
                        "encoding": "utf8",
                        "cmd": ["c:/pythonXX/python.exe", "-i", "-u"],
                        "cwd": "c:/whichever/path/you/want",
                        "syntax": "Packages/Python/Python.tmLanguage",
                        "external_id": "python",
                        "extend_env": {"PYTHONIOENCODING": "utf-8"}
                        }
                    }
                ]
                }
            ]
            }]
        }
]

Change the path in "cmd" to the correct one for your Python installation, and feel free to customize the "cwd" (Current Working Directory) path to whatever you want. This will create a new menu option under Tools -> SublimeREPL -> Python that will be protected from any package upgrades.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM