Re: Updated License Term Agreement for VC Redistributable in VS 2008 SP1

2010-04-18 Thread Tim Roberts
CM  wrote:
>
>On Apr 16, 3:31 am, Tim Roberts  wrote:
>>
>> Microsoft's intent is that you be able to distribute the non-debug runtimes
>> with any applications built with Visual Studio.  They are evil, but not
>> arbitrarily malicious.
>
>Just to be clear:  are you saying that if one has Visual Studio 2008
>Express Edition (the free one), one then has the right to redistribute
>the necessary dlls for using py2exe to make working Python 2.6
>executables?

The redistributable DLL package is freely downloadable from Microsoft.  I
don't see anything on the redistributable page that limits their use to the
paid editions only.
-- 
Tim Roberts, t...@probo.com
Providenza & Boekelheide, Inc.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python 2.7b1 and argparse's version action

2010-04-18 Thread Martin v. Loewis
> What do you think?

If you want something to happen, you need to bring this up on python-dev.

Regards,
Martin
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: My first project

2010-04-18 Thread Kushal Kumaran
On Sat, Apr 17, 2010 at 11:46 PM, Someone Something
 wrote:
> no one cares? :(
>
> On Sat, Apr 17, 2010 at 8:41 AM, Someone Something 
> wrote:
>>
>> This is my first large-scale (sort of) project in python. It is still
>> under daily development, but the core is pretty stable (although, I'm still
>> adding features). Here's the
>> code: http://github.com/Poincare/PyEventLoop or http://code.google.com/p/pyeventloop/
>> Tell me what you guys think of it (I'll be adding more examples by the end
>> of the day).
>

You didn't include a description of your project in your first email.
For those bothering to go check out the page, there's no mention of a
comparison between your project and, say, twisted.  Are you surprised
people didn't bother?

-- 
regards,
kushal
-- 
http://mail.python.org/mailman/listinfo/python-list


Call for Paper/Participation for Malaysia Open Source Conference 2010

2010-04-18 Thread darXness
Call for Paper/Participation for Malaysia Open Source Conference 2010

http://conf.oss.my/cfp.html

“OSS Towards Malaysia As A Developed Country In 2020”

Area of Interest
Cloud Computing
Computer Security
Games development
Mobile Computing
Data Freedom
Ham Radio

With the theme "OSS Towards Malaysia As A Developed Country In 2020"
MOSC 2010 able to stir the interest on development OSS's application
and produce many more OSS's application developers in Malaysia.

Of the purpose working paper call is open to all individual,
University or Company who is to present on the solutions or
applications. The working paper must be in knowledge sharing concept.
The working paper must not contain marketing materials to promote
certain product or company.

Please do note that the closing date for CFP is on May 12th, 2010 and
the selected paper will be informed immediately. For selected speakers
please submit your presentation slide before June 15nd, 2010.

Prospective speakers are invited to submit an abstract in 100-200
words by using this online form.

http://conf.oss.my/

Online Form
http://spreadsheets.google.com/a/oss.my/viewform?formkey=dEJ3RWhPYjJWaXdZUU1FeVhHTHhEWEE6MA

Event page in Facebook
http://www.facebook.com/event.php?eid=108270322543359

Twitter
http://twitter.com/mosc2010

Identi.ca
http://identi.ca/mosc2010

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


Re: getting a string as the return value from a system command

2010-04-18 Thread TomF

On 2010-04-16 12:06:13 -0700, Catherine Moroney said:


Hello,

I want to call a system command (such as uname) that returns a string,
and then store that output in a string variable in my python program.

What is the recommended/most-concise way of doing this?

I could always create a temporary file, call the "subprocess.Popen"
module with the temporary file as the stdout argument, and then
re-open that temporary file and read in its contents.  This seems
to be awfully long way of doing this, and I was wondering about 
alternate ways of accomplishing this task.


In pseudocode, I would like to be able to do something like:
hostinfo = subprocess.Popen("uname -srvi") and have hostinfo
be a string containing the result of issuing the uname command.


Here is the way I do it:

import os
hostinfo = os.popen("uname -srvi").readline().strip()

(I add a strip() call to get rid of the trailing newline.)

os.popen has been replaced by the subprocess module, so I suppose the 
new preferred method is:


from subprocess import Popen, PIPE
hostinfo = Popen(["uname", "-srvi"], stdout=PIPE).communicate()[0].strip()


Looks ugly to me, but there we are.

-Tom

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


Re: class instance customization

2010-04-18 Thread Steven D'Aprano
On Sat, 17 Apr 2010 19:55:44 +0400, Alexander wrote:
 
> Ok, I'll try to explain on the following example. Let's consider class
> MyClass that holds one string and concatenate it with other not defined
> in this class:
[...]
> and with working application:
> 
> a = MyClass()
> a.set('key1')
> 
> b1 = a.new('value1')
> b2 = a.new('value2')
> 
> print b1, "," ,b2 # give 'key1 value1 , key1 value2'
> 
> a.set('key2')
> 
> print b1, ",", b2 # give 'key2 value1 , key2 value2'

Looking at your design, I can't see any reason for SubClass to be a 
subclass of MyClass. It doesn't inherit any behaviour, and the 
constructor takes completely different arguments. Why make it a Subclass?

MyClass is dangerous: creating an instance doesn't fully initialise the 
instance, it leaves it in a half-initialised state that can cause 
exceptions from simple operations like:

instance = MyClass()
print instance

This is very bad design.

Redesigning the pair of classes, I get this:

class MyClass(object):
def __init__(self, key):
self.key = key  # No obvious need to make key a private attribute.
def new(self, value):
return AnotherClass(self, value)

class AnotherClass(object):
def __init__(self, obj, value):
self.obj = obj
self.value = value
def __str__(self):
return "%s %s" % (self.obj.key, self.value)


which gives the behaviour you ask for:

>>> a = MyClass('key1')
>>> b1 = a.new('value1')
>>> b2 = a.new('value2')
>>> print b1, "," ,b2
key1 value1 , key1 value2
>>>
>>> a.key = 'key2'
>>> print b1, "," ,b2
key2 value1 , key2 value2



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


email and unicode

2010-04-18 Thread janwillem
I have a script that extracts attachments from all emails in a mbox
(largely based on  
http://code.activestate.com/recipes/302086-strip-attachments-from-an-email-message/;
thanks ActiveState). It works fine until it encounters an attachment
with a unicode file name (Ukrainian in my case). I cannot get working
the line
msg.set_payload(replace)
which is line 39 in the activestate snippet.

How can you get the unicode file name into the replace string of line
35 of the snippet:
replace = ReplaceString % dict(content_type=ct,
   filename=fn,
   params=params)
without getting this nasty error message about ascii encoding?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: email and unicode

2010-04-18 Thread Steven D'Aprano
On Sun, 18 Apr 2010 03:02:23 -0700, janwillem wrote:

> How can you get the unicode file name into the replace string of line 35
> of the snippet:
> replace = ReplaceString % dict(content_type=ct,
>filename=fn,
>params=params)
> without getting this nasty error message about ascii encoding?

Completely untested...

fn = fn.encode('utf-8')
replace = ReplaceString % dict(
  content_type=ct, filename=fn, params=params)



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


Building a GUI Toolkit

2010-04-18 Thread Tim Diels

Hi

I was thinking of writing a GUI toolkit from scratch using a basic '2D 
library'. I have already come across the Widget Construction Kit.


My main question is: Could I build a GUI toolkit of reasonable 
performance with the Widget Construction Kit, would it still feel more 
or less lightweight? By reasonable I mean that the user wouldn't think 
of the interface as being slow or unresponsive.


I've also thought of using pyglet to build widgets with, but this would 
seem to be overkill. As a side question: by using opengl, the work would 
be delegated to the GPU rather than the CPU; is this always a good 
thing, or does it have downsides as well (performance, power usage, ...)?


Are there any other libraries that may be of interest to me?

Thanks in advance
--
http://mail.python.org/mailman/listinfo/python-list


Re: Nested list problem - please...

2010-04-18 Thread Andreas Waldenburger
On Sat, 17 Apr 2010 13:31:54 -0700 Chris Rebert 
wrote:

> On Sat, Apr 17, 2010 at 12:40 PM, Martin Hvidberg
>  wrote:
> > I have this code, it builds up a data structure of nested lists,
> > and filling data in them. My problem is that it seems that one of
> > the lists SA[1] is not a list of unique instances but rather
> > individual links to the same variable. In the example below I
> > assign 'X' to what I intended to be the first Compounds Name. But
> > rather the 'X' goes into all the Compounds Name. I thought that the
> > [:] in SAdata.extend([CP[:]]) would ensure copies rather than links
> > to. What is going wrong?  
> 
> someList[:] only copies 1-level deep. If you have a list of lists,
> none of the inner lists will be copied; you'll get a new list of
> references to the same lists instead. I think your code assumes [:]
> copies lists recursively.

Expanding on that, Martin, I think "from copy import deepcopy" should
solve that problem.

/W

-- 
INVALID? DE!

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


Re: Building a GUI Toolkit

2010-04-18 Thread Martin P. Hellwig

On 04/18/10 12:49, Tim Diels wrote:

Hi

I was thinking of writing a GUI toolkit from scratch using a basic '2D
library'. I have already come across the Widget Construction Kit.

My main question is: Could I build a GUI toolkit of reasonable
performance with the Widget Construction Kit, would it still feel more
or less lightweight? By reasonable I mean that the user wouldn't think
of the interface as being slow or unresponsive.

I've also thought of using pyglet to build widgets with, but this would
seem to be overkill. As a side question: by using opengl, the work would
be delegated to the GPU rather than the CPU; is this always a good
thing, or does it have downsides as well (performance, power usage, ...)?

Are there any other libraries that may be of interest to me?

Thanks in advance


It probably depends on how low level you want to go, I have pondered 
about the possibility myself to have an all python(ic) gui toolkit, 
capable of writing a (x11) windowing manager itself with.
But I decided that using tkinter and just live with its rough corners is 
more bang for the buck for me than to reimplement tkinter badly.


However as a thought exercise I did spend some energy on it and I had 
the following ideas.

- Need to have direct access to at least x11, cocoa  and win32gui;
  or even lower than that (if possible/reasonable).
- Only need to abstract enough so I can display a borderless window full
  screen or on any position/size.
- Need to provide a wrapper for the input devices too, e.g.: keyboard,
  mouse, joystick, touchscreen, etc.
- Optionally graphical acceleration (OpenGL, DirectX, SDL?)
- It would be good that fonts, windows, decoration and icons are all SVG
  so that all these items can scale independently.

I also had some more questions:
- How about providing an interface for video playback?
- How about audio?
- How about printing?
- How about multiple displays?
- How about odd sized displays (round, triangle, etc)?
- How to handle 'legacy' gui applications?
- Need to remain completely BSD licensed so that it is possible that it
  might some day be incorporated in the standard distribution.

So I gave up on it as it seem to me much to much work for not enough 
ROI, but I still would welcome anyone giving it a shot :-)


