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


This page removed for FERPA compliance
View this PageEdit this Page (locked)Uploads to this PageHistory of this PageHomeRecent ChangesSearchHelp Guide

Spring 2003 Homework 4

Ask your questions on Homework 4 here...


So, it doesn't matter what folder and what pictures we use? We can create our own? or use the one from class?
You're going to a directory path as input, so it better work for any directory containing JPEG images. Mark Guzdial


In the first part of the assignment instructions, you said to name the fnction " linksREMOVED" and then at the end you said to name the function hw4 - which is correct?
Student86


I fixed that, Justin – thanks! Mark Guzdial


The way the homework is stated, it sounds like we are given a specific folder with images to use. Above it sounds like we are to create a function that takes the directory as input. Can you please re-word the problem so this is more clear. Thank you

It works just like the samples example in class today. We give you the path to a directory as a string. Mark Guzdial


I created an html folder containg images called index.html using jes, but it won't open in the internet browser. this is the message i get : internet explorer could not open c:/jes1/hw4.html . ANY ADVICE.

Try double-clicking on the file and seeing what is in it, or open it again from JES. Your note is unclear: You made a folder named index.html, but tried to open a file named hw4.html? Browsers can't open folders – they can open files that are in the .html format. Mark Guzdial


the Instruction is a little confusing.I created an html page name Index.html containing images thru jes and try to open it in the browser. I thought this is what we should be doing first. the browser won't open the page.
No, absolutely not. Did you come to class and see the Samples code run? You're building code very much like that. You are not just writing an index.html file – you are writing a program that CREATES an HTML file. Mark Guzdial

On the slide, you have "Import OS" and then later in the function you have " for file in os.listdir(directory)". But in class, your program that you ran did not have this. What does it do and why would you need it?
I did have it in the program, and we discussed this WEEKS ago. It's even in the book – see page 177. It's needed to process all the files in a directory. Mark Guzdial

I got the function to work, but when I click on the image in the browser it goes to a page that says "REMOVED cannot be displayed". Is this because the images are on my computer and not the internet? Is it supposed to show the image in its real size after you click on the "thumbnail"?
What is the target for the anchors you create? You have to create <a> tags to create clickable-anchors, and you'll use href= to set the target for the anchors. That's what will show it at it's real size. You want those targets to be the actual pictures. Yes, the created HTML should run fine if you create it in the same directory as your pictures – you don't have to upload it to a Web server. Mark Guzdial


I think I almost have it, but I can't figure out what to put in the tags to get a link to each picture. I have tried so many different things, but nothing works! Can someone help me, please? Also, does the file have to have thumbnails as links to each picture? The way I understood it, it just had to have a link (which in my case will be the name of the file or some other text link).
The nice thing about HTML is that you can just type it into a file and try it. Get the effect you want in plain HTML, then write a program that generates what you wrote. Mark Guzdial

I can't figure it out either. I have the
tags with the href, but I cant figure out what the href=. How do I get the targets to be the actual pictures?
Why not the filenames of the pictures? Mark Guzdial

I got it!!!! Look closely at the number of quotations in the slide and make sure your's look like them (especially for the word file!!)

ok, so with my code i had it search to see if the last three letters in the file name are jpg or JPG so that it doesn't try to make something other than a picture a link if there are things othre than pictures in the specific folder path. however, i am afraid that this won't work on computers where the file names do not end with jpg. will this be a problem?? jessica dickerson
Nope – assume an ending of .JPG – that's fine. Mark Guzdial

Is it okay if your string is long? For example I execute "linksREMOVED("C:\Documents and Settings\Lauren Biddle\My Documents\My Pictures")" and this works for the way that my function is set up. But is this legal to get full credit for the lab?
Absolutely – that's what a solution should look like. Mark Guzdial




I have the program creating the index and making the picures links, but two of the pictures won't show up; either as the link or when I click on it. The others work properly, and even the ones that just show that red "x" for the link, have what seems to be the correct filename in the address window of the page, although it says it can't be displayed. What would make my program work for some JPEGs and not others?

Check the filenames in your generated HTML and in the window (use the detail view). Are they spelled right? Did you grab non-JPG files? Are there issues like spaces in filenames that can confuse HTML? Mark Guzdial


I'm still having some problems getting the pictures to link to the bigger versions. Here's my code: samples=samples+"

Filename: "+file
samples=samples+'
Filename

