First time here? Check out the FAQ!
1

Problem with stdin in python script (macOS)

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!

andrewd76's avatar
21
andrewd76
asked 2017-08-27 05:46:00 -0500
Wingware Support's avatar
4k
Wingware Support
updated 2019-03-13 10:15:30 -0500
edit flag offensive 0 remove flag close merge delete

Comments

add a comment see more comments

1 Answer

1

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)
Wingware Support's avatar
4k
Wingware Support
answered 2017-08-28 10:13:00 -0500
Wingware Admin's avatar
231
Wingware Admin
updated 2019-03-07 07:23:16 -0500
edit flag offensive 0 remove flag delete link

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's avatar andrewd76 (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's avatar Wingware 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's avatar andrewd76 (2017-10-03 12:54:00 -0500) edit
add a comment see more comments

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss.

Add Answer