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


Groups > comp.lang.python > #10366

Re: @PyNoobs: The Fundamental Five Built-in Functions, and Beyond!

Path csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!gegeweb.org!de-l.enfer-du-nord.net!feeder2.enfer-du-nord.net!feeder.news-service.com!newsfeed.xs4all.nl!newsfeed6.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail
Return-Path <python-python-list@m.gmane.org>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.001
X-Spam-Evidence '*H*': 1.00; '*S*': 0.00; 'skip': 0.04; '(of': 0.05; 'args': 0.05; 'received:verizon.net': 0.07; 'terry': 0.07; 'versions.': 0.07; 'python': 0.08; 'collections': 0.09; 'ids': 0.09; 'immutable': 0.09; 'object.': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:80.91.229.12': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'received:lo.gmane.org': 0.09; 'programmer': 0.11; 'debugging': 0.13; 'defined': 0.14; 'wrote:': 0.15; '*do*': 0.16; 'awesome.': 0.16; 'namespace.': 0.16; 'occasionally': 0.16; 'rantingrick': 0.16; 'reedy': 0.16; 'repr()': 0.16; 'stdout': 0.16; 'pm,': 0.16; 'jan': 0.19; 'header:In-Reply-To:1': 0.22; 'code.': 0.22; 'problem?': 0.23; 'worst': 0.23; 'code': 0.24; '(or': 0.25; 'string': 0.26; 'function': 0.26; 'helpful': 0.26; 'seeing': 0.28; 'objects': 0.28; 'bugs': 0.28; 'mode': 0.28; 'right,': 0.28; 'elements': 0.29; 'topics.': 0.29; 'lists': 0.29; 'object': 0.30; "ain't": 0.30; 'confused': 0.30; 'languages)': 0.30; 'solved': 0.30; 'strings,': 0.30; "they'll": 0.30; 'version': 0.30; 'looks': 0.30; 'programmers': 0.31; 'url:library': 0.31; 'print': 0.32; 'source': 0.32; "skip:' 10": 0.32; 'list': 0.32; 'actually': 0.33; 'to:addr:python-list': 0.34; 'header:X-Complaints-To:1': 0.34; 'header:User-Agent:1': 0.34; 'there': 0.34; 'quite': 0.34; 'behaving': 0.35; 'function.': 0.35; 'url:python': 0.37; 'comparing': 0.37; 'experiences': 0.37; 'functions.': 0.37; 'anything': 0.37; 'some': 0.37; 'but': 0.37; 'members': 0.37; 'using': 0.37; 'another': 0.38; 'getting': 0.38; 'received:org': 0.38; 'url:org': 0.38; 'user': 0.38; 'subject:: ': 0.38; 'something': 0.38; 'think': 0.38; 'two': 0.38; 'should': 0.39; 'header:Mime-Version:1': 0.39; 'url:docs': 0.39; 'help': 0.39; 'skip:s 20': 0.39; 'to:addr:python.org': 0.39; 'skip:- 50': 0.40; 'where': 0.40; 'your': 0.60; 'unique': 0.64; 'dangerous': 0.64; 'ever': 0.65; 'believe': 0.66; 'subject:!': 0.67; 'special': 0.67; 'strange': 0.68; 'friend,': 0.70; 'subject:The': 0.73; 'spaces': 0.73; 'different.': 0.84; 'irrelevant': 0.84; 'spaces.': 0.84; 'suffer': 0.84; 'syndrome': 0.84; 'url:functions': 0.84; 'surface': 0.91
X-Injected-Via-Gmane http://gmane.org/
To python-list@python.org
From Terry Reedy <tjreedy@udel.edu>
Subject Re: @PyNoobs: The Fundamental Five Built-in Functions, and Beyond!
Date Tue, 26 Jul 2011 22:53:25 -0400
References <d480e736-6b4a-42cf-85da-5563c016c711@q11g2000yqm.googlegroups.com>
Mime-Version 1.0
Content-Type text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding 7bit
X-Gmane-NNTP-Posting-Host pool-74-109-121-73.phlapa.fios.verizon.net
User-Agent Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.2.18) Gecko/20110616 Lightning/1.0b2 Thunderbird/3.1.11
In-Reply-To <d480e736-6b4a-42cf-85da-5563c016c711@q11g2000yqm.googlegroups.com>
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.12
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.1523.1311735220.1164.python-list@python.org> (permalink)
Lines 86
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1311735220 news.xs4all.nl 23881 [2001:888:2000:d::a6]:48569
X-Complaints-To abuse@xs4all.nl
Xref x330-a1.tempe.blueboxinc.net comp.lang.python:10366

