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

Spring 2006 Homework 4 questions page

Questions? Post them here and a TA will try to answer them....


Should gallery.html be a page sent from JES onto wordpad or some other program?
The gallery.html is an html page generated using JES. -poof #10

Do we submit our pictures as well? Or should our program be general so that any folder of pictures would work?

The latter. Hardcoded image paths will result in a 0. -Blake O'Hare

When my browser tries to load images from the hard drive, I need to have the path begin with "file:///" before I set the path in order for the picture to show up. If I don't have the "file:///", then it won't load but when I put it before the path everything works perfectly.

Should I include this "file:///" in my code? Is it b/c I'm using Firefox instead of another browser?

Thanks!
No, don't use an absolute URL. Just use the filename by itself because this HTML file will be written to the same folder as your images. -Blake O'Hare

How do we get the information on the width and height of the image?

getWidth(pic), getHeight(pic) -Blake O'Hare

So we do not need to include the directory in the path for the image? We can just leave the path as the image name b/c the HTML file is in the same folder as the pics?
In the end, in your HTML file, you can just say the name of the image, but when accessing your pictures in JES to use them and write them into your HTML... you will do something with the dir. Liz Helms
Remember, in your HTML file, you can only use just the image name (ie. src="pic.jpg") if the picture is in the same folder as the webpage.-poof #10
Thanks for your help!

Are we only using JPG or JPEG files to show as thumbnails? Should we also include other image types such as .PNG or .BMP, etc...?
Checking for only JPEG is ok. Include .png or .gif if you feel extra motivated. Ignore .bmp. Always. If you're generating smaller thumbnails for extra credit, then JES can only recognized JPEG and PNG formats. -Blake O'Hare

JES can also recognize ".gif"....

What two functions should we use?

Any that will benefit you when writing your code. You make them and write them yourself. I'd suggest something that you'll either (a) use multiple times or (b) will clean up your code and help you to debug. Amanda Bennett

This particular HW is kind of hard to abstract out into separate functions, so if you want to be cheap (which is fine in my book since if you can figure out how to make your code optimally readable and efficient in one function, then why should you obfuscate it?) just make your main function have 1 line in it. A line that passes the directory to another function you write, which does all the work. -Blake O'Hare
Update: my above comment was a lame hack, so I slashed the 2-functions thing from the requirements. -Blake O'Hare

Will JES run on a Linux computer?

Yes. Just download the JES source and run it as a java app. -Blake O'Hare


page.write(' "'+file+'" ')
this line is giving me an error saying: 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.
even though i have
pic=makePicture(file)
height = int(getHeight(pic))
how can i fix this???


getHeight(pic) gives you an int. Converting it to an int does nothing. I think what you're trying to do is turn it into a string which would be done with str. If the page.write line keeps giving you trouble, then put a return file right before that and see what your function spits out. If it's something that isn't in quotes, then that's the problem. -Blake O'Hare

How do we get it to count the number of jpgs?
You could define a variable and each time you go through the for loop add one to it.... Albert d'Heurle

what does file.lower() do?
The method .lower() makes a string all lower case. -Albert d'Heurle

When you check the homework will you setMediaPath()
Nope. Check the homework page to see how we will grade. -Albert d'Heurle

how will my TA know if I validated my page for the extra credit?
If we see a doctype, we'll be checking it for validation. -Blake O'Hare

I usually put a note to my TA commented out at the top (the same place where you put collaboration information)
That works too. -Blake O'Hare


My program works on my computer, but then does not show images on another computer (ie does not work). How / why would this occur? I made sure all the images were JPEGs on both computers and tested them multiple times with all different sorts of pics...
HTML standards and interpretation is defined for 100% correct HTML. If you leave off a closing tag or quote somewhere where it doesn't expect, different browsers will handle it differently. Maybe Firefox will render the broken HTML while IE doesn't display anything or vice-versa. Double check the HTML code that was output by your program with notepad. -Blake O'Hare

How do we know what doctype to use?
Use at least the same one you used for Lab 3. -Blake O'Hare

how do we calculate the size of a file for the extra credit in HW4? Is there a function like getSize()?

