View Single Post
Old Apr 20th, 2006, 2:58 PM   #4
Digit
Newbie
 
Join Date: Apr 2006
Posts: 7
Rep Power: 0 Digit is on a distinguished road
Quote:
Originally Posted by DaWei
I would recommend PHP or similar, though you can do it with VB. I don't suppose between here and May is enough time to delve into templates. Usually assignments are given far enough in advance to complete. Most people aren't expected to learn a language and produce an assignment in a couple of weeks. Someone probably needs their ass kicked. I doubt it's the teacher, though anything's possible.
Okay, thanks for the advice.
Yeah, well thats the time they gave me to do it in.
Unlucky I can't argue.
Well, I think whoever thought that that assignment was reasonable should get their ass kicked.
Doing it manually would take me well over a month since I have to do four different students and doing half a unit takes me give or take three hours.


Quote:
Originally Posted by Arevos
PHP does seem a natural choice here, but I notice that you attempted to do it manually, which implies that all you need is to have a program that can generate a set of HTML files given a fixed set of inputs.

Take the following template. Let's call it hello.tmpl:
Hello %(name)s, your score is %(random_number)d
Now the following Python code:
import random

variables = dict(
    name = "Fred",
    random_number = random.randint(80, 100)
)

file = open("hello.tmpl", "r")
text = file.read() % variables
file.close()

file = open("output.txt", "w")
file.write(text)
file.close()
When run, the Python code will create a new file called output.txt that will look something like this:
Hello Fred, your score is 87
Note that the score will be a random number between 80 and 100. Is that the sort of thing you were after, or have I gotten the wrong idea?
You have it head on.
Thats exactly what I need, I'll see if I can't upload the "example page" its how my teacher wants it to look.
It should probably clear up any confusion I might have caused, I don't know if I might have written it so that you're like "what?".

Edit:
Okay, I added an attachment with the example file my teacher gave me.
The only difference is that I had to save it as a txt so I could add it as an attachment.
If you want to see how it should look just rename it to .html
Attached Files
File Type: txt examplework.txt (15.0 KB, 21 views)

Last edited by Digit; Apr 20th, 2006 at 3:18 PM.
Digit is offline   Reply With Quote