python-idle

In Python IDLE, what's the difference between 'print'ing a variable and just writing the variable?

浪尽此生 提交于 2019-11-27 08:22:32
问题 At the IDLE interpreter I do the following with dpkt: for ts, buf in pcap: eth = dpkt.ethernet.Ethernet(buf) Now, when I try to see the contents of 'eth' I can either print it, or just write the variable name. When I do: print eth I get: O&áÿE(r @,òÀ¨ DYP?Jò}PªpÉ However, when I simply write: eth I get the more expected output of: Ethernet(src='<removed>', dst='<removed>', data=IP(src='<removed>', off=16384, dst='<removed>', sum=11506, len=40, p=6, ttl=128, id=29344, data=TCP(seq=2527752393,

How to run a python script from IDLE interactive shell?

99封情书 提交于 2019-11-27 06:04:32
How do I run a python script from within the IDLE interactive shell? The following throws an error: >>> python helloworld.py SyntaxError: invalid syntax Python2 Built-in function: execfile execfile('helloworld.py') It normally cannot be called with arguments. But here's a workaround: import sys sys.argv = ['helloworld.py', 'arg'] # argv[0] should still be the script name execfile('helloworld.py') Python3 : alternative to exefile: exec(open('helloworld.py').read()) See https://stackoverflow.com/a/437857/739577 for passing global/local variables. Deprecated since 2.6: popen import os os.popen(

Deleting consonants from a string in Python

末鹿安然 提交于 2019-11-27 05:22:20
Here is my code. I'm not exactly sure if I need a counter for this to work. The answer should be 'iiii' . def eliminate_consonants(x): vowels= ['a','e','i','o','u'] vowels_found = 0 for char in x: if char == vowels: print(char) eliminate_consonants('mississippi') Bhargav Rao Correcting your code The line if char == vowels: is wrong. It has to be if char in vowels: . This is because you need to check if that particular character is present in the list of vowels. Apart from that you need to print(char,end = '') (in python3) to print the output as iiii all in one line. The final program will be

IPython workflow (edit, run)

半世苍凉 提交于 2019-11-27 04:09:56
问题 Is there a GUI for IPython that allows me to open/run/edit Python files? My way of working in IDLE is to have two windows open: the shell and a .py file. I edit the .py file, run it, and interact with the results in the shell. Is it possible to use IPython like this? Or is there an alternative way of working? 回答1: When I'm working with python, I usually have two terminal windows open - one with IPython, and the other with a fairly customized Vim. Two good resources: http://blog.dispatched.ch

interactive shell debugging with pycharm

我的梦境 提交于 2019-11-27 02:45:47
I am new to PyCharm. I have been using IDLE for a long time. It is very convenient to use Python objects after script execution in IDLE. Is there any way to use script objects after its execution with interactive python shell using PyCharm? For example, we have a 'test' project with one file 'test.py': a = '123' print a after execution we can get the result: 123 Process finished with exit code 0 How can I use string 'a' with interactive shell? Built-in python shell for current debug session Set a breakpoint at the line of interest in your code (i.e. by clicking the gutter), and launch debug

Python IDLE: Change Python Version

China☆狼群 提交于 2019-11-27 01:51:24
I have Python 2.x and 3.x on my machine (Mac OS X 10.6). For some things I want to use ver 2, but for others I want ver 3. I like the IDLE software for editing/running, but it always uses version 3. Is there any way to change the version of the interpreter that IDLE uses? Thanks! There are different versions of IDLE installed for each Python version. Depending on how you installed Python on Mac OS X, you may find different folders in /Applications . Look for a Python 3.n (n = 1 or 2) folder with an IDLE in it. Or, from a terminal command line, you may find an idle2.6 and an idle3 or idle3.1 or

Why do I get a recursion error with BeautifulSoup and IDLE?

岁酱吖の 提交于 2019-11-26 23:18:32
I am following a tutorial to try to learn how to use BeautifulSoup. I am trying to remove names from the urls on a html page I downloaded. I have it working great to this point. from bs4 import BeautifulSoup soup = BeautifulSoup(open("43rd-congress.html")) final_link = soup.p.a final_link.decompose() links = soup.find_all('a') for link in links: print link but when I enter this next part from bs4 import BeautifulSoup soup = BeautifulSoup(open("43rd-congress.html")) final_link = soup.p.a final_link.decompose() links = soup.find_all('a') for link in links: names = link.contents[0] fullLink =

Can multiprocessing Process class be run from IDLE

两盒软妹~` 提交于 2019-11-26 21:06:41
A basic example of multiprocessing Process class runs when executed from file, but not from IDLE. Why is that and can it be done? from multiprocessing import Process def f(name): print('hello', name) p = Process(target=f, args=('bob',)) p.start() p.join() Yes. The following works in that function f is run in a separate (third) process. from multiprocessing import Process def f(name): print('hello', name) if __name__ == '__main__': p = Process(target=f, args=('bob',)) p.start() p.join() However, to see the print output, at least on Windows, one must start IDLE from a console like so. C:\Users

Objective C: Get notifications about a user's idle state

点点圈 提交于 2019-11-26 20:44:26
问题 My cocoa app runs background tasks, which I would like to stop when the user becomes idle (no keyboard/mouse input) and then resume when the user becomes active again. Is there a way to register for idle-state notifications? 回答1: In case you can't link to Carbon (ie. you want to compile x86_64 bit binary) you can wrap this function (which returns current idle time in seconds resolution as double - CFTimeInterval) in a timer: #include <IOKit/IOKitLib.h> CFTimeInterval CFDateGetIdleTimeInterval

Pasting multiple lines into IDLE

一个人想着一个人 提交于 2019-11-26 20:32:53
问题 Is there a way to paste a block of code into IDLE? Pasting line by line works, but sometimes I'd like to paste many lines at once. When I try, IDLE reads the first line and ignores the rest. >>> a = 1 b = 2 c = 3 >>> >>> a 1 >>> b Traceback (most recent call last): File "<pyshell#3>", line 1, in <module> b NameError: name 'b' is not defined 回答1: Probably not the most beautiful procedure, but this works: cmds = ''' paste your commands, followed by ''' : a = 1 b = 2 c = 3 ''' Then exec(cmds)