Show key headers only | View raw


On 7/26/2011 8:01 PM, rantingrick wrote:
>
>
> ============================================================
>   The "Fundamental Five" built-in functions
> ============================================================
> There are quite a few helpful built in functions provided to the
> python programmer however in my mind five of them are the most
> important to Python noobs. The "fundamental five" i call them. I
> believe you should not do anything with Python until you are
> completely familier with these five because most of the bugs and mis-
> understanding a new user experiences can be solved by using these five
> functions.
> ============================================================
>
> --------------------------------------------------
> 1. help()
> --------------------------------------------------
> http://docs.python.org/py3k/library/functions.html#help

help() with no args puts one into a special help mode to get info on 
various topics. help(obj) gets help on that object. I do not do the 
former much, but I increasingly use the latter.


> --------------------------------------------------
>   2. dir()
> --------------------------------------------------
> http://docs.python.org/py3k/library/functions.html#dir
>
> Python has name spaces. Name spaces are awesome. Name spaces keep code
> from clashing with other code. The dir() function will list the
> currently defined names in the current namespace. If your getting
> NameErrors check the name space with dir() function.

I use this constantly.
>
> --------------------------------------------------
>   3. repr()
> --------------------------------------------------
> http://docs.python.org/py3k/library/functions.html#repr
>
> Most new user think that printing an object to stdout is all they'll
> ever need. However when you call print -- or sys.stdout.write(object)
> -- you are only seeing a "friendly" version of the object.

This mostly applies to strings, which *do* have 2 printed versions.  It 
is occasionally very important for debugging string problems.

Printing collections alreays used repr() for members of the collection.

>
> --------------------------------------------------
>   4. type()
> --------------------------------------------------
> http://docs.python.org/py3k/library/functions.html#isinstance
>
> Ever had a TypeError? Ever had some object you were just sure was one
> type but is not behaving like that type? Then check it's type for
> Pete's sake! Even experienced programmers (of many languages) suffer
> from TypeErrors (be them subtle or not) because the type of an object
> cannot be inferred simply by looking at it's identifier. So when
> something ain't right, skip the tripe, and check the type!
>
> --------------------------------------------------
>   5. id()
> --------------------------------------------------
> http://docs.python.org/py3k/library/functions.html#id
>
> Ah yes, another source of frustration is the old "identical twin"
> syndrome (or in the worst forms; multiplicity syndrome!). Yes, on the
> surface that list of lists looks as if it contains unique elements
> HOWEVER you keep getting strange results. How are you going to find
> the problem? Hmm? Never fear my confused new friend, by comparing the
> ids of two objects you can know if they are actually the same or
> different. If the id is the same, the objects are the same.

This is the most dangerous of the builtins, as it sometimes mislead 
newbies into 'discovering' non-existent 'bugs'. The main point is that 
the id of immutable objects is mostly an irrelevant implementation 
detail, while the id of mutables may be critical. Lists of lists is a 
particular area where id() is really useful.

-- 
Terry Jan Reedy

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


Thread

@PyNoobs: The Fundamental Five Built-in Functions, and Beyond! rantingrick <rantingrick@gmail.com> - 2011-07-26 17:01 -0700
  Re: @PyNoobs: The Fundamental Five Built-in Functions, and Beyond! Thomas Jollans <t@jollybox.de> - 2011-07-27 02:39 +0200
  Re: @PyNoobs: The Fundamental Five Built-in Functions, and Beyond! Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2011-07-27 12:22 +1000
  Re: @PyNoobs: The Fundamental Five Built-in Functions, and Beyond! Terry Reedy <tjreedy@udel.edu> - 2011-07-26 22:53 -0400
    Re: @PyNoobs: The Fundamental Five Built-in Functions, and Beyond! rantingrick <rantingrick@gmail.com> - 2011-07-28 14:34 -0700

csiph-web