添加链接
link管理
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接
Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Learn more about Collectives

Teams

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Learn more about Teams

I want to get a PDF file, but I get an error: AttributeError: 'NoneType' object has no attribute 'show' . The error says that can doesn't have the attribute show . Why? As you can see, I import show from pychart.canvas .

from pychart import *
from pychart.canvas import show
can = canvas.init("pic.pdf")
x, y = (100, 500)
def show_text(str):
    global x, y
    can.show(x, y, str)
    can.show(x + 200, y, "/12/C" + font.quotemeta(str))
    y -= 20
show_text("/12/hLLeft align")
show_text("/12/hRRight align")
show_text("/12/hCCenter align")
show_text("/a20/12/hRAngled text")
def show_textv(str):
    global x, y
    can.show(x, y, str)
    x += 150
y -= 40
x = 100
show_textv("/12/vT//12//vTTop align")
show_textv("/12/vM//12//vT/12Middle align")
show_textv("/12/vB//12//vT/12Bottom align")
y -= 40
x = 100
show_text("/16/HHelvetica")
show_text("/12/CCourier")
show_text("/12/NHelvetica-Narrow")
show_text("/12/PPalatino-Roman")
show_text("/12/AAvantgarde")
show_text("/12/T/iTimes-Italic")
show_text("/12/F{ZapfDingbats}ZapfDingbats")
                Is that all of your code?  What line does the error occur on?  Glancing at the pychart documentation, it doesn't look like canvas.init should ever return None, which is what appears to be happening from what you have given us.  Also, is there a reason you are importing pychart.canvas.show - you don't appear to be using it anywhere.
– James
                Jun 5, 2012 at 9:24
                The line where the error occurs on as follows:File "C:\Users\wangling\Desktop\pdf6.py", line 8, in show_text     can.show(x, y, str) AttributeError: 'NoneType' object has no attribute 'show'
– wangling
                Jun 5, 2012 at 9:31

you actually call None.show(x, y, str) and get AttributeError, because None doesn't have 'show' attribute

To fix your problem try to investigate why can == None

Thanks for contributing an answer to Stack Overflow!

  • Please be sure to answer the question. Provide details and share your research!

But avoid

  • Asking for help, clarification, or responding to other answers.
  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.