You know how to find the length of a string. You also know how to open a file and extract its contents. -Blake O'Hare

for the files size are we looking for total number of pixels or are we looking for how many bytes it is?
The homework says to give size in MEGABYTES (that means you're looking for the number of bytes) Amanda Bennett

are we supposed to run the html code through WinSCP and validate it onto the web? or just send the JES code and the pic files to you through WebWork?
The only thing you need to turn in is your .py file. -poof #10

How do you make a table? I have tried doing the row feature from the database part of Chapter 11, but it is not working.
<table>
opens the table tag
<tr>
opens a new row for the table
<td>
this opens a new column, and what you type in here is what will show up in the table
</td>
closes the column
</tr>
closes the row
</table>
closes the table...This should all be review from your table on your webpage...
This
is
an
example
and here is the code for it:
<table border="1"><tr><td>This</td></tr><tr><td>is</td></tr><tr><td>an</td></tr><tr><td>example</td></tr></table> 
Liz Helms

I am trying to count the number of images on the page and display it, but get an error when running the code. Here is the code and error.

 code = code + "<h3> Total .JPG Files: " + value + "</h3></body></html>" 

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.

I know it has something to do with 'value' but not sure what.

try str(value) and see how that works. Amanda Bennett
That worked! Thanks-

How do we use a picture without putting the filename? I don't understand how we write the program to use any picture.

You do know the name of the directory. A function that we covered in class will give you a list of all the files in a directory, so you can use that and loop through the resulting list, knowing that each item of the list is the name of a file in the directory. Remember that you want to ignore those files whose extension indicates that they are not pictures. Colin Potts

The snake thing thinks our Homework should be due the Monday following Spring Break. Is there anyway that might happen?

Do we submit a folder with pictures with our program? Or do you just want the program?
Just the program. Your function should work with any folder of pictures. Liz Helms

How do you make functions run inside a table...when I try to make the pictures show up and all the other colums, it puts 'pic', 'file', 'getHeight(pic)', and 'getWidth(pic)'. What am I doing wrong?
Remember that really you are making one big string, so make sure you are adding things together correctly. Also try to remember the str() function and what it does, that should get rid of your getHeight and getWidth stuff... Liz Helms

How do you put the number of pics at the bottom? I am putting it at the end of my program(after the table) but it automatically puts it above the table.
Its hard to tell why its doing this without seeing your code. I would recommend visiting a TA at office hours Liz Helms


|I can pretend that I'm a TA...perhaps I'll make the homework due later, like when we get back from spring break!|


In real life extensions are granted to those who need it. I think we all REALLY need an extension. It's been a rough week for most of us...

This is college - I suggest we use our time wisely and finish what needs to be done.

Are we supposed to account for spaces in image file names? If so, is there an escape character used in reading a filename with spaces so that JES correctly interprets a filename? For example, when a picture named "camera 001.jpg" is interpreted by JES, it doesn't take into account that there is a space in the filename and tries to display a file called "camera"; does that make any sense?
Yes, it makes sense. When using os.listdir(), JES does read spaces and returns that as a string. Why do you think that the file is just being called "camera" instead of "camera 001.jpg"? If you're trying to use a variable name with spaces, you can't, but since everything you're working with is strings (for the most part), spaces shouldn't be a problem. Amanda Bennett


The jython snake talked to me too. He says the homework deadline should be extended til after spring break.

i've read through all of the other questions and answers on this page, but i still don't quite understand how to form the code to take in any picture, versus specific ones. and i assume that since its not specific pictures, the other columns need to adjust as well according to which pictures you decide to load into it. is this correct?

In class today, we will be going over three examples of generating HTML from within a program. One of them creates thumbnails in a page. Although it doesn't put them in a table, like the homework, you should find this example useful. (It's in the slides, by the way, so you don't even need to wait until this afternoon to look at the example.) If your question about the cells adjusting themselves to the images refers to the size of the cells, don't worry. You'll find that the browser kindly scales the thumbnail image to the size you require. It doesn't matter what the sizes of the original images are. If you are asking instead about how many cells there should be (because there can be any number of image files in the directory), think about how you would generate cells from within a for loop.... Colin Potts
A clarification: In the above reply and in class today, I used the term 'thumbnail' in its Photoshop sense of a small depiction of a larger image. In that sense, any small scaled version of an image qualifies as a thumbnail. The extra credit part of the homework uses the term 'thumbnail' to refer to additional stored versions of the images that are used for the web page you are creating. If the user clicks on such a thumbnail version, then (and only then) the big image is loaded. The reason for needing true thumbnail (small) versions of big images is that you don't want to have to load lots of big images onto a page from a remote website, even though the big images would appear appropriately scaled by the browser: bigger images take longer to download than smaller ones.

to validate our webpage, where should we upload it?
You could upload it to your prism webspace (making sure not to overwrite your main page) but you don't have to upload to validate. validator.w3.org allows you to validate files on your computer. -Blake O'Hare

I read the first question, but to generate this page in Jes, do we have to make a preexisting empty html page to write to, or does opening something "wt" generate a file with those attributes?
Opening in 'wt' creates a file if it does not exist. -Blake O'Hare

Is there anyway to get a library to list all of the functions that it includes???
The function dir takes in a module name and returns all functions in it. Fun fact: if you call dir with no inputs, then it will list all imported locals. -Blake O'Hare

but so how do I call that??? Ive tried typing os.dir() , os.dir , dir(os) in the black space and get a whole lot of "THat doesnt exist" for my efforts...

Does os.listdir(dir) look familiar? Liz Helms

this is still in relation to the last two questions; I'm trying to figure out how to use dir() on the library os to get it to list all the functions in it. any clues>? edit: nevermind, google and my roomate pulled through...

if we open a file with "rb" and find the length of the string, does that tell you how many bytes are in the file?

Yes. And so does 'rt' and 'r'. -Blake O'Hare

my program works but it will only do one picture it wont loop for all the .jpg or .JPG in the directory why is it doing this? also what function should i use to get the number of files in the directory?
Its hard to tell without looking at your code. Liz Helms

Webwork is not adding my file. Is this a problem with the server or is it my computer?

what about the number or pictures? i have a list of files in the directory but what function do i use to count all the jpgs?

There is not a function that will do it for you. Unless you write one yourself. Think about how you'd count anything using a for loop...Amanda Bennett

Hey, webwork still wont let me add my file for submission.....Any clues? At least just say no or not. Any response would help.
That is quite odd. If all else fails, email it to your TA to prove it was done. -Blake O'Hare

this is my code for the table(which i don't realy know if it works...) but i keep getting an error that says there is a syntax problem. i can't find it and i was wondering anyone could spot what's wrong with my code and if i am on the right track

gallery =gallery + ""+file + "" +getHeight(pic)+ "" +getWidth(pic)""
It's because you're saying height="100" and the quotes in that are getting confused with the quotes delimiting the string. Always use single quotes when you're putting HTML in strings so that the actual double quotes within the HTML doesn't conflict. -Blake O'Hare

when i use file = open(filename, "rb"), then use the function len(file), does that give me the number of bytes contained in the file, or the pic in this case? cuz the number it gives me seems waaay too low. so what does len(file) return?

how do you set the file height and width in the table for each different picture?
In your img src tag, put height = "size" example:
<img src="file.jpg" height="100"/>
Liz Helms

my ,getWidth(file), part of my code in the table is returning an error that says, input is not a picture and trying to pass an argument to a function.Am I using getWidth() correctly?
You have to make sure to make your file into a picture in JES, otherwise getWidth and getHeight wont work on a non-picture object. Liz Helms

i can't see the example u posted for me liz, it's just a blank image box:(

now i am getting error that says i am trying to access a part of the object that doesn't exist!
gallery= gallery+ ""+file.jpg+ "100 " + getWidth(file.jpg)+ ""

A portion of my code keeps coming up as an error.
My code is: file.write(body(images)) The error that is coming up says "You are trying to access a part of the object that doesn't exist." what does this mean? I have been using recipe #92 from page 255 in the book for my general format. It matches it perfectly, but this second to the last line doesn't run through JES. please help.



Link to this Page