Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #62089

Re: [newbie] trying socket as a replacement for nc

References <41954a05-c9bd-43f7-9427-915653ff8657@googlegroups.com> <mailman.4222.1387212273.18130.python-list@python.org> <a71c4874-2fbc-439d-bc2a-483feb4f3080@googlegroups.com>
Date 2013-12-17 05:35 +1100
Subject Re: [newbie] trying socket as a replacement for nc
From Chris Angelico <rosuav@gmail.com>
Newsgroups comp.lang.python
Message-ID <mailman.4228.1387218961.18130.python-list@python.org> (permalink)

Show all headers | View raw


On Tue, Dec 17, 2013 at 5:26 AM, Jean Dubois <jeandubois314@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@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

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Re: [newbie] trying socket as a replacement for nc Jean-Michel Pichavant <jeanmichel@sequans.com> - 2013-12-16 17:44 +0100
  Re: [newbie] trying socket as a replacement for nc Jean Dubois <jeandubois314@gmail.com> - 2013-12-16 10:26 -0800
    Re: [newbie] trying socket as a replacement for nc Chris Angelico <rosuav@gmail.com> - 2013-12-17 05:35 +1100
    Re: [newbie] trying socket as a replacement for nc Dave Angel <davea@davea.name> - 2013-12-16 13:42 -0500

csiph-web