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


Groups > comp.lang.python > #74956

Re: How to extract digit from a number?

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 <python.list@tim.thechases.com>
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 <python.list@tim.thechases.com>
To fl <rxjwg98@gmail.com>
Subject Re: How to extract digit from a number?
In-Reply-To <d84aa18f-7c12-4262-a746-218581783304@googlegroups.com>
References <12e1f726-c083-49db-86bd-1c9ae3151b2a@googlegroups.com> <mailman.12151.1405974457.18130.python-list@python.org> <d84aa18f-7c12-4262-a746-218581783304@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 <python-list.python.org>
List-Unsubscribe <https://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 <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.12152.1405976291.18130.python-list@python.org> (permalink)
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

Show key headers only | View raw


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 "<interactive input>", line 1, in <module>
> 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


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


Thread

How to extract digit from a number? fl <rxjwg98@gmail.com> - 2014-07-21 13:14 -0700
  Re: How to extract digit from a number? Tim Chase <python.list@tim.thechases.com> - 2014-07-21 15:26 -0500
    Re: How to extract digit from a number? fl <rxjwg98@gmail.com> - 2014-07-21 13:42 -0700
      Re: How to extract digit from a number? Roy Smith <roy@panix.com> - 2014-07-21 16:53 -0400
      Re: How to extract digit from a number? Tim Chase <python.list@tim.thechases.com> - 2014-07-21 15:57 -0500

csiph-web