in discussion School-Specific Chat / Geelong High Y12 Computing 2019 » Python and Files
From now on. Call me Moan.
From now on. Call me Moan.
Noah Rapetti, Monk way of the Drunken Fist up and ready for combat
You all have to make web pages. Hooray!
If you would like to use a funky new font you've found somewhere, you have to be careful. There's no guarantee that the other people have that font. There are a couple of solutions.
(1) Include the font with the HTML doc. A web page can use any font you like, whether it is installed on a computer or not, as long as it's accessible through the local file structure. Do this:
For example, suppose I have a font file Cthulhu.ttf in the same folder as a web page with the following code:
<html>
<head>
<style type="text/css">
@font-face { font-family: myCrazyFont; src: url(Cthulhu.ttf); }
</style>
</head>
<body>
<h1 style="font-family: myCrazyFont;">Welcome To The Nightmare</h1>
</body>
</html>
(2) Use a web font. There are lots of font collections available on the web, but many of them require you to download a font file. Some, like Google Fonts, let your web page access the fonts straight off their servers. For example, Google Fonts has a font called "Bree Serif". By adding either:
<link href="https://fonts.googleapis.com/css?family=Bree+Serif" rel="stylesheet">
<style>
@import url('https://fonts.googleapis.com/css?family=Bree+Serif');
</style>
Use it through the style tag:
<p style="font-family: 'Bree Serif';">Hi there</p>
This is the place for Geelong High's Unit 3&4 Systems Development class.
The following is a side-note to a problem flagged by Noah. If you install a funky new font, and want to use it in something that gets shared with other people, there's no guarantee that the other people have that font. There are a couple of solutions.
(1) Convert your doc to a PDF. PDFs can include font information in their files, so the doc appears exactly as you intended.
(2) Make a HTML doc (a web page). A web page can use any font you like, whether it is installed on a computer or not. Here's how:
For example, suppose I have a font file Cthulhu.ttf in the same folder as a web page with the following code:
<html>
<head>
<style type="text/css">
@font-face { font-family: myCrazyFont; src: url(Cthulhu.ttf); }
</style>
</head>
<body>
<h1 style="font-family: myCrazyFont;">Welcome To The Nightmare</h1>
</body>
</html>
Somewhere or other there's a spot where you can become a member of Wikidot (for free), and then become a member of the site. Do it! It cuts down on ads you see.
.
Role call?
Let's look at the HTML option.
By careful use of HTML and formatting you can:
Examples of where this could be used:
… and many more.
One of the things you can do with Python is write files. Python can write text files and binary files. If you knew what to write, you could write any kind of file (a .gif, .jpg, .doc, .pdf, or whatever).
However, most of those are too difficult for most people. However however, there's one easy option, and a couple of middle-difficulty ones.
HTML is a text-only format. All the formatting that appears in a web page is text "instructions". Because it is text-only, it can be created pretty easily with Python text files. Try this:
doc = open("test.htm","w")
doc.write('<!doctype html>')
doc.write('<html>')
doc.write('<head>')
doc.write('</head>')
doc.write('<body style="background: #FEA;">')
doc.write('<h1 style="color:#F00;">Amazing!</h1>')
doc.write('<p>Does this actually work?!?</p>')
doc.write('<p style="color: #080;"><i>Sure does, buddy!</i></p>')
doc.write('</body>')
doc.write('</html>')
doc.close()
Notice the file is a .htm file. Double-click the created file - it should work in the browser of your choice.
RTF is a similar text-only format, created by Microsoft as a "back up" for Word Docs. It used to be really useful in the days of Macs and PCs, because each had their own character set, and sometimes docs written on one wouldn't come out 100% correct on the other. Like HTML, it uses commands written in to the text to show formatting and stuff.
Open Document Format uses XML-type mark-up, but has the disadvantage of using zip compression. This means the file starts life as a "text-only" file, but when complete is converted into a binary file.
See http://advtue.wikidot.com/birthday-2012 for details.
Also, send me a txt on 043 778 2744 so I have your mobile number.
Speaking of which…
What are you doing Sat 14 Apr? Want to come down for a surf safari party?
Hey Wes!
Just wanted to say a big thanks for your help! I did the test on saturday just gone and it went pretty well! So i am hopeful that this year will be the year :D Thanks for helping me grasp topics i have been struggling with! Next time i am down we will have to catch up so i can say thanks in person :D
Q 8.75 A container filled with 2.46kg H2O changes its temperature from 25.24°C to 27.31°C. How much heat (in kJ) did the H2O absorb?
C(H2O) = 4.18 J/g/°C
m(H2O) = 2.46 kg = 2460 g
ΔT = 27.31°C - 25.24°C = 2.07°C
Q = C × ΔT × m = 4.18 J/g/°C × 2.07°C × 2460 g = 21285 J = 21.3 kJ
Q 8.70 If 250J of heat is added to 30.0g Cu initially at 22.0°C, what is its final temperature?
C(Cu) = 0.385 J/g/°C
m(Cu) = 30.0 g
ΔT = Q ÷ C ÷ m = 250J ÷ 0.385J/g/°C ÷ 30.0g = 21.6°C
Final temperature = 22.0°C + 21.6°C = 43.6°C ✓
Q 8.67 How much heat (in kilojoules) must be removed from 175g H2O to lower its temperature from 25°C to 15°C?
ΔT = 25°C - 15°C = 10°C
C(H2O) = 4.18 J/g/°C
m(H2O) = 175 g
Q = C × ΔT × m = 4.18J/g/°C × 10°C × 175g = 7320 J = 7.32 kJ ✓
Q 8.65 A system absorbs 300 J heat and has 700 J of work done on it. What is ΔU? Is this overall endothermic or exothermic?
ΔU = +300 J + +700J = +1000 J ✓
System is endothermic as it has absorbed heat. ✓
52 days lag! Piss poor!
Q 3.44 Calculate the mass in g of
(a) 1.25 mol of Ca3(PO4)2
M(Ca) = 40.08 g/mol
M(P) = 30.97 g/mol
M(O) = 16.00 g/mol
∴ M(Ca3(PO4)2) = 3 × 40.08 + 2 × 30.97 + 8 × 16.00 = 310.18 g/mol
Q 3.43 Calculate the molar mass of:
(a) NaHCO3
M(Na) = 22.99 g/mol
M(H) = 1.01 g/mol
M(C) = 12.01 g/mol
M(O) = 16.00 g/mol
∴ M(NaHCO3) = 22.99 + 1.01 + 12.01 + 3 × 16.00 = 84.01 g/mol