Pycharm: reading from stdin in "debug" mode

I am 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 usually call this a script with a command like cat data.txt | python script.py

that which passes data.txt to standard input.

My question is how do I set up the "Run / Debug Configuration" in PyCharm, which also passes the data.txt file to standard input, but which will allow me to use PyCharm's debug mode? I suspect I need to fill in the "Script Parameters" field correctly, but so far it hasn't escaped.

Thank.

+3


source to share


1 answer


Personally, I just use patch to replace sys.stdin.readlines () with Mock with my desired return value. Put this in a unit test and run your unit test.



Also see Reading from a file using sys.stdin in Pycharm

+1


source







All Articles