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

F

Frank Potter

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?
 
C

Chris Rebert

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
 
F

Frank Potter

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

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,734
Messages
2,569,441
Members
44,832
Latest member
GlennSmall

Latest Threads

Top