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?

Date 2014-07-21 15:57 -0500
From Tim Chase <python.list@tim.thechases.com>
Subject Re: How to extract digit from a number?
References <12e1f726-c083-49db-86bd-1c9ae3151b2a@googlegroups.com> <mailman.12151.1405974457.18130.python-list@python.org> <d84aa18f-7c12-4262-a746-218581783304@googlegroups.com>
Newsgroups comp.lang.python
Message-ID <mailman.12152.1405976291.18130.python-list@python.org> (permalink)

Show all headers | 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