--
mph

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


Firefox: all I get is XML page source code

2010-04-18 Thread Gnarlodious
Wit's end on this. I have a script outputting a stream with:
sys.stdout.buffer.write(("""\n

The script works normally in 2 browsers, but in Firefox all I see is
source code.

Also, running the script in iPhone from my server shows the same
source code. Which is a little strange since iPhone and Safari both
use Webkit. This occurs also on my home dev server.

I attempted to validate the output but all I get is error:


 Sorry, I am unable to validate this document because its content type
is text/plain, which is not currently supported by this service.
The Content-Type header is sent by your web server (or web browser if
you use the file upload interface) and depends on its configuration.
Commonly, web servers will have a mapping of filename extensions (such
as ".html") to MIME Content-Type values (such as text/html).
That you received this message can mean that your server is not
configured correctly, that your file does not have the correct
filename extension, or that you are attempting to validate a file type
that we do not support yet.


Is the output stream not recognized because of the
sys.stdout.buffer.write statement?

This is a Python3 script ending with .py. Server is Apache 2.  Hope
someone can explain.

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


Re: Usable street address parser in Python?

2010-04-18 Thread John Roth
On Apr 17, 1:23 pm, John Nagle  wrote:
>    Is there a usable street address parser available?  There are some
> bad ones out there, but nothing good that I've found other than commercial
> products with large databases.  I don't need 100% accuracy, but I'd like
> to be able to extract street name and street number for at least 98% of
> US mailing addresses.
>
>    There's pyparsing, of course. There's a street address parser as an
> example at "http://pyparsing.wikispaces.com/file/view/streetAddressParser.py";.
> It's not very good.  It gets all of the following wrong:
>
>         1500 Deer Creek Lane    (Parses "Creek" as a street type")
>         186 Avenue A            (NYC street)
>         2081 N Webb Rd          (Parses N Webb as a street name)
>         2081 N. Webb Rd         (Parses N as street name)
>         1515 West 22nd Street   (Parses "West" as name)
>         2029 Stierlin Court     (Street names starting with "St" misparse.)
>
> Some special cases that don't work, unsurprisingly.
>         P.O. Box 33170
>         The Landmark @ One Market, Suite 200
>         One Market, Suite 200
>         One Market
>
> Much of the problem is that this parser starts at the beginning of the string.
> US street addresses are best parsed from the end, says the USPS.  That's why
> things like "Deer Creek Lane" are mis-parsed.  It's not clear that regular
> expressions are the right tool for this job.
>
> There must be something out there a little better than this.
>
>                                         John Nagle

You have my sympathy. I used to work on the address parser module at
Trans Union, and I've never seen another piece of code that had as
many special cases, odd rules and stuff that absolutely didn't make
any sense until one of the old hands showed you the situation it was
supposed to handle.

And most of those files were supposed to be up to USPS mass mailing
standards.

When the USPS says that addresses are best parsed from the end, they
aren't talking about the street address; they're talking about the
address as a whole, where it's easiest if you look for a zip first,
then the state, etc. The best approach I know of for the street
address is simply to tokenize the thing, and then do some pattern
matching. Trying to use any kind of deterministic parser is going to
fail big time.

IMO, 98% is way too high for any module except one that's been given a
lot of love by a company that does this as part of their core
business. There's a reason why commercial products come with huge data
bases -- it's impossible to parse everything correctly with a single
set of rules. Those data bases also contain the actual street names
and address ranges by zip code, so that direct marketing files can be
cleansed to USPS standards.

That said, I don't see any reason why any of the examples in your
first group should be misparsed by a competent parser.

Sorry I don't have any real help for you.

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


Re: Firefox: all I get is XML page source code

2010-04-18 Thread Gnarlodious
Thanks for that, for some reason I assumed sys.stdout.buffer.write
sent the http header but I was wrong.

Even so, Firefox still refused to render prperly, but this works/:

content-type: application/xhtml+xml; charset=utf-8\n\n

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


Re: getting a string as the return value from a system command

2010-04-18 Thread Robert Kern

On 2010-04-18 03:13 , TomF wrote:

On 2010-04-16 12:06:13 -0700, Catherine Moroney said:


Hello,

I want to call a system command (such as uname) that returns a string,
and then store that output in a string variable in my python program.

What is the recommended/most-concise way of doing this?

I could always create a temporary file, call the "subprocess.Popen"
module with the temporary file as the stdout argument, and then
re-open that temporary file and read in its contents. This seems
to be awfully long way of doing this, and I was wondering about
alternate ways of accomplishing this task.

In pseudocode, I would like to be able to do something like:
hostinfo = subprocess.Popen("uname -srvi") and have hostinfo
be a string containing the result of issuing the uname command.


Here is the way I do it:

import os
hostinfo = os.popen("uname -srvi").readline().strip()

(I add a strip() call to get rid of the trailing newline.)

os.popen has been replaced by the subprocess module, so I suppose the
new preferred method is:

from subprocess import Popen, PIPE
hostinfo = Popen(["uname", "-srvi"], stdout=PIPE).communicate()[0].strip()


Looks ugly to me, but there we are.


The easy way to fix things that look ugly but are the right thing to do is to 
wrap them up into a utility function and call the utility function everywhere.


--
Robert Kern

"I have come to believe that the whole world is an enigma, a harmless enigma
 that is made terrible by our own mad attempt to interpret it as though it had
 an underlying truth."
  -- Umberto Eco

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


Re: Firefox: all I get is XML page source code

2010-04-18 Thread MRAB

Gnarlodious wrote:

Thanks for that, for some reason I assumed sys.stdout.buffer.write
sent the http header but I was wrong.

Even so, Firefox still refused to render prperly, but this works/:

content-type: application/xhtml+xml; charset=utf-8\n\n


Perhaps it's not so much that there's a problem with Firefox but that
the other browsers are guessing what the content type should be if it's
missing. (Refusing to guess is a Pythonic trait. :-))
--
http://mail.python.org/mailman/listinfo/python-list


Default paranmeter for packed values

2010-04-18 Thread Xavier Ho
G'day Pythoneers,

I ran into a strange problem today: why does Python not allow default
paranmeters for packed arguments in a function def?

>>> def test(a = 1, b = (2, 3)):
... print a, b
...
>>> test()
1 (2, 3)

>>> def t(a, *b = (3, 4)):
  File "", line 1
def t(a, *b = (3, 4)):
^
SyntaxError: invalid syntax

What was the rationale behind this design?

Cheers,

Ching-Yun Xavier Ho, Technical Artist

Contact Information
Mobile: (+61) 04 3335 4748
Skype ID: SpaXe85
Email: cont...@xavierho.com
Website: http://xavierho.com/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Default paranmeter for packed values

2010-04-18 Thread MRAB

Xavier Ho wrote:

G'day Pythoneers,

I ran into a strange problem today: why does Python not allow default 
paranmeters for packed arguments in a function def?



>> def test(a = 1, b = (2, 3)):

... print a, b
...

>> test()

1 (2, 3)


>> def t(a, *b = (3, 4)):

  File "", line 1
def t(a, *b = (3, 4)):
^
SyntaxError: invalid syntax

What was the rationale behind this design?


Perhaps it was that no-one ever thought of doing that! :-)
--
http://mail.python.org/mailman/listinfo/python-list


Re: Default paranmeter for packed values

2010-04-18 Thread Chris Rebert
On Sun, Apr 18, 2010 at 4:23 PM, Xavier Ho  wrote:
> I ran into a strange problem today: why does Python not allow default
> paranmeters for packed arguments in a function def?
>
 def test(a = 1, b = (2, 3)):
> ... print a, b
> ...
 test()
> 1 (2, 3)
>
 def t(a, *b = (3, 4)):
>   File "", line 1
>     def t(a, *b = (3, 4)):
>     ^
> SyntaxError: invalid syntax
>
> What was the rationale behind this design?

It's not specific to default arguments:

*z = (1,2,3) #==>

  File "", line 1
*z = (1,2,3)
SyntaxError: starred assignment target must be in a list or tuple

It doesn't really make sense to use * in such situations anyway, you
can just do the normal `z = (1,2,3)`.

Cheers,
Chris
--
http://blog.rebertia.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Default paranmeter for packed values

2010-04-18 Thread Stephen Hansen
On Sun, Apr 18, 2010 at 4:23 PM, Xavier Ho  wrote:

> G'day Pythoneers,
>
> I ran into a strange problem today: why does Python not allow default
> paranmeters for packed arguments in a function def?
> >>> def t(a, *b = (3, 4)):
>   File "", line 1
> def t(a, *b = (3, 4)):
> ^
> SyntaxError: invalid syntax
>
> What was the rationale behind this design?
>

Why doesn't Python allow this? Because it just doesn't. I'm not sure there's
so much as a rationale why its not that way, but there's no rationale for it
to BE that way.

A default argument is an argument which is optional, but has a default
value. *args and **kwargs are unknown optional additional arguments. I'm not
sure how you can logically combine the two premises. They are sort of
mutually exclusive, the only similarity is both are 'optional'. They're just
entirely different ways to achieve Optionality.

And since no one's ever wanted it that I can ever remember, it seems to be a
rare sort of use-case, which you could probably easily satisfy by:

def t(a, *b):
if not b:
b = (2,3)
...

Its a similar pattern to using None as the value of an optional argument as
a sentinel, to then assign the real 'default' value to it once in the
function (this pattern is used when said real default value is mutable, of
course).


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


Re: Default paranmeter for packed values

2010-04-18 Thread Xavier Ho
On Mon, Apr 19, 2010 at 9:46 AM, Chris Rebert  wrote:

> It doesn't really make sense to use * in such situations anyway, you
> can just do the normal `z = (1,2,3)`


But calling function(1.0, (0.0, 1.0, 0.0)) has been a big pet peeve of mine,
and it looks extremely ugly and, imo, unpythonic.

On Mon, Apr 19, 2010 at 9:54 AM, Stephen Hansen wrote:
def t(a, *b):
if not b:
b = (2,3)
...

Brilliant! I can live with that. =D
def t(a, *b):
if not b:
b = (2, 4)
print a, b

t(1)
1 (2, 4)
t(1, 3, 4)
1 (3, 4)
t(1, 3, 4, 5)
1 (3, 4, 5)

Cheers,
Xav
-- 
http://mail.python.org/mailman/listinfo/python-list


The ole Repetion != Concatination pitfall

2010-04-18 Thread JChG
Well I started learning Python last week, and in my first experiment I
got caught when I changed:

sieve = [ {1:True} for x in range(r)]
to
sieve = [{1:True}] * r

I was expecting it to be equivalent to
sieve = [{1:True},{1:True},...]
but instead it's
t = [{1:True}]; sieve = [t,t,...]

Okay, I see this was discussed 13 years ago, and it's a deliberate
choice.  There are other ways to do this.

But I'll still whine anyway...I'm not seeing where list repetition is
particularly useful, except when you want independent objects, like my
initialization of sieve above.  Oh well, I guess I'll just avoid it.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Default paranmeter for packed values

2010-04-18 Thread alex23
Xavier Ho wrote:
> I ran into a strange problem today: why does Python not allow default
> paranmeters for packed arguments in a function def?

>> >> def t(a, *b = (3, 4)):
>   File "", line 1
>     def t(a, *b = (3, 4)):
>                 ^
> SyntaxError: invalid syntax

> What was the rationale behind this design?

Possibly because what you're calling 'packed arguments' are really
_arbitrary_ arguments, that is, it catches those that aren't defined
in the function signature. If you want default values, you should use
default arguments.

Of course, you can always get around it with this old chestnut:

def t(a, *b):
  if not len(b): b = (3, 4)
  ...
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: python wia and RegisterEvent

2010-04-18 Thread Roger Upole
gelonida wrote:
...
> while True:
> print "sleep"
> time.sleep(10)
>
>When I plug / unplug a USB WIA device nothing shows up.
> My C# implementation prints messages on wiaEventDeviceConnected /
> wiaEventDeviceDisconnected events if I register them.
>
> What am I missing?

You need to be processing messages to receive COM events.
Try replacing your sleep loop with pythoncom.PumpMessages().

 Roger




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


Re: How to read file during module import?

2010-04-18 Thread HigStar
On Apr 13, 4:03 am, "Gabriel Genellina" 
wrote:
> En Sun, 11 Apr 2010 19:43:03 -0300,HigStar escribió:
>
> > I have had trouble with the __file__ attribute in the past, when using
> > py2exe (i.e. on the windows platform) and using the bundle feature
> > (which zips all files).
> > Using os.path.realpath( __file__ ) resolves to something like .../
> > library.zip/packageName/fileName
> > Then when trying to perform an open on a file, say .../library.zip/
> > packageName/supportingPackageName, the file can not be found.
>
> Use pkgutil.get_data 
> then:http://docs.python.org/library/pkgutil.html#pkgutil.get_data
>
> --
> Gabriel Genellina

Thanks Gabriel.
I should have been more specific with my example, the problem I had
was when trying to reference a non python file, so something like .../
library.zip/packageName/supportingDll.dll or .../library.zip/
packageName/supportingConfigFile.ini
For the DLL case, adding the directory that __file__ lives in to the
os.environ["PATH"] doesn't work.

Cheers

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


UnicodeEncodeError during repr()

2010-04-18 Thread gb345



I'm getting a UnicodeEncodeError during a call to repr:

Traceback (most recent call last):
  File "bug.py", line 142, in 
element = parser.parse(INPUT)
  File "bug.py", line 136, in parse 
ps = Parser.Parse(open(filename,'r').read(), 1)
  File "bug.py", line 97, in end_item 
r = repr(CURRENT_ENTRY)
UnicodeEncodeError: 'ascii' codec can't encode character u'\u3003' in position 
0: o\
rdinal not in range(128)

This is what CURRENT_ENTRY.__repr__ looks like:

   def __repr__(self):
k = SEP.join(self.k)
r = SEP.join(self.r)
s = SEP.join(self.s)
ret = u'\t'.join((k, r, s))
print type(ret)  # prints "", as expected
return ret

If I "inline" this CURRENT_ENTRY.__repr__ code so that the call to
repr(CURRENT_ENTRY) can be bypassed altogether, then the error
disappears.

Therefore, it is clear from the above that the problem, whatever
it is, occurs during the execution of the repr() built-in *after*
it gets the value returned by CURRENT_ENTRY.__repr__.  It is also
clearly that repr is trying to encode something using the ascii
codec, but I don't understand why it needs to encode anything.

Do I need to do something especial to get repr to work strictly
with unicode?

Or should __repr__ *always* return bytes rather than unicode?  What
about __str__ ?  If both of these are supposed to return bytes,
then what method should I use to define the unicode representation
for instances of a class?

Thanks!

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


Re: feature request for a wget -r like implementation in python3

2010-04-18 Thread gert
On Apr 16, 3:41 am, alex23  wrote:
> On Apr 16, 5:37 am, gert  wrote:
>
> > So I can make a recursive http download script
> > My goal is a one click instruction to install and launch my 
> > projecthttp://code.google.com/p/appwsgi/
>
> Here's Guido's take on wget:
>
>     import sys, urllib
>     def reporthook(*a): print a
>     for url in sys.argv[1:]:
>          i = url.rfind('/')
>          file = url[i+1:]
>          print url, "->", file
>          urllib.urlretrieve(url, file, reporthook)
>
> If you extend this, you can offer an easy-download-and-run python
> script that does the installation you want.
>

Guido is not talking about the same wget -r I think
I expected something like this

def hook(url):print(url)
def dir(url):
with urllib.request.urlopen(url) as f:
for u in f:
s=u.decode('latin1')
m=re.search('.*href="([^\.].*)"',s)
if m:
t=url+m.group(1)
if t[-1]=='/': dir(t)
else:
d=os.path.dirname(t[33:])
if d=='': d='./'
if not os.path.exists(d):
os.makedirs(os.path.dirname(t[33:]))
urllib.request.urlretrieve(t,t[33:],hook(t))
dir('http://appwsgi.googlecode.com/hg/')

How do I get rit of 33:

> But why duplicate existing effort? Why not pip[1]?
> 1:http://pypi.python.org/pypi/pip

pip is a chainsaw, I need a pocket knife

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


Re: feature request for a wget -r like implementation in python3

2010-04-18 Thread gert
On Apr 17, 1:14 am, "Gabriel Genellina" 
wrote:
> En Thu, 15 Apr 2010 16:37:37 -0300, gert  escribió:
>
> > [a wget -r like implementation in python3]
> > So I can make a recursive http download script
>
> What about calling wget itself? subprocess.call(['wget',...])
>

The only dependency I would like is python3
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: The ole Repetion != Concatination pitfall

2010-04-18 Thread Steven D'Aprano
On Sun, 18 Apr 2010 17:34:03 -0700, JChG wrote:

> But I'll still whine anyway...I'm not seeing where list repetition is
> particularly useful, except when you want independent objects, like my
> initialization of sieve above.


Or when the objects are immutable, like ints, strings or None.


pre_allocated = [None]*100
while condition:
i = get_index()
pre_allocated[i] = get_result()





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


Python 2.6 SSL module: Fails on key file error, with Errno 336265225, without a key file.

2010-04-18 Thread John Nagle

I'm starting to convert from M2Crypto to Python 2.6's SSL
module. So I tried a trivial test:

import ssl
import socket
certs = "d:/projects/sitetruth/certificates/cacert.pem"
sk = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
ssk = ssl.wrap_socket(sk, certfile=certs, cert_reqs=ssl.CERT_NONE)
ssk.connect(("www.verisign.com",443))

This is a basic HTTPS open sequence.

This yields:

Traceback (most recent call last):
  File "", line 1, in 
  File "D:\python26\lib\ssl.py", line 307, in connect
self.ca_certs)
ssl.SSLError: [Errno 336265225] _ssl.c:337:
 error:140B0009:SSL routines:SSL_CTX_use_PrivateKey_file:PEM lib

The cert file is the same PEM file I use with M2Crypto, and it's
derived from Firefox's cert file.

Why am I getting a "private key" related error?  I'm not submitting a keyfile,
just a cert file.

I've tried explicitly adding "keyfile=None" to the wrap_socket call, but
that doesn't change anything.

Python version: '2.6.1 (r261:67517, Dec  4 2008, 16:51:00) [MSC v.1500 32 bit 
(Intel)]'


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


paypal wholesale d&g shoes (paypal payment)

2010-04-18 Thread world-trade
paypal wholesale d&g shoes (paypal payment)
( http://www.jordanonline06.com/)
paypal wholesale gucci shoes (paypal payment)
( http://www.jordanonline06.com/)
paypal wholesale lv shoes (paypal payment)
( http://www.jordanonline06.com/)
paypal wholesale NBA shoes (paypal payment)
( http://www.jordanonline06.com/ )
paypal wholesale nike (paypal payment)
( http://www.jordanonline06.com/ )
paypal wholesale adidas shoes (paypal payment)
( http://www.jordanonline06.com/)
paypal wholesale chanel  shoes (paypal payment)
( http://www.jordanonline06.com/ )
paypal wholesale bape hoody (paypal payment)
( http://www.jordanonline06.com/)
paypal wholesale antick jeans (paypal payment)
( http://www.jordanonline06.com/ )
paypal wholesale diesel jeans (paypal payment)
( http://www.jordanonline06.com/)
paypal wholesale artful dudger (paypal payment)
( http://www.jordanonline06.com/)
paypal wholesale bag(lv gucci coach chanel d&g dior ed  fendi )
(paypal payment)(http://www.jordanonline06.com/)
paypal wholesale clothing (paypal payment)
( http://www.jordanonline06.com/ )
paypal wholesale lrg,jeans,hoody, (paypal payment)
( http://www.jordanonline06.com/)
paypal wholesale evisu jeans,hoody,shirt (paypal payment)
( http://www.jordanonline06.com/)

paypal wholesale Prada (paypal payment)
( http://www.jordanonline06.com/)
paypal wholesale Puma (paypal payment)( http://www.jordanonline06.com/)
paypal wholesale Sand (paypal payment)( http://www.jordanonline06.com/)
paypal wholesale Shox (paypal payment)( http://www.jordanonline06.com/)
paypal wholesale soccer (paypal payment)
( http://www.jordanonline06.com/ )
paypal wholesale lv(paypal payment)( http://www.jordanonline06.com/)
paypal wholesale Versace (paypal payment)
( http://www.jordanonline06.com/ )
paypal wholesale Women (paypal payment)
( http://www.jordanonline06.com/)
paypal wholesale Y-3 (paypal payment)( http://www.jordanonline06.com/
)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Default paranmeter for packed values

2010-04-18 Thread Gregory Ewing

MRAB wrote:

Xavier Ho wrote:


>> def t(a, *b = (3, 4)):


  File "", line 1
def t(a, *b = (3, 4)):
^
SyntaxError: invalid syntax

What was the rationale behind this design?


The concept of a default value for the * argument doesn't
really apply, because there is always a value for it, even
if it's just an empty tuple.

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


Operations on sparse matrices

2010-04-18 Thread pp
I am currently dealing with sparse matrices and have doubts on whether
we can use
1.) dot (for matrix multiplication) and inv (inverse) operations of
numpy on sparse matrices of CSR format.

I initially constructed my sparse matrix using COO format and then
converted it to CSR format now I want to know whether normal inverse
and matrix multiplications work with sparse csr matrices.

Also can these operations be applied directly to csr matrices


Thanks a lot
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Usable street address parser in Python?

2010-04-18 Thread Paul McGuire
On Apr 17, 2:23 pm, John Nagle  wrote:
>    Is there a usable street address parser available?  There are some
> bad ones out there, but nothing good that I've found other than commercial
> products with large databases.  I don't need 100% accuracy, but I'd like
> to be able to extract street name and street number for at least 98% of
> US mailing addresses.
>
>    There's pyparsing, of course. There's a street address parser as an
> example at "http://pyparsing.wikispaces.com/file/view/streetAddressParser.py";.
> It's not very good.  It gets all of the following wrong:
>
>         1500 Deer Creek Lane    (Parses "Creek" as a street type")
>         186 Avenue A            (NYC street)
>         2081 N Webb Rd          (Parses N Webb as a street name)
>         2081 N. Webb Rd         (Parses N as street name)
>         1515 West 22nd Street   (Parses "West" as name)
>         2029 Stierlin Court     (Street names starting with "St" misparse.)
>
> Some special cases that don't work, unsurprisingly.
>         P.O. Box 33170
>         The Landmark @ One Market, Suite 200
>         One Market, Suite 200
>         One Market
>

Please take a look at the updated form of this parser.  It turns out
there actually *were* some bugs in the old form, plus there was no
provision for PO Boxes, avenues that start with "Avenue" instead of
ending with them, or house numbers spelled out as words.  The only one
I consider a "special case" is the support for "Avenue X" instead of
"X Avenue" - adding support for the rest was added in a fairly general
way.  With these bug fixes, I hope this improves your hit rate. (There
are also some simple attempts at adding apt/suite numbers, and APO and
AFP in addition to PO boxes - if not exactly what you need, the means
to extend to support other options should be pretty straightforward.)

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


Re: Usable street address parser in Python?

2010-04-18 Thread Stefan Behnel

John Nagle, 17.04.2010 21:23:

  Is there a usable street address parser available?


What kind of street address are you talking about? Only US-American ones?

Because street addresses are spelled differently all over the world. Some 
have house numbers, some use letters or a combination, some have no house 
numbers at all. Some use ordinal numbers, others use regular numbers. Some 
put the house number before the street name, some after it. And this is 
neither a comprehensive list, nor is this topic finished after parsing the 
line that gives you the street (assuming there is such a thing in the first 
place).


Stefan

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


About the grammar

2010-04-18 Thread franck
Dear all,

I'm wondering why in Python's grammar, keyword arguments are specified
as:

argument: ... | test '=' test

I would have expected something like

argument: ... | NAME '=' test

Indeed, I cannot imagine a case where the keyword is something else
than an identifier. Moreover, in the Python language reference (see
http://docs.python.org/reference/expressions.html#grammar-token-keyword_item)
one can read:

keyword_item ::= identifier "=" expression

which is what I was expecting.

Does any one knows why the grammar is so coded? Any intuition?

Thanks in advance!
Franck
-- 
http://mail.python.org/mailman/listinfo/python-list


help req debugging python and c together

2010-04-18 Thread sanam singh

Hi,
I am working in gnuradio compiler. I need some help in debugging python and c 
together.
By this i mean that i have written some blocks in c that are connected together 
using python. So i need to debug( breakpoints ect ) python such that when a 
specific c block is called at the back end  (in python script ) the debugger 
takes me into the c code and after that switches back to python and so on.

Thanks in advance.
Regards,
Sanam
  
_
Hotmail: Powerful Free email with security by Microsoft.
https://signup.live.com/signup.aspx?id=60969-- 
http://mail.python.org/mailman/listinfo/python-list


Re: About the grammar

2010-04-18 Thread Steven D'Aprano
On Sun, 18 Apr 2010 23:29:44 -0700, franck wrote:

> Dear all,
> 
> I'm wondering why in Python's grammar, keyword arguments are specified
> as:
> 
> argument: ... | test '=' test


Where are you finding that?


> I would have expected something like
> 
> argument: ... | NAME '=' test
> 
> Indeed, I cannot imagine a case where the keyword is something else than
> an identifier. Moreover, in the Python language reference (see
> http://docs.python.org/reference/expressions.html#grammar-token-
keyword_item)
> one can read:
> 
> keyword_item ::= identifier "=" expression
> 
> which is what I was expecting.

This tells you that keyword arguments cannot have keywords that aren't 
identifiers:

>>> sum(1=2)
  File "", line 1
SyntaxError: keyword can't be an expression


The only thing I can think of is that you're extrapolating from use cases 
like this:


>>> def f(x):
... return x
...
>>> x=2
>>> f(x=x)
2

But that's just a special case of this:

>>> y=2
>>> f(x=y)
2


Of course, I could be completely misunderstanding what you mean.




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