0

I've recently started the Python Challenge and the current test requires a code that uses the string 24 characters in to the current page's content. I've come up with some code but cannot figure out why it only progresses to the next URL once, and then gets stuck, any thoughts? I feel I'm missing something very basic here. Thanks for your help.

import urllib
response = urllib.urlopen('http://www.pythonchallenge.com/pc/def/linkedlist.php?nothing=12345')                         #Starting URL

for i in range(10):
x = response.read()[24:]
response = urllib.urlopen('http://www.pythonchallenge.com/pc/def/linkedlist.php?nothing='+str(x))
print "MESSAGE: ", response.read()   #To display all of the page's contents, including information needed to progress to the next URL
craig
  • 47
  • 6
  • 3
    You can't read from the handle twice. Remove your `print` line or `print x` instead. – Blender Jan 03 '14 at 03:29
  • Also, you should use a `while` loop instead, as this challenge goes on for a while. – Blender Jan 03 '14 at 03:35
  • I see Blender, so it was working, I was just printing the wrong information. Thanks so much. durrutti, thanks for your advice as well, I left it as range 10 for now because I didn't want to start too big of a loop before I knew it was correct. Indentation got screwed up in the translation. – craig Jan 03 '14 at 03:42

1 Answers1

0

Should this while loop be working for more than a few minutes?? i've done well until the first sort of checkpoint where they make your loop stumble by not giving another code. Now it's been running again for several minutes since the next code i obtained manually.

Is there a proper way for me to not be 'in the dark' when the loop is working and do receive info about the process of communications as it is working?

CodeAt30
  • 874
  • 6
  • 17