Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How do I change output of variable in python?

My current code is

#imports
import requests
#setup
response = requests.get("https://randomfox.ca/floof/")
fox = response.json()
#code
print(fox['image'])

Whenever I run it, it always prints something like https://randomfox.ca/images/99.jpg.
Is there any way to change this and make it 99.jpg instead?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

import requests
import os

# Setup
response = requests.get("https://randomfox.ca/floof/")
fox = response.json()

# Extract the filename
image_url = fox['image']
filename = os.path.basename(image_url)

# Code
print(filename)
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading