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

Fall 2007 Homework 5 questions page

Questions?

So, is this supposed to take in any number of media files? And is it supposed to be a general formula for any media file input?
This is supposed to take in any file that we give it and give us the correct answer. This is only supposed to account for .jpeg, .jpg, and .wav files (regardless of capitalization). Thanks! Brittany Duncan
The columns are supposed to go [link, filename, height/length] correct? Then why does the seventh step tell us to make sounds [filename, picture, height/length]? Do we swap the first and second rows for those two, and make the filename a link instead, or is this step wrong?
I changed the instructions. It is supposed to go thumbnail link (small picture), filename, and height/length. Thanks! Brittany Duncan

The first instructions say the function should be named "media" but when it says what the TAs will do, they use a function called "gallery" Which is correct?
This should be correct now, but the correct name is "media". Thanks! Brittany Duncan

Do we pick pictures OR sounds? Or, do we pick pictures AND sounds?
This needs to account for both pictures AND sounds. Thanks! Brittany Duncan

The link goes in the first column, then the thumbnail goes in the second column, but the thumbnail also needs to be a link? Is this correct? We need two links to the same thing?
Sorry, fixed again. It should be picture link in the first column, filename with no link in the second, and then the height/length in the third. Thanks you guys for pointing all these errors out, it is best to fix them now. Brittany Duncan

Is soundPic.jpg in the directory, or somewhere else, like the media path? I don't know how to reference it in my image src tag
It is in the directory Toni Walden
The student below brought up a good point, we'll have the TA setMediaPath to the soundPic.jpg. Thanks! Brittany Duncan

But if it is in the directory, it will count as one of the images too? I put it somewhere else and used getMediaFolder. Would that be ok too? I think it works the same in the long run
That is fine, I'll change the TA directions to setMediaPath as well. Thanks! Brittany Duncan

Is the length of the sound in samples or seconds?
Seconds. Thanks! Brittany Duncan

Will we need to use os.listdir to look into the directory?
Yes, that is part of it. Listdir returns a list of all of the filenames in a directory. Nicholas Poirier
Since Mac uses / in filenames and Windows uses \, which one should we use when we are writing our code? I have a Mac, but will my file still write correctly when the program is run in Windows? Is there a way to eliminate using / or \ and make it universal?
There is a way to make it universal. There should be instructions in your book. Thanks! Brittany Duncan
There is another –even better – way that isn't in the book. If you import os, you can use os.sep. This is the separator character for whatever platform you are running on. Colin Potts
I'm a bit confused as to the concept of the directory we're supposed to be using. Are we supposed to be using a directory that already exists? Are we supposed to just stick some pictures and sounds in a folder and call it a directory? Are there particular pictures or sounds we're supposed to use?
You can use any directory that you want, as long as it has sounds and pictures of the correct format. Thanks! Brittany Duncan

Oh, and will we need to turn in whatever pictures and sound we use, or is the program supposed to work for any directory?
No, you will only turn in your code. The program should work for any directory that we give it. Thanks! Brittany Duncan

"At the bottom of your page you should have the total number of media items"
As a number? A part of the table?
As in "The total number of media items is: [some number]." Just a sentence at the bottom, not part of the table. Thanks! Brittany Duncan

The assignment mentions using both a dir and setMediaPath. Should we just pick one?

You don't have to use either; the directions say that your TA is the one who'll be using both to test your code. You could use "dir" to serve as a place-setter for your actual directory name, but you're not required to include that name, specifically, in your program. –Someone who's not a TA
When I try to give commands in the command area, I keep getting error messages about how I need to define "doctype" before I use it. Where and how am I supposed to define doctype?

If you're copying code from the book, which i think you are, doctype refers to the function that plainly returns the doctype thing in carrots


'carrot' !DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd" 'carrot'
"Carrots"?! Do you mean carets? But don't they point up rather than left and right?
Or preferably (if you use code tags as repeatedly requested ;) as follows:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">


Do we also submit our SoundPicture.jpg with the code for you to put into your directory?
Nope, if you name it appropriately (soundPic.jpg) then we will use one of our own. If you do not, then it will crash your code and be 40% off. Thanks! Brittany Duncan
For the length of the sound, do you want samples or how long the sound plays for?
My bad, just found my answer above, disregard previous post.
Please check to see if your question has been asked and answered before posting. Thanks! Brittany Duncan

