omz:forum

    • Register
    • Login
    • Search
    • Recent
    • Popular

    Welcome!

    This is the community forum for my apps Pythonista and Editorial.

    For individual support questions, you can also send an email. If you have a very short question or just want to say hello — I'm @olemoritz on Twitter.


    Posting a photo

    Pythonista
    2
    3
    1558
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • janaaron18
      janaaron18 last edited by

      Hi all!

      I have made a program, but am having problems. I want to make a dictionary that posts a photo of the thing you searched for, but right now it isn't working. Instead of actually posting the image I searched for, it gives a long string of text: PngImagePlugin.PngImageFile image mode=RGB size=1242x2208 at 0x66E8B0C>

      So, to sum up, instead of posting that text, I want it to put the actual picture up instead.

      Here's my program

      ''' import photos
      a = raw_input("Search a word ")

      if a == "friend":
      print photos.get_image(image_index=-1, original=True, raw_data=False) '''

      1 Reply Last reply Reply Quote 0
      • dgelessus
        dgelessus last edited by

        print is only used for basic text output to the console. If you give print an object that isn't text, it converts the object to text in some way. This is what's happening here - photos.get_image returns an image object, which is not text, so instead some basic data about it is displayed when you print it.

        To display an image, use its show method, for example:

        import photos
        
        img = photos.get_image()
        img.show()
        # These two lines can be shortened to:
        photos.get_image().show()
        

        When calling a function you don't always need to specify all arguments that are listed in the documentation. If some function arguments are optional, they are shown in the documentation enclosed by square brackets, or followed by an equals sign and a default value. Optional arguments don't need to be included, and it's best to leave them out entirely unless you need them. In your case it's a lot shorter and cleaner to write photos.get_image() without all the optional arguments.

        By the way, when posting code on the forums, you should put it inside a code block so that it is displayed properly. See this explanation.

        1 Reply Last reply Reply Quote 1
        • janaaron18
          janaaron18 last edited by

          Thank you!

          1 Reply Last reply Reply Quote 0
          • First post
            Last post
          Powered by NodeBB Forums | Contributors