Patrickll
Patrickll

Reputation: 21

Python IDLE not displaying code when used with command line

I have installed Python directly on a flash drive and my references within my modules all use the full path (on the flash drive) to operate. My IDLE window is not displaying the execution of my code.

I have a Python Script named: test.py which contains the following code:

 print('Hello')

 from win32com.client import Dispatch

 xl = Dispatch("Excel.Application")
 xl.Visible = True # otherwise excel is hidden

If I run the script from the Editor using: Run -> Run Module, the Excel Workbook opens successfully and the Python IDLE will display the following:

====================== RESTART: D:\MICK\Scripts\test.py ======================
Hello
>>> 

Test 2: Now, If I use Windows+R and run: D:\MICK\Scripts\test.py, the Excel Workbook opens successfully but the IDLE does not even open.

Test 3: I manually open the IDLE (located at: D:\MICK\Anaconda\Lib\idlelib\idle.pyw) and I use Windows+R to run:D:\MICK\Scripts\test.py. The Excel workbook opens, but the IDLE stays blank:

Python 3.5.2 |Anaconda 4.2.0 (32-bit)| (default, Jul  5 2016, 11:45:57) [MSC v.1900 32 bit (Intel)] on win32
Type "copyright", "credits" or "license()" for more information.
>>> 

What could be causing interference between Windows+R called scripts and Run-> Run module called scripts?

Upvotes: 0

Views: 1632

Answers (1)

ernie
ernie

Reputation: 6356

When you use Win-R, do you notice the command prompt window open and close quickly? You can see that this is what is happening byby opening a command prompt and running this as well, and noting that the "Hello" will be shown on the command prompt.

IDLE is an IDE, not a python interpreter. When you run it from the editor, it's specially wired to run in IDLE.

You shouldn't expect things to run in IDLE, unless you explicitly invoke IDLE.

When you try to run D:\MICK\Scripts\test.py, what's actually happening is Windows is looking for the handler for files with a 'py' extension, and then running the appropriate item, in this case python, so you're likely getting something like python D:\MICK\Scripts\test.py, which you'll note is not invoking IDLE.

Upvotes: 1

Related Questions