我有一个变量:
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
我该怎么做?
答案 0 :(得分: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 :(得分: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()