Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!xlned.com!feeder3.xlned.com!newsfeed.xs4all.nl!newsfeed2.news.xs4all.nl!xs4all!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.003 X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'output': 0.05; '[1,': 0.09; 'function:': 0.09; 'subject:number': 0.09; 'subject:How': 0.10; 'cc:addr:python-list': 0.11; 'python': 0.11; '"test"': 0.16; '-tkc': 0.16; '1234': 0.16; '2.7.3': 0.16; 'callable': 0.16; 'command-line': 0.16; 'from:addr:python.list': 0.16; 'from:addr:tim.thechases.com': 0.16; 'from:name:tim chase': 0.16; 'str()': 0.16; 'typeerror:': 0.16; 'wrote:': 0.18; '>>>': 0.22; 'input': 0.22; 'cc:addr:python.org': 0.22; "haven't": 0.24; 'cc:2**0': 0.24; 'cc:no real name:2**0': 0.24; 'source': 0.25; 'header:In-Reply-To:1': 0.27; 'code': 0.31; '"",': 0.31; 'file': 0.32; '(most': 0.33; 'subject:from': 0.34; 'something': 0.35; 'charset:us-ascii': 0.36; 'subject:?': 0.36; 'recent': 0.39; 'more': 0.64; 'to:addr:gmail.com': 0.65; 'mar': 0.68; 'fact,': 0.69; '2014,': 0.84; 'received:50.22': 0.84; 'shadows': 0.84; 'hopes': 0.91 Date: Mon, 21 Jul 2014 15:57:00 -0500 From: Tim Chase To: fl Subject: Re: How to extract digit from a number? In-Reply-To: References: <12e1f726-c083-49db-86bd-1c9ae3151b2a@googlegroups.com> X-Mailer: Claws Mail 3.8.1 (GTK+ 2.24.10; x86_64-pc-linux-gnu) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - boston.accountservergroup.com X-AntiAbuse: Original Domain - python.org X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - tim.thechases.com X-Get-Message-Sender-Via: boston.accountservergroup.com: authenticated_id: tim@thechases.com Cc: python-list@python.org 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: 37 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1405976291 news.xs4all.nl 2933 [2001:888:2000:d::a6]:33659 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:74956 On 2014-07-21 13:42, fl wrote: > The original source input is: > >>> a = 1234 > >>> [int(d) for d in str(a)] > > He hopes the output is: > >>> [1, 2, 3, 4] > > In fact, I get the output is: > > >>> a = 1234 > >>> [int(d) for d in str(a)] > Traceback (most recent call last): > File "", line 1, in > TypeError: 'str' object is not callable This sounds suspiciously like you have shadowed the str() function. You might search your code for something like str = "test" which shadows the built-in str() function. The code you have works at the command-line as long as you haven't shadowed the previously-existing str() function: $ python Python 2.7.3 (default, Mar 13 2014, 11:03:55) [GCC 4.7.2] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> a = 1234 >>> [int(d) for d in str(a)] [1, 2, 3, 4] -tkc