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


Groups > comp.lang.python > #74955

Re: How to extract digit from a number?

From Roy Smith <roy@panix.com>
Newsgroups comp.lang.python
Subject Re: How to extract digit from a number?
Date 2014-07-21 16:53 -0400
Organization PANIX Public Access Internet and UNIX, NYC
Message-ID <roy-E6375D.16531021072014@news.panix.com> (permalink)
References <12e1f726-c083-49db-86bd-1c9ae3151b2a@googlegroups.com> <mailman.12151.1405974457.18130.python-list@python.org> <d84aa18f-7c12-4262-a746-218581783304@googlegroups.com>

Show all headers | View raw


In article <d84aa18f-7c12-4262-a746-218581783304@googlegroups.com>,
 fl <rxjwg98@gmail.com> wrote:

> >>> 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 looks like you've overwritten str with an *instance* of a string.

When a python interpreter starts up, there are certain pre-defined 
symbols.  For example, 'str' is bound to the string class.  But, there's 
nothing to prevent you from re-defining it.  Here's an example which 
produces the same result you got:

---------------------------------------------------------------------
$ python
Python 2.7.1 (r271:86832, Jul 31 2011, 19:30:53) 
[GCC 4.2.1 (Based on Apple Inc. build 5658) (LLVM build 2335.15.00)] on 
darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> str = "foo"
>>> a = 1234
>>> [int(d) for d in str(a)] 
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: 'str' object is not callable
---------------------------------------------------------------------

Back to comp.lang.python | Previous | NextPrevious in thread | Next 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