crebert at ucsd
Apr 29, 2012, 10:42 AM
Post #3 of 3
On Sun, Apr 29, 2012 at 10:18 AM, Andres Soto <soto_andres [at] yahoo> 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.
That should work.
> Traceback (most recent call last):
> Â File "<pyshell#20>", line 1, in <module>
> Â Â str(42)
> TypeError: 'module' object is not callable
> What is it wrong?
Presumably, at some point you did:
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.