redirecting Stdin
Jon Arter
nospam at nospam.yes
Wed Dec 3 05:45:15 EST 2003
assume we have a file :
after redirection sys.stdin = file('newinput')
-----------------------------------
#newinput file
import socket
def detectip():
buf = socket.gethostname()
remotehost = socket.gethostbyname(buf)
return remotehost
if __name__ == "__main__":
print "Your IP address is", detectip()
raw_input()
------------------------
using
line=sys.stdin:readline()
exec line
This results in a parsing error when the file reading reaches the
def detectip():
sentence .
You can execute the command line as long as it is a single line
command
How to Get arround this ?
With regards
JON
On Wed, 03 Dec 2003 01:54:11 -0800, Erik Max Francis <max at alcyone.com>
wrote:
>Jon Arter wrote:
>
>> Is is Possible to redirect the Python stdin in order to receive stdin
>> commands from a file ?
>> The time of redirection can last until exiting the Python and should
>> be transparent for python it self.
>
>Sure:
>
> sys.stdin = file('newinput')
More information about the Python-list
mailing list