Re: Unpacking byte strings from a file of unknown size

2008-10-27 Thread Steven Clark
On Mon, Oct 27, 2008 at 4:29 PM, Mark [EMAIL PROTECTED] wrote: Hi; I'm trying to use the struct.unpack to extract an int, int, char struct info from a file. I'm more accustomed to the file.readlines which works well in a 'for' construct (ending loop after reaching EOF). # This does OK at

Re: struct.pack behavior

2008-06-27 Thread Steven Clark
For efficiency reasons many CPUs require particular primitive data types (integers/pointers of various sizes) to be placed in memory at particular boundaries. For example, shorts (H above, usually two bytes and probably always so in the struct module) are often required to be on even

struct.pack behavior

2008-06-25 Thread Steven Clark
Can anyone explain to me why struct.pack('HB',1,2) gives 3 bytes, whereas struct.pack('BH',1,2) gives 4 bytes? -Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: struct.pack behavior

2008-06-25 Thread Steven Clark
On Wed, Jun 25, 2008 at 7:03 PM, John Machin [EMAIL PROTECTED] wrote: On Jun 26, 9:00 am, Steven Clark [EMAIL PROTECTED] wrote: Can anyone explain to me why struct.pack('HB',1,2) gives 3 bytes, whereas struct.pack('BH',1,2) gives 4 bytes? Alignment -- read the manual. -- http

Re: value is in list?

2008-06-12 Thread Steven Clark
Hello , following scenario list_current = [ welcome, search, done, result] list_ldap = [ welcome, hello] result: list_toadd = [ hello] by words said , i want to check if list item from list_ldap exists in list_current if not i want to add it to list_toadd. Thanks! D. list_toadd =

Re: can't assign to literal

2008-06-10 Thread Steven Clark
On Tue, Jun 10, 2008 at 5:30 PM, maehhheeyy [EMAIL PROTECTED] wrote: On Jun 10, 1:21 pm, Matimus [EMAIL PROTECTED] wrote: On Jun 10, 12:53 pm, maehhheeyy [EMAIL PROTECTED] wrote: this is stopping my program from running properly. is there something wrong in my code when that happens? yes

Re: can't assign to literal

2008-06-10 Thread Steven Clark
for 1 in oids, vals head_oids: SyntaxError: can't assign to literal -- 1 is a literal, you can't assign it to something. Are you trying to use it as a variable name? -- http://mail.python.org/mailman/listinfo/python-list

Re: scope of optional arguments

2008-05-19 Thread Steven Clark
http://www.ferg.org/projects/python_gotchas.html#contents_item_6 On Mon, May 19, 2008 at 10:30 AM, cseja [EMAIL PROTECTED] wrote: If I call print walk([1,2,3], []) print walk([5,6,7]) I get [1, 2, 3] [4, 5, 6] but when I call print walk([1,2,3]) print walk([5,6,7]) I get [1, 2,

Re: Data structure recommendation?

2008-04-09 Thread Steven Clark
I believe the best way to implement this would be a binary search (bisect?) on the actual times, which would be O(log N). Though since they are timestamps they should be monotonically increasing, in which case at least you don't have to go to the expense of sorting them. Some kind of

list.sort(): heaviest item?

2008-04-08 Thread Steven Clark
If I have a list of items of mixed type, can I put something into it such that after a list.sort(), is guaranteed to be at the end of the list? Looking at http://www.python.org/doc/2.3.5/ref/comparisons.html Most other types compare unequal unless they are the same object; the choice whether one

Re: list.sort(): heaviest item?

2008-04-08 Thread Steven Clark
You can pass a cmp-function that will always make one object being greater than all others. Diez -- Yeah, I figured it out 2 minutes after I posted, d'oh! class Anvil(object): def __cmp__(self. other): return 1 Sorry for the wasted space. --

Re: Data structure recommendation?

2008-04-08 Thread Steven Clark
bisect is definitely the way to go. You should take care with floating point precision, though. One way to do this is to choose a number of digits of precision that you want, and then internally to your class, multiply the keys by 10**precision and truncate, so that you are working

Data structure recommendation?

2008-04-07 Thread Steven Clark
Hi all- I'm looking for a data structure that is a bit like a dictionary or a hash map. In particular, I want a mapping of floats to objects. However, I want to map a RANGE of floats to an object. This will be used for timestamped storage / lookup, where the float represents the timestamp.

Re: ord function problem from newbie

2008-03-17 Thread Steven Clark
print sum([ord(ch)-96 for ch in small]) On Mon, Mar 17, 2008 at 11:28 PM, [EMAIL PROTECTED] wrote: I'm trying to convert a name into a numerical value that is not consistent with ANSCII values. In my case, I convert all to lowercase, then try to sum the value of the letters entered by the

Re: Python Genetic Algorithm

2008-01-27 Thread Steven Clark
Why not make chromosome itself a class? class BasicChromosome(object): def __init__(self, data): self.data = data def crossover(self): [stuff here] You can subclass this as needed, altering the crossover method as necessary. ...perhaps I didn't understand your question.

Re: Newbie question on Classes

2008-01-10 Thread Steven Clark
On Jan 10, 2008 4:54 PM, Fredrik Lundh [EMAIL PROTECTED] wrote: Adrian Wood wrote: I can call man.state() and then woman.state() or Person.state(man) and Person.state(woman) to print the status of each. This takes time and space however, and becomes unmanageable if we start talking about

Re: Newbie question on Classes

2008-01-10 Thread Steven Clark
l = [] l.append(man) l.append(woman) # Print the state. for item in l: print item.state() Small, off-topic nitpick: please don't use l (lower-case el) as a variable name. From http://www.python.org/dev/peps/pep-0008/: Naming Conventions Names to Avoid Never use the characters `l'

Re: 2D Game Development in Python

2007-12-20 Thread Steven Clark
On Dec 20, 2007 10:30 PM, Terry Reedy [EMAIL PROTECTED] wrote: PatrickMinnesota [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] | I think I need at least this: 2D graphics, sound, input (kbd, mouse, | joystick maybe), some IPC might be nice (Stuff like: Sockets, TCP, | UDP,

Using 'property' in evolving code

2007-12-17 Thread Steven Clark
Hi all- I was reading http://dirtsimple.org/2004/12/python-is-not-java.html, in particular the part about getters and setters are evil: In Java, you have to use getters and setters because using public fields gives you no opportunity to go back and change your mind later to using getters and