Re: Qustion about struct.unpack

2007-05-01 Thread eC
On Apr 30, 9:41 am, Steven D'Aprano <[EMAIL PROTECTED]>
wrote:
> On Mon, 30 Apr 2007 00:45:22 -0700, OhKyu Yoon wrote:
> > Hi!
> > I have a really long binary file that I want to read.
> > The way I am doing it now is:
>
> > for i in xrange(N):  # N is about 10,000,000
> > time = struct.unpack('=', infile.read(8))
> > # do something
> > tdc = struct.unpack('=LiLiLiLi',self.lmf.read(32))
>
> I assume that is supposed to be infile.read()
>
> > # do something
>
> > Each loop takes about 0.2 ms in my computer, which means the whole for loop
> > takes 2000 seconds.
>
> You're reading 400 million bytes, or 400MB, in about half an hour. Whether
> that's fast or slow depends on what the "do something" lines are doing.
>
> > I would like it to run faster.
> > Do you have any suggestions?
>
> Disk I/O is slow, so don't read from files in tiny little chunks. Read a
> bunch of records into memory, then process them.
>
> # UNTESTED!
> rsize = 8 + 32  # record size
> for i in xrange(N//1000):
> buffer = infile.read(rsize*1000) # read 1000 records at once
> for j in xrange(1000): # process each record
> offset = j*rsize
> time = struct.unpack('=', buffer[offset:offset+8])
> # do something
> tdc = struct.unpack('=LiLiLiLi', buffer[offset+8:offset+rsize])
> # do something
>
> (Now I'm just waiting for somebody to tell me that file.read() already
> buffers reads...)
>
> --
> Steven D'Aprano

I think the file.read() already buffers reads... :)

-- 
http://mail.python.org/mailman/listinfo/python-list


Is this a wxPython 2.8.0 bug with GetItemText method of wxTreeCtrl?

2007-04-01 Thread eC
I use a tree control in my application and was hoping to use use the
GetItemText method to read the new label of the tree item after the
user has edited it. So in the EVT_TREE_END_LABEL_EDIT event handler,
i call this method but the old label (previous value before the edti)
is returned.
Is there something else i have to do or is this a bug?

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How can i compare a string which is non null and empty

2007-04-01 Thread eC
On Apr 2, 12:22 am, "[EMAIL PROTECTED]" <[EMAIL PROTECTED]>
wrote:
> Hi,
>
> how can i compare a string which is non null and empty?
>
> i look thru the string methods here, but cant find one which does it?
>
> http://docs.python.org/lib/string-methods.html#string-methods
>
> In java,I do this:
> if (str != null) && (!str.equals("")) 
>
> how can i do that in python?
The closest to null in python is None.
Do you initialise the string to have a value of None? eg myStr = None

if so, you can test with
if myStr == None:
   dosomething...

But you might find that you do not need to use None - just initialise
the string as empty eg myStr = ''
and then test for
if myStr != '':
or even simpler

if myStr:
  dosomething

btw. dont use 'str' - its a built in function of python

-- 
http://mail.python.org/mailman/listinfo/python-list