Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #38155
| Path | csiph.com!usenet.pasdenom.info!weretis.net!feeder4.news.weretis.net!ecngs!feeder2.ecngs.de!newsfeed.freenet.ag!news2.euro.net!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail |
|---|---|
| Return-Path | <marduk@letterboxes.org> |
| 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; 'else:': 0.03; 'exception': 0.03; 'syntax': 0.03; 'elif': 0.04; 'debug': 0.05; 'socket': 0.05; 'sys': 0.05; 'except:': 0.07; 'try:': 0.07; 'python': 0.09; '"if': 0.09; '0.1': 0.09; 'hostname': 0.09; 'port))': 0.09; 'received:internal': 0.09; 'sys.argv[0]': 0.09; 'sys.exit(2)': 0.09; 'subject:error': 0.11; '1):': 0.16; '2.0:': 0.16; 'delay,': 0.16; 'message-id:@webmail.messagingengine.com': 0.16; 'pdb': 0.16; 'received:10.202': 0.16; 'received:10.202.2': 0.16; 'received:66.111': 0.16; 'received:66.111.4': 0.16; 'received:mail.srv.osa': 0.16; 'received:messagingengine.com': 0.16; 'received:nyi.mail.srv.osa': 0.16; 'received:osa': 0.16; 'received:srv.osa': 0.16; 'syntax.': 0.16; 'syntaxerror:': 0.16; 'true:': 0.16; 'mon,': 0.16; 'wrote:': 0.17; 'feb': 0.19; 'import': 0.21; 'statement': 0.23; 'raise': 0.24; 'header:In- Reply-To:1': 0.25; 'skip:# 10': 0.27; 'interface': 0.27; 'this?': 0.28; 'address)': 0.29; 'socket,': 0.29; 'url:mailman': 0.29; 'figure': 0.30; 'url:python': 0.32; 'file': 0.32; 'could': 0.32; 'print': 0.32; 'url:listinfo': 0.32; 'to:addr:python-list': 0.33; 'another': 0.33; 'server': 0.35; '2.0': 0.35; 'data,': 0.35; 'pm,': 0.35; 'except': 0.36; 'url:org': 0.36; 'client': 0.36; 'level': 0.37; 'being': 0.37; 'why': 0.37; 'drop': 0.37; 'data': 0.37; 'subject:: ': 0.38; 'received:10': 0.38; 'to:addr:python.org': 0.39; 'skip:" 10': 0.40; 'header:Received:5': 0.40; 'url:mail': 0.40; 'think': 0.40; 'your': 0.60; 'address': 0.60; 'skip:u 10': 0.60; 'header:Message- Id:1': 0.62; 'brown': 0.65; 'life': 0.66; 'address,': 0.79; '1060': 0.84; 'effectively:': 0.84; 'random,': 0.84 |
| DKIM-Signature | v=1; a=rsa-sha1; c=relaxed/relaxed; d=letterboxes.org; h=message-id:from:to:mime-version:content-transfer-encoding :content-type:in-reply-to:references:subject:date; s=mesmtp; bh= l0zvusuZOW4yHzScsdRnOPQxzfE=; b=OBe+aYPR1FjP9uMqyAFZJcLNMuMbTy6/ JuQHNXgbJjcTYhcNd5LvJGr9OlvlYPvVHLUZRuVDfAKUvIWbNA4CLD8nm5OIXzez q115VGZbLARbc/IczGmmgv4c/dRrF/8kN2+Jds7YjTkkMkLmlhxs3Aa5NlJiGHPO XFZyn9Um5BA= |
| DKIM-Signature | v=1; a=rsa-sha1; c=relaxed/relaxed; d= messagingengine.com; h=message-id:from:to:mime-version :content-transfer-encoding:content-type:in-reply-to:references :subject:date; s=smtpout; bh=l0zvusuZOW4yHzScsdRnOPQxzfE=; b=e3L Hd2YU58pgubrUaPZf/yvQvAKDJ0LtTXD/z9RTEkCVwe9OZb/s7X0To0zdOR5vZ8p G4Gi1m6rFlk0EuhbIL4SPUkrSKNMvjU/W9M152y+a4X61Tn1UWUmx7bhoIM7alcg VhQ+lAdPnJ1ice5MnyOIeVZCQ1iWiWEoFqZ/NvkA= |
| X-Sasl-Enc | MYz6GbuxSS4WnQhiTJYpMeJBdkSxGqcxarv06tydYJuK 1360025881 |
| From | Albert Hopkins <marduk@letterboxes.org> |
| To | python-list@python.org |
| MIME-Version | 1.0 |
| Content-Transfer-Encoding | 7bit |
| Content-Type | text/plain |
| X-Mailer | MessagingEngine.com Webmail Interface - ajax-1ec1891e |
| In-Reply-To | <CABRP1o-UkR9j3Ry+xYgpFobAo0yETVvy_8pUm4UYZQO0=rSEAw@mail.gmail.com> |
| References | <CABRP1o-UkR9j3Ry+xYgpFobAo0yETVvy_8pUm4UYZQO0=rSEAw@mail.gmail.com> |
| Subject | Re: error in except |
| Date | Mon, 04 Feb 2013 19:58:01 -0500 |
| X-BeenThere | python-list@python.org |
| X-Mailman-Version | 2.1.15 |
| Precedence | list |
| List-Id | General discussion list for the Python programming language <python-list.python.org> |
| List-Unsubscribe | <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe> |
| List-Archive | <http://mail.python.org/pipermail/python-list/> |
| List-Post | <mailto:python-list@python.org> |
| List-Help | <mailto:python-list-request@python.org?subject=help> |
| List-Subscribe | <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.1345.1360025889.2939.python-list@python.org> (permalink) |
| Lines | 69 |
| NNTP-Posting-Host | 2001:888:2000:d::a6 |
| X-Trace | 1360025889 news.xs4all.nl 6852 [2001:888:2000:d::a6]:58657 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | csiph.com comp.lang.python:38155 |
Show key headers only | View raw
On Mon, Feb 4, 2013, at 04:49 PM, Rodrick Brown wrote:
> For the life of me I cant figure out why this exception is being thrown.
> How could I use pdb to debug this?
>
> $ python udp_local2.py server
> File "udp_local2.py", line 36
> except:
> ^
> SyntaxError: invalid syntax
>
>
> #!/usr/bin/env python
>
> import random, socket, sys
> s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
>
> MAX = 65535
> PORT = 1060
>
> if 2 <= len(sys.argv) <= 3 and sys.argv[1] == 'server':
> interface = sys.argv[2] if len(sys.argv) > 2 else ''
> s.bind((interface, PORT))
> print 'Listening at', s.getsockname()
> while True:
> data, address = s.recvfrom(MAX)
> if random.randint(0, 1):
> print 'The client at', address, 'says:', repr(data)
> s.sendto('Your data was %d bytes' % len(data), address)
> else:
> print 'Pretending to drop packet from', address
>
> elif len(sys.argv) == 3 and sys.argv[1] == 'client':
> hostname = sys.argv[2]
> s.connect((hostname, PORT))
> print 'Client socket name is', s.getsockname()
> delay = 0.1
> while True:
> s.send('This is another message')
> print 'Waiting up to', delay, 'seconds for a reply'
> s.settimeout(delay)
> try:
> data = s.recv(MAX)
> except socket.timeout:
> delay *= 2
> if delay > 2.0:
> raise RuntimeError('I think the server is down')
> except:
> raise
> else:
> break
> print 'The server says', repr(data)
> else:
> print >> sys.stderr, 'usage: %d server [<interfae>]' %
> sys.argv[0]
> print >> sys.stderr, ' or: %d client <host>' % sys.argv[0]
> sys.exit(2)
> --
> http://mail.python.org/mailman/listinfo/python-list
Your "except" statement is on the same level as "if delay > 2.0"..
effectively:
if delay > 2.0
...
except:
which is not valid syntax. Excepts go with try: blocks, not if: blocks.
Back to comp.lang.python | Previous | Next | Find similar | Unroll thread
Re: error in except Albert Hopkins <marduk@letterboxes.org> - 2013-02-04 19:58 -0500
csiph-web