code logs -> 2007 -> Wed, 21 Nov 2007< code.20071120.log - code.20071122.log >
--- Log opened Wed Nov 21 00:00:24 2007
00:17 AnnoDomini is now known as AD[SLEEP]
00:41 You're now known as TheWatcher[T-2]
00:44 You're now known as TheWatcher[zZzZ]
00:49 * Reiver pokes Vornicus
00:49
<@Reiver>
I has a stupid little program to write, but I am running into brick walls of syntax in Python.
00:49
<@Reiver>
And I mean /basic/ syntax.
00:49 * Reiver feels frankly quite silly.
00:49 * McMartin is also an expert
00:50 * Reiver feels kinda embarrased asking such stupid questions of you, McM~
00:50
<@McMartin>
Ask anyway =P
00:50
<@McMartin>
Otherwise you stay ignorant,
00:51
<@Reiver>
Point.
00:51
<@McMartin>
Besides, Python has some surprising corners, so if you happen to think one of those is basic, then you'll be bitten fast
00:51
<@McMartin>
Or if your editor is a twit about tabs.
00:52
<@Reiver>
I'm trying to write a small, very small program that simply loads a file, finds a specific line in it, and changes a value in it for me by a certain amount.
00:52
<@Reiver>
Starting Position Offset Z := 0
00:52
<@McMartin>
Problem 1: ":=" is Pascal.
00:52
<@Reiver>
This being a data file, that line shows up about three hundred times.
00:53
<@McMartin>
Oh, that's a file line
00:53
<@Reiver>
I want to be able to batch-change them. >.>
00:53
<@McMartin>
n/m, continue
00:53
<@McMartin>
Hmm. Well, so, your first problem is that you can't really update a file in place. You'll have to read the whole thing in and produce a new file with updated values.
00:53
<@McMartin>
Is whitespace significant?
00:55
<@McMartin>
(as in, would "Starting Position Offset Z := 0" mean the same thing)
00:55
<@Reiver>
Whitespace is significant.
00:55
<@McMartin>
OK.
00:55
<@McMartin>
Your problems then are:
00:55
<@McMartin>
(1) Getting the data in
00:55
<@McMartin>
(2) Making sense of it
00:55
<@Reiver>
...And piping out to a new file line is probably for the best anyway.
00:55
<@McMartin>
(3) Making the changes
00:55
<@McMartin>
(4) Outputting the results
00:55
<@Reiver>
Er. New file altogether~
00:56
<@McMartin>
For (1), look into file.readlines(). (2) is probably best handled with split(), but might be doable just with substrings.
00:57
<@McMartin>
(3) needs to respect the constraints, and may be tricky
00:57
<@McMartin>
(4) is probably best handled via and laternate mode of print
00:57
<@Reiver>
Cheers!
00:57 * Reiver dives into the help files for those functions.
00:58
<@McMartin>
Look up "print>>" in the tutorials.
00:58 * Reiver nod.
00:58
<@McMartin>
But actually, start just with "print" so you can eyeball the results.
00:58
<@McMartin>
By substrings I mean the a[0:14] syntax.
00:58
<@Reiver>
Hm
00:58 * Reiver glances at the file.
00:58
<@McMartin>
a.split (":=") would make it ignore whitespace, but then when you were outputting you wouldn't have proper spacing without using format strings.
00:59
<@McMartin>
Which is "string" % (tuple, of, values).
00:59
<@McMartin>
And will do things like automatically justify strings/numbers/etc and is really nice.
00:59
<@McMartin>
Ando nl
00:59
<@McMartin>
And only "obvious and simple" if you've spent a decade programming in C and its derivates already =P
01:00
<@Reiver>
Does it help that I just doublechecked, and the string "Starting Position Offset Z := " + int
01:01
<@Reiver>
* Is reproduced precisely in the entire file?
01:01
<@McMartin>
So, that's 56 characters long
01:01 * Vornicus dislikes print.
01:02
<@McMartin>
So, if you want to rely on that, you could look at x[:56] on each line and see if it matches.
01:02
<@Reiver>
And then you have an integer, which spends 95% of its time at 0 and 5% of its time anywhere between 8 and ~297e
01:02 Thaqui [~Thaqui@Nightstar-5273.dialup.xtra.co.nz] has joined #code
01:02 mode/#code [+o Thaqui] by ChanServ
01:03 Derakon[AFK] is now known as Derakon
01:03
<@Reiver>
I intend to be dropping the whole lot of them by -10, -20, or whatever. (It will require eyeballing of the final result to get the correct figure, y'see. It's shifting things into position in a game engine.)
01:04
<@McMartin>
string-to-int is int("14"), say
01:04
<@McMartin>
And int-to-string is str(14)
01:05
<@Reiver>
So once I've found the a[:56] = "Starting Position Offset Z := ", I then want to steal the remaining text on the line and convert it to an int how?
01:06
<@McMartin>
a[56:] is the rest
01:06
<@McMartin>
so int(a[56:]) should do it.
01:06
<@Reiver>
Ah!
01:06
<@McMartin>
You may have to call strip() on it to remove whitespace.
01:07
<@Reiver>
That, uh
01:07
<@Reiver>
Makes far more sense than I had expected~
01:07
<@Reiver>
(Also, does the length of the comparison affect speed significantly? I could shorten the string to just the text and get the required line anyway; it's just the output that requires the whitespace.)
01:07
<@McMartin>
x[i:j] is characters i through j in string x, including i but not j
01:07
<@McMartin>
This makes sense because that way you can have [:i] and [i:] partition the string after i characters, as just demonstrated~
01:07
<@McMartin>
And x[i:i] is the empty string.
01:08 * Reiver nods.
01:08
<@Derakon>
Reiver: never prematurely optimize code.
01:08
<@Derakon>
If, after you have it doing the right thing, you find that it's not fast enough, then you can try to make it faster.
01:08
<@McMartin>
And, uh, if comparing strings of length 56 is too dear, stop running the script on your alarm clock.
01:08 * Derakon snerks.
01:08 * Reiver grins. Right, then~
01:09
<@McMartin>
Bear in mind that reading anything from disk will, regardless of read time, take several million instructions worth of time.
01:09
<@Reiver>
Ah, yes.
01:09
<@Reiver>
And this file is 1.91 MB.
01:09
<@McMartin>
You are, as they say, "I/O bound".
01:09
<@Derakon>
That's nothing, comparatively speaking.
01:10
<@Derakon>
I mean, I regularly scan through many 400+MB files at work. That takes several minutes.
01:10
<@McMartin>
He's doing less than a regexp match on each line. He's still I/O bound.
01:10
<@Reiver>
Indeed, though I've been dealing with a lot of programs that can take the better part of a minute to output a formulatically generated 205 KB file, so I've gotten cautious about speed~
01:11 * Vornicus regularly scans /usr/share/dict/words using egrep, and gets nigh instant results.
01:11
<@McMartin>
If you're scanning it regularly, it's probably in the memory cache, Vorn.
01:11
< Vornicus>
By "regularly" I mean "once every few days"
01:26
<@Reiver>
Cheers, McM.
01:26
<@Reiver>
It was fairly elementary stuff I know, but I haven't touched Python in over a year and a half... >.>
01:27
<@McMartin>
I don't consider format strings elementary if you weren't a C programmer first.
01:27
<@McMartin>
Slices are your friends, though they generally aren't what you use since usually you want whitespace to not matter
01:28
<@McMartin>
Speaking of format strings, I need to learn OCaml's versions thereof.
01:32 * Vornicus fiddles, wishes he could read the data that's in the art files.
01:45
<@Derakon>
Hrm. Dragon Spirit is also very hard to play at 2x.
01:46 * Vornicus <3 format strings.
01:55 * Vornicus fiddles. Wishes he had the resources to produce nearly as much art as he needs, in a style similar to the original. Does not have much skill.
01:57
<@Derakon>
What're you working with here?
01:57
< Vornicus>
King's Bounty.
01:58
<@Derakon>
And what're you trying to do?
01:58
< Vornicus>
Remake it, so Dad can play it without having to fuck with such silliness as DOSBox.
01:58
<@Derakon>
Ah.
01:59 Thaqui [~Thaqui@Nightstar-5273.dialup.xtra.co.nz] has quit [Quit: This computer has gone to sleep]
02:27 gnolam [lenin@Nightstar-10613.8.5.253.static.se.wasadata.net] has quit [Quit: Z?]
02:53
<@Derakon>
Okay, you know what's even worse when played at 2x? Recca.
03:15
< Vornicus>
okay. 13 each water, forest, mountain, desert; 7 castle; hill grove plains dungeon town sign treasure grass; 4 armies; 3 battlefield obstacles; 8 artifact overworld icons; 8 artifact tiles; 4 continent navigation charts; 8 static menu icons. 102 static arts, not including splashes. They're all the same shape.
03:20
< Vornicus>
hill grove plains dungeon town castle intro win lose. 9 splashes.
03:22
< Vornicus>
25 creatures, 17 villains, 2 avatars, 4 animated menu icons. 48 animations.
03:26
< Vornicus>
oop, 104 - also need 2 bridges.
03:45 Forj [~Forj@Nightstar-10789.ue.woosh.co.nz] has joined #code
03:45 mode/#code [+o Forj] by ChanServ
04:43 GeekSoldier|bed is now known as GeekSoldier|work
05:14 Thaqui [~Thaqui@Nightstar-5273.dialup.xtra.co.nz] has joined #code
05:14 mode/#code [+o Thaqui] by ChanServ
06:56 Derakon is now known as Derakon[AFK]
07:39 AD[SLEEP] is now known as AnnoDomini
08:09 AnnoDomini [AnnoDomini@Nightstar-28949.neoplus.adsl.tpnet.pl] has quit [Quit: We sense... something... something ancient... a sickly smell... a chilling wind. My ancestors scream from within their chambers in my mind but I cannot understand their words. This feeling... a memory? It sickens us, and for the first time in our lives for the first time in generations... We fear.]
08:13 Vornicus is now known as Vornicus-Latens
08:15 AnnoDomini [AnnoDomini@Nightstar-28949.neoplus.adsl.tpnet.pl] has joined #Code
08:15 mode/#code [+o AnnoDomini] by ChanServ
08:52 Thaqui [~Thaqui@Nightstar-5273.dialup.xtra.co.nz] has quit [Quit: This computer has gone to sleep]
09:05 You're now known as TheWatcher
09:27 Forj [~Forj@Nightstar-10789.ue.woosh.co.nz] has quit [Connection reset by peer]
10:59 GeekSoldier|work [~Rob@Nightstar-2940.pools.arcor-ip.net] has quit [Ping Timeout]
11:03 GeekSoldier|work [~Rob@Nightstar-2940.pools.arcor-ip.net] has joined #code
12:03 Pi [~sysop@Nightstar-24414.hsd1.wa.comcast.net] has quit [Ping Timeout]
12:13 Reiver [~reaverta@Admin.Nightstar.Net] has quit [Quit: I ATENT'T DEAD]
12:16 ReivZzz [~reaverta@Admin.Nightstar.Net] has joined #Code
13:08 gnolam [lenin@Nightstar-10613.8.5.253.static.se.wasadata.net] has joined #Code
13:08 mode/#code [+o gnolam] by ChanServ
14:01 Pi [~sysop@Nightstar-24414.hsd1.wa.comcast.net] has joined #code
14:29 GeekSoldier|work [~Rob@Nightstar-2940.pools.arcor-ip.net] has quit [Connection reset by peer]
14:33 GeekSoldier|work [~Rob@Nightstar-3993.pools.arcor-ip.net] has joined #code
14:40 GeekSoldier|work is now known as GeekSoldier
16:42 Derakon[AFK] [~Derakon@Nightstar-8000.hsd1.wa.comcast.net] has quit [Operation timed out]
17:10 You're now known as TheWatcher[afk]
17:20 GeekSoldier is now known as GeekSoldier|drinkin
18:30 Vornicus-Latens is now known as Vornicus
18:34 You're now known as TheWatcher
19:33 * AnnoDomini needs to make a JavaBean to pass programming this semester.
19:34
<@AnnoDomini>
http://commons.wikimedia.org/wiki/Image:Digital_clock_changing_numbers.jpg <- A clock which looks like this.
19:34
< MyCatVerbs>
Mmmm, baked beans.
19:34 * AnnoDomini is sadly clueless.
19:36
<@AnnoDomini>
So... nobody knows where one could download a clockBean?
19:37
<@AnnoDomini>
(If not, I will have to waste a weekend of my life on this crap. Maybe more.)
19:37 * jerith recommends the Brilliant Paula Bean.
19:37
< MyCatVerbs>
Oh deities, no.
19:37
<@AnnoDomini>
Nono, it was 'Brillant'.
19:38
< MyCatVerbs>
Aieeee.
19:49 ToxicFrog [~ToxicFrog@Admin.Nightstar.Net] has quit [Client exited]
19:54
< Vornicus>
Anno: probably your best bet would be to create a 7seg "font" and use that.
19:54
<@AnnoDomini>
... GENIUS!
19:54 * AnnoDomini hugs Vornicus.
20:06
<@AnnoDomini>
Hm. Is there a way to use an actual premade font here?
20:11
< Vornicus>
Probably. You'll have to package it into your bean though, and that I don't know how to do
20:17
<@AnnoDomini>
Hrm. That's what I want to do, as I'm loathe to risk adding it as a system/JDK font via sneakage.
20:42 * AnnoDomini ponders being sneaky, and using several labels with - and | characters for the segments. He figures that would actually be less a chore than using the graphics mode.
20:50 Thaqui [~Thaqui@Nightstar-5273.dialup.xtra.co.nz] has joined #code
20:50 mode/#code [+o Thaqui] by ChanServ
21:01 Thaqui [~Thaqui@Nightstar-5273.dialup.xtra.co.nz] has quit [Ping Timeout]
21:08 AnnoDomini [AnnoDomini@Nightstar-28949.neoplus.adsl.tpnet.pl] has quit [Ping Timeout]
21:08 Thaqui [~Thaqui@Nightstar-12324.jetstream.xtra.co.nz] has joined #code
21:08 mode/#code [+o Thaqui] by ChanServ
21:13 AnnoDomini [AnnoDomini@Nightstar-29238.neoplus.adsl.tpnet.pl] has joined #Code
21:13 mode/#code [+o AnnoDomini] by ChanServ
22:19 ToxicFrog [~ToxicFrog@Admin.Nightstar.Net] has joined #code
22:19 mode/#code [+o ToxicFrog] by ChanServ
23:06 Chalcedon [~Chalcedon@Nightstar-10789.ue.woosh.co.nz] has joined #code
23:06 mode/#code [+o Chalcedon] by ChanServ
23:06 * gnolam ponders variadic functions.
23:09
<@McMartin>
Almost always a premature optimization, at least for any language with sensible collection types.
23:10 * AnnoDomini checks once again if anyone knows how to include a font in a JavaBean?
23:11
<@McMartin>
I've never really messed with Beans beyond the method naming conventions, sorry. =/
23:12
<@AnnoDomini>
Uh... then any way to include one in a .jar?
23:13
<@McMartin>
Oh, sure, that's easy. .jar files are just .zip files that are guaranteed to have specific files in them.
23:14
<@McMartin>
How to make data be read out of the same jar that a classfile was read from is almost certainly possible, because everyone does it, but I'm not sure offhand if there's an easy way.
23:14
<@McMartin>
The hard way is to find yourself in the classpath and open yourself up with the java.util.JarFile class.
23:16 * AnnoDomini hrms. It looks to be simpler to just do the hacky coloured "-" and "|" for the segments.
23:16
<@ToxicFrog>
There's some special filename you can use, like resource:///foo
23:16
<@ToxicFrog>
That will open files inside the jar rather than in the filesystem.
23:16
<@ToxicFrog>
I don't recall the details, though.
23:17 * gnolam decides against variadic functions.
23:18
<@gnolam>
I'm stressing the poor AVR enough already.
23:19 * AnnoDomini had an opportunity to mess with VGA today.
23:19
<@McMartin>
int 10h!
23:19
<@McMartin>
A000:0000!
23:19
<@AnnoDomini>
Using a FLEX10K board.
23:21
<@AnnoDomini>
It's more fun than doing problems from the damned archaic, bug-ridden PDF which the rest of the class is using. The teacher said I don't have to do those, and will be doing VGA and keyboard-handling stuffs. I don't mind.
23:21
<@McMartin>
Heh.
23:21 * AnnoDomini yays for being good at something.
23:22
<@AnnoDomini>
I got the monitor to display something like a nordic national flag. Only I kinda exceeded the resolution.
23:22
<@AnnoDomini>
10 bits on horizontal and vertical, but only 640x480.
23:22 * McMartin nods
23:23
<@McMartin>
The A000:0000 thing was from the days when VGA usually meant 8-bit 320x200.
23:23 * AnnoDomini thinks he understands what he needs to do to create the Snake-like thing to pass the class.
23:24
<@AnnoDomini>
Storing n previous states in a sort of array register thingy. Now I only need to work out how to do keyboard inputs.
23:24
<@McMartin>
Do you have hardware interrupts?
23:25
<@AnnoDomini>
I'm not sure. Not very good at Microprocessor Technology.
23:25 Thaqui [~Thaqui@Nightstar-12324.jetstream.xtra.co.nz] has quit [Quit: This computer has gone to sleep]
23:25 * AnnoDomini is not sure what they are, even.
23:25
<@McMartin>
the way Real Computers do it, the keyboard sends a stream of events to the controller, which accepts them as interrupts, interprets the values, and puts them in a buffer for the main system to use.
23:26
<@McMartin>
A hardware interrupt means that at any point the hardware can command the CPU to start running from a different PC.
23:26
<@AnnoDomini>
I see.
23:26
<@AnnoDomini>
But I don't know. We haven't touched that thing yet.
23:27
<@McMartin>
Ah. In that case, "It Depends."
23:27
<@McMartin>
(tm)
23:28
<@McMartin>
Digital joysticks usually end up essentially being mapped to a magic memory location that is a bitmap of which direction/buttons are being pushed
23:28
<@AnnoDomini>
I guess input will be some kind of register. On keypress, it changes value to the key's code, and stays that way until something else is pressed. I don't know.
23:28 * AnnoDomini is overdue for sleepage now, though.
23:28
<@McMartin>
If that's all there is, you're sitting pretty
23:29
<@McMartin>
Writing a full featured keyboard controller that properly handles chording, etc, would be a royal pain.
23:29 Thaqui [~Thaqui@Nightstar-12324.jetstream.xtra.co.nz] has joined #code
23:29 mode/#code [+o Thaqui] by ChanServ
23:29
<@AnnoDomini>
IIRC, we're being given a rudimentary keyboard handling VHDL component.
23:29 * AnnoDomini sleeps now.
23:30
<@McMartin>
Sleep well
23:30
<@McMartin>
And yeah, in that case my only wisdom is "find its interface when you get it."
23:50
<@gnolam>
Hmm. This comms protocol specification references messages that don't actually exist.
23:50
<@gnolam>
Why on Earth haven't we noticed until now?
23:50
<@gnolam>
Hmm... maybe it was lost in a revision?
23:50 * gnolam checks SVN.
23:52
<@gnolam>
... nope.
23:52
<@gnolam>
Been like that all the time. Huh.
--- Log closed Thu Nov 22 00:00:30 2007
code logs -> 2007 -> Wed, 21 Nov 2007< code.20071120.log - code.20071122.log >