python-idle

How to write and run more than one code in Python IDLE?

和自甴很熟 提交于 2019-12-02 04:41:29
How do you get that code, see below, run in IDLE? I am stuck in my course right now and I could not find an explanation. I know how to run in IDLE just one "def" or code, pressing F5, write e.g. hash_string('udacity', 3) in the shell, "Enter", result. In that code, with more than one code it will not work, of course. For a deeper understanding I want to run it in the Python Online Tutor, condition is that it will work in IDLE or vice versa. Further I would like to know, why the input #print hashtable_get_bucket(table, "Zoe") results in: #>>> [['Bill', 17], ['Zoe', 14]] Why does 'Bill', 17,

What does “== RESTART <path> ==” in the IDLE Shell mean?

空扰寡人 提交于 2019-12-02 04:29:18
I have a simple script I wrote, and when trying to run it (F5) , I get this msg: ================== RESTART: C:\Users\***\Desktop\tst.py ================== I restarted the shell, reopened the script, but still, the same msg appears. I use python 3.5.1 and I tried to simplify the script as much as possible, but I still get this result. Now my script is only one line with a simple print(1) command and I still get this msg. Was there something wrong with the shell installation? I have a simple script I wrote, and when trying to run it (F5) That's the hotkey for IDLE to run a file. It is not

Idle time of a process in Linux

放肆的年华 提交于 2019-12-02 03:54:20
I need to calculate CPU usage (user mode, system mode, idle time) of a process in Linux. I am able to calculate usage in user and system mode using utime and stime values from /proc/PID/stat , but I found nothing which is related to idle time. I know I can get idle time from /proc/stat but this value is related to machine, not for particular process. Is it possible to calculate idle time of a process knowing its PID (reading data from /proc directory)? I don't know much about it but maybe the following works: 1) Get the process start up time. Im sure thats possible 2) Generate time difference

Change printed text color in Idle?

故事扮演 提交于 2019-12-02 03:15:26
Is there a way to specify the color a text is printed within Idle for Python 3.2? I'm looking for something like: print("foo", "#fafafa") print("bar", "#4f4f4f") http://docs.python.org/library/idle.html#syntax-colors To change the color scheme, edit the [Colors] section in config.txt. Edit: As you've edited your question, here is an edited answer. See http://www.daimi.au.dk/~mailund/scripting2005/lecture-notes/process-management.html for how to use terminal escape sequences in Python to change the color of things. Will they work in IDLE? I don't know. But they will work in most terminals. 来源:

New line on error message in KeyError - Python 3.3

吃可爱长大的小学妹 提交于 2019-12-01 21:30:16
I am using Python 3.3 through the IDLE. While running a code that looks like: raise KeyError('This is a \n Line break') it outputs: Traceback (most recent call last): File "test.py", line 4, in <module> raise KeyError('This is a \n Line break') KeyError: 'This is a \n Line break' I would like it to output the message with the line break like this: This is a Line Break I have tried to convert it to a string before or using os.linesep but nothing seems to work. Is there any way I can force the message to be correctly shown on the IDLE? If I raise an Exception (instead of KeyError ) then the

How do I print colored text in IDLE's terminal?

喜你入骨 提交于 2019-12-01 21:12:25
问题 This is very easily a duplicate question--because it is. However, there are very many inadequate answers to this (e.g. try curses ! -- pointing to a 26 page documentation). I just want to print text in a color other than blue when I'm outputting in IDLE. Is it possible? What's an easy way to do this? I'm running Python 3.6 on Windows. Please explain with an example. (I have found that ANSI codes do not work inside IDLE, only on the terminal.) 回答1: Put this at the "start" of your code: import

How do I print colored text in IDLE's terminal?

╄→尐↘猪︶ㄣ 提交于 2019-12-01 18:34:15
This is very easily a duplicate question--because it is. However, there are very many inadequate answers to this (e.g. try curses ! -- pointing to a 26 page documentation). I just want to print text in a color other than blue when I'm outputting in IDLE. Is it possible? What's an easy way to do this? I'm running Python 3.6 on Windows. Please explain with an example. (I have found that ANSI codes do not work inside IDLE, only on the terminal.) Put this at the "start" of your code: import sys try: color = sys.stdout.shell except AttributeError: raise RuntimeError("Use IDLE") And then use color

IDLE won't highlight my syntax

我与影子孤独终老i 提交于 2019-12-01 18:08:22
Using IDLE and Python version 2.7.3. Only when I start a new file it highlights for a few lines and then just stops after I press F5. So all my text becomes plain black. If there are equally good/better command line and editor combinations out there, you may always suggest them. This happened to me too. Save it as .py (manually type .py in the document name), and the highlighting will come back. I usually have to save the file as .py before IDLE will do any syntax highlighting at all. Not sure why it would highlight for a few and then stop though. I've never had that happen. Alex Check the key

Python IDLE compatible with multithreading?

南楼画角 提交于 2019-12-01 17:50:20
It seems that IDLE (part of the standard Python Windows install) will not execute multithreaded programs correctly without nasty hangs or bugout crashes. Does anyone know of a way to fix this? The following program will always hang in IDLE but complete normally when executed with the Python interpreter directly: import threading, time printLock = threading.Lock() def pl(s): printLock.acquire() print s printLock.release() class myThread( threading.Thread ): def run(self): i = 0 for i in range(0,30): pl(i) time.sleep(0.1) t = myThread() t.start() while threading.activeCount() > 1: time.sleep(1)

starting Python IDLE from command line to edit scripts

折月煮酒 提交于 2019-12-01 16:47:34
I've tried many variations of this command: idle.py -e filepath , but it simply starts IDLE like normal, not opening any extra windows for editing, and not throwing any errors. So how can I do the equivalent of opening IDLE, file>open>filepath via the command line (or perhaps even a Python module)? Redouane Zait Make a new text file, and put something like this in it: C:\Python26\Lib\idlelib\idle.pyw "C:\file1.py" "C:\file2.py" In your actual script, you'll replace "C:\file1.py" and "C:\file2.py" with your files' paths, save as a .bat, and then launch it. That should do what you want. You need