Advertisement
Fhernd

clases_como_funciones.py

Sep 29th, 2018
7,234
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.46 KB | None | 0 0
  1. from urllib.request import urlopen
  2.  
  3. class PlantillaUrl:
  4.     def __init__(self, plantilla):
  5.         self.plantilla = plantilla
  6.  
  7.     def abrir(self, **kwargs):
  8.         return urlopen(self.plantilla.format_map(kwargs))
  9.  
  10.  
  11. yahoo = PlantillaUrl('https://samples.openweathermap.org/data/2.5/forecast?id={id}&appid=b1b15e88fa797225412429c1c50c122a1')
  12. for linea in yahoo.abrir(id='524901', appid='b1b15e88fa797225412429c1c50c122a1'):
  13.     print(linea.decode('utf-8'))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement