pythonpython-3.ximagestdiostddraw

Why can't I draw a picture using stddraw?


I'm trying to simply draw a picture using stddraw with this code:

def main():
    if len(sys.argv) <= 1:
        stdio.writeln("ERROR: Too few Arguments")
    else:
        pic = sys.argv[1]

        stddraw.picture(pic)

        stddraw.show()

if __name__ == "__main__": main()

but each time I run it with input like "picture.jpg" I get this error:

AttributeError: 'str' object has no attribute 'width'

Why is it processing it as a string and what do I need to do to make it work?


Solution

  • from introcs import Picture, stddraw
    
    def main():
        if len(sys.argv) <= 1:
            stdio.writeln("ERROR: Too few Arguments")
        else:
            pic_file = sys.argv[1]
            pic = Picture(pic_file)  # Create a Picture object
    
            stddraw.picture(pic)
    
            stddraw.show()
    
    if __name__ == "__main__":
        main()