Python-URL! - weekly Python news and links (Aug 6)

2009-08-07 Thread Gabriel Genellina
QOTW:  The economy rises and falls, money comes and goes, but a great
conference has permanent good effects.  Well, a lot more permanent than
government fiscal policy, anyway. - Python Software Foundation Director
bitter-in-victory-gracious-in-defeat-ly y'rs timbot


Is python free of buffer overflow errors?
http://groups.google.com/group/comp.lang.python/t/a31faac6feced289/

Lessons learned in implementation of a write-once dict:
http://groups.google.com/group/comp.lang.python/t/bc8b91669257e246/

Methods, attributes, iterators, lambdas, and how Ruby handles them:
http://groups.google.com/group/comp.lang.python/t/6e4fc61946513405/

Python 3 allows for custom types to be used as a class namespace 
not just dicts):
http://groups.google.com/group/comp.lang.python/t/50caadd10d2cca16/

Could Python be used to write a device driver?
http://groups.google.com/group/comp.lang.python/t/4efc28f9fe45b69e/

The various meanings of the underscore character '_' in identifiers:
http://groups.google.com/group/comp.lang.python/t/e32d577ad3d5a208/

Generate a new object each time a name is imported:
http://groups.google.com/group/comp.lang.python/t/b7112f74e2efa8bd/

heapq.nlargest takes a key argument - why not the other functions in
the same module?
http://groups.google.com/group/comp.lang.python/t/a5095d3f4b54f79b/

Immutable objects and how they could improve concurrency [old thread,
still alive]:

http://groups.google.com/group/comp.lang.python/t/cb0cf56c52321ccc/5c82cd09767ba85a?#5c82cd09767ba85a

How to modify a variable in an outer (non global) scope:
http://groups.google.com/group/comp.lang.python/t/e0e64250bd82825f/

Best way to add private directories to sys.path:
http://groups.google.com/group/comp.lang.python/t/cb43cf90d72f6833/

Interval arithmetic:
http://groups.google.com/group/comp.lang.python/t/71f050d8f5987244/

Ensure that no more than three instances of the same program are
running at the same time:
http://groups.google.com/group/comp.lang.python/t/af7ae6429c2bda1e/

Some people don't like the way Python documentation is managed/presented:
http://groups.google.com/group/comp.lang.python/t/a52b22cd90b15ef8/



Everything Python-related you want is probably one or two clicks away in
these pages:

Python.org's Python Language Website is the traditional
center of Pythonia
http://www.python.org
Notice especially the master FAQ
http://www.python.org/doc/FAQ.html

PythonWare complements the digest you're reading with the
marvelous daily python url
 http://www.pythonware.com/daily

Just beginning with Python?  This page is a great place to start:
http://wiki.python.org/moin/BeginnersGuide/Programmers

The Python Papers aims to publish the efforts of Python enthusiasts:
http://pythonpapers.org/
The Python Magazine is a technical monthly devoted to Python:
http://pythonmagazine.com

Readers have recommended the Planet sites:
http://planetpython.org
http://planet.python.org

comp.lang.python.announce announces new Python software.  Be
sure to scan this newsgroup weekly.
http://groups.google.com/group/comp.lang.python.announce/topics

Python411 indexes podcasts ... to help people learn Python ...
Updates appear more-than-weekly:
http://www.awaretek.com/python/index.html

The Python Package Index catalogues packages.
http://www.python.org/pypi/

Much of Python's real work takes place on Special-Interest Group
mailing lists
http://www.python.org/sigs/

Python Success Stories--from air-traffic control to on-line
match-making--can inspire you or decision-makers to whom you're
subject with a vision of what the language makes practical.
http://www.pythonology.com/success

The Python Software Foundation (PSF) has replaced the Python
Consortium as an independent nexus of activity.  It has official
responsibility for Python's development and maintenance.
http://www.python.org/psf/
Among the ways you can support PSF is with a donation.
http://www.python.org/psf/donations/

The Summary of Python Tracker Issues is an automatically generated
report summarizing new bugs, closed ones, and patch submissions. 

http://search.gmane.org/?author=status%40bugs.python.orggroup=gmane.comp.python.develsort=date

Although unmaintained since 2002, the Cetus collection of Python
hyperlinks retains a few gems.
http://www.cetus-links.org/oo_python.html

Python FAQTS
http://python.faqts.com/

The Cookbook is a collaborative effort to capture useful and
interesting recipes.

Re: how to kill subprocess when Python process is killed?

2009-08-07 Thread alex23
On Aug 7, 3:42 pm, mark.v.we...@gmail.com mark.v.we...@gmail.com
wrote:
 When I kill the main process (cntl-C) the subprocess keeps running.
 How do I kill the subprocess too? The subprocess is likey to run a
 long time.

You can register functions to run when the Python process ends by
using the atexit[1] module.

The following has been tested  works under Python 2.6 on Windows XP:

import atexit

def cleanup():
print 'stop the subprocess in here'

atexit.register(cleanup)

while True:
pass


[1]: http://docs.python.org/library/atexit.html
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: SDMX format

2009-08-07 Thread Stefan Behnel
xamdam wrote:
 Does anyone know of python libs for writing SDMX XML format?
 http://www.SDMX.org/resources/SDMXML/schemas/v2_0/common

Looks like the page behind that link is broken, but in general, working
with XML formats in Python isn't hard at all when you use ElementTree or
lxml. The latter also has support for XML-Schema validation, and you might
be interested in lxml.objectify for handling data centric XML formats
(assuming that's the case here).

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


Re: How to fetch an XML file using an HTTPS query

2009-08-07 Thread Stefan Behnel
Tycho Andersen wrote:
 Blah, forgot to include the list. When is python-list going to get Reply-To?

Hopefully never.

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


Re: How to force SAX parser to ignore encoding problems

2009-08-07 Thread Stefan Behnel
Łukasz wrote:
 I have a problem with my XML parser (created with libraries from
 xml.sax package). When parser finds a invalid character (in CDATA
 section) for example �, throws an exception SAXParseException.
 
 Is there any way to just ignore this kind of problem. Maybe there is a
 way to set up parser in less strict mode?
 
 I know that I can catch this exception and determine if this is this
 kind of problem and then ignore this, but I am asking about any global
 setting.

The parser from libxml2 that lxml provides has a recovery option, i.e. it
can keep parsing regardless of errors and will drop the broken content.

However, it is *always* better to fix the input, if you get any hand on it.
Broken XML is *not* XML at all. If you can't fix the source, you can never
be sure that the data you received is in any way complete or even usable.

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


Re: help with threads

2009-08-07 Thread Michael Mossey
Ah yes, that explains it. Some of these long computations are done in
pure C, so I'm sure the GIL is not being released.
Thanks.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Generators through the C API

2009-08-07 Thread Stefan Behnel
Duncan Booth schrieb:
 Lucas P Melo lukepada...@gmail.com wrote:
 
 Hello, I'm a total noob about the C API. Is there any way to create a 
 generator function using the C API? I couldn't find anything like the 
 'yield' keyword in it.

 Thanks in advance.
 
 You define a new type with tp_flags including Py_TPFLAGS_HAVE_ITER. 
 Anything that would be a local variable in your generator needs to become 
 an attribute in the type.
 
 The tp_init initialization function should contain all the code up to the 
 first yield, tp_iter should return self and tp_iternext should execute code 
 up to the next yield.

This is pretty easy to do in Cython (or Pyrex), BTW. Just write a class
with an __iter__ and __next__ method, and Cython will generate the C-API
code as expected.

http://docs.cython.org/docs/special_methods.html#iterators

Note that Cython doesn't currently support the yield statement, but
that's certainly on the ToDo list.

http://trac.cython.org/cython_trac/ticket/83

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


Re: Re: Web page data and urllib2.urlopen

2009-08-07 Thread Kushal Kumaran
On Fri, Aug 7, 2009 at 3:47 AM, Dave Angelda...@ieee.org wrote:


 Piet van Oostrum wrote:

 snip

 DA All I can guess is that it has something to do with browser type or
 DA cookies.  And that would make lots of sense if this was a cgi page.
  But
 DA the URL doesn't look like that, as it doesn't end in pl, py, asp, or
 any of
 DA another dozen special suffixes.


Note that the URL does not have to have any special suffix for it to
be dynamically generated.  See any page at wikipedia, for example.
Mediawiki, the software running the site, is a php application.




 DA Any hints, anybody???


 If you look into the HTML that Firefox gets, there is a lot of
 javascript in it.


 But the raw page didn't have any javascript.  So what about that original
 raw page triggered additional stuff to be loaded?

FWIW, I'm getting a ton of javascript in the page downloaded using
your code fragment.

 Is it user agent, as someone else brought out?  And is there somewhere I
 can read more about that aspect of things?  I've mostly built very static
 html pages, where the server yields the same page to everybody.  And some
 form stuff, where the  user clicks on a 'submit button to trigger a script
 that's not shown on the URL line.


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


Re: Special chars with HTMLParser

2009-08-07 Thread Stefan Behnel
Fafounet wrote:
 I am parsing a web page with special chars such as #xE9; (which
 stands for é).
 I know I can have the unicode character é from unicode
 (\xe9,iso-8859-1)
 but with those extra characters I don' t know.
 
 I tried to implement handle_charref within HTMLParser without success.
 Furthermore, if I have the data ab#xE9;cd, handle_data will get ab,
 handle_charref will get xe9 and then handle_data doesn't have the end
 of the string (cd).

Any reason you can't use a tree based HTML parser like the one in
lxml.html? That would eliminate this kind of problem altogether, as you'd
always get a well-decoded unicode string from the tree content.

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


Re: unicode() vs. s.decode()

2009-08-07 Thread Mark Lawrence

Michael Ströder wrote:

Thorsten Kampe wrote:

* Michael Ströder (Thu, 06 Aug 2009 18:26:09 +0200)

timeit.Timer(unicode('äöüÄÖÜß','utf-8')).timeit(1000)

17.23644495010376

timeit.Timer('äöüÄÖÜß'.decode('utf8')).timeit(1000)

72.087096929550171

That is significant! So the winner is:

unicode('äöüÄÖÜß','utf-8')
Unless you are planning to write a loop that decodes äöüÄÖÜß one 
million times, these benchmarks are meaningless.


Well, I can tell you I would not have posted this here and checked it if it
would be meaningless for me. You don't have to read and answer this thread if
it's meaningless to you.

Ciao, Michael.
I believe that the comment these benchmarks are meaningless refers to 
the length of the strings being used in the tests.  Surely something 
involving thousands or millions of characters is more meaningful? Or to 
go the other way, you are unlikely to write

for c in 'äöüÄÖÜß':
u = unicode(c, 'utf-8')
...
Yes?

--
Kindest regards.

Mark Lawrence.

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


Re: Parsing Binary Structures; Is there a better way / What is your way?

2009-08-07 Thread Hendrik van Rooyen
On Thursday 06 August 2009 20:50:30 Martin P. Hellwig wrote:
 Thanks all for your insights and suggestions.
 It seems to me that there are a couple of ways to this bit manipulation
 and a couple of foreign modules to assist you with that.

 Would it be worth the while to do a PEP on this?
 Personally I think that it would be nice to have a standard module in
 Python for this but perhaps there is a good reason that there isn't
 already one.

I agree that it would be nice - I think it would be nice if something
like this is added to the struct module to give a this is the obvious
way that python handles foreign data module

- Hendrik


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


Re: one method of COM object needs a variant type variable

2009-08-07 Thread MICHÁLEK Jan Mgr .
Thanks Gabriel,
I seen this before, but I don't know, what's mean 'compatible object'. I need 
create object who will like as an variant type.
Je.
it looks lieke this:
...
obj=win32com.client.Dispatch('Geomedia.PointGeometry') #geometry object
gss=win32com.client.Dispatch('Geomedia.GeometryStorageService')#geometry 
strorage object

gss.GeometryToStorage(obj, out) #out must be a variant type variable
.
oRS.Fields(Geometry).Value = out # writing blob into recordset via ADO
 
 
En Thu, 06 Aug 2009 09:37:55 -0300, MICHÁLEK Jan Mgr.  

Michalek.Jan at uhul.cz http://mail.python.org/mailman/listinfo/python-list 
 escribió:



 How i can use this type in win32.com? One method of com object (geomedia  

 storage service) needs this variable for storage geometry of geometry  

 object (this variable will be writen into blob in DB). Is possible make  

 this variable in py??



Any compatible object may be used on the Python side, the pywin32 library  

manages the conversion automatically.



See  

http://docs.activestate.com/activepython/2.4/pywin32/html/com/win32com/HTML/PythonCOM.html



-- 

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


Re: unicode() vs. s.decode()

2009-08-07 Thread Steven D'Aprano
On Fri, 07 Aug 2009 08:04:51 +0100, Mark Lawrence wrote:

 I believe that the comment these benchmarks are meaningless refers to
 the length of the strings being used in the tests.  Surely something
 involving thousands or millions of characters is more meaningful? Or to
 go the other way, you are unlikely to write for c in 'äöüÄÖÜß':
  u = unicode(c, 'utf-8')
  ...
 Yes?

There are all sorts of potential use-cases. A day or two ago, somebody 
posted a question involving tens of thousands of lines of tens of 
thousands of characters each (don't quote me, I'm going by memory). On 
the other hand, it doesn't require much imagination to think of a use-
case where there are millions of lines each of a dozen or so characters, 
and you want to process it line by line:


noun: cat
noun: dog
verb: café
...


As always, before optimizing, you should profile to be sure you are 
actually optimizing and not wasting your time.



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


Re: help with threads