Okay, I just realized something. If we have the soundPic.jpg in the directory for the thumbnail for sounds, it will have its own row. Is that okay?
That is fine. There are alternate solutions outlined above. Thanks! Brittany Duncan
Is there a method (terminology?) that will allow us to find the number of files in a directory? Does it at least exist?
Not that I know of, and even if there is, don't use it. You should keep a count. Thanks! Brittany Duncan
do we name it soundPic.jpg as it says in the instructions or soundPicture.jpg as you said above?
soundPic.jpg as it says in the directions. Thanks! Brittany Duncan
In the 15 point extra credit, should we update the links to pictures and sounds so they appear correctly on index1.html, or leave them broken?
Fix them, it isn't very hard. Thanks! Brittany Duncan
I can't get my images to show up. I have them at the exact directory they are at because I use the os.listdir and I have all the right filenames. Is this not right?

<td><img src="C:\Documents and Settings\alex\My Documents\school\2007 - 2008\cs 1315\hw\hw5\stuff\fightclub.jpg"></td>

It's not my python code because I can't do it with just HTML either.

Am I just missing something?
What is supposed to be show there is
....deleted
Please put <CODE> tags around your code! You have been told this EVERY assignment since the beginning of the semester. I have edited your question above so that people can read it.. (You can see what this looks like if you click on "Edit" in the menu bar above.) Colin Potts
As a partial answer to your question: Is the TA going to use your computer or his or her computer? Maybe I will be grading your homework on my Macintosh..... Colin Potts
Are we supposed to uses media paths, taking in a directory or both? If both which should be used for what?
Regarding the reading of files, your question is answered in the homework specification (Point 2). Regarding writingyou should save the HTML into the same directory that you are reading files from. If you have already finished the homework and wrote the file to the mediaPath, that is okay too. Colin Potts
When it says to have the filename in the second column, can we have the full filename (as in the media path, with all of the users/yourname/file/filename) or can we only have that last part of the path?
Since the problem doesn't specify, you can do either. However, it is more natural just to give the file name without the complete path. That was our intention. Colin Potts
do we need to turn in a soundPic.jpg? or will the TAs have a picture called that already
Brittany has already answered this question. Colin Potts

Okay. When I open my generated webpqage in Internet Explorer, it works fine. But when I use Mozilla firefox, some of the thumbnails fail to show. Should I just accept this and hope my TA uses Internet Explorer or try to get the program to work for either Browser.
It should be valid HTML. Sometimes one browser may be more insistent on the HTML being valid while another is more forgiving and makes a lucky, correct guess. Are you closing all your tags? Also, tags should be correctly nested (e.g. <TD><IMG...></IMG...></TD>, not <TD><IMG...></TD></IMG...>) Colin Potts

Does the total number of media items include soundPic?
No. (Simple answer that replaces a waffly answer I posted earlier.) Colin Potts


do we need to put the information into an actual table with dividing lines and everything or just in a general layout of a table?
As long as it is an HTML table, it's a table. To quench your thirst for learning (but not for extra credit, sorry) you can go further and experiment with ways to create borders and padding. There are many online tutorials on HTML if you explore. Colin Potts


omg, FF and IE is not consistent (surprise surprise), not even for this simple task. I am even using the strict dtd. FF will not show thumbnail, IE will, then IE will not play sound, but FF will. What should I do? I am using Vista in case you want to know (lots of IE 7 alerts and blocking , etc.) and am using the newest FF.
When you view the page in one of the web browsers, go up to the tool bar click "view" and then select "source"/"source code". Look at the HTML you wrote and make sure everything looks correct. Often times a when something shows up correctly in one browser but not another, something in the HTML is not exactly right, but close enough that one of the browsers can guess what you mean. This error could be something as simple as a typo, or something as silly as forgetting to close one of your tags. If you can't for the life of you see anything wrong with your HTML, then feel free to e-mail the HTML file to one us so we can help you figure out what is going on or jsut stop by office hours tomorrow. Toni Walden


