How to use Input Redirection from file

Viewed 19

I've been having an issue with input() redirection in Python 3.10.7.

Given Test1.py...

num1 = int(input())
print("Output is: ",num1)

...and Test1.txt...

345

...this command...

test1.py < test1.txt

...fails with the error...

At line:1 char:17
+ python test1.py < test1.txt
+ ~The '<' operator is reserved for future use.
+ CategoryInfo : ParserError: (:) [], ParentContainsErrorRecordException
+ FullyQualifiedErrorId : RedirectionNotSupported

The script works fine when run from the command line. Trying to use the redirect fails with the error as seen above. Why?

0 Answers
Related