2009-08-07 Thread Hendrik van Rooyen
On Friday 07 August 2009 05:02:10 Michael Mossey wrote:
 Hello,

 My problem is that in some cases, the network thread appears to stop,
 while the main thread is doing a long computation.

Is this computation done in pure python or are you calling some
underlying thing in C?

I would be surprised if a pure python computation thread were to hog
the cpu  - have you been able to figure out what the computation thread is
actually doing when the hogging occurs?

 I'm hoping someone can give me a general idea what to read about. For
 example, under what conditions does a thread stop running? Can other
 threads take priority? Are there certain operations that block other
 threads (such as disk access)?

AFAIK python threads are all at the same level of priority, and the running
thread is interrupted every N python bytecode instructions, so what you are
experiencing should not happen.

Try to figure out, if you can, where the computation thread is spending
its time.

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


Re: SMTP

2009-08-07 Thread Oli Schacher
Sarmad George schrieb:

 msg = Hello World

Your sending your message without any headers (no subject etc). So
probably your message lands in the recipients spam folder.

Try:
msg = To: recipi...@example.com
Subject: hello world

Hello there


The blank line between the headers and the body is important!

Also make sure to use a sender address that is allowed to send through
your smtp relay. yahoo.com sender is probably a bad idea. Check your
Yahoo Inbox, you might even have a bounce message there telling you that
the final mail server didn't accept your message.

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


Pywin32 @ windows 7

2009-08-07 Thread Algirdas Brazas

Hi all,

Did anyone manage to get windows extensions installet on windows 7 64 bit? As 
far as I try I get only Setup program invalid or damaged.


Al. 



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


Re: help with threads

2009-08-07 Thread Jean-Michel Pichavant

Michael Mossey wrote:

Hello,

I have a simple application that needs one thread to manage networking
in addition to the main thread that does the main job. It's not
working right. I know hardly anything about threads, so I was hoping
someone could point me in the right direction to research this.

Basically, I have a program that does some computational work, and
also conveys its status to a monitor program elsewhere on the network
via sockets. I wanted to use a thread to manage the networking so that
the main program can run without regard to networking (i.e. they would
be asynchronous). So the network thread loops and calls select.

My problem is that in some cases, the network thread appears to stop,
while the main thread is doing a long computation.

I'm hoping someone can give me a general idea what to read about. For
example, under what conditions does a thread stop running? Can other
threads take priority? Are there certain operations that block other
threads (such as disk access)?

Thanks,
Mike
  
I may be a little out of subject, anyway *if* you are writing also the 
server side program, you should really take a look at

http://docs.python.org/library/xmlrpclib.html
or
http://pyro.sourceforge.net/

... and forget about network coding :o)

To help you for your initial question, exceptions in thread are not 
propagated to the main thread, so when an unhanded exception occurs in 
your thread, it will just stop. Maybe this is what is happening.


A quick workaround is to embed all you threaded code in a try except 
clause and log the exception before re-raising it. You should only do 
that for debugging purpose.


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


Re: Python docs disappointing - group effort to hire writers?

2009-08-07 Thread Jean-Michel Pichavant

alex23 wrote:

Paul Rubin http://phr...@nospam.invalid wrote:
  

The PHP docs as I remember are sort of regular (non-publically
editable) doc pages, each of which has a public discussion thread
where people can post questions and answers about the topic of that
doc page.  I thought it worked really well.  The main thing is that
the good stuff from the comment section gets folded into the actual
doc now and then.



I'd still like to see this kept out of the official docs as much as
possible, mostly for reasons of brevity  clarity. I think the
official docs should be considered definitive and not require a
hermeneutic evaluation against user comments to ensure they're still
correct...

How about a secondary site that embeds the docs and provides
commenting functionality around it? That's certainly a finitely scoped
project that those with issues about the docs could establish and
contribute to, with the possibility of it gaining official support
later once it gains traction.



  
Very good Idea. I'd like to get a commented/user improved python 
documentation site with examples and I also love the current python 
documentation.


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


Re: Web page data and urllib2.urlopen

2009-08-07 Thread Piet van Oostrum
 Dave Angel da...@ieee.org (DA) wrote:

DA Piet van Oostrum wrote:
 snip
DA If Mozilla had seen a page with this line in an appropriate place, it'd
DA immediately begin loading the other page, at someotherurl  But there's no
DA such line.
 
 
 
DA Next, I looked for javascript.  The Mozilla page contains lots of
DA javascript, but there's none in the raw page.  So I can't explain Mozilla's
DA differences that way.
 
 
 
DA I did notice the link to /m/Content/mobile2.css, but I don' t know any way
DA a CSS file could cause the content to change, just the display.
 
 
 
DA All I can guess is that it has something to do with browser type or
DA cookies.  And that would make lots of sense if this was a cgi page.  But
DA the URL doesn't look like that, as it doesn't end in pl, py, asp, or any of
DA another dozen special suffixes.
 
 
 
DA Any hints, anybody???
 
 
 If you look into the HTML that Firefox gets, there is a lot of
 javascript in it.
 

DA But the raw page didn't have any javascript.  So what about that original
DA raw page triggered additional stuff to be loaded?
DA Is it user agent, as someone else brought out?  And is there somewhere I
DA can read more about that aspect of things?  I've mostly built very static
DA html pages, where the server yields the same page to everybody.  And some
DA form stuff, where the  user clicks on a 'submit button to trigger a script
DA that's not shown on the URL line.

Yes, if you specify a 'normal' web browser as user agent you do get the
Javascript:

import urllib2

request = 
urllib2.Request('http://www.marketwatch.com/story/mondays-biggest-gaining-and-declining-stocks-2009-07-27')
request.add_header('User-Agent', 'Mozilla/5.0 (Macintosh; U; Intel Mac OS X 
10.5; en-US; rv:1.9.0.13) Gecko/2009073021 Firefox/3.0.13')

opener = urllib2.build_opener() 
page = opener.open(request).read()
print page

-- 
Piet van Oostrum p...@cs.uu.nl
URL: http://pietvanoostrum.com [PGP 8DAE142BE17999C4]
Private email: p...@vanoostrum.org
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: problem

2009-08-07 Thread Piet van Oostrum
 sumit sumit.jh...@gmail.com (s) wrote:

s i want 2 hav the header files for regular expression to non
s deterministin autometa
s so whr should i find it?plz help

What header files? C? You can find lots of header files by googling. But
the header files contain only the interface, not the implementation. And
conversion from regular expression to non-deterministic automaton is an
implementation matter, so the header file will not help you there. You
will need the C or C++ file.

And then, do you want Python's implementation or any implementation.
Please be specific when you ask something.

Start by googling for regex.h for general software.
Python header file is in
http://svn.python.org/view/python/trunk/Modules/sre.h and the
implementation in http://svn.python.org/view/python/trunk/Modules/_sre.c
but I don't think it goes non deterministic. For that you can better
look into the general 'grep'-like software. For example start here:
http://arglist.com/regex/ 
-- 
Piet van Oostrum p...@cs.uu.nl
URL: http://pietvanoostrum.com [PGP 8DAE142BE17999C4]
Private email: p...@vanoostrum.org
-- 
http://mail.python.org/mailman/listinfo/python-list


How to reset document string

2009-08-07 Thread Anand K Rayudu

Dear All,

We have extended and embedded python into my our application.
We exposed few APIs to python using

Py_InitModule(myModuleName, myMethods);
where my methods are

static PyMethodDef VistaDbMethods[] = {
  { (char *)myAPI,_myAPICFunctionPtr ,METH_VARARGS,usage: MyHelp) }


Now problem is ml_doc (Document string). Most of the time the strings 
given by development team is not descriptive enough, so support team 
want to enhance these docstring on need basis and supply to customer
The idea is we will provide get latest help option from application, 
which will contact our webserver or allow user to pick new help 
document,  which will re apply the help on fly.

From then on our script editors will show the new enhanced help.
How do I achieve this.

I tried to change Module.MyAPI.__doc__ = My new doc

This failles as it is read only attribute.

Another approach could be calling  Py_InitModule(myModuleName, 
myMethods); with new help string. But It is not working,

So I am not sure what is the right way to do it

Thanks in advance for  all your kind help

Regards,
Anand



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


Re: unicode() vs. s.decode()

2009-08-07 Thread Thorsten Kampe
* Steven D'Aprano (06 Aug 2009 19:17:30 GMT)
 On Thu, 06 Aug 2009 20:05:52 +0200, Thorsten Kampe wrote:
   That is significant! So the winner is:
   
   unicode('äöüÄÖÜß','utf-8')
  
  Unless you are planning to write a loop that decodes äöüÄÖÜß one
  million times, these benchmarks are meaningless.
 
 What if you're writing a loop which takes one million different lines of 
 text and decodes them once each?
 
  setup = 'L = [abc*(n%100) for n in xrange(100)]'
  t1 = timeit.Timer('for line in L: line.decode(utf-8)', setup)
  t2 = timeit.Timer('for line in L: unicode(line, utf-8)', setup)
  t1.timeit(number=1)
 5.6751680374145508
  t2.timeit(number=1)
 2.682251165771
 
 Seems like a pretty meaningful difference to me.

Bollocks. No one will even notice whether a code sequence runs 2.7 or 
5.7 seconds. That's completely artificial benchmarking.

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


Re: Cython + setuptools not working with .pyx,only with .c-files

2009-08-07 Thread Diez B. Roggisch

David Cournapeau schrieb:

On Thu, Aug 6, 2009 at 7:38 PM, Diez B. Roggischde...@nospam.web.de wrote:

Hi,


I'm trying to build a Cython-extension as Egg.

However, this doesn't work - I can either use distutils to build the
extension, creating a myextension.c-file on the way.

If that's there, I can use setuptools to build the egg.

But when I remove the .c-file, the .pyx-file isn't used to re-generate it.

This is my setup.py:


import os
import glob
from setuptools import setup, Extension
#from distutils.core import setup
#from distutils.extension import Extension

from Cython.Distutils import build_ext


What happens if you import setuptools *after* Cython.distutils ? My
guess - I could be wrong - is that both Cython.distutils and
setuptools monkey-patch distutils, and that setuptools does not see
Cython.Distutils. It could also be an incompatibility between
Cython.Distutils and setuptools (the design of distutils forces you to
take into account the details of things modified by every distutils
extension).


