python-idle

Python IDLE compatible with multithreading?

霸气de小男生 提交于 2019-12-04 03:30:09
问题 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

How to stop Python program execution in IDLE

会有一股神秘感。 提交于 2019-12-04 02:49:46
I have a python script that uses plt.show() as it's last instruction. When it runs, IDLE just hangs after the last instruction. I get the image but I don't get the prompt back. On other scripts I typically use ctrl-c to break the program (sometimes doesn't work immediately) but how do I get the prompt back with the plt.show() ? Ctrl-c doesn't work... Are there other ways to stop the program? This is IDLE on Windows, if it makes any difference. I have seen this problem with IDLE and matplotlib when using them on Windows. I don't know the exact cause, but Ctrl-c a couple times has typically

what is the difference between cmd and idle when using tqdm?

戏子无情 提交于 2019-12-04 02:01:47
问题 recently I want to add a simple progress bar to my script, I use tqdm to that, but what puzzle me is that the output is different when I am in the IDLE or in the cmd for example this from tqdm import tqdm import time def test(): for i in tqdm( range(100) ): time.sleep(0.1) give the expected output in the cmd 30%|███ | 30/100 [00:03<00:07, 9.14it/s] but in the IDLE the output is like this 0%| | 0/100 [00:00<?, ?it/s] 1%|1 | 1/100 [00:00<00:10, 9.14it/s] 2%|2 | 2/100 [00:00<00:11, 8.77it/s] 3%

bs4: “soup.title.string” doesn't work on IDLE but Terminal

夙愿已清 提交于 2019-12-03 20:23:46
Mac OS X 10.9 Python 2.7 IDLE BeautifulSoup 4 installed (successfully) I followed BS4 documentation and was practicing some of the functions on IDLE . The following code works and was able to print out title & title.name. from bs4 import BeautifulSoup html = """ <html><head><title>The Dormouse's story</title></head> <body> <p class="title"><b>The Dormouse's story</b></p> <p class="story">Once upon a time there were three little sisters; and their names were <a href="http://example.com/elsie" class="sister" id="link1">Elsie</a>, <a href="http://example.com/lacie" class="sister" id="link2">Lacie

Set Python IDLE as Default Program to Open .py Extensions [closed]

时光怂恿深爱的人放手 提交于 2019-12-03 18:03:53
问题 Closed. This question is off-topic. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed 5 years ago . I am on Windows 7 . I have Python 2.7.8 (64 bit) installed. Today, I changed the default program that opens .py files from IDLE to Windows Command Processor and stupidly selected the checkbox that said "always use the selected program to open this kind of file". What I want to do is change my default program

Exit gracefully if file doesn't exist

这一生的挚爱 提交于 2019-12-03 16:16:33
问题 I have following script in Python 3.2.3: try: file = open('file.txt', 'r') except IOError: print('There was an error opening the file!') sys.exit() #more code that is relevant only if the file exists How do I exit gracefully, if the file doesn't exist (or there is simply an error opening it)? I can use exit() , but that opens a dialog panel asking if I want to kill the application. I can use sys.exit() , but that raises a SystemExit exception which doesn't looks great in output. I get

Expand width of shell in Python's IDLE

霸气de小男生 提交于 2019-12-03 15:24:17
I'm new to python and I'm using Python's IDLE. Using numpy, I created a 24 x 24 matrix. I simply want to look at the matrix. I've maximized the shell on my monitor, so there's plenty of room to print the entire 24 columns' width, but it's only printing the first 13 columns of then continuing onto the next line to print the next 11 columns (had trouble in Stack Overflow copying and pasting what it's doing). The entire right half of the Shell window is blank (it's compressing everything to fit in the left half). This is harder to read than if it printed 24 columns wide. Can anyone tell me how to

How to get the list of all initialized objects and function definitions alive in python?

夙愿已清 提交于 2019-12-03 08:08:38
问题 Say that in the python shell (IDLE) I have defined some classes, functions, variables. Also created objects of the classes. Then I deleted some of the objects and created some others. At a later point in time, how can I get to know what are the currently active objects, variables, and methods definitions active in the memory? 回答1: Yes. >>> import gc >>> gc.get_objects() Not that you'll find that useful. There is a lot of them. :-) Over 4000 just when you start Python. Possibly a bit more

Python IDLE is not starting on Windows 7

送分小仙女□ 提交于 2019-12-03 07:29:30
I used to use Python 2.7 and then IDLE was working. I uninstalled it and installed Python 3.1. Right now Idle cannot launch. What should i do to get it running? NOTE: I tried c:\Python31\pythonw.exe c:\Python31\Lib\idlelib\idle.py i uninstalled 3.1 and installed back 2.7, not working neither... Alex Martelli In the past, I've often found that when I had some issues with the python.org version of some Python release, specifically on Windows, installing instead the activepython version of the same release, from ActiveState, made the problems go away. So, in your shoes, the first thing I would

Exit gracefully if file doesn't exist

China☆狼群 提交于 2019-12-03 04:48:44
I have following script in Python 3.2.3: try: file = open('file.txt', 'r') except IOError: print('There was an error opening the file!') sys.exit() #more code that is relevant only if the file exists How do I exit gracefully, if the file doesn't exist (or there is simply an error opening it)? I can use exit() , but that opens a dialog panel asking if I want to kill the application. I can use sys.exit() , but that raises a SystemExit exception which doesn't looks great in output. I get Traceback (most recent call last): File "file", line 19, in <module> sys.exit() SystemExit I can use os.exit()