\n'
Can someone tell me what I'm doing wrong? Thanks!

Let me try that again:
samples=samples+'<a href="+file+">Filename</a><image src="'+file+'" height="100" /></p>\n'
The problem is that you've placed "Filename" as the anchor text, what's clickable. You need the IMAGE be what's clickable. (I showed how to do this in class this morning, and talked about it on Monday.) Mark Guzdial

ok, so i just read through everyones comments and my code is nothing like anyone else's. is this a problem. it does work and i tested it out, but does it have to be like the one in the notes from class or could we do it a totally different way? Jessica Dickerson

Of course it can be a totally different way! That's fine! Mark Guzdial

CODE POSTED

As requested, I posted genSamples2.py that I built in lecture this morning, on the Syllabus and Lecture Slides-Spring 2003 page next to the HTML lecture day. Mark Guzdial


I am a little confused about the wording for how we turn this in. I should save my jes file as "hw4.py" and then my program should be called def linksREMOVED()? Susan Holloman
Exactly. Mark Guzdial

Few questions...(sorry)
No need to apologize! That's what this page is for! Mark Guzdial
1. What do you want the top of the html page to say?...I used the one from your example Samples from C:/..../pics
I don't care. Whatever you'd like. Mark Guzdial
2. I have all of my pictures in order but when I put the cursor on it, it shows the directory. Is this right? The anchor shouldnt take us anywhere right?
Purposely blank
No, the anchor should take you to the picture. My guess is that you forgot the filename in the href. Mark Guzdial

One more thing! How many pictures do you want in the directory? Will 7 be enough?
Purposely blank
We'll be testing on our own directories. It should work for any reasonable number (say, a few hundred). Mark Guzdial

I've gotten the code to work and I made my samples file. When I pull up the html page, there are links to the pictures, but they don't go anywhere (just pulls up page with "REMOVED not found" at the top). I can't figure out what is wrong! any suggestions?
It also looks like when I click on the first picture that the 2nd link goes to that picture.
Look at your HTML. What do the href's look like? Do they have the names of the pictures? If they don't, that's why you're getting the erorr that you are. Mark Guzdial

sorry....that was from Student88


Nevermind...I fixed my own problem. I love it when that happens! Student88
ME, TOO! Mark Guzdial

samples=samples+"<p><a href="+file/"><image src=" '+file+' "height="100"/></p>\n'</a>
I keep getting an error when I input this. Jes can't read it as python. What is going on?
Check your quotes. The file/" should probably be file+"/. There are similar errors elsewhere in that line. Mark Guzdial

How do I just keep the words on here so this blank picture won't show up?
Huh? Try again, please. What's "here"? What "blank picture"? Mark Guzdial