Tried that, nothing changed :(

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


Re: need help with an egg

2009-08-07 Thread Diez B. Roggisch

jo schrieb:

Hi,

I am very new to python

I created an egg on a machine.  The Python version on that  is 2.5.
Copied that egg to a machine which has Python 2.6.

unzip -t Myproj-0.1-py2.5.egg
The above command shows all the files I need

When I run the easy_install, I get the foll. error.  Is it because of
the version?  Or am I doing something wrong?  Or the way I understand
the egg works is wrong.  Can anyone please help?
If it's the version issue, does that mean I cannot use that egg on my
machine with 2.6 version?

Installed /usr/local/lib/python2.6/dist-packages/Myproj-0.1-py2.5.egg
Processing dependencies for Myproj==0.1
Searching for Myproj==0.1
Reading http://pypi.python.org/simple/Myproj/
Couldn't find index page for 'Myproj' (maybe misspelled?)
Scanning index of all packages (this may take a while)
Reading http://pypi.python.org/simple/
No local packages or download links found for Myproj==0.1
error: Could not find suitable distribution for Requirement.parse
('Myproj==0.1')


Yes, eggs are (at least) python version specific. They can even be 
OS-specific.



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


Re: How to reset document string

2009-08-07 Thread Diez B. Roggisch

Anand K Rayudu schrieb:

Dear All,

We have extended and embedded python into my our application.
We exposed few APIs to python using

Py_InitModule(myModuleName, myMethods);
where my methods are

static PyMethodDef VistaDbMethods[] = {
  { (char *)myAPI,_myAPICFunctionPtr ,METH_VARARGS,usage: MyHelp) }


Now problem is ml_doc (Document string). Most of the time the strings 
given by development team is not descriptive enough, so support team 
want to enhance these docstring on need basis and supply to customer
The idea is we will provide get latest help option from application, 
which will contact our webserver or allow user to pick new help 
document,  which will re apply the help on fly.

 From then on our script editors will show the new enhanced help.
How do I achieve this.

I tried to change Module.MyAPI.__doc__ = My new doc

This failles as it is read only attribute.

Another approach could be calling  Py_InitModule(myModuleName, 
myMethods); with new help string. But It is not working,

So I am not sure what is the right way to do it


To put the right docstrings into the embedded interpreter. I don't know 
about your processes, but either the support just suggests better 
strings  developers put them in there, or maybe some sort of shared 
header-file could be used that the developers use  support enhances. 
Something like this:



--- docstrings.h ---

#define VistaDbMethods__doc__ usage: MyHelp


And if that's enhanced over time by the support-staff, docs will get 
better. Hopefully.


Alternatives are:

 - beating your developers with a clue-stick into submission that good 
docs are important

 - write a usage-guide using e.g. sphinx and release that as add-on-docs.

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


Re: Python docs disappointing - group effort to hire writers?

2009-08-07 Thread Paul Rubin
alex23 wuwe...@gmail.com writes:
 I'd still like to see this kept out of the official docs as much as
 possible, mostly for reasons of brevity  clarity. I think the
 official docs should be considered definitive and not require a
 hermeneutic evaluation against user comments to ensure they're still
 correct...

Such evaluation would only do them good.  The official docs are full
of errors and omissions, which is why we have this thread going on
here in the newsgroup.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: pylucene installation problem on Ubuntu 9.04

2009-08-07 Thread KK
I tried doing something silly.
I went to the directory /usr/local/lib/python2.6/site-packages and
then tried to compile/run the file called PyLucene.py the way we
compile/run python scripts, then from there i started the python
interpreter by typing python ( which is actually python2.6), then i
tried to import that module, [un]fortunately it din't give that error
message but something else, you can see below:

kk-laptop:/usr/local/lib/python2.6/site-packages$ python
Python 2.6.2 (release26-maint, Apr 19 2009, 01:56:41)
[GCC 4.3.3] on linux2
Type help, copyright, credits or license for more information.
 indexDir = '/opt/lucene/index'
 import PyLucene
WARNING: could not properly read security provider files:
 file:///usr/local/gcc-3.4.6/lib/security/libgcj.security
 file:///usr/local/gcc-3.4.6/lib/security/classpath.security
 Falling back to standard GNU security provider


then tried to copy and paste my sample code for indexing data to
lucene, this way:


 writer = IndexWriter(indexDir, StandardAnalyzer(), True)
 title = this is sample page title
 content = This is sample page content for testing pylucene tool

 doc = Document()
 doc.add(Field(title, title, Field.Store.YES, Field.Index.TOKENIZED))
 doc.add(Field(content, content, Field.Store.YES, Field.Index.TOKENIZED))
 writer.addDocument(doc)
 writer.optimize()



and surprisingly it din't give any other error. to crosscheck things i
went to the lucene index directory and fired LUKE and luckily found
that doc being indexed by lucene, even i tried searching for some
words and found they are working fine. So Pylucene seems to be working
partially, in my case. But I think python is not able to load the
PyLucene module (btw, i din't see any __init__ scripts which, i guess,
are used for bootstrapping external modules, right?). Then what is the
fix for this? do we have to add some __init__ scripts to make python
load PyLucene module when it starts? do i sound silly? What is the
best/easiest way to get this working? I've spend quite a lot of time
jsut to make PyLucene running but to no avail.
BTW, I tried to start the python interpreter from other locations and
tried imporitn this PyLucene module but got the same irritating error
message saying module not found.
Also trying to run my sample indexer from cli using the normal way[kk-
laptop$ python indexer.py] gave the same error message.

Any help/advice is highly appreciated.
Thanks,
KK

On Aug 7, 8:22 am, KK dioxide.softw...@gmail.com wrote:
 On Aug 7, 12:38 am, Jon Clements jon...@googlemail.com wrote:



  On 6 Aug, 19:49, KK dioxide.softw...@gmail.com wrote:

   hi all,
   I've trying to install pylucene on my linux box from last 2 days but
   not able to do so. first i tried to install it using apt-get like
   this,
   kk-laptop$ sudo apt-get install pylucene
   and it did install python2.5, python2.5-minimal and pylucene. I must
   mention one thing that I already had python2.6 on my box as the
   default python i.e /usr/bin/python is linked to python2.6. Anyway s,
   now i started the python interpreter using python command from cli
   and then to make sure pylucene has been installed i tried to import
   the module and to my surprise it said module pylucene not found.
   I thought I should enter the python2.6 env and do the same , so i
   tried starting the python2.6 interpreter using python2.6 as the
   command and tried importing the same module and again it failed giving
   the same irritating message.
    As a final try i pulled the source code of pylucene and as per the
   comments given there in the README file, copied the mentioned files to
   site-packages directory of python2.6 and then tried importing the
   module and then got the same error message saying no module name
   pylucene is present. I'm sick of this error !
   Can someone point me what is the issue? If it is due to multiple
   version of python running on box, can someone tell me which one to
   remove or someone tell me how to get the whole thing running? I'll
   very much thankful to you guys.

   Thanks,
   KK.

  If you installed using apt, have you a pylucene directory under /usr/
  local/lib/python2.6/dist-packages/?

  Also, if you run python, and import sys; print sys.path
  whats it show?

  Jon.

 Yes I've a dirctory called dist-packages under python2.6 but that
 doesn't contain anything on pylucene [it has lupyne, which i installed
 day before yesterday and importing lupyne doesn't give any error msg,
 but again it is dependent on pylucene]
 # for python the output is :
 --
 kk-laptop$ python
 Python 2.6.2 (release26-maint, Apr 19 2009, 01:56:41)
 [GCC 4.3.3] on linux2
 Type help, copyright, credits or license for more information. 
 import sys
  print sys.path

 ['', '/usr/lib/python2.6', '/usr/lib/python2.6/plat-linux2', '/usr/lib/
 python2.6/lib-tk', '/usr/lib/python2.6/lib-old', '/usr/lib/python2.6/
 lib-dynload', 

Re: Parsing Binary Structures; Is there a better way / What is your way?

2009-08-07 Thread andrew cooke
On Aug 5, 10:46 am, Martin P. Hellwig martin.hell...@dcuktec.org
wrote:
 Hi List,

 On several occasions I have needed (and build) a parser that reads a
 binary piece of data with custom structure. For example (bogus one):

 BE
 +-+-+-+-+--++
 | Version | Command | Instruction | Data Length | Data | Filler |
 +-+-+-+-+--++
 Version: 6 bits
 Command: 4 bits
 Instruction: 5 bits
 Data Length: 5 bits
 Data: 0-31 bits
 Filler: filling 0 bits to make the packet dividable by 8

hi,

sorry i'm a bit late here, but lepl does exactly this.  also, as you
asked for in another post, the BitString class allows arbitrary
indexing into a sequence of bits.  and because it's part of a
recursive descent parser you can match anything (lepl will handle -
although less efficiently - left recursive and ambiguous grammars).

see the example at http://www.acooke.org/lepl/binary.html#matching
which constructs an ethernet frame and then parses it, extracting the
source and destination addresses.

feel free to email me with more questions.

disclaimer: this is quite new and i don't know of anyone that actually
uses it; it is also Python3 only (because it uses bytes()).

andrew


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


Re: Cython + setuptools not working with .pyx,only with .c-files

2009-08-07 Thread David Cournapeau
On Fri, Aug 7, 2009 at 7:09 PM, Diez B. Roggischde...@nospam.web.de wrote:


 Tried that, nothing changed :(

Then you will have to modify Cython.Distutils to be aware of
setuptools, I think (and soon Distribute... ).

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


Re: unicode() vs. s.decode()

2009-08-07 Thread garabik-news-2005-05
Thorsten Kampe thors...@thorstenkampe.de wrote:
 * Steven D'Aprano (06 Aug 2009 19:17:30 GMT)
 What if you're writing a loop which takes one million different lines of 
 text and decodes them once each?
 
  setup = 'L = [abc*(n%100) for n in xrange(100)]'
  t1 = timeit.Timer('for line in L: line.decode(utf-8)', setup)
  t2 = timeit.Timer('for line in L: unicode(line, utf-8)', setup)
  t1.timeit(number=1)
 5.6751680374145508
  t2.timeit(number=1)
 2.682251165771
 
 Seems like a pretty meaningful difference to me.
 
 Bollocks. No one will even notice whether a code sequence runs 2.7 or 
 5.7 seconds. That's completely artificial benchmarking.


For a real-life example, I have often a file with one word per line, and
I run python scripts to apply some (sometimes fairy trivial)
transformation over it. REAL example, reading lines with word, lemma,
tag separated by tabs from stdin and writing word into stdout, unless it
starts with '' (~6e5 lines, python2.5, user times, warm cache, I hope
the comments are self-explanatory)

no unicode
user0m2.380s

decode('utf-8'), encode('utf-8')
user0m3.560s

sys.stdout = codecs.getwriter('utf-8')(sys.stdout);sys.stdin = 
codecs.getreader('utf-8')(sys.stdin)
user0m6.180s

unicode(line, 'utf8'), encode('utf-8')
user0m3.820s

unicode(line, 'utf-8'), encode('utf-8')
user0m2.880sa

python3.1
user0m1.560s

Since I have something like 18 million words in my currenct project (and
  600 million overall) and I often tweak some parameters and re-run the
  transformations, the differences are pretty significant.

Personally, I have been surprised by:
1) bad performance of the codecs wrapper (I expected it to be on par with 
   unicode(x,'utf-8'), mayble slightly better due to less function calls
2) good performance of python3.1 (utf-8 locale)


-- 
 ---
| Radovan Garabík http://kassiopeia.juls.savba.sk/~garabik/ |
| __..--^^^--..__garabik @ kassiopeia.juls.savba.sk |
 ---
Antivirus alert: file .signature infected by signature virus.
Hi! I'm a signature virus! Copy me into your signature file to help me spread!
-- 
http://mail.python.org/mailman/listinfo/python-list


how to overload operator (a x b)?

2009-08-07 Thread dmitrey
hi all,
is it possible to overload operator   ? (And other like this one,
eg =  =,   , =  =)
Any URL/example?
Thank you in advance, D.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python docs disappointing - group effort to hire writers?

2009-08-07 Thread Dave Angel

alex23 wrote:

Paul Rubin http://phr...@nospam.invalid wrote:
  

The PHP docs as I remember are sort of regular (non-publically
editable) doc pages, each of which has a public discussion thread
where people can post questions and answers about the topic of that
doc page.  I thought it worked really well.  The main thing is that
the good stuff from the comment section gets folded into the actual
doc now and then.



I'd still like to see this kept out of the official docs as much as
possible, mostly for reasons of brevity  clarity. I think the
official docs should be considered definitive and not require a
hermeneutic evaluation against user comments to ensure they're still
correct...

How about a secondary site that embeds the docs and provides
commenting functionality around it? That's certainly a finitely scoped
project that those with issues about the docs could establish and
contribute to, with the possibility of it gaining official support
later once it gains traction.


  
I share your concern about unmonitored comments.  However, it seems a 
useful possibility would be for the official pages to each have 
specially-marked links that possibly lead to such user comments.  
Clearly they'd have to marked carefully, so that naive users don't 
confuse the two.  But otherwise, it feels like a good idea.


In my case, I usually access the docs via the Windows help file.  So 
it'd be quite easy for me to recognize that once I've gotten to a 
browser page, I'm not in Kansas any more.  But that could be also 
accomplished by having a very different stylesheet for the user comments 
page.


DaveA

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


Re: how to overload operator (a x b)?

2009-08-07 Thread Diez B. Roggisch

dmitrey schrieb:

hi all,
is it possible to overload operator   ? (And other like this one,
eg =  =,   , =  =)
Any URL/example?
Thank you in advance, D.


http://docs.python.org/reference/datamodel.html#object.__lt__

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


Re: Web page data and urllib2.urlopen

2009-08-07 Thread Dave Angel


Piet van Oostrum wrote:

snip


snip

DA But the raw page didn't have any javascript.  So what about that original
DA raw page triggered additional stuff to be loaded?
DA Is it user agent, as someone else brought out?  And is there somewhere I
DA can read more about that aspect of things?  I've mostly built very static
DA html pages, where the server yields the same page to everybody.  And some
DA form stuff, where the  user clicks on a 'submit button to trigger a script
DA that's not shown on the URL line.



Yes, if you specify a 'normal' web browser as user agent you do get the
Javascript:

import urllib2

request = 
urllib2.Request('http://www.marketwatch.com/story/mondays-biggest-gaining-and-declining-stocks-2009-07-27')
request.add_header('User-Agent', 'Mozilla/5.0 (Macintosh; U; Intel Mac OS X 
10.5; en-US; rv:1.9.0.13) Gecko/2009073021 Firefox/3.0.13')

opener = urllib2.build_opener() 
page = opener.open(request).read()

print page

  

Thanks much.  That's a key I didn't understand.

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


Bug or feature: double strings as one

2009-08-07 Thread durumdara
Hi!

I found an interesting thing in Python.
Today one of my defs got wrong result.

When I checked the code I saw that I miss a , from the list.

l = ['ó' 'Ó']

Interesting, that Python handle them as one string.

print ['ó' 'Ó']
['\xf3\xd3']

I wanna ask that is a bug or is it a feature?

In other languages, like Delphi (Pascal), Javascript, SQL, etc., I
must concatenate the strings with some sign, like + or ||.

This technic is avoid the mistyping, like today. But in python I can
miss the concat sign, and I got wrong result...

Thanks for your help and for your answer:
   dd


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


Re: How to reset document string

2009-08-07 Thread Carl Banks
On Aug 7, 2:54 am, Anand K Rayudu an...@esi-india.com wrote:
 Dear All,

 We have extended and embedded python into my our application.
 We exposed few APIs to python using

  Py_InitModule(myModuleName, myMethods);
 where my methods are

 static PyMethodDef VistaDbMethods[] = {
    { (char *)myAPI,_myAPICFunctionPtr ,METH_VARARGS,usage: MyHelp) }

 Now problem is ml_doc (Document string). Most of the time the strings
 given by development team is not descriptive enough, so support team
 want to enhance these docstring on need basis and supply to customer
 The idea is we will provide get latest help option from application,
 which will contact our webserver or allow user to pick new help
 document,  which will re apply the help on fly.
  From then on our script editors will show the new enhanced help.
 How do I achieve this.

Sounds very cool.  I have a few ideas.

1. Since you say you are embedding Python in your application, the
most direct way might be to modify the Python interpreter to allow the
__doc__ attribute to be changed.  You'd have to modify the PyCFunction
type (defined in methodobject.h and methodobject.c) to allow
overriding the compiled-in doc field.

2. Instead of replacing the __doc__ attribute of the function, just
replace the whole function with a wrapper.  So, for instance, if your
application decides to update the docstring for myModuleName.myAPI(),
instead of running code like this:

myModuleName.myAPI.__doc__ = 'new docstring'

run code like this:

def create_wrapper(func,docstring):
def wrapper(*args):
return func(*args)
wrapper.__doc__ = doc
return wrapper
myModuleName.myAPI = create_wrapper(
 myModuleName.myAPI,'new docstring')

So now myApi is a Python function with the new docstring that calls
the old function.  (Note: if you are concerned with efficiency, it's
possible to write a wrapper in C that has very little overhead.)

This approach has minor disadvantages (such as if any code write from
myModuleName import myAPI--it won't see the new version) but it may be
the easiest approach.

3. Instead of customizing the __doc__ attribute, store any custom
docstrings in a dictionary keyed by the function.

custom_doc[myModuleName.myApi] = 'new docstring'

Your script editor, when looking for documentation, will first search
in this custom area to see if the docstring has been overridden; if
so, use that; if not, use the docstring.  Something like this:

def documentation_to_use_in_script_editor(func):
try:
return custom_doc[func]
except KeyError:
return func.__doc__

That has the negative of the special docstring not being visible at an
interactive prompt.


I have given you some fairly vague answers, hopefully that'll give you
some idea.  It sounds like you have an ambitious project, suggesting
that you are probably good enough to implement the suggestions.


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


Re: Bug or feature: double strings as one

2009-08-07 Thread Diez B. Roggisch

durumdara schrieb:

Hi!

I found an interesting thing in Python.
Today one of my defs got wrong result.

When I checked the code I saw that I miss a , from the list.

l = ['ó' 'Ó']

Interesting, that Python handle them as one string.

print ['ó' 'Ó']
['\xf3\xd3']

I wanna ask that is a bug or is it a feature?

In other languages, like Delphi (Pascal), Javascript, SQL, etc., I
must concatenate the strings with some sign, like + or ||.

This technic is avoid the mistyping, like today. But in python I can
miss the concat sign, and I got wrong result...


It's a feature. It is sometimes used in cases where you want to split a 
longer text into several lines, but without introducing newlines.


like this (the parentheses are there for the parser not to puke):


foo = (foobarbaz
   padamm)

It has the potential to produce errors as you have seen them, though.

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


pulldom extracting records from recordset

2009-08-07 Thread S.Selvam
Hi all,

I am using pulldom to handle large xml files.It works fine, but i do not
know how to store a particular set of  records(as xml) out of the recordset.
-code-
from xml.dom import pulldom
hamlet_file = open(input_xml/inp_test.xml)
events = pulldom.parse(hamlet_file)
for (event, node) in events:
  if event == pulldom.START_ELEMENT:
if node.tagName == Record:
 events.expandNode(node)
 print node  #this does not work as it is a object
--

Whenever the node name is a Record,i process it. I want to store the all the
nodes meeting my requirement.
  For eg,i need output as below,

 Record
a
 a1hi/a1
   /a
   b
---
   /b
/Record

 Record
a
 a1hello/a1
   .
   .
Where input xml might contain 'n' number of Records.
I have been struggling to figure it out.I would be happy to get a solution
for this.

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


Re: Bug or feature: double strings as one

2009-08-07 Thread Peter Otten
durumdara wrote:

 I found an interesting thing in Python.
 Today one of my defs got wrong result.
 
 When I checked the code I saw that I miss a , from the list.
 
 l = ['ó' 'Ó']
 
 Interesting, that Python handle them as one string.
 
 print ['ó' 'Ó']
 ['\xf3\xd3']
 
 I wanna ask that is a bug or is it a feature?

Feature:

http://docs.python.org/reference/lexical_analysis.html#string-literal-concatenation

Peter

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


Re: how to overload operator (a x b)?

2009-08-07 Thread Benjamin Kaplan
On Fri, Aug 7, 2009 at 8:00 AM, dmitreydmitrey.kros...@scipy.org wrote:
 hi all,
 is it possible to overload operator   ? (And other like this one,
 eg =  =,   , =  =)
 Any URL/example?
 Thank you in advance, D.

That isn't an operator at all. Python does not support compound
comparisons like that. You have to do a  b and b  c.
 --
 http://mail.python.org/mailman/listinfo/python-list

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


Re: Web page data and urllib2.urlopen

2009-08-07 Thread Piet van Oostrum
 Dave Angel da...@ieee.org (DA) wrote:

DA Piet van Oostrum wrote:
 snip
 
 snip
DA But the raw page didn't have any javascript.  So what about that original
DA raw page triggered additional stuff to be loaded?
DA Is it user agent, as someone else brought out?  And is there somewhere I
DA can read more about that aspect of things?  I've mostly built very static
DA html pages, where the server yields the same page to everybody.  And some
DA form stuff, where the  user clicks on a 'submit button to trigger a script
DA that's not shown on the URL line.
 
 
 Yes, if you specify a 'normal' web browser as user agent you do get the
 Javascript:
 
 import urllib2
 
 request = 
 urllib2.Request('http://www.marketwatch.com/story/mondays-biggest-gaining-and-declining-stocks-2009-07-27')
 request.add_header('User-Agent', 'Mozilla/5.0 (Macintosh; U; Intel Mac OS X 
 10.5; en-US; rv:1.9.0.13) Gecko/2009073021 Firefox/3.0.13')
 
 opener = urllib2.build_opener() page = opener.open(request).read()
 print page
 
 
DA Thanks much.  That's a key I didn't understand.

You can even specify the headers in the Request constructor:


url = 
'http://www.marketwatch.com/story/mondays-biggest-gaining-and-declining-stocks-2009-07-27'
hdr = {'User-Agent': 'Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.5; en-US; 
rv:1.9.0.13) Gecko/2009073021 Firefox/3.0.13'}
request = urllib2.Request(url = url, headers = hdr)

-- 
Piet van Oostrum p...@cs.uu.nl
URL: http://pietvanoostrum.com [PGP 8DAE142BE17999C4]
Private email: p...@vanoostrum.org
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: pulldom extracting records from recordset

2009-08-07 Thread S.Selvam
On Fri, Aug 7, 2009 at 6:10 PM, S.Selvam s.selvams...@gmail.com wrote:

 Hi all,

 I am using pulldom to handle large xml files.It works fine, but i do not
 know how to store a particular set of  records(as xml) out of the recordset.
 -code-
 from xml.dom import pulldom
 hamlet_file = open(input_xml/inp_test.xml)
 events = pulldom.parse(hamlet_file)
 for (event, node) in events:
   if event == pulldom.START_ELEMENT:
 if node.tagName == Record:
  events.expandNode(node)
  print node  #this does not work as it is a object
 --

 Whenever the node name is a Record,i process it. I want to store the all
 the nodes meeting my requirement.
   For eg,i need output as below,

  Record
 a
  a1hi/a1
/a
b
 ---
/b
 /Record

  Record
 a
  a1hello/a1
.
.
 Where input xml might contain 'n' number of Records.
 I have been struggling to figure it out.I would be happy to get a solution
 for this.

 --
 Yours,
 S.Selvam


Hi all,
   I just found the solution,
 *node.toprettyxml()*
 has done it.



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


Re: how to kill subprocess when Python process is killed?

2009-08-07 Thread Piet van Oostrum
 mark.v.we...@gmail.com mark.v.we...@gmail.com (M) wrote:

M I am writing a Python program that launches a subprocess (using
M Popen).
M I am reading stdout of the subprocess, doing some filtering, and
M writing to
M stdout of the main process.

M When I kill the main process (cntl-C) the subprocess keeps running.
M How do I kill the subprocess too? The subprocess is likey to run a
M long time.

M Context:
M I'm launching only one subprocess at a time, I'm filtering its stdout.
M The user might decide to interrupt to try something else; the user
M wants the process and all subprocesses to go away in response
M to a cntl-C

M I'm new to python; solution must be for Python 2.5 (windows) to help
M me.

M Any help and/or pointers appreciated.

When the parent dies, the child should die when it's writing on the
broken pipe. At least that's how it works in Unix systems. I don't know
about Windows, however.

To let the dying be fast you should make sure that stdout in the child
is unbuffered.

-- 
Piet van Oostrum p...@cs.uu.nl
URL: http://pietvanoostrum.com [PGP 8DAE142BE17999C4]
Private email: p...@vanoostrum.org
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Is python buffer overflow proof?

2009-08-07 Thread Thorsten Kampe
* Neil Hodgson (Tue, 04 Aug 2009 13:32:55 GMT)
 Thorsten Kampe:
  You cannot create your own buffer overflow in Python as you can in 
C 
  and C++ but your code could still be vulnerable if the underlying Python 
  construct is written in C.
 
Python's standard library does now include unsafe constructs.

I don't doubt that. If Python contains a buffer overflow vulnerability 
your code will also be susceptible to that. Please read the link I 
provided as an example.

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


Re: how to overload operator (a x b)?

2009-08-07 Thread alex23
On Aug 7, 10:50 pm, Benjamin Kaplan benjamin.kap...@case.edu wrote:
 That isn't an operator at all. Python does not support compound
 comparisons like that. You have to do a  b and b  c.

You know, it costs nothing to open up a python interpreter and check
your certainty:

 x = 10
 1  x  20
True

This is a _very_ common pattern.

 class X(object):
...   def __lt__(self, other):
... print 'in lt'
... return True
...   def __gt__(self, other):
... print 'in gt'
... return True
...
 x = X()
 1  x  20
in gt
in lt
True
 20  x  1
in gt
in lt
True

dmitrey: Diez' advice was the best you received.
-- 
http://mail.python.org/mailman/listinfo/python-list


Changing Remote Registry

2009-08-07 Thread Kevin Holleran
Good morning,

I fear the answer to this is that I just cannot do this

I wrote a python script that goes out to a bunch of remote machines and
queries the registry for some values.  Effectively, there have been some
software upgrades that have been done as the need arose but we need to do
them across the organization now.  There are three, and the script checks
all three and returns the values.  One of these just needs to be a registry
change as it is a client server application that the server was upgraded and
the clients need a change to a registry value to work.

Long story short, I am using _winreg to do this.

hKey = _winreg.OpenKey (keyPath, path, 0, _winreg.KEY_SET_VALUE)
value,type = _winreg.QueryValueEx(hKey, item)
if (value == wrongValue):
   _winreg.SetValue(hKey,'',_winreg.REG_SZ,correctValue)


When I do this I receive the error:

_winreg.SetValue WindowsError: [Error 5] Access Denied


I am running this from my machine as a domain admin, connecting to the
remote machine which is also on the domain.
I am connecting to the remote registry with:

keyPath = _winreg.ConnectRegistry(r\\ +
ipAddress,_winreg.HKEY_LOCAL_MACHINE)


Thanks for any help.

--
Kevin Holleran
Master of Science, Computer Information Systems
Grand Valley State University
Master of Business Administration
Western Michigan University
Completion December 2009
CCNA, ISA, MCSA, MCDST, MCP

We are what we repeatedly do. Excellence, then, is not an act, but a
habit. - Aristotle

A man flattened by an opponent can get up again. A man flattened by
conformity stays down for good.  - Thomas J. Watson
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: unicode() vs. s.decode()

2009-08-07 Thread alex23
Thorsten Kampe thors...@thorstenkampe.de wrote:
 Bollocks. No one will even notice whether a code sequence runs 2.7 or
 5.7 seconds. That's completely artificial benchmarking.

But that's not what you first claimed:

 I don't think any measurable speed increase will be
 noticeable between those two.

But please, keep changing your argument so you don't have to admit you
were wrong.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Problem in installing PyGreSQL

2009-08-07 Thread Scott David Daniels

Dennis Lee Bieber wrote:

On Thu, 6 Aug 2009 16:00:15 +0530, Thangappan.M
thangappan...@gmail.com declaimed the following in
gmane.comp.python.general:

  File ./setup.py, line 219, in finalize_options
except (Warning, w):
NameError: global name 'w' is not defined

What would be the solution?
Otherwise can you tell how to install DB-API in debian machine.

Sorry... 1) I run on WinXP; 2) I don't build packages, relying on
pre-built binaries; 3) I run MySQL.

