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
-
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) ''' -
print
is only used for basic text output to the console. If you giveprint
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 youprint
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.
-
Thank you!