How do you check to see if it works after you input linksREMOVED (blah blah blah? What comes next?
It should create an HTML page that you can then open in a browser to see what it looks like. Mark Guzdial

yeah i keep getting an error as well, i even copied the code professor Guzdial posted to try to see what i was doing wrong and i get an error with that code too.

my error was it can't read it as python by the way.
You have to get the string addition right. "blah"+"blah" will you give you "blahblah". "blah" "blah" (no +) will give you an error that it doesn't look like Python. Mark Guzdial

In the instructions, it says to have the height of 100, but does it matter about the width? Is it ok to set the width to 100 too?
It's okay to set it like that, but then you'll get square icons that don't look like the original picture. Mark Guzdial

I have been getting my function to work, I have an html file and it works fine. Today I tried it and I keep getting the error "A syntax error is contained in the code – I can't read it as Python" All of my friends are getting the same thing. I know the code works, I have the file to proove it. Why won't it work now? (And yes, I have re-started my computer.)
You changed a space or a "+" or a quote somewhere. You can send me the file and I'll look at it, but you definitely did change the file. Mark Guzdial


I keep getting the same error when I try to run it as well.
Then look very carefully at each line and make sure that the quotes match and that you only have plus signs between strings. Mark Guzdial


When running the program what comes after this line?
makeSampleREMOVED(r"c://mydocuments and settings/hw4images/samplepics")
I keep getting errors like"python can't read and file not found.
Not sure how to answer this. Did you come to class and watch me do this in class? Mark Guzdial
Try using "\" instead of "/" - Jose


This is just a guess, but I wonder if JES will only run that program once and save the resulting file to the JES directory. Once its in your JES file, JES might see that the file has already been created, and therefore throw out an error because it can't replace the first file you made. Dr. Guzdial can correct me if I am wrong, but that was the first thing that I could come up with.
Brittany Selden
Nope – I ran the samples program several times in a row, making modifications each time. You can run it as often as you like. Mark Guzdial


oh god i hate myself i've had the right code the whole time but when i executed it in the command line i forgot to put the r and quotes around the path.

Why hate yourself? YOU FIGURED IT OUT! YOU RULE! Mark Guzdial


what EXACTLY do you use as input? My comp keeps giving me "error-I can't read as python." what does that mean? i think i have it except for the input! Kelly Farrell
"I can't read as Python" has nothing to do with the input. Check your code very carefully to make sure that quotes and parentheses match. Mark Guzdial



I have completed the function and got it to load and all that good stuff. I tried to view my hw4.py in Internet Explorer to make sure everything was good with it. It showed me a screen with my code written on it, but broken up with "Samples from "+directory+"" in huge, bold letters. There was also a blank square box underneath it. What does this mean? Have I done something wrong?-REMOVED Williams
REMOVED, don't look at HW4.py in IE. Look at the .html file you created in IE. Browsers understand HTML, not Python code. Mark Guzdial

will someone post the anchor line??? please?!?!
The anchor line? What do you mean? Mark Guzdial


If anyone can help me, please IM me at GTKelly26. I NEED help. Kelly Farrell

Kelly, 404-894-5618 is my office number. I'll be here for another 20 minutes or so. Mark Guzdial

My file works for making the samples page–but I just can seem to get it to link the pictures. I have moved and and ahref all over the place and taken them in and out and nothing changed. Can anyone offer me any suggestions? Here is my line of code that needs work I think :
samplesfile.write('

\n
')
Student117

Ahhh!! What happened there?

Prof. Guzdial, I called you but you must have already left. My main problem is, I cannot seem to get the exact wording/spacing right on the anchor line. I have tried everything and I can't seem to get it to work. Everything else is great!! Any thoughts or troubleshooting ideas?
Here is what I have so far starting with the "if" statement:

if file.endswith(".jpg"):


samplesfile.write("<p>Filename: "+file+"<br />")

samplesfile.write('<image src="'+file+'" height="100"width="100"/></p>\n')

<p><a href="+file+"><image src="+file+"height="100"width="100"/></a></p>

Kelly Farrell

hmm, that didn't work ... ummm ... Kelly Farrell
Sorry – I had to leave at 3:35 to go coach my daughter's soccer team. What's with that line of HTML that's outside of a samplesfile.write function call? Mark Guzdial

ideas?

Yeh–mine didn't either Kelly!! Student117


^
its in html. you need to like put spaces in between the html part or i think theres another way to post html code without it converting... like 's or something?

If you put <html><pre> before your code, then </pre></html> after, you'll be able to get it to look all right.Mark Guzdial


so do we need to specify each .jpg file name? and also do we need to specify a new .html file for each anchor link to go to?

i mean i know this is supposed to just generate a page for multiple users so we arent supposed to use specifics right?

more or less im confused on the directions. could you elaborate as to what exactly you want?

[sorry im terrible with the terminology of this stuff i hope i got my point across]Whitney Watts|You need only ONE .html file. All the href's will refer to your JPEG images. You don't need to specify the JPEG file names – instead, the os.listdir() function will create a list of all of them in the input directory. It should work very much like the samples example I gave in class.Mark Guzdial|

Does it matter if your title is at the top or bottom of your page? If it does matter, how do you move it from the bottom to the top?Kelly FarrellP.S.- ignore all my other questions!
The title with the <title> tag must be in the <head> of the file. If you want a heading at the top, it should appear at the top.Mark Guzdial

I got it!! But note to others who may have the same problem I did–spacing is very important for a href!!
Summer McWilliams: 
_

man oh man i finally got it!
tips: dont forget that you can view the source ... and be careful with the quotes and stuff.Whitney Watts|YAY SUMMER AND WHITNEY!Mark Guzdial|


Watch out for this!
If your code has mismatched "+" then you might get weird error messages from JES...
(ex: samplesfile.write("Filename: "+file" ") - Jose

How come "linksREMOVED("C:\Program Files\JES\mediasources") doesn't work consistantly...? It worked the other day for hw4 but today it wouldn't work with the exact same program? What am I doing wrong?





Link to this Page