Path: csiph.com!usenet.pasdenom.info!weretis.net!feeder1.news.weretis.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.xs4all.nl!newsfeed2.news.xs4all.nl!xs4all!news.tele.dk!news.tele.dk!small.news.tele.dk!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.000 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'scripts': 0.03; 'subject:: [': 0.04; 'syntax': 0.04; 'interpreter.': 0.07; 'subject:trying': 0.09; 'variant': 0.09; 'cc:addr:python-list': 0.11; 'python': 0.11; 'def': 0.12; 'expert.': 0.16; 'first:': 0.16; 'folks,': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'fully,': 0.16; 'port)': 0.16; 'success:': 0.16; 'syntaxerror:': 0.16; 'wrote:': 0.18; 'subject:] ': 0.20; 'written': 0.21; 'import': 0.22; 'cc:addr:python.org': 0.22; 'print': 0.22; 'cc:2**0': 0.24; 'least': 0.26; 'header:In-Reply-To:1': 0.27; 'tried': 0.27; 'host': 0.29; 'am,': 0.29; 'dec': 0.30; 'message- id:@mail.gmail.com': 0.30; "skip:' 10": 0.31; 'jean': 0.31; 'file': 0.32; 'something': 0.35; 'test': 0.35; 'but': 0.35; 'received:google.com': 0.35; 'simple': 0.61; 'invalid': 0.68; 'to:none': 0.92; '2013': 0.98 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:cc :content-type; bh=mcd7Iy1skUTICj08kCPO5DV7ytwW7tgXuhXS+HxQ/RE=; b=A0fFs0WvC8gPgsPIIc6un+4qE4jS7snBoxlj6T7xGJQU+tq8dAAGxCWgA65RvOmqRX F5ZRoALyB9OzyJwcjfMyuzJTuTQOv5xR4D/DwxP3bfbAt6M1wPhJdeJdNLcmCyhUJi+1 0pvV+eGteuK1m3zZL4kuKwj9gZuNSu2uchMwuOL6w73KkqVtvN5S+eVQAUV9oGCk0eFC gkGfRgJ75ZZuxYTIELl46rcZFPt+7ATclA+z4Y0FZ9VFUoL2Wdoc8+wu9XWafUOZ1UEB sd3Ji6USJ31I7W8nhnUmQELwse9mUlLaIEA71ODWeK5arPWGxaJpkg1ckf11V5UnJf53 yqYQ== MIME-Version: 1.0 X-Received: by 10.66.66.234 with SMTP id i10mr21753269pat.127.1387218958182; Mon, 16 Dec 2013 10:35:58 -0800 (PST) In-Reply-To: References: <41954a05-c9bd-43f7-9427-915653ff8657@googlegroups.com> Date: Tue, 17 Dec 2013 05:35:57 +1100 Subject: Re: [newbie] trying socket as a replacement for nc From: Chris Angelico Cc: "python-list@python.org" Content-Type: text/plain; charset=UTF-8 X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 45 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1387218961 news.xs4all.nl 2968 [2001:888:2000:d::a6]:37731 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:62089 On Tue, Dec 17, 2013 at 5:26 AM, Jean Dubois 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