"At the bottom of your page you should have the total number of media items." Does this mean
A) all files in the directory (including .gif and .bmp files in the directory)
B) number of rows (all .jpgs and .wavs)
All files ending in .jpg, .jpeg, .JPG, .JPEG, .wav, or .WAV that are in the directory. Toni Walden


Ok, I know this was asked a couple of times earlier but I want to clarify. Is it ok if we put the soundPic.jpg in the directory or do we have to use getMediaPath("soundPic.jpg") in our code?
You can use either, but take into account the fact that Colin said your count should NOT include soundPic.jpg. Thanks! Brittany Duncan


So Toni said that the total number of media items should include all forms of .jpg and .wav. So, should this or should this not include soundPic.jpg if that file is in our directory?
OK, I got my stuff to work; I had to precede all of the absolute references with 'file:///'. I am using Windows. What is the MAC OS version of that? or will i need to precede the directory provided by pickAFolder() with anything?

Please read the previous replies before asking questions. Thanks! Brittany Duncan

Is anybody else having trouble with opening audio in Vista IE 7?
It works in FF by the way on the same copmuter.


is there any way that you can specify where you want to create an html file? I can only find examples that create it in your jes folder, or will you move the html from the jes folder into the directory before you open it?
There's an example in the html2.pdf file on the slides and code, I believe, but, simply put, you want the HTML file to be written into the same folder as is specified in the parameter being passed into your media() function. This is probably called 'dir', as that's the example used most often. You can use string concatenation to add the dir variable with the '\\media.html' file. Chris Phillips

In Internet Explorer, after click the link to a sound file it prompts to download the file,but in firefox it plays the file. Is this ok?
Yes. That has to do with how your browser is set up, rather then something that your code is doing. Chris Phillips
Also, about the 2 functions requirement, does this mean 2 functions in addition to the one named media()?
Brittany'll have to answer that. However, to be safe, you can always just add two functions to your code arbitrarily. Almost any chunk of your code can be changed into a called function, if you felt so inclined. Chris Phillips

My program only works if setMediaPath() and directory are the same folder (and directory contains soundPic.jpg). If I setMediaPath() to another folder with soundPic.jpg, my program gives me a "There is no file at (setMediaPath() folder)" error.

Nevermind. I think I have fixed it.

the link for the Fugu isn't working. the apple website says the page can't be found
Fugu is a supported download from OIT. It should be downloadable from http://www.oit.gatech.edu (Go to the Software > Software Distribution menu item) Colin Potts

Hey, my webpage displays pictures in Internet Explorer and not in Mozilla Firefox! Suppose this screws me up in grading?
Make sure your HTML code is correct, with proper end tags. IE and FF parse incorrectly formatted tags differently, so if you forgot end tags, or something, it will display differently. See a TA if you can't figure out what is wrong. Chris Phillips

Will the TAs, when they grade our work, put soundPic.jpg in the directory with the other media items, or will soundPic.jpg be in an arbitrary location? If the former case is true, that essentially eliminates the need of setting/getting the media path. If the latter is true, how do we make getMediaPath("soundPic.jpg") a string so we can put it in the HTML portion of our code?
It'll be in the same directory as the other media items. Chris Phillips

I am getting this error
The error was:__add__ nor __radd__ defined for these operands
Inappropriate argument type.
An attempt was made to call a function with a parameter of an invalid type. This means that you did something such as trying to pass a string to a method that is expecting an integer.
Could the problem be that I am trying to "add" a string and an integer? as in
"<td>" + getWidth(pic)
.. if so, how can I get the number produced from the getWidth(pic) to be a string that can be added to the html string?
Typecast it. Use str() to convert something to a string. Stick the integer into the paranthesis there, and it'll convert it to a string. Chris Phillips

a collaboration statement is just a comment at the top of your code, right? (i worked alone)
...I hope you're asking this in the "I always worked with people before and now am doing it alone and I'm not sure what the collaboration statement would be in such a case" sort of sense, rather then the "I never have included a collaboration statement before" sort of sense. But, yes, it's just your name, your GTID, and saying who you worked with, and with what materials. If you worked alone using only course materials, then say so. Either way, it's to be commented out at the top of your code. Chris Phillips

