Spoiler to Python Challenge (help!!!)

2005-09-27 Thread Ian Vincent
Damn this is annoying me.

I have a webpage with a BZ2 compressed text embedded in it looking like:

'BZh91AY&SYA\xaf\x82\r\x00\x00\x01\x01\x80\x02\xc0\x02\x00 \x00!\x9ah3M
\x07<]\xc9\x14\xe1BA\x06\xbe\x084'

Now, if I simply copy and paste this into Python and decompress it - it 
works a treat.

However, I want to read the file containing this data, extract the data 
and decompress it and this for some reason does not work.

I am doing the following (excuse the probably very long handed way of 
doing it):

file = urllib.urlopen(url, proxies=proxies)
line = file.readlines()
file.close()
line = line[20:]
line = line[:-1]
user = line[0]
password = line[1]
user = user[5:]
user = user[:-2]
user = str(user)
password = password[5:]
password = password[:-2]

This gives me a user string of:

BZh91AY&SYA\xaf\x82\r\x00\x00\x01\x01\x80\x02\xc0\x02\x00 \x00!\x9ah3M
\x07<]\xc9\x14\xe1BA\x06\xbe\x084

But if I put this into the decompression function, I get a error of 
'IOError: invalid data stream'.

I know it is the escape characters but how do I get these to be correctly 
converted into a string compatible with bz2.decompress()?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Spoiler to Python Challenge (help!!!)

2005-09-28 Thread Ian Vincent
"Terry Reedy" <[EMAIL PROTECTED]> wrote in 
news:[EMAIL PROTECTED]:
> 
> please, line = line[20:-1], etc, is easier to read and understand ;-)

Thanks, i'll put that in.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Spoiler to Python Challenge (help!!!)

2005-09-28 Thread Ian Vincent
Terry Hancock <[EMAIL PROTECTED]> wrote in
news:[EMAIL PROTECTED]: 
> 
> Took me a long time to figure out what you meant. ;-)
> 
> So the string actually contains the backslashes, not the escaped
> characters. 
> 
> This works:
> 
 bz2.decompress(eval(repr(user)))
> 'huge'

Unfortunately, it doesn't. Get the same error.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Spoiler to Python Challenge (help!!!)

2005-09-29 Thread Ian Vincent
Terry Hancock <[EMAIL PROTECTED]> wrote in 
news:[EMAIL PROTECTED]:
> 
 bz2.decompress(eval('"' + user + '"'))
> 
> Sorry about that.  I was trying the other as an alternative,
> but in fact, it doesn't work.  So ignore that.

Excellent! Thanks.
-- 
http://mail.python.org/mailman/listinfo/python-list


How to use generators?

2005-11-09 Thread Ian Vincent




I have never used generators before but I might have now found a use for 
them. I have written a recursive function to solve a 640x640 maze but it 
crashes, due to exceeding the stack.  The only way around this I can 
think of is to use Generator but I have no idea how to.

The function is as below:

def solve_maze(x,y):
if y <= 0:
success = 1
elif x <= 0 or x > 640 or y >= 640:
success = 0
elif maze_array[x][y] == 1:
success = 0
elif im.getpixel((x,y)) == (255, 255, 255, 255):
success = 0
else:
maze_array[x][y] = 1
if solve_maze(x,y-1) == 1:
success = 1
elif solve_maze(x+1,y) == 1:
success = 1
elif solve_maze(x-1,y) == 1:
success = 1
else:
success = solve_maze(x,y+1)

if success == 1:
print im.getpixel((x,y))

return success

#Main
wibble = solve_maze(x,y)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How to use generators?

2005-11-10 Thread Ian Vincent
Tom Anderson <[EMAIL PROTECTED]> wrote in
news:[EMAIL PROTECTED]: 
> 
> Exactly - using a queue means you'll do a breadth-first rather than a 
> depth-first search, which will involve much less depth of recursion.
> See: 

Thanks for the answers but found a easier (admittedly cheating) way around 
the problemrun the code on my 64bit Linux system at home.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Writing pins to the RS232

