Re: Ensure a variable is divisible by 4
Nick Craig-Wood wrote: [EMAIL PROTECTED] [EMAIL PROTECTED] wrote: I am sure this is a basic math issue, but is there a better way to ensure an int variable is divisible by 4 than by doing the following; x = 111 x = (x /4) * 4 You should use // for future compatibility which is guaranteed to be an integer division whereas / isn't (see from __future__ import division) Eg (x // 4) * 4 For the particular case of 4 being 2**2, you might consider x ~0x3 which is a common idiom. Thanks for the tip about integer division and I will experiment with your other suggestion. -- http://mail.python.org/mailman/listinfo/python-list
Re: Using win32gui.SendMessage and SysListView32 control
Thanks for your help. I will check them out. -- http://mail.python.org/mailman/listinfo/python-list
Ensure a variable is divisible by 4
I am sure this is a basic math issue, but is there a better way to ensure an int variable is divisible by 4 than by doing the following; x = 111 x = (x /4) * 4 Just seems a bit clunky to me. -- http://mail.python.org/mailman/listinfo/python-list
Using win32gui.SendMessage and SysListView32 control
Hope someone can steer me in the right direction. I am trying to use python to collect the values from a Win32 application's control. I can successfull query an retreive the values ListBox, Edit and Buttons, however, the application uses a control called a 'SysListView32' Control. MSDN says that this descends from CListView control and the msdn website reference for this control is; http://msdn2.microsoft.com/en-gb/library/ms670560.aspx (scroll to the message constants) This page seems to imply that the control can be queried with messages, however, my problem seems to be that pywin32.win32con does not define a constant for the LVM series of messages. Any other suggestions ?? I am looking for something similar to code below which does a fine job of collecting all of the text values from a ListBox control; count = win32gui.SendMessage(hndl,win32con.LB_GETCOUNT) vals = [] for i in range(count): strlen = win32gui.SendMessage(hndl,win32con.LB_GETTEXTLEN) text = ' '*(strlen+1) #Buffer for returned text -50 characters lentext = win32gui.SendMessage(hndl,win32con.LB_GETTEXT,i,text) txt = text[0:lentext] print Hndl: %8s Class: %-10s TxtLen:%3s TxtVal: %s% (hndl,clname,lentext,txt) vals.append(txt.strip()) Thanks in advance. -- http://mail.python.org/mailman/listinfo/python-list
Reading text labels from a Win32 window
Does anyone know of a way to read text labels from a Win32 application. I am familiar with using pywin32 and the SendMessage function to capture text from Buttons,text boxex, comboboxes, etc, however, the text I am would like to capture doesn't appear to be in a control. -- http://mail.python.org/mailman/listinfo/python-list
Re: struggling with memory release using ctypes wrapper
Oops, found the problem in my code. Sorry for wasting peoples time if you're viewing. -- http://mail.python.org/mailman/listinfo/python-list
struggling with memory release using ctypes wrapper
I was wondering if a ctypes expert could point me in the right direction. I am using the wrapper for the freeimage library to create multipage TIFF files from a group of png images. The images load and save fine, the problem seems to be that the memory used during the bitmap creation isn't being released properly until the python program ends and python exits. The multipage tiff's are created in a loop (ie, creating 3 tiffs from a group of 14 png files). As the loop progresses, the files are built, but the amount of memory that is used and reported by Windows XP taskmanager is not released until python program exits at which time the amount of memory reported is exactly the same as the start of the processing. I am using WinXP SP2, Python 2.4.4, ctypes 1.0.1 and the latest freeimage libarary and wrapper. My questions is this, I have scoured the freeimage site and am confident that I am making the correct calls to the library and in the correct sequence to release the resources allocated by the freeimage dll. After each call to unload the resources, I have checked the return values, and every thing *seems* ok in this regard. I have even used the gc module in DEBUG mode and nothing is reported as uncollectible. My questions: Is there some other method to evaluate a running python program to see what memory is consumed and objects which have this memory allocated?? -- http://mail.python.org/mailman/listinfo/python-list
FreeImagePy creating thumbnails from TIFF
I a trying to create a series of thumbnail images from a multpage TIFF file. The sample code is below. When it executes, we get the following error; FreeImagePy.constants.FreeImagePy_ColorWrong: 'Wrong color 1 in function: FreeImage_MakeThumbnail. I can use: (8, 24, 32)' Any suggestions? fname = 01-PJ2306.tif img = FIPY.Image() img.load(fname) #NOTE: the follow method results #getFormat: ((18, 0), ('TIFF', 'MINISWHITE'), (200, 200)) #getColorUsed: 2 #getNumPages: 8 for pg in range(img.getNumPages()): print 'page;',pg bmp = FIPY.Image() bmp.new((300,300),fileType=FIF_TIFF) bmp.setBitmap(img) bmp.thumbnail(300,convert=True) bmp.save(first_thumb_+str(pg), FIF_PNG) img.setCurrentPage(pg+1) del bmp Using the above img we were able to successfully create the seperate pages as PNG files in a working directory, however, our goal is to use to display a series of thumbnails in a wxpython application. The app will stored references back to the orginal document with the correspondng page number. Essentially we want to avoid having to cleanup a working directory of the PNG pages. ... but if someone has suggestions on this, we are interested too ! Thanks in avance. -- http://mail.python.org/mailman/listinfo/python-list
Re: ADO with Python
Ralf wrote: Is their anybody with xperience in using the both and can provide me with some xamples. Thx a lot Ralf I found the tutorial on this site helpful. http://www.mayukhbose.com/python/ado/index.php -- http://mail.python.org/mailman/listinfo/python-list
Event notification system - where to start ?
We have been asked to develop and application for a client that is a 'notification system. We would like to use python, but are struggling to find the right starting point. Any suggestions, tips or sample code would be appreciated. Application outline; Machine A is running a listener application that is connected to a another device via the serial post and waits for events. We have not problem working with the serial port, or the waiting for the event to happen. When A received a specific event, it needs to send a message to machine B that and event has occurred and that type of event. Machine B will take the event notification, processes some additional information (ie. database lookups) and then notify a series of clients that have registered with machine B to receive events. I think this is sometimes called published/subscriber ??? We have looked at xmlrpc, but at there would be no outside clients, it seems to have a little more overhead than we need. We also looked at the asyncore and asynchat, but are having difficulty gettng starting with these. If someone has a working example of a chat server using these modules they could share it would be very helpful. So ... any suggestions ? -- http://mail.python.org/mailman/listinfo/python-list
Re: groupby is brilliant!
Frank; I would just like to thank-you for this timely post. I am working on a reporting project that needed groupby functionality and I was going to sit down this morning to rework some very ugly code into some not quite so ugly code. Your post got me pointed to in the right direction and the end results will be much more flexible and ALOT more maintainable. Thanks. -- http://mail.python.org/mailman/listinfo/python-list
Re: Inserting Records into SQL Server - is there a faster interface than ADO
The utility is designed to run in the background and maintain/update a parallel copy of a production system database. We are using the stored procedure to do a If Exist, update, else Insert processing for each record. The originating database is a series of keyed ISAM files. So we need to read each record, perform some simple data conversions and then update the SQL database. We are using Python to read the originating database and perform the record conversion and then posting the results back to SQL Server. We designed our utility to run a night so that the SQL server is up to date the next day and ready for reporting. Thanks for your tips on BCP. I will investigate further as it looks like it might be useful for the initial loading of the data and perhaps some changes to the our utility program to minimize the amount of data that needs to be read/processed. Geoff. -- http://mail.python.org/mailman/listinfo/python-list
Inserting Records into SQL Server - is there a faster interface than ADO
I have a program that reads records from a binary file and loads them into an MS-SQL Server database. It is using a stored proc, passing the parameters. I am using pywin32 to create a connection object. Once the connection is open I simple pass the SQL formatted commands using cnx.Execute(sqlstring). My test examples; 20,000 records using the ADO connection: 0:04:45:45 If I setup the program to not send the record to the database - so all other variables and processes are constant, it simply just skips the cnx.Execute(sqlstring) step, then it takes only 0:00:25:78 to process thru the same number of trx. Obviously the times in my test are that , but I have a client that woud like to use this and has several million transactions to content with. So my questions is Is there a faster method I can use to connect to the SQL server ? Or does anyone have any optimization tips the can offer ? -- http://mail.python.org/mailman/listinfo/python-list
Re: Converting from Microsoft Binary Format floats to Python Float
Well, thank-you again. It's a bit embarassing, but you are correct ... It was a typo on in the sample data. A bit frustrated with myself as I checked, and double checked, but I guess became a bit blinded to the problem. Sorry to waste your time, and appreciate your assistance and patience. Geoff. -- http://mail.python.org/mailman/listinfo/python-list
Converting from Microsoft Binary Format floats to Python Float
In the '80's, Microsoft had a proprietary binary structure to handle floating point numbers, In a previous thread, Bengt Richter posted some example code in how to convert these to python floats; http://groups.google.com/group/comp.lang.python/browse_thread/thread/42150ccc20a1d8d5/4aadc71be8aeddbe#4aadc71be8aeddbe I copied this code and modified it slightly, however, you will notice that for one of the examples, the conversion isn't exact. Can anyone advise me on how to modify this code to correct for this situation ? I think the problem may be related to the different lengths of the mantissa. For double precision (8bytes) MBF format had 55 where as Python floats (IEEE) has only 52 ?? Sample Code Below -- # Conversion of Microsoft Binary Format numbers to Python Floats import binascii as bn import struct as st data = [(1234567890,'00AF052C139F'), (4069954144,'0060929672A0'), (99.99, '703D0AD7FF237494'), ( 8.88, '400ad7a3709c2d91'), ( 2.22, '400ad7a3709c2d8f'), ( 3.33, 'b047e17a54350290'), ( 1500.34, '7814ae47e18a3b8b'), ( 42345.00, '00692590'), ] def msd2float(bytes): #take out values that don't make sense possibly the NaN and Infinity ?? if sum(bytes) in [0,72,127]: return 0.0 b = bytes[:] sign = bytes[-2]0x80 b[-2] |= 0x80#hidden most sig bit in place of sign exp = bytes[-1] - 0x80 - 56 #exponent offset acc = 0L for i,byte in enumerate(b[:-1]): acc |=(long(byte)(i*8)) return (float(acc)*2.0**exp)*((1.,-1.)[sign!=0]) for line in data: inval = line[0] binval = bn.unhexlify(line[1]) le_bytes = list(st.unpack('',binval)) outval = msd2float(le_bytes) print In:,inval, \nOut:,outval,\n Sample Output C:/Python24/pythonw.exe -u C:/pytest/dms/Test MBF.pyw In: 1234567890 Out: 1234567895.5 In: 4069954144 Out: 4069954144.0 In: 99.99 Out: 99.99 In: 8.88 Out: 8.88 In: 2.22 Out: 2.22 In: 3.33 Out: 3.33 In: 1500.34 Out: 1500.34 In: 42345.0 Out: 42345.0 End Sample Output -- http://mail.python.org/mailman/listinfo/python-list
Re: Anyone recognize this numeric storage format - similar to float, but not quite
I am not sure if you are still watching this thread, but I seem to have a bit of a problem with the code sample you so graciously provided. It seems to work in all instances, except the original example I provided (namely, 1234567890). On my system, the number 1234567890, gets converted to 1234567895.5. I made a few changes to your original program, but it is largely the same with different test samples samples. Any thoughts ?? Sample Code Below -- # Conversion of Microsoft Binary Format numbers to Python Floats import binascii as bn import struct as st data = [(1234567890,'00AF052C139F'), (4069954144,'0060929672A0'), (99.99, '703D0AD7FF237494'), ( 8.88, '400ad7a3709c2d91'), ( 2.22, '400ad7a3709c2d8f'), ( 3.33, 'b047e17a54350290'), ( 1500.34, '7814ae47e18a3b8b'), ( 42345.00, '00692590'), ] def msd2float(bytes): if sum(bytes) in [0,72,127]: #take out values that don't make sense possible the NaN and Infinity ?? return 0.0 b = bytes[:] sign = bytes[-2]0x80 b[-2] |= 0x80 #hidden most sig bit in place of sign exp = bytes[-1] - 0x80 - 56 #exponent offset acc = 0L for i,byte in enumerate(b[:-1]): acc |=(long(byte)(i*8)) return (float(acc)*2.0**exp)*((1.,-1.)[sign!=0]) for line in data: val = line[0] binval = bn.unhexlify(line[1]) le_bytes = list(st.unpack('',binval)) test = msd2float(le_bytes) print In:,val, \nOut:,test,\n Sample Output C:/Python24/pythonw.exe -u C:/pytest/dms/Test MBF.pyw In: 1234567890 Out: 1234567895.5 In: 4069954144 Out: 4069954144.0 In: 99.99 Out: 99.99 In: 8.88 Out: 8.88 In: 2.22 Out: 2.22 In: 3.33 Out: 3.33 In: 1500.34 Out: 1500.34 In: 42345.0 Out: 42345.0 -- http://mail.python.org/mailman/listinfo/python-list
Re: Anyone recognize this numeric storage format - similar to float, but not quite
Thanks Bengt for directing me to your previous post. I think I agree with you on the reversing bit and the constant MSB. In reworking my examples I was always changing the 0 to 1. -- http://mail.python.org/mailman/listinfo/python-list
Anyone recognize this numeric storage format - similar to float, but not quite
We are working on a project to decipher a record structure of an old accounting system that originates from the late80's mid-90's. We have come across a number format that appears to be a float but doesn't match any of the more standard implementations. so we are hoping this is a recognizable number storage format with an identifiable name AND pre-built conversion method similiar to the struct modules available in python. Here is what we have determined so far. Example Number: 1234567890 This get stored on disk as 8 bytes, resulting in the following HEX characters; 00 00 00 A4 05 2c 13 9f If we changed the order so that it is little Endian we get; 9F 13 2c 05 A4 00 00 00 If the HEX is converted to binary it looks like; 1001 00010011 00101100 0101 10100100 0 If the example number 1234567890 is converted to binary it looks like; 10010011 00101100 0101 1010010 To extract the example number, you need to do the following; 1) take the decimal value of the first byte and subtract 128 2) This tells you how many of the following bits to are significant and must be read 3) Once the remaining bits are read, reverse the first bit of that group (ie if it is a 0 make it a 1) 4) convert the result to decimal ... and presto, the example number ! Using a fixed width font it is easy to see the match at the bit level; 1001 0001001100101100010110100100 100100110010110001011010010 If you are interested, the following are three other examples; Orig Hex: 00 00 00 60 92 96 72 A0 Actual Value: 4069954144 Orig Hex: 00 00 80 22 A3 26 3C A1 Actual Value: 6313297477 So ... does anyone recognize this ?? Is there a built-in conversion method in Python ?? Thanks in advance. -- http://mail.python.org/mailman/listinfo/python-list
Re: Does any one recognize this binary data storage format
Thanks so much for this. It is exactly what I was looking for. If I am simply reading the bytes from disk, would I still need to convert the these values HEX characters first with Hexlify, or is there a more direct route ? ie. convert them to the double float directly from the byte values ? -- http://mail.python.org/mailman/listinfo/python-list
Re: Does any one recognize this binary data storage format
Thanks again. Sort of thru me off, but is working perfectly now. -- http://mail.python.org/mailman/listinfo/python-list
Recommendations for CVS systems
I was wondering if anyone could make recomendations/comments about CVS systems, their experiences and what perhaps the strengths of each. Currently we have 2 developers but expect to grow to perhaps 5. Most of the developement is Python, but some C, Javascript, HTML, etc. The IDE what have been using/experimenting with are drPython and eclipse with PyDev. TIA -- http://mail.python.org/mailman/listinfo/python-list
Does any one recognize this binary data storage format
I am hoping someone can help me solve a bit of a puzzle. We are working on a data file reader and extraction tool for an old MS-DOS accounting system dating back to the mid 80's. In the data files, the text information is stored in clearly readable ASCII text, so I am comfortable that this file isn't EBCIDIC, however, the some of the numbers are stored in a format that we can't seem to recognize or unpack using the standard python tools (struct, binascii) ... or or atleast our understanding of how these tools work ! Any assistance would be appreciated. Here are a few examples of telephone numbers; Exmaple 1: Phone 1: 5616864700 Hex On Disk: C0DBA8ECF441 Phone 2: 5616885403 Hex on Disk: B0E9ADECF4F1 Another example: Phone 1: 8003346488 Hex On Disk: 800396d0fd41 Phone2: 9544261331 Hex On Disk: F8f50ec70142 Phone3: 9544278601 Hex On Disk: 481211c70142 TIA. -- http://mail.python.org/mailman/listinfo/python-list
Re: Does any one recognize this binary data storage format
the extension on the files is *.mas but I a pretty sure it is not relevant. I beleive it used by the application. I can posted records as it will take up to much space. But all three phone numbers are stored in 8 bytes with null bytes (ie. 00) stored in the leading positions (ie. the left hand side) I do have some more examples; I have inserted the leading null bytes and seperated with spaces for clarity. Ex #1) 333- Hex On disk: 00 00 00 80 6a 6e 49 41 Ex #2) 666- Hex On disk: 00 00 00 80 6a 6e 59 41 Ex#3) 777- Hex On Disk: 00 00 00 40 7C AB 5D 41 Ex#4) 123-4567 Hex On Disk: 00 00 00 00 87 D6 32 41 Ex#5) 000-0001 Hex On disk: 00 00 00 00 00 00 F0 3F Ex#6) 999- Hex On disk: 00 00 00 E0 CF 12 63 41 -- http://mail.python.org/mailman/listinfo/python-list