Path: csiph.com!usenet.pasdenom.info!gegeweb.org!de-l.enfer-du-nord.net!feeder2.enfer-du-nord.net!newsfeed.eweka.nl!eweka.nl!feeder3.eweka.nl!newsfeed.xs4all.nl!newsfeed6.news.xs4all.nl!xs4all!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.002 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'subject:Python': 0.05; 'python': 0.08; 'block.': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'syntax.': 0.09; 'win32': 0.12; '"copyright",': 0.16; '"credits"': 0.16; '"license"': 0.16; '"w")': 0.16; '"with"': 0.16; '2.7.2': 0.16; 'destructor': 0.16; 'does,': 0.16; 'rachel': 0.16; 'syntaxerror:': 0.16; 'syntax': 0.16; 'wrote:': 0.18; '>>>': 0.18; "aren't": 0.21; 'maybe': 0.21; 'header:In-Reply-To:1': 0.22; 'btw,': 0.23; 'invalid': 0.28; 'bit': 0.28; 'example': 0.29; 'keeps': 0.30; 'lock': 0.30; 'creates': 0.31; 'objects': 0.32; 'header:User-Agent:1': 0.33; 'object': 0.33; 'file': 0.34; 'header:X-Complaints-To:1': 0.34; 'from:addr:yahoo.co.uk': 0.34; 'probably': 0.35; 'to:addr:python- list': 0.35; 'two': 0.36; 'received:org': 0.36; 'executing': 0.37; 'created': 0.37; 'but': 0.37; 'could': 0.38; 'that.': 0.39; 'called': 0.40; 'or,': 0.40; 'received:78': 0.40; 'to:addr:python.org': 0.40; 'type': 0.61; 'more': 0.61; 'here': 0.64; 'show': 0.66; 'special': 0.66; 'respect.': 0.67; '"list': 0.84; '11:44': 0.84; 'received:as13285.net': 0.84 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: Mark Lawrence Subject: Re: Python is readable Date: Thu, 15 Mar 2012 14:06:01 +0000 References: <4f612b19$0$1379$4fafbaef@reader2.news.tin.it> <8e72d74f-c844-4de3-8a37-f6b1fdc2291f@y27g2000yqy.googlegroups.com> <50e9ceec-40f1-4ead-b2b6-87328b30d084@ow8g2000pbc.googlegroups.com> <4f61c828$0$1390$4fafbaef@reader2.news.tin.it> <4f61d728$0$1375$4fafbaef@reader2.news.tin.it> Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Gmane-NNTP-Posting-Host: host-78-147-178-49.as13285.net User-Agent: Mozilla/5.0 (Windows NT 6.0; rv:10.0.2) Gecko/20120216 Thunderbird/10.0.2 In-Reply-To: <4f61d728$0$1375$4fafbaef@reader2.news.tin.it> X-Antivirus: avast! (VPS 120315-0, 15/03/2012), Outbound message X-Antivirus-Status: Clean X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.12 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: 47 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1331820337 news.xs4all.nl 6861 [2001:888:2000:d::a6]:40382 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:21669 On 15/03/2012 11:48, Kiuhnm wrote: > On 3/15/2012 12:14, Thomas Rachel wrote: >> Am 15.03.2012 11:44 schrieb Kiuhnm: >> >>> Let's try that. >>> Show me an example of "list comprehensions" and "with" (whatever they >>> are). >> >> with open("filename", "w") as f: >> f.write(stuff) > > Here f is created before executing the block and destroyed right after > leaving the block. f's destructor will probably close the file handle. > >> with lock: >> do_something_exclusively() > > It's clear what it does, but I don't know if that's special syntax. > Maybe objects can have two special methods that are called respect. on > entering and leaving the with-block. > Or, more likely, lock creates an object which keeps the lock "acquired". > The lock is released when we leave the block. > So we could inspect the lock with > with lock as l: > inspect l... > do_some..... > > BTW, aren't those ':' redundant? > > Kiuhnm Nope. Python 2.7.2 (default, Jun 12 2011, 15:08:59) [MSC v.1500 32 bit (Intel)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> with open("filename", "w") as f File "", line 1 with open("filename", "w") as f ^ SyntaxError: invalid syntax -- Cheers. Mark Lawrence.