![]() ![]() |
| |||||||||
| Hotspots: Slides and Code TA Corner Comments? Announcements FAQ Static Webspace | ||||||||||
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() |
| I think that's what was suggested in the assignment... sounds like a good idea. -K.K. Lamberty |
| Maybe yoou'd want to try starting with a count=3 and decrement count... you could try a while loop if you think that would be better. Otherwise, think about how you can make sure you go through the loop 3 times (if each time through the loop you grab one headline). -K.K. Lamberty |
| Never mind, the website had changed while I was writing my code and I didn't refresh. My code works just fine. |
| If you have found the headlines and made them into strings, one option is to use addText(pic, x, y, "string to display"). Also, if you want to add to a string, you would need to do something like string=string+'what to add to the string'. One more thing... you might want to review dot notation (this is in your book too). Dot notation is used when you need an object to do something... when you use a method that only the object has the ability to do to itself. It looks like you've gotten confused about where the objet goes. if you are calling string1.writeTo(fileName) as you mention above, then you are asking the object string to write to itself the file you have given it. You probably really want to have the file writing the string to itself... the object doing the work goes before the dot. However, I think addText is what you probably want anyhow. -K.K. Lamberty |
| The variable 'end' needs to be a number. If you wanted to have the whole string, then you could use len(string) to produce a number that tells you how many characters long the string is. Keep in mind that since the first character is 0, the length of the string actually is one greater than the index of the last character in the string. This function is used in the "drawing-and-dots" powerpoint presentation from breakout a few weeks ago, which also shows some things about using dot notation and some examples of what you can do with strings. -K.K. Lamberty |
| Correct. The headlines but not the stories. -K.K. Lamberty |
| To get the first headline, you must have first figured out an index in the code slightly before the first headline. From there, you used .find and .rfind, and there's your first headline. From doing this, you obviously must have the index of where the first headline ended. Repeat the same procedure for the 2nd and 3rd headlines, using the end of the previous headline as the left boundary rather than 'In The News'. -Blake O'Hare |
| You are essentially drawing 100 frames. Each time you draw a frame, don't change the location of any given headline by more than 5 pixels. On page 267 in your book, how many pixels does the text move for each frame? Hint: Look at the use of the addText function to figure this out. - K.K. Lamberty |
| Yes, this code is similar to the code you'd need to find a headline, but you do need to find 3 headlines, so you will need to really understand what is happening in recipe 76 to make your code do the right thing. you might try walking through the code and drawing the curloc, tempstart, and temploc so that you can follow along. |
| If curloc is not equal to -1, then execute the loop. Remember that if the thing you're looking for can't be found in the string, the find method returns a location or index of -1... so this is saying as long as you haven't found the thing you're looking for and you haven't gotten to the end of the string without finding the thing you're looking for, keep executing this loop. -K.K. Lamberty |
| (Please) try it at the command line in JES and find out. -K.K. Lamberty |
| It's hard to say without more detail, but one common problem is to forget to cast the frame number as a string. Does that help? Otherwise, you might consider posting a little more detail to help us help you. -K.K. Lamberty |
| Note that on page 234 just before recipe 82, it mentions how 82 builds on and improves 76, so, yep... it's more like 82, but it's not unlike 76. -K.K. Lamberty |
| Internet Explorer seems to have random issues with viewing HTML source. GET A DECENT BROWSER! In the meantime here's the HTML source for yahoo.com that you can look at to figure out how to write your program. -Blake O'Hare |
| Well, Blake, I think you probably could have said something like 'try a different browser', but it was nice to offer the html code... -kk |
import urllib
connection=urllib.urlopen("http://www.yahoo.com")
headlines = connection.read()
connection.close()
curloc = headlines.find("In The News")
if curloc <> -1:
headloc = headlines.find("",curloc)
headstart = headlines.rfind(">",0,headloc)
string1 = headlines[headstart+1:headloc]
print string1
curloc2 = headlines.find(string1+"")
if curloc2 <> -1:
headloc = headlines.find("",curloc2)
headstart = headlines.rfind(">",0,headloc)
string2 = headlines[headstart+1:headloc]
print string2
curloc3 = headlines.find(string1+"")
| Think about what you are asking the code to look for and where you are asking it to start looking. The 'find()' method returns the index of the first character of the thing if it finds it. Walk through your code and specifically focus on where you are telling the object to start looking for the stuff you are looking for. You are very close. The code is doing exactly what you tell it. -K.K. Lamberty |
| This is in the ppt slides entitled "drawing-and-dots". rfind, like find, starts from the index you tell it to, but it goes backwards instead of forwards as it looks for the string you are searching for. It returns the index of the first letter or character in the string, though, just like find does. -kk |