2005-11-28 Thread Ian Vincent
Peter Hansen <[EMAIL PROTECTED]> wrote in
news:[EMAIL PROTECTED]: 
> 
> All true, but then Jay might get into electrical compatibility issues,
> and may not realize that the output levels of RS-232 serial hardware
> are not simply 0 and 5V levels, but rather +9V (or so) and -9V (and
> with variations from 6V up to 13V seen in the wild), and without much
> in the way of drive capability.  Using this to control custom hardware
> would probably be an exercise in frustration and kind of pointless in 
> comparison to using parallel hardware, which at least has more typical
> logic voltage levels.

You can get ICs that convert RS232 to TTL voltage levels.
-- 
http://mail.python.org/mailman/listinfo/python-list


TKinter, Entry objects and dynamic naming

2005-09-13 Thread Ian Vincent
I am hoping someone may be able to help.

I am using Python and TKinter to create a GUI program that will 
eventually create an XML file for a project I am working on. Now, the XML 
file contents changes depending on the type of file it represents - so I 
am dynamically creating the TK Entry boxes. The problem is, I want the 
variable assigned to each of these boxes to be dynamically assigned as 
well but I cannot see how to do this (if it is indeed possible).

Example

If the file the XML is to represent is a spreadsheet - I want the first 
entry box to be:

spreadsheetField = StringVar()
value = Entry(root, relief=SUNKEN, justify=LEFT, 
textvariable=spreadsheetField)

however, if the file is a document - I want the first entry box to be:

documentField = StringVar()
value = Entry(root, relief=SUNKEN, justify=LEFT, 
textvariable=documentField)

I have quite a few Entry boxes for each file type (about 10) and a lot of 
filetypes (over 80), so I do not want to have a custom function for each 
filetype if I can help it.

I have looked at using a dictionary but I cannot get my head around how 
to do that either.

If anyone can give me any ideas, I would be very grateful.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: TKinter, Entry objects and dynamic naming

2005-09-13 Thread Ian Vincent
Ian Vincent <[EMAIL PROTECTED]> wrote in
news:[EMAIL PROTECTED]: 
> 
> I have looked at using a dictionary but I cannot get my head around
> how to do that either.

I have tried this now but the Entry field just does not seem to work:

def add_variable(self, root, varname):
 Label(root, text=varname + ': ').grid(row=self.row, column=0, 
sticky=E)
 self.properties[varname] = StringVar()
 value = Entry(root, relief=SUNKEN, justify=LEFT, 
textvariable=self.properties[varname])
 value.grid(row=self.row, column=1, sticky=E+W)
 self.row = self.row + 1
 return value


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


Re: Help need with converting Hex string to IEEE format float

2004-12-17 Thread Ian Vincent
Max M <[EMAIL PROTECTED]> wrote in news:41bf121e$0$280
[EMAIL PROTECTED]:
> 
> ##
> st = '80 00 00 00'
> 
> import binascii
> import struct
> 
> s = ''.join([binascii.a2b_hex(s) for s in st.split()])
> v = struct.unpack("f", s)[0]
> print v
> ##

This one worked great for what I was trying to do.

Thanks to everybody for your help.

TTFN

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


Jython Sounds Examples

2006-10-10 Thread Ian Vincent
I have been hunting around Google hits for any source code examples of 
using sound (preferably WAV) under Jython with no success (minus several 
using other toolkits such as JNRI and JES). Does anybody know if any such 
examples exist and if so, I would be grateful for a pointer in their 
direction?
-- 
http://mail.python.org/mailman/listinfo/python-list


Jythonc Problem

2006-07-04 Thread Ian Vincent
I cannot find a Jython newsgroup, so apologies in advance if this 
question has been posted to the wrong group.

Just written my first Jython program (previously written Python ones) 
and it is working fine in 'interpreted mode'. I now want to compile it 
into Java classes but I get the following error:

Traceback (innermost last):
  File "/usr/share/jython/Tools/jythonc/jythonc.py", line 5, in ?
  File "/usr/share/jython/Tools/jythonc/main.py", line 299, in main
  File "/usr/share/jython/Tools/jythonc/main.py", line 162, in 
getOptions
AttributeError: class 'org.python.modules.os' has no attribute 'path'

Jython version is Jython 2.2a0 installed from the Suse 10.0 rpm
Java version is 1.4.2_06-b03 (possibly also installed from the Suse 10.0 
rpm.

Any help would be appreciated.

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