Convert binary file


, Specifically, I'm trying to convert the Internet Explorer history file (index.dat) into a readable format. Anyone done something similar or know of any functions that may help with such a task I'm not sure exactly what kind of file ...
Posted On: Sunday 25th of November 2012 10:51:32 PM Total Views:  52
View Complete with Replies

RELATED TOPICS OF Python Programming PROGRAMMING LANGUAGE




how to convert a multiline string to an anonymous function?

Simple question here: I have a multiline string representing the body of a function. I have control over the string, so I can use either of the following: str = ''' print state return True ''' str = ''' def f(state): print state return True ''' and I want to convert this into the function: def f(state): print state return True but return an anonmyous version of it, a la 'return f' so I can assign it independently. The body is multiline so lambda doesn't work. I sort of need something like: def function_constructor(str): f = eval(str) # What should this be return f functions = {} for node in nodes: function[node] = function_constructor(node.text) I'm getting stuck because 'def' doesn't seem to work in an eval function, and exec actually modifies the namespace, so I run into collisions if I use the function more than once. I know I'm missing something stupid here, but I'm stuck just the same...
VIEWS ON THIS POST

100

Posted on:

Wednesday 7th November 2012
View Replies!

Re: convert xhtml back to html

On 2008-04-24 19:16, John Krukoff wrote: >> -----Original Message----- >> From: python-list-bounces+jkrukoff=ltgc.com@python.org [mailtoython- >> list-bounces+jkrukoff=ltgc.com@python.org] On Behalf Of Tim Arnold >> Sent: Thursday, April 24, 2008 9:34 AM >> To: python-list@python.org >> Subject: convert xhtml back to html >> >> hi, I've got lots of xhtml pages that need to be fed to MS HTML Workshop >> to >> create CHM files. That application really hates xhtml, so I need to >> convert >> self-ending tags (e.g. ) to plain html (e.g. ). >> >> Seems simple enough, but I'm having some trouble with it. regexps trip up >> because I also have to take into account 'img', 'meta', 'link' tags, not >> just the simple 'br' and 'hr' tags. Well, maybe there's a simple way to do >> that with regexps, but my simpleminded )]+/> doesn't work. I'm >> not >> enough of a regexp pro to figure out that lookahead stuff. >> >> I'm not sure where to start now; I looked at BeautifulSoup and >> BeautifulStoneSoup, but I can't see how to modify the actual tag. You could filter the XHTML through mxTidy and set the hide_endtags to 1: http://www.egenix.com/products/pytho...mental/mxTidy/ -- Marc-Andre Lemburg eGenix.com Professional Python Services directly from the Source (#1, Apr 24 2008) >>> Python/Zope Consulting and Support ... http://www.egenix.com/ >>> mxODBC.Zope.Database.Adapter ... http://zope.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ :::: Try mxODBC.Zope.DA for Windows,Linux,Solaris,MacOSX for free ! :::: eGenix.com Software, Skills and Services GmbH Pastor-Loeh-Str.48 D-40764 Langenfeld, Germany. CEO Dipl.-Math. Marc-Andre Lemburg Registered at Amtsgericht Duesseldorf: HRB 46611
VIEWS ON THIS POST

50

Posted on:

Wednesday 7th November 2012
View Replies!

How to convert latex-based docs written with Python 2.5 to 2.6 framework

HI! I had a look on how Doc/ is organized with Python 2.6. There are files with suffix .rst. Hmm... I'm maintaing existing docs for python-ldap which I might have to convert to the new concept in the long run. What's the recommended procedure for doing so Any pointer Ciao, Michael.
VIEWS ON THIS POST

82

Posted on:

Wednesday 7th November 2012
View Replies!

TypeError: only length-1 arrays can be converted to Python scalars.

Hi , Could anybody tell me what is the problem with the following sequence with which I always get the above error message. I use Numeric and Python 2.4 x=array([1,2,3,4]) y=exp(x) Nure
VIEWS ON THIS POST

103

Posted on:

