f



What's wrong with my python? I can't use string

I have a xxx.py which has code as below:

import string

print dir(string)
print string.printable


when I run it, I got the strange error:

"<?xml version=\"1.0\" encoding=\"gbk\"?>\n"
"<root>\n"
"<result>##result##</result>\n"
"<msg>##msg##</msg>\n"
"<pass_no>##pass_no##</pass_no>\n"
"<pot_num>##pot_num##</pot_num>\n"
"<pots_mashed>##pots_mashed##</pots_mashed>\n"
"<yb_used>##yb_used##</yb_used>\n"
"<right>##right##</right>\n"
"</root>\n"
['__builtins__', '__doc__', '__file__', '__name__', 'str']
Traceback (most recent call last):
  File "del2.py", line 4, in ?
    print string.printable
AttributeError: 'module' object has no attribute 'printable'

It seems that I did not import the right string module I want. Can
someone give me a clue, please?

0
could.net (106)
2/10/2009 7:13:24 AM
comp.lang.python 77058 articles. 6 followers. Post Follow

2 Replies
579 Views

Similar Articles

[PageSpeed] 18

On Mon, Feb 9, 2009 at 11:13 PM, Frank Potter <could.net@gmail.com> wrote:
> I have a xxx.py which has code as below:
>
> import string
>
> print dir(string)
> print string.printable
>
>
> when I run it, I got the strange error:
>
> "<?xml version=\"1.0\" encoding=\"gbk\"?>\n"
> "<root>\n"
> "<result>##result##</result>\n"
> "<msg>##msg##</msg>\n"
> "<pass_no>##pass_no##</pass_no>\n"
> "<pot_num>##pot_num##</pot_num>\n"
> "<pots_mashed>##pots_mashed##</pots_mashed>\n"
> "<yb_used>##yb_used##</yb_used>\n"
> "<right>##right##</right>\n"
> "</root>\n"
> ['__builtins__', '__doc__', '__file__', '__name__', 'str']
> Traceback (most recent call last):
>  File "del2.py", line 4, in ?
>    print string.printable
> AttributeError: 'module' object has no attribute 'printable'
>
> It seems that I did not import the right string module I want. Can
> someone give me a clue, please?

Sounds like the wrong `string` module is being imported. What's the
output of `print string.__file__`?

Cheers,
Chris

-- 
Follow the path of the Iguana...
http://rebertia.com
0
clp2 (1575)
2/10/2009 7:20:35 AM
On Feb 10, 3:20=A0pm, Chris Rebert <c...@rebertia.com> wrote:
> On Mon, Feb 9, 2009 at 11:13 PM, Frank Potter <could....@gmail.com> wrote=
:
> > I have a xxx.py which has code as below:
>
> > import string
>
> > print dir(string)
> > print string.printable
>
> > when I run it, I got the strange error:
>
> > "<?xml version=3D\"1.0\" encoding=3D\"gbk\"?>\n"
> > "<root>\n"
> > "<result>##result##</result>\n"
> > "<msg>##msg##</msg>\n"
> > "<pass_no>##pass_no##</pass_no>\n"
> > "<pot_num>##pot_num##</pot_num>\n"
> > "<pots_mashed>##pots_mashed##</pots_mashed>\n"
> > "<yb_used>##yb_used##</yb_used>\n"
> > "<right>##right##</right>\n"
> > "</root>\n"
> > ['__builtins__', '__doc__', '__file__', '__name__', 'str']
> > Traceback (most recent call last):
> > =A0File "del2.py", line 4, in ?
> > =A0 =A0print string.printable
> > AttributeError: 'module' object has no attribute 'printable'
>
> > It seems that I did not import the right string module I want. Can
> > someone give me a clue, please?
>
> Sounds like the wrong `string` module is being imported. What's the
> output of `print string.__file__`?
>
> Cheers,
> Chris
>
> --
> Follow the path of the Iguana...http://rebertia.com

Thank you so much ~
I got it.
I have a string.py in the same directory:(
and when I output string.__file__ as you told me, I know it.

0
could.net (106)
2/10/2009 7:26:52 AM
Reply: