[newbie] trying socket as a replacement for nc
Chris Angelico
rosuav at gmail.com
Mon Dec 16 13:35:57 EST 2013
On Tue, Dec 17, 2013 at 5:26 AM, Jean Dubois <jeandubois314 at gmail.com> wrote:
>> Try something simple first:
>> import telnetlib
>> host = '10.128.59.63'
>> port = 7000
>> t = Telnet(host, port)
>> def flush()
>> t.read_very_eager()
>> def sendCmd(cmd)
>> t.write('%s\n' % cmd)
>> return flush()
>> flush()
>> print sendCmd('*IDN?')
>> print sendCmd('*OPC?')
> Still no success:
> jean at mantec:~$ ./test.py
> File "./test.py", line 7
> def flush()
> ^
> SyntaxError: invalid syntax
>
>
> Tried it both with python2 and python3, same error...
Folks, the OP isn't an expert. Please test your scripts before posting!
I don't have everything I need to test this fully, but here's a
variant of the above that's at least syntactically correct:
from telnetlib import *
host = '10.128.59.63'
port = 7000
t = Telnet(host, port)
def flush():
t.read_very_eager()
def sendCmd(cmd):
t.write('%s\n' % cmd)
return flush()
flush()
print sendCmd('*IDN?')
print sendCmd('*OPC?')
It's written for Python 2, so use that interpreter.
ChrisA
More information about the Python-list
mailing list