我有這個代碼,我想優化,因爲它啓動它獲得音量:(。我想製作一個數組,並從他調用的值,而不是像每個對象創建代碼我現在做:我怎樣才能使它動態
post_data_groups = {'profile': '46', 'clear': 'Remove+Avatar'}
post_data_documents = {'folder1': '30', 'remove': 'Delete+Documents'}
urlAdmin_groups = 'http://site.com/management.php?Category=6&uid=196'
urlModerator_groups = 'http://site.com/management.php?Category=6&uid=197'
..........
,然後文件:
urlAdmin_documents = 'http://site.com/management.php?Category=3&uid=196'
urlModerator_documents = 'http://site.com/management.php?Category=3&suid=197'
.... and so on
data_groups= urllib.urlencode(post_data_groups)
data_documents= urllib.urlencode(post_data_documents)
然後我打電話給他們這樣的:
response = opener.open(urlAdmin_groups, data_groups)
response = opener.open(urlAdmin_documents, data_documents)
........... and so on
the_page = response.read()
因爲只有類別和uid更改,我怎樣才能使循環調用它們?
我試過的東西,但我沒有找到神奇的解決方案。你能給我一個循環的例子嗎? – 2013-02-26 15:52:13
@MikeThunder:已完成。 :-) – 2013-02-26 15:53:38