Change Contents of the Bubble
Welcome to CS1315. Click on the python to add comments.

Looking for the book? They have it at the Engineer's Bookstore at 748 Marietta St NW. Here is there website: http://www.engrbookstore.com/ - Monica

Hotspots: Slides and CodeTA CornerComments?AnnouncementsFAQStatic Webspace
View this PageEdit this PageUploads to this PageHistory of this PageHomeRecent ChangesSearchHelp Guide

Summer 2004 Homework 6 Questions

Questions on building your news ticker tape stories?


Obviously searching for a href=s/ isn't going to get the job done because there are many other instances of it, so is it best to search for after In The News?
I think that's what was suggested in the assignment... sounds like a good idea. -K.K. Lamberty

what kind of for loop would be appropriate to get three headlines, not just the first one?
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

When I run my program, everything is working except for some reason my code grabs the first, third and forth headline instead of the first, second, and third. Is there any difference in code on this website that might make this happen?
Never mind, the website had changed while I was writing my code and I didn't refresh. My code works just fine.

Is there some way to write out text? I tried to do return statements for my headlines and that didn't work so I'm trying to figure out some way to call the strings when I make the tickertape, but they are two different functions. I tried string1.writeTo(filename), but I made it .txt, and I guess it has to be a jpg or a wav file.
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

Here's a problem that came up in Breakout today...What if your browser won't let you view the source? You can save the page to your computer and then view the source in Notepad. Lauren Walker

is there anyway...in dot notation to say from 0-end? for ex. say you wrote this code...

file=file.open(filename, "rt")
string=file.readlines()
file.close()
<\code><\html>
and then you wanted to say that something equalled the lines of text in that file...all of them, but there is no preiod or anything at the end. so something like...string1=string[0, end] excpet end doesn't work...is there something you could write there that would go to the end of the text?
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

thanks

To clarify...the tickertapes run the headlines, not the actual stories, correct?
Correct. The headlines but not the stories. -K.K. Lamberty


Ok.. I've got the first headline going from the source to the tickertape correctly, and I've hardcoded strings("CS 1315","hw6") to represent the second and third headlines. I now just need to figure out how to search for the second and third headlines correctly. Where do I go from here?
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

"don't have the ticker tapes move more than 5 pixels per frame."
how can this be done or if some one could explain me what it means by the above sentence.
So in thsi homework we dont have to move the 100 frames at any frames per seconds. how do you make pixels move per sec.
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

ok to get the headlines can I do something like what the recepie no 76 is doing on page 22 7 . Can I do the way it gets the weather form ajc-weather.html.
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.
But I have one more question in that recepie what does if curloc <>-1 do.
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

what happens when you make somehing a string the already is a string?...like if i do item = str(function()) then somewhere esle have newitem = str(item), what will happen?
(Please) try it at the command line in JES and find out. -K.K. Lamberty

my code stops at the writePictureTo line, any reason why? it looks to be correct form.
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

i am bit confused...wouldn't you use something like recipe 82 rather than 76 for this assignment?
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

I am haveing trouble getting my computer to view source, can anyone give me some suggestion on how to get this to work?
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

I am having an issuse getting more than one headline, I can get the first headline but instead of printing the next two headlines it just keeps printing the first one. I figured out everything else except that.

My code looks like this
 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
Could anyone please explain how the rfind functions works ?
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

Link to this Page