RE: Mysterious xml.sax Encoding Exception

2008-02-02 Thread Peck, Jon
Yes, the characters were from the 0-127 ascii block but encoded as utf-16, so 
there is a null byte with each nonzero character.  I.e., 
\x00?\x00x\x00m\x00l\x00

Here is something weird I found while experimenting with ElementTree with this 
same XML string.

Consider the same XML as a Python Unicode string, so it is actually encoded as 
utf-16 and as a string containing utf-16 bytes.  That is
u'?xml version=1.0 encoding=UTF-16 st' ...
or
'\xff\xfe\x00?\x00x\x00m\x00l\x00 
\x00v\x00e\x00r\x00s\x00i\x00o\x00n\x00=\x00\x001\x00.\x000\x00\x00'...

So if these are x and y
y = x.encode(utf-16)

The actual bytes would be the same, I think, although y is type str and x is 
type unicode.

xml.sax.parseString documentation says

parses from a buffer string received as a parameter, 

so one might imagine that either x or y would be acceptable, and the bytes 
would be interpreted according to the encoding declaration in the byte stream.

And, in fact, both do work with xml.sax.parseString (at least for me).  With 
etree.parse(StringIO.StringIO...) though, only the str form works.

Regards,
Jon Peck


-Original Message-
From: Jeroen Ruigrok van der Werven [mailto:[EMAIL PROTECTED] 
Sent: Saturday, February 02, 2008 12:57 AM
To: JKPeck
Cc: python-list@python.org
Subject: Re: Mysterious xml.sax Encoding Exception

-On [20080201 19:06], JKPeck ([EMAIL PROTECTED]) wrote:
In both of these cases, there are only plain, 7-bit ascii characters
in the xml, and it really is valid utf-16 as far as I can tell.

Did you mean to say that the only characters they used in the UTF-16 encoded
file are characters from the Basic Latin Unicode block? 

-- 
Jeroen Ruigrok van der Werven asmodai(-at-)in-nomine.org / asmodai
イェルーン ラウフロック ヴァン デル ウェルヴェン
http://www.in-nomine.org/ | http://www.rangaku.org/
We have met the enemy and they are ours...
-- 
http://mail.python.org/mailman/listinfo/python-list

Finding the Process Path

2005-10-03 Thread Peck, Jon








I have Python code running in an
application, and I would like to find the full path of the process executable
where it is running. I can do this with win32api.GetModuleFileName(0) on
Windows, but I would like a solution that uses only standard modules and works
cross platform. Any suggestions?



TIA.



Jon K Peck (Kim)

[EMAIL PROTECTED]

312-651-3435

233 S Wacker Dr

Chicago, IL 60606








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

RE: Finding the Process Path

2005-10-03 Thread Peck, Jon
Thanks, but this doesn't tell me what I am looking for.

I am looking for the path for the current process (which will not be the Python 
interpreter).

I see, though, that this is available as sys.executable

Regards,
Jon Peck

-Original Message-
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of gene tani
Sent: Monday, October 03, 2005 7:39 AM
To: python-list@python.org
Subject: Re: Finding the Process Path

other ways to get at info:

if sys.hexversion  0x010502F0:

sys.versioninfo, version, etc.

platform.architecture, processor etc.

distutils.sysconfig.get_makefile_filename(  )

Benji York wrote:
 Peck, Jon wrote:
  I have Python code running in an application, and I would like to find
  the full path of the process executable where it is running.

 Like this?

   import sys
   sys.executable
 '/usr/bin/python'
 --
 Benji York

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


RE: Finding the Process Path

2005-10-03 Thread Peck, Jon
Problem solved, but sys.executable seems to be (mostly) what I need.  The 
context here is that my code is embedded in another process, so the Python 
interpreter is not the process executable, and in fact argv is not set (for 
various reasons not related to Python.)

If I run this code directly through the interpreter, of course Python is what I 
get from sys.executable.

-Original Message-
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Steve Holden
Sent: Monday, October 03, 2005 9:26 AM
To: python-list@python.org
Subject: Re: Finding the Process Path

Peck, Jon wrote:
 Thanks, but this doesn't tell me what I am looking for.
 
 I am looking for the path for the current process (which will not be the 
 Python interpreter).
 
Actually the core image will be that of the Python interpreter.

 I see, though, that this is available as sys.executable
 
The interpreter? That's correct.

What you probably want is

import os, sys
print os.path.abspath(sys.argv[0])

this will give you the path to the Python script the interpreter is running.

regards
  Steve
-- 
Steve Holden   +44 150 684 7255  +1 800 494 3119
Holden Web LLC www.holdenweb.com
PyCon TX 2006  www.python.org/pycon/

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


NaN Vs None

2005-09-23 Thread Peck, Jon








In choosing a way to represent a value of
no information for a float, would it be better to use NaN or None? None has the advantage of standard behavior
across platforms, but NaN seems to propagate
more easily  at least on Windows.

For example,



NaN+1 = NaN

but

None+1

raises an exception.



Thanks in advance for any advice.





Jon K Peck (Kim)

[EMAIL PROTECTED]

312-651-3435

233 S Wacker Dr

Chicago, IL 60606








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