However, based upon the examples in the Tutorial, that line should
not have the (, ). A parenthesised (tuple) is suppose to contain a list
of exceptions, and the parameter to catch the exception specifics has to
be outside the list.

Best I can suggest is editing that particular line and removing the
(, ) -- then try rebuilding.

I'll also re-ask: All you are installing is the Python adapter to
the database. DO YOU HAVE A RUNNING PostgreSQL server that you can
connect to?


Just to be a bit more explict:
Change file setup.py's line 219 from:
 except (Warning, w):
to either (OK in Python 2.6 and greater):
   except Warning as w:
or (works for Python 2.X):
   except Warning, w:


--Scott David Daniels
scott.dani...@acm.org
--
http://mail.python.org/mailman/listinfo/python-list


Re: Python docs disappointing - group effort to hire writers?

2009-08-07 Thread alex23
Paul Rubin http://phr...@nospam.invalid wrote:
 Such evaluation would only do them good.  The official docs are full
 of errors and omissions, which is why we have this thread going on
 here in the newsgroup.

And there is a process for reporting and correcting such errors and
omissions, which is what I pointed out in my post.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Changing Remote Registry

2009-08-07 Thread MRAB

Kevin Holleran wrote:

Good morning,

I fear the answer to this is that I just cannot do this

I wrote a python script that goes out to a bunch of remote machines and 
queries the registry for some values.  Effectively, there have been some 
software upgrades that have been done as the need arose but we need to 
do them across the organization now.  There are three, and the script 
checks all three and returns the values.  One of these just needs to be 
a registry change as it is a client server application that the server 
was upgraded and the clients need a change to a registry value to work.


Long story short, I am using _winreg to do this.

hKey = _winreg.OpenKey (keyPath, path, 0, _winreg.KEY_SET_VALUE)
value,type = _winreg.QueryValueEx(hKey, item)
if (value == wrongValue):
   _winreg.SetValue(hKey,'',_winreg.REG_SZ,correctValue)
   