Wednesday 7th November 2012
View Replies!

Parallel port control with USB->Parallel converter

I want to control some motors using the parallel port.. however, my laptop does not have any parallel ports (very few do). What I do have is a USB->Parallel converter... I thought about using PyParallel, but the USB->Parallel converter doesn't actually map to the LPT port .. and PyParallel only looks for LPT ports Has anyone tried doing this What are my options for controlling parallel connections on a laptop with no parallel port I also thought about controlling the USB natively.. but since I dont have any instructions on how to do this with my Velleman USB->Parallel port converter... i guess I would be totally blind.
VIEWS ON THIS POST

58

Posted on:

Wednesday 7th November 2012
View Replies!

convert pdf to png

I need to take the take the pdf output from reportlab and create a preview image for a web page. so png or something. I am sure ghostscript will be involved. I am guessing PIL or ImageMagic all sugestions welcome. Carl K
VIEWS ON THIS POST

56

Posted on:

Wednesday 7th November 2012
View Replies!

how to convert tuple to a "list of single values" ?

hello, The next piece of code bothers me: ptx, pty, rectWidth, rectHeight = self._point2ClientCoord (p1, p2 ) dc.SetClippingRegion ( ptx, pty, rectWidth, rectHeight ) Because I want to write it in 1 line, and without the use of intermediate variables (for which I have to invent names ;-) like this: dc.SetClippingRegion ( self._point2ClientCoord (p1, p2 ) ) Now that doesn't work, because - dc.SetClippingRegion() requires 4 integer parameters - _point2ClientCoord() returns a tupple of 4 integers I can't think of a solution, is there any
VIEWS ON THIS POST

59

Posted on:

Wednesday 7th November 2012
View Replies!

int('\x23') != 0x23 (a.k.a convert char to integer of its byte representation)

I am looking for the best way to convert a string of length 1 (= 1 character as string) to integer that has the same value as numeric representation of that character. Background: I am writing functions abstracting endianness, e.g. converting a string of length 4 to the appropriate integer value (e.g. '\x01\x00\x00\x00' = 2**24 for big endian memory, 2**0 for little endian memory). For this, I need to know the numeric value of each byte and sum them according to endianness. I thought that something like int('\x01') might work, provided the argument is string of length 1, but that throws an error: >>> int('\x12') Traceback (most recent call last): File "", line 1, in ValueError: invalid literal for int(): The code I want to write looks like this: mem = '\x11\x22\x33\x44' factor = 1 sum = 0 for byte in mem: sum += int(byte) * factor factor *= 2**8 Could you please tell me how to achieve what I want in Python (it would be straightforward in C)
VIEWS ON THIS POST

98

Posted on:

Wednesday 7th November 2012
View Replies!

Re: How to convert None to null value

En Fri, 07 Sep 2007 06:19:25 -0300, pradeep kumar escribi: > i am trying to insert records from one table to another table in postgres > sql using the the following code > > posConn.query("insert into > usr(usr_id,usr_name,usr_passwd,grp_cde,usr_type,usr_chk_till_val, \ > > usr_active,usr_daily_auth,usr_lst_login,usr_lst_logout,usr_shift_id,usr_role_level) > values \ > ('%s','%s','%s',%s,%i,%d,'%s',%i,%i,%i,%i,%i)" > %(row[0],row[1],row[2],row[3],row[4],row[5], \ > row[7],row[8],row[10],row[11],row[12],row[14]) ) > > here row[4] column is having null value so python consides it as None but > will insert into the table it inserts as None not null value - You are building the sql statement "by hand": don't do that. The query method receives two arguments: an sql template with placeholders, and a tuple of arguments. This way, None objects are correctly translated into NULL values, embedded quotes are correctly handled, etc. An important point is security - building the sql statement by hand may open the door to sql injection attacks. See for details. - You don't need those \ for line continuation: any expression containing an open ( [ { automatically continues on the following lines until all ) ] } are closed. - Python automatically joins contiguous strings. Combining all the above: posConn.query("insert into usr " "(usr_id,usr_name,usr_passwd,grp_cde,usr_type," "usr_chk_till_val,usr_active,usr_daily_auth," "usr_lst_login,usr_lst_logout,usr_shift_id," "usr_role_level) values " "(%s,%s,%s,%s,%i,%d,%s,%i,%i,%i,%i,%i)" , (row[0],row[1],row[2],row[3],row[4],row[5], row[7],row[8],row[10],row[11],row[12],row[14])) Note the TWO arguments to the query method: all those string fragments are joined into a single string, followed by a comma, and a tuple containing 6 parameters. Parameter markers may be %s,%s,%s... as above, or :1,:2,:3... or ,,... The exact syntax depends on your specific database adapter - you'll have to read its documentation. -- Gabriel Genellina
VIEWS ON THIS POST

