Re: convert integer to string

2012-04-29 Thread Chris Rebert
On Sun, Apr 29, 2012 at 10:18 AM, Andres Soto  wrote:
> I have already
 import string
 from string import *
> but I can not still convert an integer to string

There is no need to import the `string` module to do that. Most of the
`string` module is deprecated.
`str` is the *built-in* type for character strings; so no import is necessary

Also, imports of the form `from X import *` are generally to be avoided.

 str(42)

That should work.

> Traceback (most recent call last):
>   File "", line 1, in 
>     str(42)
> TypeError: 'module' object is not callable

> What is it wrong?

Presumably, at some point you did:
import string
str = string
Or similar, thus shadowing the built-in type. As I said, there's no
need to `import string`, and the `str` type is built-in, so both these
lines are unnecessary.

Cheers,
Chris
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: convert integer to string

2012-04-29 Thread MRAB

On 29/04/2012 18:18, Andres Soto wrote:

I have already

>> import string
>> from string import *

but I can not still convert an integer to string

>> str(42)

Traceback (most recent call last):
File "", line 1, in 
str(42)
TypeError: 'module' object is not callable

>>

What is it wrong?


At some point you have bound "str" to a module.

Normally you would be getting this:

>>> str is __builtins__.str
True
--
http://mail.python.org/mailman/listinfo/python-list


convert integer to string

2012-04-29 Thread Andres Soto
I have already
>>> import string

>>> from string import *

but I can not still convert an integer to string
>>> str(42)
Traceback (most recent call last):
  File "", line 1, in 
    str(42)
TypeError: 'module' object is not callable
>>> 
What is it wrong?
Thank you
 
Prof. Dr. Andrés Soto
DES DACI
UNACAR-- 
http://mail.python.org/mailman/listinfo/python-list