When I do this I receive the error:

_winreg.SetValue WindowsError: [Error 5] Access Denied


I am running this from my machine as a domain admin, connecting to the 
remote machine which is also on the domain.

I am connecting to the remote registry with:

keyPath = _winreg.ConnectRegistry(r\\ + 
ipAddress,_winreg.HKEY_LOCAL_MACHINE)



Thanks for any help. 


What is 'ipAddress'? Is it an actual IP address? The documentation says
it should be the computer name.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Bug or feature: double strings as one

2009-08-07 Thread Grant Edwards
On 2009-08-07, durumdara durumd...@gmail.com wrote:
 Hi!

 I found an interesting thing in Python.
 Today one of my defs got wrong result.

 When I checked the code I saw that I miss a , from the list.

 l = ['?' '?']

 Interesting, that Python handle them as one string.

 print ['?' '?']
 ['\xf3\xd3']

 I wanna ask that is a bug or is it a feature?

You wanna?

 In other languages, like Delphi (Pascal), Javascript, SQL, etc., I
 must concatenate the strings with some sign, like + or ||.

In other languages like Ruby, awk, C, C++, etc. adjacent string
constants are concatenated.

-- 
Grant Edwards   grante Yow! Is it clean in other
  at   dimensions?
   visi.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: how to overload operator (a x b)?

2009-08-07 Thread Diez B. Roggisch

alex23 schrieb:

On Aug 7, 10:50 pm, Benjamin Kaplan benjamin.kap...@case.edu wrote:

That isn't an operator at all. Python does not support compound
comparisons like that. You have to do a  b and b  c.


You know, it costs nothing to open up a python interpreter and check
your certainty:


x = 10
1  x  20

True

This is a _very_ common pattern.


class X(object):

...   def __lt__(self, other):
... print 'in lt'
... return True
...   def __gt__(self, other):
... print 'in gt'
... return True
...

x = X()
1  x  20

in gt
in lt
True

20  x  1

in gt
in lt
True

dmitrey: Diez' advice was the best you received.


Not really. I didn't get the chaining, and Peter is right that for that 
there is no real overloading.


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


Re: M2Crypto: How to generate subjectKeyIdentifier / authorityKeyIdentifier

2009-08-07 Thread Scott David Daniels

Matthias Güntert wrote:

M2Crypto has a couple of bugs open related that, with potential
workarounds that I haven't yet deemed polished enough to checkin, but
which might help you out:

https://bugzilla.osafoundation.org/show_bug.cgi?id=7530
https://bugzilla.osafoundation.org/show_bug.cgi?id=12151


... Generating the 'subjectKeyIdentifier':

 ...

def get_public_key_fingerprint(self):
h = hashlib.new('sha1')
h.update(self.keypair.as_der())
client_serial = h.hexdigest().upper()
client_serial_hex = ''
for byte in xrange(20):
 client_serial_hex += client_serial[byte*2] + client_serial[byte*2
+1]
if byte  19:
client_serial_hex += ':'
return client_serial_hex 
...


More tersely (code golf?):

def get_public_key_fingerprint(self):
digest = hashlib.sha1(self.keypair.as_der()).hexdigest().upper()
return ':'.join(digest[pos : pos+2] for pos in range(0, 40, 2))

--Scott David Daniels
scott.dani...@acm.org


--Scott David Daniels
scott.dani...@acm.org
--
http://mail.python.org/mailman/listinfo/python-list


Re: Processes not exiting

2009-08-07 Thread ma3mju
On 3 Aug, 09:36, ma3mju matt.u...@googlemail.com wrote:
 On 2 Aug, 21:49, Piet van Oostrum p...@cs.uu.nl wrote:

   MRAB pyt...@mrabarnett.plus.com (M) wrote:
  M I wonder whether one of the workers is raising an exception, perhaps due
  M to lack of memory, when there are large number of jobs to process.

  But that wouldn't prevent the join. And you would probably get an
  exception traceback printed.

  I wonder if something fishy is happening in the multiprocessing
  infrastructure. Or maybe the Fortran code goes wrong because it has no
  protection against buffer overruns and similar problems, I think.
  --
  Piet van Oostrum p...@cs.uu.nl
  URL:http://pietvanoostrum.com[PGP8DAE142BE17999C4]
  Private email: p...@vanoostrum.org

 I don't think it's a memory problem, the reason for the hard and easy
 queue is because for larger examples it uses far more RAM. If I run
 all of workers with harder problems I do begin to run out of RAM and
 end up spending all my time switching in and out of swap so I limit
 the number of harder problems I run at the same time. I've watched it
 run to the end (a very boring couple of hours) and it stays out of my
 swap space and everything appears to be staying in RAM. Just hangs
 after all poison has been printed for each process.

 The other thing is that I get the message here telling me I broke
 out of the loop after seeing the poison pill in the process and I get
 all the things queued listed as output surely if I were to run out of
 memory I wouldn't expect all of the jobs to be listed as output.

 I have a serial script that works fine so I know individually for each
 example the fortran code works.

 Thanks

 Matt

Any ideas for a solution?
-- 
http://mail.python.org/mailman/listinfo/python-list


RE: Changing Remote Registry

2009-08-07 Thread Kevin Holleran

  Good morning,

 I fear the answer to this is that I just cannot do this

 I wrote a python script that goes out to a bunch of remote machines and
 queries the registry for some values.  Effectively, there have been some
 software upgrades that have been done as the need arose but we need to do
 them across the organization now.  There are three, and the script checks
 all three and returns the values.  One of these just needs to be a registry
 change as it is a client server application that the server was upgraded and
 the clients need a change to a registry value to work.

 Long story short, I am using _winreg to do this.

 hKey = _winreg.OpenKey (keyPath, path, 0, _winreg.KEY_SET_VALUE)
 value,type = _winreg.QueryValueEx(hKey, item)
 if (value == wrongValue):
   _winreg.SetValue(hKey,'',_winreg.REG_SZ,correctValue)

 When I do this I receive the error:

 _winreg.SetValue WindowsError: [Error 5] Access Denied


 I am running this from my machine as a domain admin, connecting to the
 remote machine which is also on the domain.
 I am connecting to the remote registry with:

 keyPath = _winreg.ConnectRegistry(r\\ +
 ipAddress,_winreg.HKEY_LOCAL_MACHINE)


 Thanks for any help.

 What is 'ipAddress'? Is it an actual IP address? The documentation says
 it should be the computer name.
 --
 http://mail.python.org/mailman/listinfo/python-list



Thanks for the response.  From my experience that does not matter.  It is an
actual IP address.  I can connect to the registry fine, its just the
writing.  I read that value and other values.  It errors on the
_winreg.KEY_SET_VALUE.  I am wondering if Windows just will not let the
registry be changed remotely in this way or if there is something else I
have to do.

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


Re: Processes not exiting

2009-08-07 Thread ma3mju
On 3 Aug, 09:36, ma3mju matt.u...@googlemail.com wrote:
 On 2 Aug, 21:49, Piet van Oostrum p...@cs.uu.nl wrote:

   MRAB pyt...@mrabarnett.plus.com (M) wrote:
  M I wonder whether one of the workers is raising an exception, perhaps due
  M to lack of memory, when there are large number of jobs to process.

  But that wouldn't prevent the join. And you would probably get an
  exception traceback printed.

  I wonder if something fishy is happening in the multiprocessing
  infrastructure. Or maybe the Fortran code goes wrong because it has no
  protection against buffer overruns and similar problems, I think.
  --
  Piet van Oostrum p...@cs.uu.nl
  URL:http://pietvanoostrum.com[PGP8DAE142BE17999C4]
  Private email: p...@vanoostrum.org

 I don't think it's a memory problem, the reason for the hard and easy
 queue is because for larger examples it uses far more RAM. If I run
 all of workers with harder problems I do begin to run out of RAM and
 end up spending all my time switching in and out of swap so I limit
 the number of harder problems I run at the same time. I've watched it
 run to the end (a very boring couple of hours) and it stays out of my
 swap space and everything appears to be staying in RAM. Just hangs
 after all poison has been printed for each process.

 The other thing is that I get the message here telling me I broke
 out of the loop after seeing the poison pill in the process and I get
 all the things queued listed as output surely if I were to run out of
 memory I wouldn't expect all of the jobs to be listed as output.

 I have a serial script that works fine so I know individually for each
 example the fortran code works.

 Thanks

 Matt

Any ideas?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: how to overload operator (a x b)?

2009-08-07 Thread Robert Lehmann
On Fri, 07 Aug 2009 08:50:52 -0400, Benjamin Kaplan wrote:

 On Fri, Aug 7, 2009 at 8:00 AM, dmitreydmitrey.kros...@scipy.org
 wrote:
 hi all,
 is it possible to overload operator   ? (And other like this one,
 eg =  =,   , =  =)
 Any URL/example?
 Thank you in advance, D.
 
 That isn't an operator at all. Python does not support compound
 comparisons like that. You have to do a  b and b  c.

Python actually allows you to chain comparison operators, automatically 
unpacking ``a  b  c`` to ``a  b and b  c``::

 class C(object):
...   def __lt__(self, other):
... print self, LESS-THAN, other
... return True
... 
 a = C(); b = C(); x = C()
 a  x  b
__main__.C object... LESS-THAN __main__.C object...
__main__.C object... LESS-THAN __main__.C object...
True

 x = 42
 40  x  50 # between 40 and 50
True
 50  x  60 # between 50 and 60
False
 1 == True  2 == 2.0  3  4 != 5  0 # yikes, unreadable! but legal.
True
 # same as: (1 == True) and (True  2) and (2 == 2.0) ...

HTH,

-- 
Robert Stargaming Lehmann

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


Re: Changing Remote Registry

2009-08-07 Thread MRAB

Kevin Holleran wrote:


On Fri, Aug 7, 2009 at 10:11 AM, MRAB pyt...@mrabarnett.plus.com 
mailto:pyt...@mrabarnett.plus.com wrote:


Kevin Holleran wrote:

Good morning,

I fear the answer to this is that I just cannot do this

I wrote a python script that goes out to a bunch of remote
machines and queries the registry for some values.  Effectively,
there have been some software upgrades that have been done as
the need arose but we need to do them across the organization
now.  There are three, and the script checks all three and
returns the values.  One of these just needs to be a registry
change as it is a client server application that the server was
upgraded and the clients need a change to a registry value to work.

Long story short, I am using _winreg to do this.

hKey = _winreg.OpenKey (keyPath, path, 0, _winreg.KEY_SET_VALUE)
value,type = _winreg.QueryValueEx(hKey, item)
if (value == wrongValue):
  _winreg.SetValue(hKey,'',_winreg.REG_SZ,correctValue)
   

Hmm. If you're querying with (hKey, item), shouldn't you also be setting
with (hKey, item), not (hKey,'')?


When I do this I receive the error:

_winreg.SetValue WindowsError: [Error 5] Access Denied


I am running this from my machine as a domain admin, connecting
to the remote machine which is also on the domain.
I am connecting to the remote registry with:

keyPath = _winreg.ConnectRegistry(r\\ +
ipAddress,_winreg.HKEY_LOCAL_MACHINE)


Thanks for any help.

What is 'ipAddress'? Is it an actual IP address? The documentation says
it should be the computer name.
-- 
http://mail.python.org/mailman/listinfo/python-list




Thanks for the response.  From my experience that does not matter.  It 
is an actual IP address.  I can connect to the registry fine, its just 
the writing.  I read that value and other values.  It errors on the 
_winreg.KEY_SET_VALUE.  I am wondering if Windows just will not let the 
registry be changed remotely in this way or if there is something else I 
have to do.



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


Re: how to overload operator (a x b)?

2009-08-07 Thread Scott David Daniels

Benjamin Kaplan wrote:

 Python does not support compound
comparisons like that. You have to do a  b and b  c.


Funny, my python does.  This has been around a long time.
I am not certain whether 1.5.2 did it, but chained comparisons
have been around for a long time.

 'a' 'd' 'z'
True
 'a' 'D' 'z'
False

--Scott David Daniels
scott.dani...@acm.org
--
http://mail.python.org/mailman/listinfo/python-list


Re: Processes not exiting

2009-08-07 Thread MRAB

ma3mju wrote:

On 3 Aug, 09:36, ma3mju matt.u...@googlemail.com wrote:

On 2 Aug, 21:49, Piet van Oostrum p...@cs.uu.nl wrote:


MRAB pyt...@mrabarnett.plus.com (M) wrote:

M I wonder whether one of the workers is raising an exception, perhaps due
M to lack of memory, when there are large number of jobs to process.

But that wouldn't prevent the join. And you would probably get an
exception traceback printed.
I wonder if something fishy is happening in the multiprocessing
infrastructure. Or maybe the Fortran code goes wrong because it has no
protection against buffer overruns and similar problems, I think.
--
Piet van Oostrum p...@cs.uu.nl
URL:http://pietvanoostrum.com[PGP8DAE142BE17999C4]
Private email: p...@vanoostrum.org

I don't think it's a memory problem, the reason for the hard and easy
queue is because for larger examples it uses far more RAM. If I run
all of workers with harder problems I do begin to run out of RAM and
end up spending all my time switching in and out of swap so I limit
the number of harder problems I run at the same time. I've watched it
run to the end (a very boring couple of hours) and it stays out of my
swap space and everything appears to be staying in RAM. Just hangs
after all poison has been printed for each process.

The other thing is that I get the message here telling me I broke
out of the loop after seeing the poison pill in the process and I get
all the things queued listed as output surely if I were to run out of
memory I wouldn't expect all of the jobs to be listed as output.