40

Posted on:

Wednesday 7th November 2012
View Replies!

converting 64-bit fixed-point to float

Hi Group, troubles with converting signed 32.32, little-endian, 2's complement back to floating point. I have been trying to brew it myself. I am running Python 2.5 on a Mac. Here is the C-code I have been trying to leverage: double FPuint8ArrayToFPDouble(uint8 *buffer, int startIndex) { uint32 resultDec = 0; uint32 resultWh = 0; int i; for(i = 0; i < 4; i++) { resultDec += (uint32)buffer[startIndex + i] * pow(2, (i*8)); resultWh += (uint32)buffer[startIndex + i + 4] * pow(2, (i*8)); } return ( (double)((int)resultWh) + (double)(resultDec)/4294967296.0 ); } Here is my version in Python, with some test code built in: from ctypes import * def conv64(input): input1=[0]*8 input1[0]=c_ushort(input[0]) input1[1]=c_ushort(input[1]) input1[2]=c_ushort(input[2]) input1[3]=c_ushort(input[3]) input1[4]=c_ushort(input[4]) input1[5]=c_ushort(input[5]) input1[6]=c_ushort(input[6]) input1[7]=c_ushort(input[7]) #print input1[0].value, input1[1].value,input1[2].value,input1[3].value #print input1[4].value,input1[5].value,input1[6].value,input1[7].value #print resultDec=c_ulong(0) resultWh=c_ulong(0) for i in range(4): dec_c=c_ulong(input1[i].value) Wh_c=c_ulong(input1[i+4].value) resultDec.value=resultDec.value+dec_c.value*2**(i*8) resultWh.value=resultWh.value+Wh_c.value*2**(i*8) conval=float(int(resultWh.value))+float(resultDec.value)/4294967296.0 #print conval return conval #tabs got messed up bringing this into MacSoup #these are 64-bit fixed point format (signed 32.32, little-endian, 2's complement) #should be -1 conv64_0=[0, 0, 0, 255, 255, 255, 255, 255] #should be 0 conv64_1=[0, 0, 0, 0, 0, 0, 0, 0] #should be 0.20000 conv64_1_2=[51, 51, 51, 51, 0, 0, 0, 0] #should be 1 conv64_2=[0, 0, 0, 0, 1, 0, 0, 0] #should be 2 conv64_3=[0, 0, 0, 0, 2, 0, 0, 0] #should be 298.15 conv64_4=[102, 102, 102, 38, 42, 1, 0, 0] #should be -0.2 conv64_5=[205,204,204,204,255,255,255,255] output0=conv64(conv64_0) print "output should be -1 is "+str(output0) output1=conv64(conv64_1) print "output should be 0 is "+str(output1) output1_2=conv64(conv64_1_2) print "output should be 0.2 is "+str(output1_2) output2=conv64(conv64_2) print "output should be 1 is "+str(output2) output3=conv64(conv64_3) print "output should be 2 is "+str(output3) output4=conv64(conv64_4) print "output should be 298.15 is "+str(output4) output5=conv64(conv64_5) print "output should be -0.2 is "+str(output5) Finally, here is the output I get from my code: >>> output should be -1 is 4294967296.0 output should be 0 is 0.0 output should be 0.2 is 0.199999999953 output should be 1 is 1.0 output should be 2 is 2.0 output should be 298.15 is 298.15 output should be -0.2 is 4294967295.8
VIEWS ON THIS POST

