Created
September 29, 2018 13:12
-
-
Save Fhernd/a83845a4ea8c4e0fc7909996705be0ad to your computer and use it in GitHub Desktop.
Clases como funciones. Python.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from urllib.request import urlopen | |
class PlantillaUrl: | |
def __init__(self, plantilla): | |
self.plantilla = plantilla | |
def abrir(self, **kwargs): | |
return urlopen(self.plantilla.format_map(kwargs)) | |
yahoo = PlantillaUrl('https://samples.openweathermap.org/data/2.5/forecast?id={id}&appid=b1b15e88fa797225412429c1c50c122a1') | |
for linea in yahoo.abrir(id='524901', appid='b1b15e88fa797225412429c1c50c122a1'): | |
print(linea.decode('utf-8')) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment