2012-01-15 225 views
0

我有一個變量:在一個循環變化的變量

user = "jobrr" 

我要循環以下,但改變什麼變量每個循環週期(所以在循環結束後表示預定義什麼爲即將到來的循環變量將)

example loop as long as y = true 
    openurl = urllib.urlopen("https://api.twitter.com/1/statuses/user_timeline.json?include_entities=true&contributor_details&include_rts=true&screen_name="+user+"&count=3600") 
    user = user + "a" #just for example 

我該怎麼做?

回答

6
user = 'username' 
y = True 

while y: 
    openurl = urllib.urlopen("https://api.twitter.com/1/statuses/user_timeline.json?include_entities=true&contributor_details&include_rts=true&screen_name="+user+"&count=3600") 
    user += "a" 
    #You have to do something in here to change y or this will be an infinite loop 
1
user = 'username' 
y = True 

while y: 
    openurl = urllib.urlopen("https://api.twitter.com/1/statuses/user_timeline.json?include_entities=true&contributor_details&include_rts=true&screen_name="+user+"&count=3600") 
    user = function_that_returns_user_name() 

你只需要定義function_that_returns_user_name()

+0

我覺得這種方法對於長期發展更可持續(我懷疑你會得到,只是「一個的追加到它的名字真正的比賽)。 – Makoto 2012-01-15 17:26:28

+0

@Makoto,我同意,這就是爲什麼我寫了我的答案。但OP有選擇。 :-) – joaquin 2012-01-15 18:32:31