I'm debugging this script in PyCharm:
import sys
def read_in():
lines = sys.stdin.readlines()
for i in range(len(lines)):
lines[i] = lines[i].replace('\n','')
return lines
def main():
lines = read_in()
print lines
if __name__ == '__main__':
main()
I normally call this script using a command like cat data.txt | python script.py which feeds data.txt into Standard Input.
My question is how can I setup a "Run/Debug Configuration" in PyCharm which feeds data.txt into Standard Input in the same way, but which will allow me to use PyCharm's awesome debugging mode? I suspect that I need to correctly fill out the "Script Parameters" field -- but this has eluded me so far.
Thanks.
Personally, I'd just use patch to replace sys.stdin.readlines() with a Mock, with the return value you desire. Place that into a unit test, and run the unit test.
Also, see Reading from a file with sys.stdin in Pycharm
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With