we do not need to include the width of the picture, do we?
The directions don't say you do, so no. Chris Phillips

Could someone please answer this: My program only works if setMediaPath() and directory are the same folder (and directory contains soundPic.jpg). If I setMediaPath() to another folder with soundPic.jpg, my program gives me a "There is no file at (setMediaPath() folder)" error.
Why don't you just put soundPic.jpg in the directory? Thanks! Brittany Duncan

Can I get any hints on bringing my information from the os.listdir part to the """+ part in the table?
E-mail a TA with more specific questions. Thanks! Brittany Duncan
os.listdir returns a list of strings. Each string is a file name. You can find the elements of the string by using [...] notation, and so you should be able to put each string into a particular place in your HTML. Colin Potts

I am having trouble figuring out how to "link" to a page with a larger picture, or with a sound. Do we need to make a new function that creates a whole different page with this... I dont know if that makes sense but any help would be appreciated. thanks
You need to "link" to the location of the picture. Thanks! Brittany Duncan

Follow up to the Could someone please answer this:/Are the TA's then going to put my soundPic in the same folder as their pictures and sounds
Yep. Chris Phillips

Thank you very much

wherever i have triple quotations, my code is returning \n... why? how can I fix this?
Because that's what you're telling it to do. If you really believe that triple quotes are the cause of this behavior, you would try using double or single quotes before posting your message. Try that and see what happens. Colin Potts

for the 15 point extra credit, http://www.prism.gatech.edu/~prismID/index1.html does not work but
http://www.prism.gatech.edu/~prismID/ does, is this ok?
Did you upload a file called index1.html, or did you upload one called index.html? It sounds likely you did the latter. But if you did the former, and that indeed is what is happening, it'll probably still count, though Brittany would need to say for sure. Chris Phillips

what is the size limit of our prism sites? and is it alright to have music files on our website?


ok so its not the triple quotes.. sorry :(. Its the fact that I have hit enter to move the code of the string down to the next line so that its not one huge line. Any suggestions
Don't know what the original question is, but, don't forget you can use string concatenation. You can use var = "string", then var = var + " other string", to get var to be equal to "string other string".
Well, you do have to use triple quotes if your string is longer than a single line. However, I think that the above answer is on the right track. You are probably intending to build up the string incrementally by adding more and more stuff on the end. If you say something like string = "\n" for your last assignment instead of string = string + "\n" all the earlier stuff will be overwritten and you will be left with a lonely newline. Colin Potts

do we need to add a comment to our hw5.py file that indicates we did one of the extra credits?
It would appear from one of Brittany's comments that you should do so, yeah. Chris Phillips

How do you write a string to a folder?
You can't. If, however, you mean how do you write a string to a file, you use file.write(string). Check the html2.pdf file in the Slides and code to see some examples of this. Chris Phillips

do relational databases and shelving have anything to do with this assignment?

Nope. Thanks! Brittany Duncan

Does it matter if we have a row at the top labeling the columns, or is it strictly one row per media item. Also can we tweak the cellpadding and such to make it look a bit nicer?
Go for it! Stick in a heading row if you like, and tweak away to your heart's content. Colin Potts
You wild, crazy, adventurous person you. :P Chris Phillips

My program runs and creates the html file, but for some reason it doesn't actually write anything to the file. I have included file.write. Are there any TA's that might be able to take a look at my code and help me out please?
You need file.close() at the end of your function. Not A TA

It seems as though Chris Phillips is online. Thanks! Brittany Duncan
Ouch. Thanks a lot. (twitch) Chris Phillips

My html code generates the pics and sounds, but when I use JES to write the file the same html code is generated, but the pictures are not showing. why is this?? thank you
Check the source code of the HTML that is generated, and make sure that the image path is correct. Chris Phillips

whenever I try to get the height of a picture with this:
height=samples=samples+getHeight(makePicture(file))
, it tells me that there is not file at .\(my file)...
I'm not sure where ther '.\' is coming from??
Try using makePicture(dir + os.sep + file), where dir is the directory taken in as a parameter through media(). If the code you supplied above is in a subfunction, you'll need to pass the directory to the subfunction as a parameter to be able to reference it. Chris Phillips

When trying to write my string to the file, I get an error message that says:
The error was:java.lang.NullPointerException
I wasn't able to do what you wanted.
The error java.lang.NullPointerException has occured.

Anybody know what this means?
It means a TA is going to have to look at your code, unless someone has dealt with the exact issue you're having. That's a very broad error that can be fixed, but is almost guaranteed to require someone tracing through your code. Chris Phillips

THe extra credit says not to use the "scaling utility"... what's that?
It is on the software download page. Colin Potts

My function is running but the html file isn't being saved anywhere. Any ideas why?
If it's not been saved anywhere, you aren't writing it. But how do you know that it's not being saved anywhere? If it is being saved somewhere other than where you are looking, your filename variable is incorrect. It could be that you are doing something with your folder/directory separator. For example, instead of saving a file called "media.htlml" in a directory called "dir", you may be saving a file called "dir//media.html". Something like that. Colin Potts

Is the html file supposed to be named index1.html or media.html? It seems a bit unclear
My fault for my previous answer (which I have now changed): the file your program generates should be media.html. If you upload it for extra credit, you should change the name to index1.html. Colin Potts

Is there a function that counts the total number of elements in a list- not the number of times something is in the list as the count() function does, but the total number of items in the list?

nevermind. I figured it out. It's len(list)

For the extra credit, is it necessary to use the writePictureTo function when generating the thumbnails? I managed to get it to work by importing the Picture module and using (imageVariable).write(getMediaPath(fileName)) to generate the thumbnails...

^Well, after editing the picture, of course.
No. You found an effective but different way to do what the question asks. Good for you. Colin Potts

If the soundPic is placed in the directory with the other media items, then are we supposed to include a row for it as well( it does end in .jpg), even if it isn't counted in the total items at the bottom of the page?
Bottom line: it's up to you. It's not in the spirit of the assignment to do this. As I said in answer to another question, in a real program as opposed to a homework assignment, the soundpic image would be brought in from a standard directory. You wouldn't be able to assume as a programmer that the user would conveniently always supply such an image for you in the input directory! So if it is in the directory, I would ignore it as one of the jpgs you need to show. Anybody reading this who has included the soundpic.jpg as one of the rows can just ignore this answer and submit. The instructions were ambiguous. Colin Potts

The FUGU program for Mac no longer exists to download.. what should we do if we have a mac and want to do the extra credit?
OK, so the posted link is no longer valid. Have you tried to download from the OIT site – as suggested in a previous answer? Colin Potts (And, BTW, don't you people ever use google? ;) )

if we are suppose to disply the length of the sound and getLength function generates the largest sample and we do not know how many samples per second the sound is how do we calculate the length in seconds
There is a function in JES to find the sampling rate of a sound. Colin Potts

When we upload the page to the server, however, we would need to include the SoundPic.jpg or it will not show. Also we need to change the href so that it goes no more to "C: wherever", but to the directory where all the other files are. Is this so? I mean, am I thinking correctly?
Your reference to the soundpic should either use getMediaPath or the same directory as the other files (as answered several times above). You should NEVER refer to the full path of a file like "C:\....", since it obviously won't work on any other computer. Colin Potts

Are the TA's going to throw any non-jpeg or non-wav files in the directory? Or can we count on it being all jpgs and wavs that will go into our function? I ask because I wrote a function that only identifies if a file is a .jpg or one of its variants, and if it isn't, it treats it as a wav. Will that screw me up?
Like, they won't throw a .pdf file in there just to see if our function messes up will they?
I plan to. It's not hard to make sure that you only deal with wavs or jpgs. You have a function to see if a file is a jpg or variant, well, you can probably write another that is virtually identical, to see if it's a wav or variant. If you can tell the difference between a jpg and wav, you can tell the difference between a jpg and wave and something that isn't either. Chris Phillips


i know what is wrong with it , pich is not a string it the functiong getHeight returns a number, but how do i make the number into a string so that i can return it? for instance my function will mess up when I type file.write(jpg(filename))
I removed your code, because I think it gives too much away. The answer to your question is to use the function str() which will convert 34 (for example) to "34". Colin Potts

I can not figure out how to make it link to a bigger image or the sound to play when you click the link where can i go to find out
Slides and code would be good. But, to make it link, all you have to do is create an anchor tag directing to the file. Chris Phillips

If the Page Source is correct, but pictures do not load, can we be penalized???
If somehow your source code was correct, but the pictures were not loading (because presumably the picture goblins had devoured them sometime between JES reading them, and the HTML file being opened), then no, you'd not be penalized. However, chances are really high your source code is incorrect, or is not pointing to where the files are actually located, in which case, yes, you'll be penalized. Chris Phillips

my HTML code works outside of JES linking my pics and sounds, but the once it is written by JES everything is showing up exept the pics and the links. I've tried adding makeSound, but that didn't work. I've tried getMediaPath which I knew wasn't going to work. I also tried just leaving it as the filename in my HTML code and it's still not showing up on the new html page. Also, do we have to name out pic without the sound a certain name like we named soundPic.jpg???
I don't understand the exact problem that you're describing, but here's what you should do: Look at the HTML you are generating – not the web page in the browser, the actual HTML source. You will probably find that the file names are malformed in some simple way. Colin Potts

ok thx..ill try that & get back

I just checked the actual code and it is exactly the same as my original html code, but the links and pictures are not showing up. I set my directory to where my sounds and pics are located. It's wierd.
If you are using relative pathing (i.e., a href=thing.jpg, rather than a href=C:\stuff\morestuff\thing.jpg), make sure you are creating the media.html file in the same directory as your media files. Chris Phillips

I am using relative pathing. fileName=dir + "media.html". shouldn't that line in my code take care of creating media.html in the same as the directory??
No. When you do file = open(...), use dir + os.sep + "media.html". Then, when you're adding in files to your a and img tags, use just the filename, not the directory path as well. That may help.

Ok, I'm having the same trouble with a lot of people regarding pictures and how they are displayed in either Firefox or Internet Explorer. It comes down to whether or not you need quotation marks around the image's source. For instance:

<td><a href=picture1.jpg><img src=picture1.jpg height=75></a></td>


shows up correctly in internet explorer and firfox for whenever I create a row for a .jpg file.

However, whenever I create a row for a wav file:
<td><a href=demboynohavenogun.wav><img src="C:\Documents and Settings\Andrew\My Documents\GT\CS1315\HW5\soundPic.jpg" height=75></a></td>

this shows up properly in IE but not in Firfox (the link to the sound works, but soundPic.jpg doesn't show on Firefox.

What is the proper HTML way for getting an image source from a local (ie, C:\.....) location? Because it loads with or without quotes on the .jpg rows, but in firefox it will not load no matter what I've tried for .wav rows.
The best way is to make sure that you are writing your html file in the same directory as your images (including soundPic.jpg), and that you reference the file with relative pathing, so you don't have "C:\Documents and Settings...", but instead just have 'soundPic.jpg' being written. Chris Phillips

thanks...now it's working. I didn't know I had to call my media like that. Thank again.

Right, but if I do it like that, but you guys aren't having soundPic.jpg in the same folder as you are setting to be the directory, but rather it will be in the Media Path. So will you guys have soundPic.jpg in the folder you are setting to the directory? What's the point of set and getMediaPath if it will be in the directory?
It's going to be in the same place as all the other pics. I assume the reason Brittany even mentioned setMediaPath(), is to give you the option of using getMediaPath() in situations where it seemed appropriate to do so, because you've had more experience with using getMediaPath(). The TA will be setting the media path, and the directory, to the same place, and that place will contain the soundPic.jpg file. We're sorry if that was not evidently clear. Chris Phillips

It says dir = pickAFolder() on the instructions- and no, it is not evidently clear that they would be set to the same place.
Ah. That part is probably left over from a similar assignment that some of the wordage was taken from, where you -did- supply the soundPic.jpg. In this, it doesn't really matter, I don't think. Do it either way, if you go with getMediaPath(), and it doesn't show the file, and your TA knocks points off, then point out how it doesn't display across all browsers (nor could it be uploaded to your webspace in such a case, so the extra credit is essentially undoable). I'll make sure we accept both. Chris Phillips



Link to this Page