134

Posted on:

Wednesday 7th November 2012
View Replies!

[ANN] csv2txt.py csv file convertion script

csv2text is a program I wrote to illustrate a point I made on comp.lang.python about not just creating great Python modules, or Python programs, but of doing both at the same time. This program makes the CSV module of Python more accessible by creating a program 'filter' that guesses and parses a csv file type on standard input and generates different formats on standard output. At the moment, output types are CSV, HTML (as an HTML table), and a text format that is written to be easily parsed by tools such as TCL or AWK that may not have such a powerful CSV reader module handy. The text format has conversions to allow AWK to handle CSV files with fields that contain embedded newlines (XL can generate that type of CSV file). Homepage: http://www.paddyx.pwp.blueyonder.co....xt/README.html Cheers, Paddy.
VIEWS ON THIS POST

95

Posted on:

Wednesday 7th November 2012
View Replies!

Re: How to convert unicode string to unsigned char *

On Mon, 5 May 2008 15:41:08 +0200, Simon Posnjak wrote: >Hi! > >I have a C module for which I created a wrapper with swig. The function def is: > >C: > >int some_thing(unsigned char * the_str); > >eg: ...
VIEWS ON THIS POST

53

Posted on:

Saturday 10th November 2012
View Replies!

convert xhtml back to html

hi, I've got lots of xhtml pages that need to be fed to MS HTML Workshop to create CHM files. That application really hates xhtml, so I need to convert self-ending tags (e.g.
) to plain html (e.g.
). ...

VIEWS ON THIS POST

25

Posted on:

Saturday 10th November 2012
View Replies!

Re: WindowsXP/ CTypes - How to convert ctypes array to a string?

dudeja.rajat@gmail.com wrote: > I've used CTYPES module to access a function from a dll. This function > provides me the version of the dll. This information is accessible to > me as an array of 4 long inetegers. information as ...
VIEWS ON THIS POST

152

Posted on:

Sunday 11th November 2012
View Replies!

Suggestion for converting PDF files to HTML/txt files

Could someone suggest me ways to convert PDF files to HTML files\t Does Python have any modules to do that job\t
VIEWS ON THIS POST

80

Posted on:

Sunday 11th November 2012
View Replies!

How to convert markup text to plain text in python?

I have some marked up text and would like to convert it to plain text, by simply removing all the tags. Of course I can do it from first principles but I felt that among all Python's markup tools there ...
VIEWS ON THIS POST

50

Posted on:

Sunday 11th November 2012
View Replies!

How do I convert escaped HTML into a string?

I've done a google search on this but, amazingly, I'm the first guy to ever need this! Everyone else seems to need the reverse of this. Actually, I did find some people who complained about this and rolled their own ...
VIEWS ON THIS POST

34

Posted on:

Monday 12th November 2012
View Replies!

Re: How to use win32com to convert a MS WORD doc to HTML ?

2008/8/19 Lave : > all ! > > I'm a totally newbie huh > > I want to convert MS WORD docs to HTML, I found python windows > extension win32com can make this. But I can't find the ...
VIEWS ON THIS POST

50

Posted on:

Sunday 25th November 2012
View Replies!

Re: convert unicode characters to visibly similar ascii characters

Peter Bulychev wrote: > Thank you for you answer. > > If you only want this to work for a subset, please define that subset. > > Actually, I want to convert only punctuations (dots, commas, hyphens > and so ...
VIEWS ON THIS POST

38

Posted on:

Sunday 25th November 2012
View Replies!

convert binary to float

I have tried and tried... I'd like to read in a binary file, convert it's 4 byte values into floats, and then save as a .txt file. This works from the command line (import struct); In [1]: f = open("test2.pc0", ...
VIEWS ON THIS POST

13

Posted on:

Sunday 25th November 2012
View Replies!