I have a serial script that works fine so I know individually for each
example the fortran code works.

Thanks

Matt


Any ideas for a solution?


A workaround is to do them in small batches.

You could put each job in a queue with a flag to say whether it's hard 
or easy, then:


while have more jobs:
move up to BATCH_SIZE jobs into worker queues
create and start workers
wait for workers to finish
discard workers
--
http://mail.python.org/mailman/listinfo/python-list


Re: Changing Remote Registry

2009-08-07 Thread Kevin Holleran
 On Fri, Aug 7, 2009 at 10:46 AM, MRAB pyt...@mrabarnett.plus.com wrote:

 Kevin Holleran wrote:


 On Fri, Aug 7, 2009 at 10:11 AM, MRAB pyt...@mrabarnett.plus.commailto:
 pyt...@mrabarnett.plus.com wrote:

Kevin Holleran wrote:

Good morning,

I fear the answer to this is that I just cannot do this

I wrote a python script that goes out to a bunch of remote
machines and queries the registry for some values.  Effectively,
there have been some software upgrades that have been done as
the need arose but we need to do them across the organization
now.  There are three, and the script checks all three and
returns the values.  One of these just needs to be a registry
change as it is a client server application that the server was
upgraded and the clients need a change to a registry value to work.

Long story short, I am using _winreg to do this.

hKey = _winreg.OpenKey (keyPath, path, 0, _winreg.KEY_SET_VALUE)
value,type = _winreg.QueryValueEx(hKey, item)
if (value == wrongValue):
  _winreg.SetValue(hKey,'',_winreg.REG_SZ,correctValue)


 Hmm. If you're querying with (hKey, item), shouldn't you also be setting
 with (hKey, item), not (hKey,'')?


 When I do this I receive the error:

_winreg.SetValue WindowsError: [Error 5] Access Denied


I am running this from my machine as a domain admin, connecting
to the remote machine which is also on the domain.
I am connecting to the remote registry with:

keyPath = _winreg.ConnectRegistry(r\\ +
ipAddress,_winreg.HKEY_LOCAL_MACHINE)


Thanks for any help.

What is 'ipAddress'? Is it an actual IP address? The documentation says
it should be the computer name.
--http://mail.python.org/mailman/listinfo/python-list



 Thanks for the response.  From my experience that does not matter.  It is
 an actual IP address.  I can connect to the registry fine, its just the
 writing.  I read that value and other values.  It errors on the
 _winreg.KEY_SET_VALUE.  I am wondering if Windows just will not let the
 registry be changed remotely in this way or if there is something else I
 have to do.

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


Sorry, that line is correct, I was removing specific information relevant to
our infrastructure.  That is the valuename.  The error I am getting is:


Traceback (most recent call last):
  File script.py, line 53, in module
value,type = _winreg.QueryValueEx(hKey,item)
WindowsError: [Error 5] Access is denied

But the real error is here I believe:

   hKey = _winreg.OpenKey (keyPath, path, 0, _winreg.KEY_SET_VALUE)

When I just do a:

   hKey = _winreg.OpenKey (keyPath, path, 0, _winreg.KEY_READ)

I receive no errors.

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


Executing untrusted code

2009-08-07 Thread Emanuele D'Arrigo
Greetings everybody,

I've been reading and mulling about python and security, specifically
in terms of executing code that may or may not be trustworthy. I
understand that libraries such as Rexec and Bastion are now deprecated
because they have known vulnerabilities that may be exploited to
circumvent the restrictions imposed.

So, am I right in understanding that is not possible to execute a
piece of code in a way that limits the objects and attributes that it
can access or that limits its access to file system and sockets? Are
there best practices to at least minimize some of the risks associated
with untrusted code execution?

And whatever happened to this:

http://sayspy.blogspot.com/2007/05/i-have-finished-securing-python.html

seemed to be a step forward in the right direction!

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


Re: Changing Remote Registry

2009-08-07 Thread MRAB

Kevin Holleran wrote:
On Fri, Aug 7, 2009 at 10:46 AM, MRAB pyt...@mrabarnett.plus.com 
mailto:pyt...@mrabarnett.plus.com wrote:


Kevin Holleran wrote:


On Fri, Aug 7, 2009 at 10:11 AM, MRAB
pyt...@mrabarnett.plus.com mailto:pyt...@mrabarnett.plus.com
mailto:pyt...@mrabarnett.plus.com
mailto:pyt...@mrabarnett.plus.com wrote:

   Kevin Holleran wrote:

   Good morning,

   I fear the answer to this is that I just cannot do this

   I wrote a python script that goes out to a bunch of remote
   machines and queries the registry for some values.
 Effectively,
   there have been some software upgrades that have been done as
   the need arose but we need to do them across the organization
   now.  There are three, and the script checks all three and
   returns the values.  One of these just needs to be a registry
   change as it is a client server application that the
server was
   upgraded and the clients need a change to a registry
value to work.

   Long story short, I am using _winreg to do this.

   hKey = _winreg.OpenKey (keyPath, path, 0,
_winreg.KEY_SET_VALUE)
   value,type = _winreg.QueryValueEx(hKey, item)
   if (value == wrongValue):
 _winreg.SetValue(hKey,'',_winreg.REG_SZ,correctValue)
 


Hmm. If you're querying with (hKey, item), shouldn't you also be setting
with (hKey, item), not (hKey,'')?


   When I do this I receive the error:

   _winreg.SetValue WindowsError: [Error 5] Access Denied


   I am running this from my machine as a domain admin,
connecting
   to the remote machine which is also on the domain.
   I am connecting to the remote registry with:

   keyPath = _winreg.ConnectRegistry(r\\ +
   ipAddress,_winreg.HKEY_LOCAL_MACHINE)


   Thanks for any help.

   What is 'ipAddress'? Is it an actual IP address? The
documentation says
   it should be the computer name.
   --http://mail.python.org/mailman/listinfo/python-list



Thanks for the response.  From my experience that does not
matter.  It is an actual IP address.  I can connect to the
registry fine, its just the writing.  I read that value and
other values.  It errors on the _winreg.KEY_SET_VALUE.  I am
wondering if Windows just will not let the registry be changed
remotely in this way or if there is something else I have to do.

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



Sorry, that line is correct, I was removing specific information 
relevant to our infrastructure.  That is the valuename.  The error I am 
getting is:



Traceback (most recent call last):
  File script.py, line 53, in module
value,type = _winreg.QueryValueEx(hKey,item)
WindowsError: [Error 5] Access is denied

But the real error is here I believe:

   hKey = _winreg.OpenKey (keyPath, path, 0, _winreg.KEY_SET_VALUE)

When I just do a:

   hKey = _winreg.OpenKey (keyPath, path, 0, _winreg.KEY_READ)

I receive no errors.

Thanks.


If it's complaining _as soon as_ you request write permission then I'd
say that was a permissions problem, not an error! :-)
--
http://mail.python.org/mailman/listinfo/python-list


Re: how to overload operator (a x b)?

2009-08-07 Thread exarkun

On 12:50 pm, benjamin.kap...@case.edu wrote:
On Fri, Aug 7, 2009 at 8:00 AM, dmitreydmitrey.kros...@scipy.org 
wrote:

hi all,
is it possible to overload operator  �? (And other like this one,
eg = �=,  �, = �=)
Any URL/example?
Thank you in advance, D.


That isn't an operator at all. Python does not support compound
comparisons like that. You have to do a  b and b  c.


That's partially correct.  There is no compound less than operator, or
whatever you want to call that.  However, Python does support compound
comparisons like that:

  1  2  3
 True
  1  3  2
 False
  1 == 2 == 3
 False
  2 == 2 == 2
 True
 
Jean-Paul
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: how to kill subprocess when Python process is killed?

2009-08-07 Thread mark.v.we...@gmail.com
On Aug 7, 12:57 am, alex23 wuwe...@gmail.com wrote:
 On Aug 7, 3:42 pm, mark.v.we...@gmail.com mark.v.we...@gmail.com
 wrote:

  When I kill the main process (cntl-C) the subprocess keeps running.
  How do I kill the subprocess too? The subprocess is likely to run a
  long time.

 You can register functions to run when the Python process ends by
 using the atexit[1] module.

 The following has been tested  works under Python 2.6 on Windows XP:

     import atexit

     def cleanup():
         print 'stop thesubprocessin here'

     atexit.register(cleanup)

     while True:
         pass

 [1]:http://docs.python.org/library/atexit.html

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


Re: Bug or feature: double strings as one

2009-08-07 Thread Scott David Daniels

Grant Edwards wrote:

On 2009-08-07, durumdara durumd...@gmail.com wrote:

In other languages, like Delphi (Pascal), Javascript, SQL, etc., I
must concatenate the strings with some sign, like + or ||.


In other languages like Ruby, awk, C, C++, etc. adjacent string
constants are concatenated.


I must learn this etc. language, I hear it mentioned all the time :-)

--Scott David Daniels
scott.dani...@acm.org

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


Re: Python docs disappointing - group effort to hire writers?

2009-08-07 Thread Kee Nethery
During all this conversation there was a ticket posted in the bug  
tracking system with the suggestion of each section in the official  
docs linking to a fixed wiki page that can contain user contributions.


The ticket has been closed because this addition to the official docs  
is already in the works.


So ... to everyone who thinks there needs to be a place for user  
comments to augment the official docs, it's supposed to happen. Same  
with corrections to the docs, there is supposed to be a place per  
section where people can post corrections to the docs.


I'm looking forward to the acceleration of improvements to the  
official docs based upon easy to provide user feedback. Glad to see  
that the bug tracking system is going to not be the primary means for  
documentation changes.


Kee

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


py2exe-created exe results in application failed to initialize

2009-08-07 Thread Rick King

Hi everyone,
I want to package up an application into an exe using py2exe but the 
result produces the dreaded


application failed to initialize 0x142 error.

I'm using wxPython and basically just took the sample for wxpython GUI 
that came with py2exe and changed the name. My setup is python 2.6, 
wxpython 2.8. My setup.py looks like the following.


from distutils.core import setup
import py2exe
import sys

class Target:
   def __init__(self, **kw):
   self.__dict__.update(kw)
   # for the versioninfo resources
   self.version = 0.1
   self.company_name = OWDC
   self.copyright = no copyright
   self.name = FileTool

manifest_template = '''
?xml version=1.0 encoding=UTF-8 standalone=yes?
 etc.
'''

RT_MANIFEST = 24

FileTool = Target(
   description = FileTool,
   script = filetoolGUI.py,
   other_resources = [(RT_MANIFEST, 1, manifest_template % 
dict(prog=FileTool))],

   dest_base = FileTool)

setup(
   options = {py2exe: {compressed: 1,optimize: 2,ascii: 
1,bundle_files: 1}},

   zipfile = None,
   windows = [FileTool],
   )

Any help will be greatly appreciated!

Rick King
Southfield MI USA

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


Extracting matrix from a text file

2009-08-07 Thread bbarbero

Hello to all!!

I am new in python, and I am running it on Mac with Smultron editor. I  
need to read a textfile that includes numbers (in a matrix form),  
indexes, and strings, like this:


Marsyas-kea distance matrix for MIREX 2007 Audio Similarity Exchange
Q/R 1   2   3   4   5
1   0   4.54592 4.36685 5.29463 3.85728
2   4.54592 0   3.97667 5.02151 4.64284
3   4.36685 3.97667 0   4.98743 4.83683
4   5.29463 5.02151 4.98743 0   6.04393
5   3.85728 4.64284 4.83683 6.04393 0



So I just want to keep the matrix in the middle for math computations.

0   4.54592 4.36685 5.29463 3.85728
4.54592 0   3.97667 5.02151 4.64284
4.36685 3.97667 0   4.98743 4.83683
5.29463 5.02151 4.98743 0   6.04393
3.85728 4.64284 4.83683 6.04393 0

I've seen and tried a lot of ways, like split or isinstance.. but  
never get the wanted result does anyone have an idea, or hint?  
Thank you once more for your help!


Best Regards,
Bea


This message was sent using IMP, the Internet Messaging Program.
--
http://mail.python.org/mailman/listinfo/python-list


question: why isn't a byte of a hash more uniform? how could I improve my code to cure that?

2009-08-07 Thread László Sándor
Hi all,
I am a Python novice, and right now I would be happy to simply get my job
done with it, but I could appreciate some thoughts on the issue below.

I need to assign one of four numbers to names in a list. The assignment
should be pseudo-random: no pattern whatsoever, but deterministic,
reproducible, and close to uniform. My understanding was that hash functions
would do the job. As I only needed 2 bits of treatment, I picked a byte of
the hashes generated, and even taken mod 4 of it. See the code below.

After I have written a short Python script that hashes my textfile line by
line and collects the numbers next to the original, I checked what I got.
Instead of getting around 25% in each treatment, the range is 17.8%-31.3%. I
understand that the pseudo-randomness means that the treatments should not
be neat and symmetric. Still, this variation is unacceptable for my purpose.
My understanding was that good hash functions generate numbers that look
completely random, and picking only a byte should not change that. I thought
the promise was also to get close to uniformity:
http://en.wikipedia.org/wiki/Hash_function#Uniformity. I tried all the
hashes in the hashlib module, and picked bytes from the beginning and the
end of the hashes, but treatments never were close to uniform (curiously,
always the last treatment seems to be too rare).

Maybe it is an obvious CS puzzle, I'm looking forward to standing corrected.

Thanks!

Laszlo

The script:

#! /usr/bin/python

f = open('names.txt', 'r')
g = open('nameshashed.txt', 'a')

import hashlib

