python-idle

How to repeat last command in python interpreter shell?

本秂侑毒 提交于 2019-11-27 16:57:36
How do I repeat the last command? The usual keys: Up, Ctrl+Up, Alt-p don't work. They produce nonsensical characters. (ve)[kakarukeys@localhost ve]$ python Python 2.6.6 (r266:84292, Nov 15 2010, 21:48:32) [GCC 4.4.4 20100630 (Red Hat 4.4.4-10)] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> print "hello world" hello world >>> ^[[A File "<stdin>", line 1 ^ SyntaxError: invalid syntax >>> ^[[1;5A File "<stdin>", line 1 [1;5A ^ SyntaxError: invalid syntax >>> ^[p File "<stdin>", line 1 p ^ SyntaxError: invalid syntax >>> I use the following to enable history

IPython workflow (edit, run)

不问归期 提交于 2019-11-27 16:54:40
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? 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/2009/05/24/vim-as-python-ide/ http://dancingpenguinsoflight.com/2009/02/python-and-vim-make-your-own-ide/

Import module works in terminal but not in IDLE

女生的网名这么多〃 提交于 2019-11-27 16:10:00
I am trying to import pyodbc module on a windows computer. It works in the terminal, but not the IDLE. The error message in IDLE is: Traceback (most recent call last): File "FilePath/Filename.py", line 3, in <module> import pyodbc ImportError: No module named pyodbc This typically occurs when multiple versions of python are installed with different paths. You can check to see if you have multiple installations by opening up the IDLE terminal and using import sys sys.version sys.path These commands will print the system PATH and version of the current instance of python. Use this in both IDLE

Terminating idle mysql connections

孤者浪人 提交于 2019-11-27 11:33:49
I see a lot of connections are open and remain idle for a long time, say 5 minutes. Is there any solution to terminate / close it from server without restarting the mysql service? I am maintaining a legacy PHP system and can not close the connections those are established to execute the query. Should I reduce the timeout values in my.cnf file those defaults to 8 hours? # default 28800 seconds interactive_timeout=60 wait_timeout=60 Manual cleanup: You can KILL the processid. mysql> show full processlist; +---------+------------+-------------------+------+---------+-------+-------+--------------

When running a python script in IDLE, is there a way to pass in command line arguments (args)?

故事扮演 提交于 2019-11-27 11:26:58
I'm testing some python code that parses command line input. Is there a way to pass this input in through IDLE? Currently I'm saving in the IDLE editor and running from a command prompt. I'm running Windows. It doesn't seem like IDLE provides a way to do this through the GUI, but you could do something like: idle.py -r scriptname.py arg1 arg2 arg3 You can also set sys.argv manually, like: try: __file__ except: sys.argv = [sys.argv[0], 'argument1', 'argument2', 'argument2'] (Credit http://wayneandlayne.com/2009/04/14/using-command-line-arguments-in-python-in-idle/ ) In a pinch, Seth's #2 worked

How to launch python Idle from a virtual environment (virtualenv)

旧街凉风 提交于 2019-11-27 11:13:16
I have a package that I installed from a virtual environment. If I just launch the python interpreter, that package can be imported just fine. However, if I launch Idle, that package cannot be imported (since it's only available in one particular virtualenv and not global). How can I launch Idle from a virtualenv, so that all packages from the virtualenv would be available? IDLE is essentially from idlelib.PyShell import main if __name__ == '__main__': main() So you can launch it yourself unless you built the virtualenv without default packages. Short answer Start the virtual environment Run

Python: Why is IDLE so slow?

好久不见. 提交于 2019-11-27 09:02:00
IDLE is my favorite Python editor. It offers very nice and intuitive Python shell which is extremely useful for unit-testing and debugging, and a neat debugger. However, code executed under IDLE is insanely slow. By insanely I mean 3 orders of magnitude slow: bash time echo "for i in range(10000): print 'x'," | python Takes 0.052s, IDLE import datetime start=datetime.datetime.now() for i in range(10000): print 'x', end=datetime.datetime.now() print end-start Takes: >>> 0:01:44.853951 Which is roughly 2,000 times slower. Any thoughts, or ideas how to improve this? I guess it has something to do

SyntaxError near “print”? [closed]

天涯浪子 提交于 2019-11-27 08:40:47
问题 can anybody please tell me why this is giving me syntax error in idle? def printTwice(bruce): print bruce, bruce SyntaxError: invalid syntax 回答1: Check the version of Python being used; the variable sys.version contains useful information. That is invalid in Python 3.x, because print is just a normal function and thus requires parenthesis: # valid Python 3.x syntax .. def x(bruce): print(bruce, bruce) x("chin") # .. but perhaps "cleaner" def x(bruce): print(bruce, bruce) (The behavior in

Importing from a Package in IDLE vs Shell

泄露秘密 提交于 2019-11-27 08:37:28
问题 Importing a whole package works in IDLE, but not in shell. The following works fine in IDLE: import tkinter as tk tk.filedialog.askopenfilename() In shell, I get this error: AttributeError: 'module' object has no attribute 'filedialog' I understand that I have to import tkinter.filedialog to make this work in shell. Why the difference between IDLE and shell? How can I make IDLE act like shell? It can be frustrating to have a script working in IDLE, and failing in shell. I am using Python 3.4.

Python script run through IDLE has no output

落花浮王杯 提交于 2019-11-27 08:27:09
问题 I’m using the Windows version of Python 2.7 with IDLE. If I run the following code import os os.getcwd() through IDLE (Run module F5), I get no output in the Python shell. If I double-click on test.py in Explorer, however, the current working directory is displayed. If I do a print command in IDLE, it shows up. Why doesn’t os.getcwd() have any output in IDLE, while print does? 回答1: When you call a function, that function may return a value, and in this case os.getcwd() returns a string. Here,