Search code examples
pythonloopsif-statementcontinue

passing to another loop in python


word1 = 'index.php/1'
word2 = 'index.php/2'
try:        
    tentativa1 = urllib2.urlopen(site + word1)
    tentativa2 = urllib2.urlopen(site + word2)

except URLError as e:
    tentativa1 = e
    tentativa2 = e

lista = [tentativa1, tentativa2]
    for website in lista:
     if website.code == 200:
        website = website.read()
        print '\n:)' if 'registration' in website else '\n:/'
        print '\n:)' if 'there is no form' in website else '\n:/'

the idea is to "continue" the code after the first "if". How can I do it?


Solution

  • First, I want to say that your question is very unclear. Hence, most of this answer is guesswork.

    However, when I read your post/comments, I got an idea that you want something like this:

    lst = [tentativa1, tentativa2]
    for item in lst:
        if item.code == 200:
            item = item.read()
            print '\n:)' if 'registration' in item else '\n:/'
            print '\n :)' if 'there is no form' in item else '\n:/'
    

    Also, continue is used to jump to the top of the nearest enclosing for/while loop. Meaning, you would not use it here because that functionality is not required.