Path: csiph.com!usenet.pasdenom.info!weretis.net!feeder1.news.weretis.net!feeder.erje.net!eu.feeder.erje.net!xlned.com!feeder1.xlned.com!news2.euro.net!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; 'python.': 0.02; 'python,': 0.02; 'subject:Python': 0.05; 'context': 0.05; 'things.': 0.05; 'encouraging': 0.07; 'javascript,': 0.07; 'lines.': 0.07; 'null,': 0.07; 'python': 0.09; "'#'": 0.09; 'braces': 0.09; 'executes': 0.09; 'macros': 0.09; 'overwrite': 0.09; 'skip:# 30': 0.09; 'cc:addr:python-list': 0.10; ':-)': 0.13; 'language': 0.14; 'do,': 0.15; '"if"': 0.16; 'blocks': 0.16; 'cc:name:python list': 0.16; 'chris,': 0.16; 'conditional': 0.16; 'curly': 0.16; 'earlier.': 0.16; 'editor,': 0.16; 'ideal.': 0.16; 'indent': 0.16; 'obsessed': 0.16; 'overwriting': 0.16; 'parentheses': 0.16; 'quirks': 0.16; 'statement.': 0.16; 'w/o': 0.16; 'string': 0.17; 'wrote:': 0.17; 'pfxlen:0': 0.17; 'tend': 0.17; 'variables': 0.17; 'module': 0.19; '(not': 0.20; 'variable': 0.20; 'file.': 0.20; 'all,': 0.21; 'bit': 0.21; 'earlier': 0.21; 'facility': 0.22; 'cc:2**0': 0.23; 'insert': 0.23; "python's": 0.23; 'statement': 0.23; "haven't": 0.23; 'testing': 0.24; 'cc:addr:python.org': 0.25; 'header:In- Reply-To:1': 0.25; 'separate': 0.27; 'see,': 0.27; 'message- id:@mail.gmail.com': 0.27; "doesn't": 0.28; '"do': 0.29; '(unless': 0.29; 'colon': 0.29; 'declared': 0.29; 'served': 0.29; 'whitespace': 0.29; 'no,': 0.29; 'this.': 0.29; 'that.': 0.30; 'usually': 0.30; 'week.': 0.30; 'function': 0.30; 'code': 0.31; 'etc.)': 0.32; 'defining': 0.33; 'maintained': 0.33; 'zero': 0.33; 'equal': 0.33; 'languages': 0.33; 'point.': 0.33; 'agree': 0.34; 'received:google.com': 0.34; 'thanks': 0.34; 'clear': 0.35; 'false': 0.35; 'received:209.85': 0.35; 'something': 0.35; 'there': 0.35; 'but': 0.36; 'characters': 0.36; 'anything': 0.36; 'test': 0.36; 'one,': 0.37; 'does': 0.37; 'level': 0.37; 'being': 0.37; 'why': 0.37; 'received:209': 0.37; 'well.': 0.37; 'subject:: ': 0.38; 'easier': 0.38; 'mean': 0.38; 'some': 0.38; 'things': 0.38; 'several': 0.39; 'where': 0.40; 'help': 0.40; 'your': 0.60; 'easy': 0.60; 'skip:u 10': 0.60; 'most': 0.61; "you'll": 0.62; 'time,': 0.62; 'more': 0.63; 'within': 0.64; 'legal': 0.65; 'more...': 0.65; 'carefully': 0.71; 'special': 0.73; 'yourself': 0.77; '2013': 0.84; 'compulsory': 0.84; 'enforced': 0.84; 'oscar': 0.84; 'shock': 0.84 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=x-received:mime-version:in-reply-to:references:from:date:message-id :subject:to:cc:content-type:content-transfer-encoding; bh=ta2fUn4x7uxZuvzb4xlO+GwvxX8sTGD1dSjsRIIdSt8=; b=DKH4di/TWyzSkVMgbyQrh9uPomXtqs8quaa/WuzWfR6doWtvWgvLDiMr1QtPHQRAJG 85yeeZao/39RA+hyBK78c9PxghOycvcQFAjwmGVh8i736tn7UXCE3eUPAt2WKD94uwYA igY5uKHS5hW7X+EJknubRDzWvEwE3P6BhgVk2LWsynWHP6ShUQyUPWriNfc4Gwpw2I3i tzyAjibLAr6MxOcUYrYDlE47sM6stEjAhgCuMhqWayca18ODHE/gk8TyeCoxlKwEoo/O gyoUkW4eOIEMP3uN7afXXNlXOa1UvQQeout66N+S+PlwmrRCwt2A9aKjQ3r5rCDHxuGW PdUQ== X-Received: by 10.220.239.14 with SMTP id ku14mr33236511vcb.57.1361489275051; Thu, 21 Feb 2013 15:27:55 -0800 (PST) MIME-Version: 1.0 In-Reply-To: <5c262e95-b3a8-4f2a-b752-84b30bf4f81e@googlegroups.com> References: <5c262e95-b3a8-4f2a-b752-84b30bf4f81e@googlegroups.com> From: Oscar Benjamin Date: Thu, 21 Feb 2013 23:27:34 +0000 Subject: Re: Python Newbie To: piterrr.dolinski@gmail.com Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Cc: Python List 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: 115 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1361489278 news.xs4all.nl 6947 [2001:888:2000:d::a6]:40137 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:39489 On 21 February 2013 22:40, wrote: > Thanks to all for quick relies. > > Chris, you are (almost) spot on with the if blocks indentation. This is w= hat I do, and it has served me well for 15 years. > > code > code > > if (some condition) > { > code > code > } > > code > code So you already indent blocks in an "if" construct? This is good practise in some languages and is enforced in Python. Once I got used to it I found that the compulsory whitespace made it easier to read conditional code blocks. > > This is what I call code clarity. With Python, I am having to do this > > code > code > > ############################## > > if (some condition): > code > code > > ############################## > > code > code > > It does the job, but is not ideal. Do you mean that you literally insert a line of '#' characters before and after in "if" block? There's no need to do that. Just allow yourself to acclimatise to the significant whitespace and you'll find that it's easy to see where the block begins and ends. > > I am nervous about using variables "out of the blue", without having to d= eclare them. For example, when I write "i =3D 0" it is perfectly OK to Pyth= on without 'i' being declared earlier. How do I know that I haven't used th= is variable earlier and I am unintentionally overwriting the value? I find = I constantly have to use the search facility in the editor, which is not fu= n. > > You see, Javascript, for one, behaves the same way as Python (no variable= declaration) but JS has curly braces and you know the variable you have ju= st used is limited in scope to the code within the { }. With Python, you ha= ve to search the whole file. No, you only have to search the whole function which for me is rarely more than 20 lines. The statement "i=3D0" when inside a function will not overwrite anything outside the function (unless you use the global/nonlocal statements). I rarely use global variables or module level variables and if I do then I usually have a special place in a module/script for defining them. I also tend to name them in ALLCAPS just like C-preprocessor macros that need to be carefully maintained in a separate "namespace". > > Thanks to Chris, Ian and Dave for explaining the () issue around if and f= or statement. I don't agree with this, but I understand your points. The re= ason why I like parentheses is because they help with code clarity. I am ob= sessed with this. :-) After all, there is a reason why so many languages ha= ve required them for several decades. You'll get used to using the colon in the same way. > > What about Python's ambiguity? > For example, in C you would write > > if (myVar !=3D 0) > do something > > in Python, this is legal > > if (not myVar): > do something > > What does this mean? Is it a test for myVar being equal to zero or a test= for null, or else? All of those things. It executes "do something" if myVar is 1) zero (whether int/float/complex etc.) 2) False 3) None 4) an empty collection (list/set/tuple etc.) 5) an empty string 6) and more... If the context doesn't make it clear what you are testing for then use a more specific test (myVar!=3D0 works just as well). > I want to learn a new language but Python's quirks are a bit of a shock t= o me at this point. I have been Pythoning only for about a week. > > In the mean time, thanks to most of you for encouraging me to give Python= a chance. I will do my best to like it, w/o prejudice. Many of the things that have confused/concerned you are things that I actually like about Python. Given time you may do as well. Oscar