我正在用Python弄溼我的腳。我從來沒有做過任何編程或從未做過什麼,我真的很感激,如果有人會解釋his_hers的答案,而不是隻發佈它,因爲我想學習一些東西!更好的是不發佈answere,但只是提示我應該看什麼或什麼:)將列表中的值插入到字符串中python
我有很多價值觀(數字)一個一方的列表。 另一方面,我有一個URL需要通過多個列表中的數字進行更新,然後將其保存到另一個列表中以便進一步處理。
#borders of the bbox
longmax = 15.418483 #longitude top right
longmin = 4.953142 #longitude top left
latmax = 54.869808 #latitude top
latmin = 47.236219 #latitude bottom
#longitude
longstep = longmax - longmin
longstepx = longstep/100 #longitudal steps the model shall perfom
#latitude
latstep = latmax - longmin
latstepx = latstep/100 #latitudal steps the model shall perform
#create list of steps through coordinates longitude
llong = []
while longmin < longmax:
longmin+=longstepx
llong.append(+longmin)
#create list of steps through coordinates latitude
llat = []
while latmin < latmax:
latmin+=latstepx
llat.append(+latmin)
#create the URLs and store in list
for i in (llong):
"https://api.flickr.com/services/rest/?method=flickr.photos.search&format=json&api_key=5....lback=1&page=X&per_page=500&bbox=i&accuracy=1&has_geo=1&extras=geo,tags,views,description",sep="")"
正如您所看到的,我嘗試從flickr向REST API發出請求。 我不明白的是:
- 我怎麼循環都要經過我的列表,插入從列表中值在URL中的某一點?
- 如何告訴循環在將第一個數字從列表「llong」和「llat」中插入之後單獨保存每個URL,然後繼續處理下兩個數字。
任何提示?
你已經打敗了我的答案。您還可以添加「打印」www.google.com/%s「%word」嗎?並在'urls.append(「www.google.com/%f%f」%(lat,lon))''上做同樣的事情?這將使您的答案更全面,從而爲OP提供更多的知識和選擇。 – alvits
@alvits我認爲字符串格式是首選的方法,我會添加一個鏈接到一個討論差異的SO問題。 –
太棒了。我學到了很多!謝謝Padraic! – Stophface