Ask Your Question
1

Problem with stdin in python script (macOS)

asked 2017-08-27 05:46:00 -0500

andrewd76 gravatar image

updated 2019-03-13 10:15:30 -0500

Hi,

I have problem with this script in WingIDE:

http://introcs.cs.princeton.edu/pytho... use this file:http://introcs.cs.princeton.edu/python/15inout/usa.txt as "Run arguments" in "Launch configurations" (< usa.txt).

Libraries:

http://introcs.cs.princeton.edu/python/code/stdio.py
http://introcs.cs.princeton.edu/python/code/stddraw.pyI

run this file, but nothing happens.

If I run this file in Geany - it works.It works in Terminal too (python plotfilter.py < usa.txt)

Is it my mistake or bug in WingIDE?

Thanks!

edit retag flag offensive close merge delete

1 Answer

Sort by » oldest newest most voted
1

answered 2017-08-28 10:13:00 -0500

updated 2019-03-07 07:23:16 -0500

Wingware Admin gravatar image

Wing does not interpret the < operator like the bash command line so it's not going to send the contents of usa.txt to the code when you set the arguments to this.  The only work-arounds I can think of are either to use wingdbstub to initiate debug so you can type a command line with < outside of Wing (see http://wingware.com/doc/debug/debuggi... for details) or modify your code to start by reading the file and redirect stdio.  It would be something like this untested code:

import sys
from StringIO import StringIO  # In Python 3 it's from io import StringIO instead
f = open('usa.txt')
txt = f.read()
f.close()
sys.stdin = StringIO(txt)
edit flag offensive delete link more

Comments

Thank you for support! I've initiate debug outside of Wing and received an error: 

"Debugger: Debug process paused; pid=1930; Listening on TCP/IP port 50005
Allowed hosts: 127.0.0.1 [0 modules loaded]
General: Document Open Failed::Failed to open document '/Applications/WingIDE.app/Contents/Resources/bin/dbg/src/wingbase/channel.py'"

There is no such a file in this directory.

andrewd76 gravatar imageandrewd76 ( 2017-08-28 15:11:00 -0500 )edit

Sorry, appears we did not get notice of this comment as we usually do.  I'd need more information to diagnose this.  It's trying to stop on an exception in the debugger internals, but I am not sure why.  It should never do that.  You can get a log from the debug side by setting kLogFile in wingdbstub.py and then we can interpret that if you email it to us.  Although I realize you may have moved on to other things by now, since this reply is 5 weeks late.  We'll look into what is happening to the email notices from this forum (they mostly work, but I'm finding some missed items).

Wingware Support gravatar imageWingware Support ( 2017-10-03 12:40:00 -0500 )edit

Well, I've just copy this file from Wing (win edition). It's OK now. Thanks for support!

andrewd76 gravatar imageandrewd76 ( 2017-10-03 12:54:00 -0500 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

2 followers

Stats

Asked: 2017-08-27 05:46:00 -0500

Seen: 32 times

Last updated: Mar 07