for line in f:
line = line.rstrip()
h = str(hashlib.sha512(line).hexdigest())
s = line + ',' + str(ord(h[64])%4) + '\n'
g.write(s),
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Cython + setuptools not working with .pyx,only with .c-files

2009-08-07 Thread Stefan Behnel
Diez B. Roggisch wrote:
 I'm trying to build a Cython-extension as Egg.
 
 However, this doesn't work - I can either use distutils to build the
 extension, creating a myextension.c-file on the way.
 
 If that's there, I can use setuptools to build the egg.
 
 But when I remove the .c-file, the .pyx-file isn't used to re-generate it.

setuptools monkeypatch into distutils to support Pyrex if it's installed,
but most non-bleeding-edge versions do not know about Cython and thus break
the Cython distutils support when Pyrex isn't there as well.

What helps is to put a fake Pyrex installation into your sys.path, like

http://codespeak.net/svn/lxml/trunk/fake_pyrex/

as done at the top of

http://codespeak.net/svn/lxml/trunk/setup.py

I haven't tried if newer setuptools versions have been fixed yet.

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


Re: Extracting matrix from a text file

2009-08-07 Thread alex23
On Aug 8, 2:19 am, bbarb...@inescporto.pt wrote:
 I am new in python, and I am running it on Mac with Smultron editor. I  
 need to read a textfile that includes numbers (in a matrix form),  
 indexes, and strings, like this:

 Marsyas-kea distance matrix for MIREX 2007 Audio Similarity Exchange
 Q/R     1       2       3       4       5
 1       0       4.54592 4.36685 5.29463 3.85728
 2       4.54592 0       3.97667 5.02151 4.64284
 3       4.36685 3.97667 0       4.98743 4.83683
 4       5.29463 5.02151 4.98743 0       6.04393
 5       3.85728 4.64284 4.83683 6.04393 0

 So I just want to keep the matrix in the middle for math computations.

         0       4.54592 4.36685 5.29463 3.85728
         4.54592 0       3.97667 5.02151 4.64284
         4.36685 3.97667 0       4.98743 4.83683
         5.29463 5.02151 4.98743 0       6.04393
         3.85728 4.64284 4.83683 6.04393 0

 I've seen and tried a lot of ways, like split or isinstance.. but  
 never get the wanted result does anyone have an idea, or hint?  
 Thank you once more for your help!


isinstance? Are you just randomly trying functions hoping they'll
work? :)

Untested code follows:

with open(textfile,'r') as textfile:
header = textfile.next() # skip the header
col_0_size = 8 # cos it does
for line in textfile:
newline = line[col_0_size:] # strip off the index column
columns = newline.split(' ') # will give you a tuple of
strings
one, two, three, four, five = map(float, columns) # turns the
strings into floats
# do whatever you want to those values here

This is fairly standard text handling with Python, if you haven't
already you should really work through the Python tutorial[1],
especially the section on strings [2], and if you have, perhaps David
Mertz's 'Text Processing in Python'[3] may be of use.

1: http://docs.python.org/tutorial/
2: http://docs.python.org/tutorial/introduction.html#strings
3: http://gnosis.cx/TPiP/
-- 
http://mail.python.org/mailman/listinfo/python-list


PEP 8 exegetics: conditional imports?

2009-08-07 Thread kj


Conditional imports make sense to me, as in the following example:

def foobar(filename):
if os.path.splitext(filename)[1] == '.gz':
import gzip
f = gzip.open(filename)
else:
f = file(filename)
# etc.

And yet, quoth PEP 8:

- Imports are always put at the top of the file, just after any module
  comments and docstrings, and before module globals and constants.

...which seems to condemn conditional imports unequivocally. 

Then again, the PEP 8 scriptures do not explicitly mention conditional
imports at all, as far as I can tell, which leaves open the
possibility that they are still righteous. 

In fact, venerable passages in the Python standard library source
code, if properly interpreted, can be seen to carry out conditional
imports, such as this fragment recovered from random.py:

if a is None:
try:
a = long(_hexlify(_urandom(16)), 16)
except NotImplementedError:
import time
a = long(time.time() * 256) # use fractional seconds

Or even more clearly, this one from test/pystone.py:

if __name__ == '__main__':
import sys



I seek the wisdom of the elders.  Is there a consensus on the matter
of conditional imports?  Are they righteous?  Or are they the way
of the wicked?

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


Re: Bug or feature: double strings as one

2009-08-07 Thread Grant Edwards
On 2009-08-07, Scott David Daniels scott.dani...@acm.org wrote:
 Grant Edwards wrote:
 On 2009-08-07, durumdara durumd...@gmail.com wrote:
 In other languages, like Delphi (Pascal), Javascript, SQL, etc., I
 must concatenate the strings with some sign, like + or ||.
 
 In other languages like Ruby, awk, C, C++, etc. adjacent string
 constants are concatenated.

 I must learn this etc. language, I hear it mentioned all the time :-)

Definitely.  Not only does it have _all_ the features, it even
manages to simultaneously have several mutually-exclusive
features.

-- 
Grant Edwards   grante Yow! I'm meditating on
  at   the FORMALDEHYDE and the
   visi.comASBESTOS leaking into my
   PERSONAL SPACE!!
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: question: why isn't a byte of a hash more uniform? how could I improve my code to cure that?

2009-08-07 Thread Tim Chase

After I have written a short Python script that hashes my textfile line by
line and collects the numbers next to the original, I checked what I got.
Instead of getting around 25% in each treatment, the range is 17.8%-31.3%.


That sounds suspiciously like 25% with a +/- 7% fluctuation one 
might expect to see from non-random source data.


Remember that your outputs are driven purely by your inputs in a 
deterministic fashion -- if your inputs are purely random, then 
your outputs should more closely match your expected bin'ing.  If 
your inputs aren't random, you get a taste of your own medicine 
(my file has just the number 42 on every line...why isn't my 
output random?).  And randomness-of-hash-output is a red herring 
since hashing is *not* random.


Your input is also finite -- an aspect which leaves you a far cry 
from the full hash-space.  If an md5 has 32 bytes (256 bits) of 
data, your input would have to cover 2**256 possible inputs to 
see the full profile of your outputs.  That's a lot of input :)


-tkc




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


Re: Extracting matrix from a text file

2009-08-07 Thread MRAB

alex23 wrote:

On Aug 8, 2:19 am, bbarb...@inescporto.pt wrote:
I am new in python, and I am running it on Mac with Smultron editor. I  
need to read a textfile that includes numbers (in a matrix form),  
indexes, and strings, like this:


Marsyas-kea distance matrix for MIREX 2007 Audio Similarity Exchange
Q/R 1   2   3   4   5
1   0   4.54592 4.36685 5.29463 3.85728
2   4.54592 0   3.97667 5.02151 4.64284
3   4.36685 3.97667 0   4.98743 4.83683
4   5.29463 5.02151 4.98743 0   6.04393
5   3.85728 4.64284 4.83683 6.04393 0

So I just want to keep the matrix in the middle for math computations.

0   4.54592 4.36685 5.29463 3.85728
4.54592 0   3.97667 5.02151 4.64284
4.36685 3.97667 0   4.98743 4.83683
5.29463 5.02151 4.98743 0   6.04393
3.85728 4.64284 4.83683 6.04393 0

I've seen and tried a lot of ways, like split or isinstance.. but  
never get the wanted result does anyone have an idea, or hint?  
Thank you once more for your help!



isinstance? Are you just randomly trying functions hoping they'll
work? :)

Untested code follows:

with open(textfile,'r') as textfile:
header = textfile.next() # skip the header
col_0_size = 8 # cos it does
for line in textfile:
newline = line[col_0_size:] # strip off the index column
columns = newline.split(' ') # will give you a tuple of
strings

[snip]
Or:
columns = line.split(' ')[1 : ]
--
http://mail.python.org/mailman/listinfo/python-list


Re: PEP 8 exegetics: conditional imports?

2009-08-07 Thread alex23
On Aug 8, 2:50 am, kj no.em...@please.post wrote:
 Conditional imports make sense to me, as in the following example[...]
 And yet, quoth PEP 8:

     - Imports are always put at the top of the file, just after any module
       comments and docstrings, and before module globals and constants.

 ...which seems to condemn conditional imports unequivocally.

Really? It doesn't mention conditionals at all, it simply says that
imports should occur before globals and constants, not before
conditions. If you want to put conditions around your imports, then
that's the place to do it.

 I seek the wisdom of the elders.  Is there a consensus on the matter
 of conditional imports?  Are they righteous?  Or are they the way
 of the wicked?

Bear in mind that PEP 8 primarily applies to submissions to the
standard library, in order to provide a standard that aids in
understanding them. If a module is used throughout a body of code,
it's helpful to list these modules at the top of the code, for
clarity. However, if a module is only required under exceptional
conditions, you'll often see it imported at the point which it's
required: as the import occurs near the code, this mitigates the
initial requirement somewhat, and reduces the startup time of the
code.

The style guide also states:
But most importantly: know when to be inconsistent -- sometimes
the style
guide just doesn't apply.  When in doubt, use your best judgment.
Look
at other examples and decide what looks best.  And don't hesitate
to ask!

Checks around imports are often used to provide cross-version
compatibility. Embedded imports are often used when the code relying
on them is barely used. These are all very common uses.

pystone is a good example. Nothing within the modular code of pystone
requires sys, it's only imported if the module is executed, primarily
for error reporting  argument handling.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Bug or feature: double strings as one

2009-08-07 Thread kj
In h5h7cu$n4p$0...@news.t-online.com Peter Otten __pete...@web.de writes:

durumdara wrote:

 I found an interesting thing in Python.
 Today one of my defs got wrong result.
 
 When I checked the code I saw that I miss a , from the list.
 
 l = ['ó' 'Ó']
 
 Interesting, that Python handle them as one string.
 
 print ['ó' 'Ó']
 ['\xf3\xd3']
 
 I wanna ask that is a bug or is it a feature?

Feature, as others have pointed out, though I fail to see the need
for it, given that Python's general syntax for string (as opposed
to string literal) concatenation is already so convenient.  I.e.,
I fail to see why

x = (first part of a very long string 
 second part of a very long string)

is so much better than

x = (first part of a very long string  +
 second part of a very long string)

FWIW, C has the same concatenation feature for string literals.
E.g., the following is valid C:

printf(first part of a very long string 
   second part of a very long string\n);

kynn

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


Re: Extracting matrix from a text file

2009-08-07 Thread alex23
MRAB pyt...@mrabarnett.plus.com wrote:
 Or:
          columns = line.split(' ')[1 : ]

Even better, well spotted.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python docs disappointing - group effort to hire writers?

2009-08-07 Thread r
On Aug 7, 11:03 am, Kee Nethery k...@kagi.com wrote:
...(snip)
 I'm looking forward to the acceleration of improvements to the  
 official docs based upon easy to provide user feedback. Glad to see  
 that the bug tracking system is going to not be the primary means for  
 documentation changes.

+1

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


Re: Bug or feature: double strings as one

2009-08-07 Thread alex23
kj no.em...@please.post wrote:
 Feature, as others have pointed out, though I fail to see the need
 for it, given that Python's general syntax for string (as opposed
 to string literal) concatenation is already so convenient.  I.e.,
 I fail to see why

 x = (first part of a very long string 
      second part of a very long string)

 is so much better than

 x = (first part of a very long string  +
      second part of a very long string)

My impression is it's mostly for one of clarity. It's especially
useful with regular expressions, as it allows for comments to document
each element of the regex (following example shamelessly taken from
the docs (albeit with personal preferences on formatting))):

re.compile(
[A-Za-z_]   # letter or underscore
[A-Za-z0-9_]*   # letter, digit or underscore
)

Not having the plus sign present does assist (IMO) in the ease of
parsing the regex.
re.compile(
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: unicode() vs. s.decode()

2009-08-07 Thread alex23
garabik-news-2005...@kassiopeia.juls.savba.sk wrote:
 I am not sure I understood that. Must be my English :-)

I just parsed it as blah blah blah I won't admit I'm wrong and
didn't miss anything substantive.


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


Re: Python docs disappointing - group effort to hire writers?

2009-08-07 Thread alex23
Kee Nethery k...@kagi.com wrote:
 I'm looking forward to the acceleration of improvements to the  
 official docs based upon easy to provide user feedback. Glad to see  
 that the bug tracking system is going to not be the primary means for  
 documentation changes.

I'm not sure what you see as being fundamentally different between
open access to a bug tracker  open access to a wiki, other than it
being a lot more difficult to have threaded discussion on a wiki.

Why exactly is posting an open comment on a bug tracker somehow
inferior to posting an open comment on a wiki?
-- 
http://mail.python.org/mailman/listinfo/python-list


questions about object references

2009-08-07 Thread William
I have a question.  Suppose I do the following:

def myfunc(a,b):
  return a+b

myfunc2=myfunc

is there anyway to find all of the references to myfunc?  That is, can I find 
out all of the functions that may be aliased to myfunc?

second question:



class MyClass(object):
 def __init__(a,b):
   self.a=a
   self.b=b
  def myfunc(self):
    return self.a+self.b

myclass=MyClass(3,4)
myclass.myfunc2=myclass.myfunc

Is there any way to find all the references to myclass.myfunc--in this case,
myclass.myfunc2?

Thanks,
William

is there a way to 





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


Re: Python docs disappointing - group effort to hire writers?

2009-08-07 Thread David Robinow
On Fri, Aug 7, 2009 at 1:48 PM, alex23wuwe...@gmail.com wrote:
 Why exactly is posting an open comment on a bug tracker somehow
 inferior to posting an open comment on a wiki?
 When one believes that development is controlled by a cabal which is
