Fhernd icon

clases_como_funciones.py

Fhernd | PRO | 09/29/18 01:12:16 PM UTC | 0 ⭐ | 8474 👁️ | Never ⏰ | []
Python |

460 B

|

None

|

0 👍

/

0 👎

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'))

Comments

  •  icon
    01/01/70 12:00:00 AM UTC
    Plain Text |

    0 B

    |

    👍

    /

    👎