Reputation: 83
I'm new to python so this is probably really obvious. If I am inputting a web address into python and there are pages which are similar but have different web addresses due to different years in the address, can I create a variable somehow and put this in there?
An example would be: ftp://ftp.cdc.noaa.gov/Datasets/ncep.reanalysis/surface/air.sig995.2006.nc
I would be looking at changing the 2006 to say 2012.
Upvotes: 0
Views: 98
Reputation: 369074
url_pattern = 'ftp://ftp.cdc.noaa.gov/Datasets/ncep.reanalysis/surface/air.sig995.{}.nc'
for year in range(2006, 2012+1):
url = url_pattern.format(year)
print(url)
Upvotes: 3