jealous of outsiders and actively prevents improvements to the docs,
any change, even if only in perception, helps to weaken the hold of
the evil forces holding back the success of Python.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Changing Remote Registry

2009-08-07 Thread Tim Golden

Kevin Holleran wrote:

Long story short, I am using _winreg to do this.

hKey = _winreg.OpenKey (keyPath, path, 0, _winreg.KEY_SET_VALUE)
value,type = _winreg.QueryValueEx(hKey, item)
if (value == wrongValue):
   _winreg.SetValue(hKey,'',_winreg.REG_SZ,correctValue)


When I do this I receive the error:

_winreg.SetValue WindowsError: [Error 5] Access Denied


As an alternative, try using WMI instead. You'll have to look up the docs
a bit, but to get you started:

code
import wmi

reg = wmi.WMI (remote-machine, namespace=default).StdRegProv

print reg.methods.keys ()

/code

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


Re: PEP 8 exegetics: conditional imports?

2009-08-07 Thread Albert Hopkins
On Fri, 2009-08-07 at 16:50 +, kj wrote:
 
 Conditional imports make sense to me, as in the following example:
 
 def foobar(filename):
 if os.path.splitext(filename)[1] == '.gz':
 import gzip
 f = gzip.open(filename)
 else:
 f = file(filename)
 # etc.
 
 And yet, quoth PEP 8:
 
 - Imports are always put at the top of the file, just after any module
   comments and docstrings, and before module globals and constants.
 
 ...which seems to condemn conditional imports unequivocally. 
 
 Then again, the PEP 8 scriptures do not explicitly mention conditional
 imports at all, as far as I can tell, which leaves open the
 possibility that they are still righteous. 
 
 In fact, venerable passages in the Python standard library source
 code, if properly interpreted, can be seen to carry out conditional
 imports, such as this fragment recovered from random.py:
 
 if a is None:
 try:
 a = long(_hexlify(_urandom(16)), 16)
 except NotImplementedError:
 import time
 a = long(time.time() * 256) # use fractional seconds
 
 Or even more clearly, this one from test/pystone.py:
 
 if __name__ == '__main__':
 import sys
 
 

I can't speak for others... but generally you can tell when an import
belongs at the top of a module and when you need to make exceptions.  I
would say that, as a general rule, they go up top (easier to identify
what external dependencies a module have).  There are, of course,
exceptions:

  * Exceptions and other not-often-executed blocks
  * Inside test functions (where the imported modules are only used
by tests
  * Inside main() functions where the imported modules are only used
if the module is run as a script
  * When startup-time is important. Often it's necessary to have you
module up and running in an instant and import expensive
modules as-needed.
  * Dynamic import such as plugins, etc.

Of course, like everything else in PEP 8, it's meant as a guide and
not as an order.  YMMV.

-a


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


passing menu label to function

2009-08-07 Thread J Wolfe
Hi,

I would like to pass the label name of a menu to the command it is
calling, is that possible?

self.menuitem.menu.add_command(label=pass this,command = lambda i =
self.self.menuitem.menu.cget(label): self.function(i))

def function(self, i)
 print i   # print the label name


Any help would be appreciated!
Thanks!
Jonathan
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python docs disappointing - group effort to hire writers?

2009-08-07 Thread alex23
David Robinow drobi...@gmail.com wrote:
  When one believes that development is controlled by a cabal which is
 jealous of outsiders and actively prevents improvements to the docs,
 any change, even if only in perception, helps to weaken the hold of
 the evil forces holding back the success of Python.

Yeah, it's clearly all ego and assholes that's preventing Python from
being the enochian equivalent of programming languages :)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: PEP 8 exegetics: conditional imports?

2009-08-07 Thread Albert Hopkins
On Fri, 2009-08-07 at 16:50 +, kj wrote:
 
 Conditional imports make sense to me, as in the following example:
 
 def foobar(filename):
 if os.path.splitext(filename)[1] == '.gz':
 import gzip
 f = gzip.open(filename)
 else:
 f = file(filename)
 # etc.
 

I should add that in your example I would probably still put the import
at the top, e.g.:

import gzip
[...]

def foobar(filename):
if os.path.splitext(filename)[1] == '.gz':
f = gzip.open(filename)
else:
f = open(filename)

Reason being is that if later on I decide I want to write another
function inside my module that does the same thing I don't have to do
the same conditional import.

Even better, if this is something you find yourself doing often you can
create your own smart open and put it in a library:

# file anyfile

import __builtin__
import gzip

def open(filename, ...):
if filename.endswith('.gz'):
f = gzip.open(filename, ...)
else:
f = __builtin__.open(f, ...)

return f

Then:

 import anyfile
 f = anyfile.open(filename, ...)

-a


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


Database query execution times in Python?

2009-08-07 Thread pwnedd

Hi all,

I've been writing some code using libraries based on the Python Database API
2.0 (MySQLdb  pg), and so far things are working really well. There is one
thing that I have not been able to figure out how to do, however: 

Retrieve the time is took a given query to execute.

Does anyone know if this is possible?

Any help would be greatly appreciated.

Thanks!
Keith


-- 
View this message in context: 
http://www.nabble.com/Database-query-execution-times-in-Python--tp24870050p24870050.html
Sent from the Python - python-list mailing list archive at Nabble.com.

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


Re: question: why isn't a byte of a hash more uniform? how could I improve my code to cure that?

2009-08-07 Thread László Sándor

Thank you, Tim. My comments are below.

On 2009-08-07 13:19:47 -0400, Tim Chase python.l...@tim.thechases.com said:


After I have written a short Python script that hashes my textfile line by
line and collects the numbers next to the original, I checked what I got.
Instead of getting around 25% in each treatment, the range is 17.8%-31.3%.


That sounds suspiciously like 25% with a +/- 7% fluctuation one might 
expect to see from non-random source data.


Could you help me where this range comes from? (If all my lines were 
42, I wouldn't hit this range. So it cannot be a rule. Right?)




Remember that your outputs are driven purely by your inputs in a 
deterministic fashion -- if your inputs are purely random, then your 
outputs should more closely match your expected bin'ing.  If your 
inputs aren't random, you get a taste of your own medicine (my file 
has just the number 42 on every line...why isn't my output random?).  
And randomness-of-hash-output is a red herring since hashing is *not* 
random.


Thanks, I tried to be correct with pseudo-random. I understand that 
everything is dependent on input. I want it to be the case. However, I 
hoped that good hashes produce random-looking output from input with 
very little variation. It would be strange if I could not get more than 
18% of lines with a remainder of 3 (after division by 4), whatever hash 
I try just because these are names of people.




Your input is also finite -- an aspect which leaves you a far cry from 
the full hash-space.  If an md5 has 32 bytes (256 bits) of data, your 
input would have to cover 2**256 possible inputs to see the full 
profile of your outputs.  That's a lot of input :)


-tkc


OK, I understand. Could anyone suggest a better way to do this, then?

(Recap: random-looking, close-to uniform assignment of one number out 
of four possibilities to strings.)


Thanks, everyone.

Laszlo

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


Re: Module updating plans for Python 3.1: feedparser, MySQLdb

2009-08-07 Thread John Nagle

Buck wrote:

I use MySQLdb quite a bit in my work. I could volunteer to help update
it. Are there any particular bugs we're talking about or just a
straight port to 3.0?


   It's a non-trivial port.  There's a release candidate for Python 2.6;
see

https://sourceforge.net/project/shownotes.php?release_id=672239

but that was back in March and hasn't advanced since then.

There's an unofficial port of MySQLdb to
Python 2.6 for Windows.  See

https://sourceforge.net/forum/forum.php?thread_id=3108914forum_id=70460

The MySQLdb developer says that conversion to 3.0 is hard, and he's busy
doing other things.

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


Is feedparser deprecated?

2009-08-07 Thread John Nagle

  Feedparser requires SGMLlib, which has been removed from Python 3.0.
Feedparser hasn't been updated since 2007. Does this mean Feedparser
is dead?

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


Survey: Does your company use Python? Do you know a company that uses Python?

2009-08-07 Thread VanL
This is a survey to find as many companies using Python as we can. You 
can see the survey below:


http://spreadsheets.google.com/viewform?formkey=dHlwaUxIY2g0ZXpUMk4tREZDSTY3bkE6MA..

You don't need to work at the company to add it to this list! We will 
filter for duplicates.


The answers to this survey will be kept private. If you still don't want 
to identify yourself, no problem! We just want to know where Python is 
being used.



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


Re: passing menu label to function

2009-08-07 Thread Peter Otten
J Wolfe wrote:

 I would like to pass the label name of a menu to the command it is
 calling, is that possible?
 
 self.menuitem.menu.add_command(label=pass this,command = lambda i =
 self.self.menuitem.menu.cget(label): self.function(i))
 
 def function(self, i)
  print i   # print the label name

A simple pure-python approach:

def add_command_with_label(menu, label, command):
menu.add_command(label=label, command=lambda: command(label))

# ...

function = self.function
menu = self.menuitem.menu
add_command_with_label(menu, pass this, function)

Alternatively, if you plan to change the labels during runtime:

index = 1 # indices start at 1, not 0
menu.add_command(label=whatever, command=lambda index=index, menu=menu: 
function(menu.entrycget(index, label)))

(all untested, likely to contain typos)

Peter

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


Re: Setuptools - help!

2009-08-07 Thread Peter Chant
Robert Kern wrote:

 You need to put main.py into the pphoto package.
 
 $ mkdir pphoto/
 $ mv main.py pphoto/
 $ touch pphoto/__init__.py
 

Thanks, it worked.  Any ideas how to run the resulting scripts without
installing or running as root?

Pete


-- 
http://www.petezilla.co.uk
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: question: why isn't a byte of a hash more uniform? how could I improve my code to cure that?

2009-08-07 Thread Ethan Furman

László Sándor wrote:

Thank you, Tim. My comments are below.

On 2009-08-07 13:19:47 -0400, Tim Chase python.l...@tim.thechases.com 
said:


After I have written a short Python script that hashes my textfile 
line by
line and collects the numbers next to the original, I checked what I 
got.
Instead of getting around 25% in each treatment, the range is 
17.8%-31.3%.



That sounds suspiciously like 25% with a +/- 7% fluctuation one might 
expect to see from non-random source data.



Could you help me where this range comes from? (If all my lines were 
42, I wouldn't hit this range. So it cannot be a rule. Right?)




Remember that your outputs are driven purely by your inputs in a 
deterministic fashion -- if your inputs are purely random, then your 
outputs should more closely match your expected bin'ing.  If your 
inputs aren't random, you get a taste of your own medicine (my file 
has just the number 42 on every line...why isn't my output random?).  
And randomness-of-hash-output is a red herring since hashing is *not* 
random.



Thanks, I tried to be correct with pseudo-random. I understand that 
everything is dependent on input. I want it to be the case. However, I 
hoped that good hashes produce random-looking output from input with 
very little variation. It would be strange if I could not get more than 
18% of lines with a remainder of 3 (after division by 4), whatever hash 
I try just because these are names of people.




Your input is also finite -- an aspect which leaves you a far cry from 
the full hash-space.  If an md5 has 32 bytes (256 bits) of data, your 
input would have to cover 2**256 possible inputs to see the full 
profile of your outputs.  That's a lot of input :)


-tkc



OK, I understand. Could anyone suggest a better way to do this, then?

(Recap: random-looking, close-to uniform assignment of one number out of 
four possibilities to strings.)


Thanks, everyone.

Laszlo



Well,  a very simplistic method is to use the length of the input string 
modulus four.  If the names have decently random lengths, that may work.


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


Re: PEP 8 exegetics: conditional imports?

2009-08-07 Thread Peter Otten
kj wrote:

 Conditional imports make sense to me, as in the following example:
 
 def foobar(filename):
 if os.path.splitext(filename)[1] == '.gz':
 import gzip
 f = gzip.open(filename)
 else:
 f = file(filename)
 # etc.
 
 And yet, quoth PEP 8:
 
 - Imports are always put at the top of the file, just after any module
   comments and docstrings, and before module globals and constants.
 
 ...which seems to condemn conditional imports unequivocally.
 
 Then again, the PEP 8 scriptures do not explicitly mention conditional
 imports at all, as far as I can tell, which leaves open the
 possibility that they are still righteous.
 
 In fact, venerable passages in the Python standard library source
 code, if properly interpreted, can be seen to carry out conditional
 imports, such as this fragment recovered from random.py:
 
 if a is None:
 try:
 a = long(_hexlify(_urandom(16)), 16)
 except NotImplementedError:
 import time
 a = long(time.time() * 256) # use fractional seconds
 
 Or even more clearly, this one from test/pystone.py:
 
 if __name__ == '__main__':
 import sys
 
 
 
 I seek the wisdom of the elders.  Is there a consensus on the matter
 of conditional imports?  Are they righteous?  Or are they the way
 of the wicked?

If you want to take a rational approach measure speed and memory footprint 
of your program both with the conditional and unconditional imports. Then go 
with the conditional imports only if you can demonstrate a noticeable 
benefit.

This criterion is unlikely to be met for the examples you give above. time 
is a built-in module, and gzip a thin wrapper around zlib which is also 
built-in.

Peter

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


Re: PEP 8 exegetics: conditional imports?

2009-08-07 Thread Christian Heimes

kj wrote:

I seek the wisdom of the elders.  Is there a consensus on the matter
of conditional imports?  Are they righteous?  Or are they the way
of the wicked?


imports in functions are dangerous and may lead to dead locks if they 
are mixed with threads. An import should never start a thread and you 
should avoid to import code in threads.


Christian

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


  1   2   >