[ANN] Leipzig Python User Group - Meeting, April 8, 2008, 08:00pm

2008-04-07 Thread Mike Müller
=== Leipzig Python User Group ===

We will meet on Tuesday, April 8 at 8:00 pm at the training
center of Python Academy in Leipzig, Germany
( http://www.python-academy.com/center/find.html ).

Food and soft drinks are provided. Please send a short
confirmation mail to [EMAIL PROTECTED], so we can prepare
appropriately.

Everybody who uses Python, plans to do so or is interested in
learning more about the language is encouraged to participate.

While the meeting language will be mainly German, we will provide
English translation if needed.

Current information about the meetings are at
http://www.python-academy.com/user-group .

Mike



== Leipzig Python User Group ===

Wir treffen uns am Dienstag, 08.04.2008 um 20:00 Uhr
im Schulungszentrum der Python Academy in Leipzig
( http://www.python-academy.de/Schulungszentrum/anfahrt.html ).

Für das leibliche Wohl wird gesorgt. Eine Anmeldung unter
[EMAIL PROTECTED] wäre nett, damit wir genug Essen
besorgen können.

Willkommen ist jeder, der Interesse an Python hat, die Sprache
bereits nutzt oder nutzen möchte.

Aktuelle Informationen zu den Treffen sind unter
http://www.python-academy.de/User-Group zu finden.

Viele Grüße
Mike



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

Support the Python Software Foundation:
http://www.python.org/psf/donations.html


ANN: Leo 4.4.8 final

2008-04-07 Thread Edward K Ream
Leo 4.4.8 final is now available at:
http://sourceforge.net/project/showfiles.php?group_id=3458package_id=29106

This version features a new ipython plugin that provides a two-way bridge
between Leo and IPython.  See 
http://webpages.charter.net/edreamleo/IPythonBridge.html

Leo is a text editor, data organizer, project manager and much more. See:
http://webpages.charter.net/edreamleo/intro.html

The highlights of Leo 4.4.8:

- Leo's source code is now managed by bzr: see link below.
- Leo's discussion is now hosted by Google Groups: see link below.
- Arguments to g.es and g.es_print can be translated using gettext.
- Completed ILeo: a bridge between IPython and Leo.
  See http://webpages.charter.net/edreamleo/IPythonBridge.html
- Minibuffer commands may have arguments.
- @menu trees can now refer to commands created by
  @command and @button nodes.
- Added support for common @commands nodes in settings files.

Links:
--
Leo:  http://webpages.charter.net/edreamleo/front.html
Forum:http://groups.google.com/group/leo-editor
Download: http://sourceforge.net/project/showfiles.php?group_id=3458
Bzr:  http://code.launchpad.net/leo-editor/
Quotes:   http://webpages.charter.net/edreamleo/testimonials.html

Edward K. Ream   email:  [EMAIL PROTECTED]
Leo: http://webpages.charter.net/edreamleo/front.html


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

Support the Python Software Foundation:
http://www.python.org/psf/donations.html


setuptools_bzr 1.1

2008-04-07 Thread Barry Warsaw
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

I'm happy to announce the setuptools_bzr 1.1 plugin for Python's  
setuptools.  This allows setuptools to find your Python package files  
kept under the Bazaar revision control system.  setuptools_bzr 1.1  
should be compatible with Bazaar 1.3.

This version fixes bug #178159 where directories were being  
incorrectly returned from the file finder.

setuptools_bzr 1.1 is available in egg and source tarball format on  
the Python Package Index (a.k.a. Cheeseshop):

http://pypi.python.org/pypi/setuptools_bzr/1.1

To use the plugin, just modify your setup() function in setup.py like  
so:

setup(...
setup_requires = [
'setuptools_bzr',
],
...)

The project home page is on Launchpad:

https://launchpad.net/setuptoolsbzr

Enjoy,
- -Barry

-BEGIN PGP SIGNATURE-
Version: GnuPG v1.4.8 (Darwin)

iQCVAwUBR/rfanEjvBPtnXfVAQLikgP+Jp023OFRLqGaqFCT6yjkzdAhl5Sz2dAc
fvQp+1jm/VIHG4Ig0pddDecGW2i6/4yd3NdJl6cLgqoHd9m7yRu0tt8IUpqIUkw1
pSe+kBHiOsf5jj926DKvDufH1BAlIASe5g/xwiSOsYp7iAjruPe3XGq0Zl2N5U0B
dlt/ZkqeCwg=
=/ulc
-END PGP SIGNATURE-
-- 
http://mail.python.org/mailman/listinfo/python-announce-list

Support the Python Software Foundation:
http://www.python.org/psf/donations.html


Re: how to do load script; run script in a loop in embedded python?

2008-04-07 Thread Gabriel Genellina
En Thu, 03 Apr 2008 20:52:31 -0300, [EMAIL PROTECTED] escribió:

 Hi, all,

 I am currently involved in a project that needs to load/run a python
 script dynamically in a C application. The sample code is as
 following:

 PyObject *LoadScript(char *file, char *func)
 {
 PyObject *pName, *pModule, *pDict, *pFunc;

 pName = PyString_FromString(file);
 pModule = PyImport_Import(pName);
 pDict = PyModule_GetDict(pModule);
 pFunc = PyDict_GetItemString(pDict, func);
 return pFunc;
 }

Remember to check all PyObject* return values, NULL means there was an  
error.
And pay attention to reference counts! Read the section about reference  
counts in both books, Extending and Embedding, and the Python API  
Reference. http://docs.python.org/

 The first loop is perfectly ok, but on the second loop, script loading
 is successful but running will always fail.

fail in what form? A Python exception? The program freezes? A core dump?

-- 
Gabriel Genellina

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


Re: splitting an XML file on the basis on basis of XML tags

2008-04-07 Thread Stefan Behnel
[EMAIL PROTECTED] schrieb:
 Hi all,
 
  i have an XML file with the following structure::
 
 r1
 r2-|
 r3 |
 r4 |
 .   |
 .   |  constitutes one record.
 .   |
 .   |
 .   |
 /r4|
 /r3|
 /r2|
 r2
 .
 .
 .---|
 .   |
 .   |
 .   |-- there are n
 records in between
 .   |
 .   |
 .   |
 .   |
 .
 .
 /r2
 r2-|
 r3 |
 r4 |
 .   |
 .   |  constitutes one record.
 .   |
 .   |
 .   |
 /r4|
 /r3|
 /r2|
 /r1
 
 
Here r1 is the main root tag of the XML, and r2.../r2
 constitutes one record. What I would like to do is
 to extract everything (xml tags and data) between nth r2 tag and (n
 +k)th r2 tag. The extracted data is to be
 written down to a separate file.

What do you mean by written down to a separate file? Do you have a specific
format in mind?

In general, you can try this:

 from xml.etree import cElementTree as ET
 itercontext = ET.iterparse(thefile.xml, events=(start, end)
 event,root = itercontext.next()
 for event,element in itercontext:
... if event == end and element.tag == r2:
... print ET.tostring(element) # write record subtree as XML
... root.clear() # one record done, clean up everything

http://effbot.org/zone/element-iterparse.htm

You can also do things like

... print element.findtext(r3/r4)

Read the ElementTree tutorial to learn how to extract your data:

http://effbot.org/zone/element.htm#searching-for-subelements

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


Re: Parsing HTML?

2008-04-07 Thread Stefan Behnel
Benjamin wrote:
 I'm trying to parse an HTML file.  I want to retrieve all of the text
 inside a certain tag that I find with XPath.  The DOM seems to make
 this available with the innerHTML element, but I haven't found a way
 to do it in Python.

import lxml.html as h
tree = h.parse(somefile.html)
text = tree.xpath(string( some/[EMAIL PROTECTED] ))

http://codespeak.net/lxml

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


Re: html DOM

2008-04-07 Thread Stefan Behnel
Sam the Cat wrote:
 Is there a package that would allow me the same or similar functionality
 for modifying html code via the DOM model as I have in JavaScript ?  I'd
 like to parse an html file, then modify it and save the result.  I am
 not trying to do this online, rather I would like to do this on a batch
 of files stored on my hard drive.  I have found several packages that
 allow me to parse and dissect html but none that allow me to modify the
 object and save the results -- perhaps I am overlooking the obvious

http://codespeak.net/lxml/lxmlhtml.html

Here are some performance comparisons of HTML parsers:

http://blog.ianbicking.org/2008/03/30/python-html-parser-performance/

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


Re: How to get an XML DOM while offline?

2008-04-07 Thread Stefan Behnel
william tanksley wrote:
 I want to parse my iTunes Library xml. All was well, until I unplugged
 and left for the train (where I get most of my personal projects
 done). All of a sudden, I discovered that apparently the presence of a
 DOCTYPE in the iTunes XML makes xml.dom.minidom insist on accessing
 the Internet... So suddenly I was unable to do any work.
 
 I don't want to modify the iTunes XML; iTunes rewrites it too often.
 How can I prevent xml.dom.minidom from dying when it can't access the
 Internet?
 
 Is there a simpler way to read the iTunes XML? (It's merely a plist,
 so the format is much simpler than general XML.)

Try lxml. Since version 2.0, its parsers will not access the network unless
you tell it to do so.

http://codespeak.net/lxml

It's also much easier to use than minidom and much faster:

http://blog.ianbicking.org/2008/03/30/python-html-parser-performance/

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


Re: Python Data Utils

2008-04-07 Thread Jesse Aldridge
 Docstrings go *after* the def statement.

Fixed.

 changing (  to ( and  ) to ).

Changed.


I attempted to take out everything that could be trivially implemented
with the standard library.
This has left me with... 4 functions in S.py.  1 one of them is used
internally, and the others aren't terribly awesome :\  But I think the
ones that remain are at least a bit useful :)

 The penny drops :-)

yeah, yeah

 Not in all places ... look at the ends_with function. BTW, this should
 be named something like fuzzy_ends_with.

fixed

 fuzzy_match(None, None) should return False.

changed

 2. make_fuzzy function: first two statements should read s =
 s.replace(.) instead of s.replace(.).

fixed

 3. Fuzzy matching functions are specialised to an application; I can't
 imagine that anyone would be particularly interested in those that you
 provide.

I think it's useful in many cases.  I use it all the time.  It helps
guard against annoying input errors.

 A basic string normalisation-before-comparison function would
 usefully include replacing multiple internal whitespace characters by
 a single space.

I added this functionality.


 5. Casual inspection of your indentation function gave the impression
 that it was stuffed

Fixed

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


Getting jabber:iq:last with xmpppy

2008-04-07 Thread georgeencina
Hi,
I'm trying to do the following with the xmpppy library:
- log on to the google jabber server
- get idle time of one specific person on my roster.

Idle time means the values of jabber:iq:last.

When I do this in pidgin with the xmpp console open, I get the
following conversation:

(me)
iq type='get' id='purpleb22cf798' to='[EMAIL PROTECTED]/
Gaim2AD95550'
query xmlns='jabber:iq:last'/
/iq

(other person)
iq type='result' id='purpleb22cf798' to='[EMAIL PROTECTED]/
GaimA9B7F02F' from='[EMAIL PROTECTED]/Gaim2AD95550'
query xmlns='jabber:iq:last' seconds='126517'/
/iq

Now, I'd like to do the same in python.
I'm logged in to the server with the following code.

import xmpp
login = 'georgeencina' # @gmail.com
pwd = 'secret'
cnx = xmpp.Client('gmail.com')
cnx.connect( server=('talk.google.com',5223) )
cnx.auth(login,pwd, 'idlewatcher')

What would be the next step? I saw there is an xmpp.Iq class, which I
suppose is what I need to work with to construct the message I
observed in Pidgin.

Does anyone have some quick lines of code on how to construct and send
the message, and how to receive the response?

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


Re: How to get an XML DOM while offline?

2008-04-07 Thread Fredrik Lundh
Stefan Behnel wrote:

 Is there a simpler way to read the iTunes XML? (It's merely a plist,
 so the format is much simpler than general XML.)
 
 Try lxml. Since version 2.0, its parsers will not access the network unless
 you tell it to do so.
 
 http://codespeak.net/lxml

which makes it true for all ET implementations (the whole idea that 
parsing a file should result in unexpected network access is of course a 
potential security risk and one of a number of utterly stupid design 
decisions in XML).

you'll find plist reading code here, btw:

   http://effbot.org/zone/element-iterparse.htm#incremental-decoding

replace the import with from xml.etree import cElementTree if you're 
running 2.5.

(not sure if that one works with lxml, though, but that should be 
fixable.  you can at least reuse the unmarshaller dict).

/F

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


Re: while-loops enter the last time after condition is filled?

2008-04-07 Thread Sumit
On Apr 6, 4:53 am, [EMAIL PROTECTED] wrote:
 it seems to me from my results that when i use a while-loop it will
 execute once after the condition is met.
Perhaps your condition is wrong. Please provide the code where this
occured.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Help replacing os.system call with subprocess call

2008-04-07 Thread Matt Nordhoff
David Pratt wrote:
 Hi. I am trying to replace a system call with a subprocess call. I have 
 tried subprocess.Popen and subprocess.call with but have not been 
 successful. The command line would be:
 
 svnadmin dump /my/repository  svndump.db
 
 This is what I am using currently:
 
 os.system('svnadmin dump %s  %s' % (svn_dir,
  os.path.join(backup_dir, 'svndump.db')))
 
 Many thanks.

Try this:

import os.path
import subprocess

p = subprocess.Popen(
['svnadmin', 'dump', svndir],
stdout=subprocess.PIPE,
)

fh = open(os.path.join(backup_dir, 'svndump.db'), 'wb')

while True:
chunk = p.stdout.read(2**20) # 1 MB
if not chunk:
break
fh.write(chunk)

fh.close()

It reads svnadmin's stdout in 1 MB chunks, in case it's large enough
that reading the whole thing into RAM at once would be a bad idea.

No error handling. For one, you might want to add a try...finally to
ensure that fh will get closed. (Or if you have Python 2.5, use a with
statement! :-) ) Also, Popen will raise an OSError if svnadmin can't be
found or something. And this isn't even considering svnadmin erroring out...

svnadmin's stderr will go to your stderr.

I didn't test it, but I'm pretty sure it will work. (I spotted a syntax
error while writing that though.) I don't have much experience with
Popen's stdio objects, so it's possible you'd need to do something like
call p.wait() to wait for it to exit before being able to read its stdout.

It could be slower than the os.system version, since now Python is doing
all of the I/O, instead of your shell, but I doubt that'll be a big problem.

(Also, insert suggestion about using a good VCS. ;-) )
-- 
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Help replacing os.system call with subprocess call

2008-04-07 Thread Matt Nordhoff
Matt Nordhoff wrote:
 David Pratt wrote:
 Hi. I am trying to replace a system call with a subprocess call. I have 
 tried subprocess.Popen and subprocess.call with but have not been 
 successful. The command line would be:

 svnadmin dump /my/repository  svndump.db

 This is what I am using currently:

 os.system('svnadmin dump %s  %s' % (svn_dir,
  os.path.join(backup_dir, 'svndump.db')))

 Many thanks.
 
 Try this:
 
 import os.path
 import subprocess
 
 p = subprocess.Popen(
 ['svnadmin', 'dump', svndir],
 stdout=subprocess.PIPE,
 )
 
 fh = open(os.path.join(backup_dir, 'svndump.db'), 'wb')
 
 while True:
 chunk = p.stdout.read(2**20) # 1 MB
 if not chunk:
 break
 fh.write(chunk)
 
 fh.close()
 
 It reads svnadmin's stdout in 1 MB chunks, in case it's large enough
 that reading the whole thing into RAM at once would be a bad idea.
 
 No error handling. For one, you might want to add a try...finally to
 ensure that fh will get closed. (Or if you have Python 2.5, use a with
 statement! :-) ) Also, Popen will raise an OSError if svnadmin can't be
 found or something. And this isn't even considering svnadmin erroring out...
 
 svnadmin's stderr will go to your stderr.
 
 I didn't test it, but I'm pretty sure it will work. (I spotted a syntax
 error while writing that though.) I don't have much experience with
 Popen's stdio objects, so it's possible you'd need to do something like
 call p.wait() to wait for it to exit before being able to read its stdout.
 
 It could be slower than the os.system version, since now Python is doing
 all of the I/O, instead of your shell, but I doubt that'll be a big problem.
 
 (Also, insert suggestion about using a good VCS. ;-) )

This might work too:

import os.path
import subprocess

fh = open(os.path.join(backup_dir, 'svndump.db'), 'wb')

p = subprocess.Popen(
['svnadmin', 'dump', svndir],
stdout=fh,
)

# Wait for svnadmin to exit so that fh can be closed
p.wait()
fh.close()

With this, svnadmin's stdout is directly set to the file. Python isn't
being an intermediary reading from stdout and writing it to the file. At
least, that's how I expect it would work.

I didn't test this either. In particular, if Popen doesn't behave how I
expect it should, it might buffer the entirety of stdout in memory or
something, which would be bad if your svn repo is really large...
-- 
-- 
http://mail.python.org/mailman/listinfo/python-list


ldap

2008-04-07 Thread mr . enx
sorry, i'm new with Python.
 I must do interaction beetween Python and Ldap, and I  don't know how
do this.
Searching on the web I know that exists PythonLdap, but I dont'know if
this is best choise or not.

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


Re: Adherence to PEP 8 for published code (was: ANN: pry unit testing framework)

2008-04-07 Thread Aldo Cortesi
Thus spake Ben Finney ([EMAIL PROTECTED]):

 PEP 8 only has the force that people grant it. Nevertheless, it's a
 style guide that's widely accepted in the Python community, and
 adhering to it in one's code makes it easier to read for the majority,
 because it reduces the needless inconsistencies between different
 bodies of code.
 
 Conversely, deliberately diverging from the widely-accepted style
 guide increases the cognitive load on the reader; if that divergence
 is not done for a very good reason, one is imposing needless burden on
 every reader of the code.

This is getting silly. Let's recap. You are upset because I prefer this
widely-used method naming convention:

object.myName()

... to this one, which was recently adopted as a recommendation in PEP
008 for modules in the standard library:

object.my_name()

By doing so, you say, I am imposing needless burden on every reader
of my code... Well, lets look at the facts:

First, PEP 8 recommends a naming scheme only for the standard library,
and it is not follwed consistently even there. 

Second, mixedCase is very common both inside and outside the Python
project. No-one who codes regularly in Python can be unfamiliar with
it, even if they never stray beyond the standard library. 

Third, this is a minor, recently-introduced convention. Anyone would 
dislike code that chose not to name classes with an initial capital, or
used something other than self as the first method parameter. Method
naming conventions are far, far fuzzier.  The primary issue is simply
to clearly distinguish between words in multi-word names - mymethodname
would be bad, MYMETHODNAME would be even worse, but my_method_name and
myMethodName are both perfectly legible.


You are mis-interpreting the intent behind PEP-8 if you think its
authors intended to provoke shrill public condemnation of any module
that dares to use a long-standing, widely-used alternative method
naming scheme. In fact, PEP 8 contains an entire section warning
against exactly this kind of inflexible and small-minded application of
its recommendations - perhaps you should read it sometime.


  You're also vastly overstating the impact of a minor naming
  convention choice. Calling this a large black mark smacks of
  scare-mongering to me.
 
 When distributing code with the expectation that others use it, it's a
 large black mark if it deliberately shun the widely-accepted,
 easily-followed coding standards, for the above reasons.
 
 I don't see why that would be scary. If you find it so, you have my
 sympathy.

You re-enforce the point you're trying to counter beautifully. Thanks
for driving my argument home.






Regards,


Aldo



-- 
Aldo Cortesi
M: +61 419 492 863
P: +61 1300 887 007
W: www.nullcube.com
-- 
http://mail.python.org/mailman/listinfo/python-list


First Python project - comments welcome!

2008-04-07 Thread Paul Scott

I have started, and made some progress (OK it works, but needs some
love) on my first real Python application.

http://cvs2.uwc.ac.za/trac/python_tools/browser/podder

I would love some feedback on what I have done. In total this has taken
me 5 nights to do (I am working on it at night as PHP, not Python, is my
day job), so it can probably do with *lots* of improvement. All code is
GPL.

If anyone on this list is willing/able, please do give me a few
pointers, even if it is This is total crap - RTFM and come back when
you are ready I would really appreciate it!

Many thanks, and thank you to this community for helping me through the
initial bumps of getting into Python - a great dev tool IMHO!

--Paul

All Email originating from UWC is covered by disclaimer 
http://www.uwc.ac.za/portal/public/portal_services/disclaimer.htm 
-- 
http://mail.python.org/mailman/listinfo/python-list

csv.DictReader and unicode

2008-04-07 Thread Laszlo Nagy
This program

fin = codecs.open(fname,r,encoding=UTF-8)
eader = csv.DictReader(fin)
for values in reader:
pass

results in:

  File run.py, line 23, in process_file
for values in reader:
  File /usr/local/lib/python2.5/csv.py, line 83, in next
row = self.reader.next()
UnicodeEncodeError: 'ascii' codec can't encode character u'\xf6' in 
position 13: ordinal not in range(128)

As you can see the exception is thrown in csv.py. How it is possible? 
The csv.DictReader should not use ascii codec for anything, because the 
file encoding is UTF-8.

Please help.

Best,

   Laszlo

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


Re: ldap

2008-04-07 Thread Diez B. Roggisch
[EMAIL PROTECTED] wrote:

 sorry, i'm new with Python.
  I must do interaction beetween Python and Ldap, and I  don't know how
 do this.
 Searching on the web I know that exists PythonLdap, but I dont'know if
 this is best choise or not.

Who cares? Use it, and see if it's good enough for your needs. Then, if not,
see if alternatives are better.

There seldomly is the best if there are several options, because the
details and quirks of various solutions might appeal to one and repulse
someone else. But nobody is going to know what *you* like best.

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


Re: csv.DictReader and unicode

2008-04-07 Thread Laszlo Nagy
Peter Otten wrote:
 Laszlo Nagy wrote:

   
 This program

 fin = codecs.open(fname,r,encoding=UTF-8)
 eader = csv.DictReader(fin)
 for values in reader:
 pass

 results in:

   File run.py, line 23, in process_file
 for values in reader:
   File /usr/local/lib/python2.5/csv.py, line 83, in next
 row = self.reader.next()
 UnicodeEncodeError: 'ascii' codec can't encode character u'\xf6' in
 position 13: ordinal not in range(128)

 As you can see the exception is thrown in csv.py. How it is possible?
 The csv.DictReader should not use ascii codec for anything, because the
 file encoding is UTF-8.
 

 The csv module doesn't support unicode. 
I understand that csv does not support unicode. I figured out that the 
exception will not be thrown if I open the file with the built in open() 
call.
 Read the values as byte strings and decode afterwards.
   
Is there a plan to make csv reader compatible with unicode?

Thanks,

Laszlo

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


Re: csv.DictReader and unicode

2008-04-07 Thread Peter Otten
Laszlo Nagy wrote:

 This program
 
 fin = codecs.open(fname,r,encoding=UTF-8)
 eader = csv.DictReader(fin)
 for values in reader:
 pass
 
 results in:
 
   File run.py, line 23, in process_file
 for values in reader:
   File /usr/local/lib/python2.5/csv.py, line 83, in next
 row = self.reader.next()
 UnicodeEncodeError: 'ascii' codec can't encode character u'\xf6' in
 position 13: ordinal not in range(128)
 
 As you can see the exception is thrown in csv.py. How it is possible?
 The csv.DictReader should not use ascii codec for anything, because the
 file encoding is UTF-8.

The csv module doesn't support unicode. Read the values as byte strings and
decode afterwards.

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


Re: csv.DictReader and unicode

2008-04-07 Thread Jarek Zgoda
Laszlo Nagy napisał(a):
 This program
 
 fin = codecs.open(fname,r,encoding=UTF-8)
 eader = csv.DictReader(fin)
 for values in reader:
pass
 
 results in:
 
  File run.py, line 23, in process_file
for values in reader:
  File /usr/local/lib/python2.5/csv.py, line 83, in next
row = self.reader.next()
 UnicodeEncodeError: 'ascii' codec can't encode character u'\xf6' in
 position 13: ordinal not in range(128)
 
 As you can see the exception is thrown in csv.py. How it is possible?
 The csv.DictReader should not use ascii codec for anything, because the
 file encoding is UTF-8.

Reader works with byte strings, not unicode objects.

-- 
Jarek Zgoda
Skype: jzgoda | GTalk: [EMAIL PROTECTED] | voice: +48228430101

We read Knuth so you don't have to. (Tim Peters)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: ldap

2008-04-07 Thread David Harrison
On 07/04/2008, [EMAIL PROTECTED] [EMAIL PROTECTED] wrote:
 sorry, i'm new with Python.
   I must do interaction beetween Python and Ldap, and I  don't know how
  do this.
  Searching on the web I know that exists PythonLdap, but I dont'know if
  this is best choise or not.

  Thank's

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


I've used python-ldap for writing scripts to interact with LDAP
directories quite a few times, check it out here at the cheeseshop:

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


Re: Python Data Utils

2008-04-07 Thread John Machin
On Apr 7, 4:22 pm, Jesse Aldridge [EMAIL PROTECTED] wrote:

  changing (  to ( and  ) to ).

 Changed.

But then you introduced more.


 I attempted to take out everything that could be trivially implemented
 with the standard library.
 This has left me with... 4 functions in S.py.  1 one of them is used
 internally, and the others aren't terribly awesome :\  But I think the
 ones that remain are at least a bit useful :)

If you want to look at stuff that can't be implemented trivially using
str/unicode methods, and is more than a bit useful, google for
mxTextTools.


  A basic string normalisation-before-comparison function would
  usefully include replacing multiple internal whitespace characters by
  a single space.

 I added this functionality.

Not quite. I said whitespace, not space.

The following is the standard Python idiom for removing leading and
trailing whitespace and replacing one or more whitespace characters
with a single space:

def normalise_whitespace(s):
return ' '.join(s.split())

If your data is obtained by web scraping, you may find some people use
'\xA0' aka NBSP to pad out fields. The above code will get rid of
these if s is unicode; if s is str, you need to chuck
a .replace('\xA0', ' ') in there somewhere.

HTH,
John

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


Re: A funnily inconsistent behavior of int and float

2008-04-07 Thread Colin J. Williams
Mark Dickinson wrote:
 On Apr 6, 1:29 pm, Lie [EMAIL PROTECTED] wrote:
 I've noticed some oddly inconsistent behavior with int and float:

 Python 2.5.1 (r251:54863, Mar  7 2008, 03:39:23)
 [GCC 4.1.3 20070929 (prerelease) (Ubuntu 4.1.2-16ubuntu2)] on linux2 
 int('-  345')

 -345

 works, but

 float('-   345.083')
 Traceback (most recent call last):
   File stdin, line 1, in module
 ValueError: invalid literal for float(): -   345.083
 
 This is a known issue, that has been fixed for Python 3.0.
 It was decided not to risk breakage by changing this in
 Python 2.x.  See:
 
 http://bugs.python.org/issue1779
 
 Mark

This is good but the documentation for 
3.0 is missing the syntax documentation 
from 2.5

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


Re: csv.DictReader and unicode

2008-04-07 Thread Peter Otten
Laszlo Nagy wrote:

 Read the values as byte strings and decode afterwards.

Or monkey-patch:

import csv

def make_reader(fin, encoding=UTF-8): 
reader = csv.DictReader(fin)
reader.reader = ([col.decode(encoding) for col in row] for row in 
reader.reader)
return reader

fin = open(example.csv)
for record in make_reader(fin):
print record

 Is there a plan to make csv reader compatible with unicode?

I don't know.

Peter 

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


Re: splitting an XML file on the basis on basis of XML tags

2008-04-07 Thread bijeshn

 What do you mean by written down to a separate file? Do you have a specific
 format in mind?



sorry, it should be extracted into separate files. i.e. if i have an
XML file containing 10 million records, i need to split the file to
100 files containing 100,000 records each.

i hope this is clearer...
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python-by-example - new online guide to Python Standard Library

2008-04-07 Thread Gerard Flanagan
On Apr 3, 8:33 pm, AK [EMAIL PROTECTED] wrote:
 AK wrote:
  Hello,

  I find that I learn easier when I go from specific examples to a more
  general explanation of function's utility and I made a reference guide
  that will eventually document all functions, classes and methods in
  Python's Standard Library. For now, I covered about 20 most important
  modules. I will be adding more modules and eventually I'll cover
  everything. Here's my progress so far, let me know if this is useful;
  I'll be glad to hear comments/suggestions/etc:

 http://www.lightbird.net/py-by-example/

 I uploaded an updated site incorporating most of the suggestions I
 received and fixing some errors along the way. I will be adding more
 examples to modules that are already covered and will try to add more
 modules during the following week. Thanks again to all who posted advice
 and comments!


I don't know if you've heard of Sphinx, it's being used to generate
the Python 2.6 docs but can also be used standalone. It may have
benefits for a project like yours, particularly with regard to
collaboration and maintainability over the long-term. I've been
playing about with it myself and put together a `very` basic site
using a few of the pages from your site:

The generated html is here:

http://gflanagan.net/site/python/pbe/pbe-sphinx-skeleton-build-0.1.tar.gz
http://gflanagan.net/site/python/pbe/pbe-sphinx-skeleton-build-0.1.zip

And the actual Sphinx 'app':

http://gflanagan.net/site/python/pbe/pbe-sphinx-skeleton-0.1.tar.gz
http://gflanagan.net/site/python/pbe/pbe-sphinx-skeleton-0.1.zip

For which you would need Sphinx (obviously): http://sphinx.pocoo.org/
which depends on docutils: http://docutils.sourceforge.net/
and pygments: http://pygments.org/

There's a make.bat for windows and a MakeFile for unix but the latter
is untested.

I've no time to spend on it further, but you're welcome to what's
there if you've any interest. (I repeat, it's just a proof of concept
- don't expect too much.)

As you might see, I preferred 'doctest' style code rather than the
commented results, but each to their own.

Sphinx uses ReST as its input format - below is what I cooked up for
'restifying' your html, not perfect but a brave attempt!

All the best.

Gerard

--

import textwrap
import re
import os
from BeautifulSoup import BeautifulSoup

def onmatch(m):
return '\nRESULT' + m.group(2)

result = re.compile('span class=result(# )?(.*?)/span',
re.DOTALL | re.MULTILINE)
src = 'c:/workspace/pbe/orig/'

for infile in os.listdir(src):
if not infile.endswith('-module.html'):
continue
title = infile[:-5]
infile = src + infile
outfile = infile[:-4] + 'rst'
out = open(outfile, 'wb')
out.write(title + '\n')
out.write('='*len(title) + '\n\n')

soup = BeautifulSoup(open(infile).read())

for p in soup.findAll('ul'):
print  out
for line in textwrap.wrap(p.span.contents[0], 79):
print  out,  line.lstrip()
#code = ''.join(comment.sub(onmatch, str(p.pre)))
code = result.sub(onmatch, str(p.pre)).splitlines()[1:-1]
if code:
print  out
print  out, '::'
print  out
for line in code:
line = line.strip()
if line:
leader = ''
if line.startswith('RESULT'):
line = line[len('RESULT'):]
else:
leader += ' '
print  out,  leader + line
else:
print  out
print  out

out.close()
--

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


Re: splitting an XML file on the basis on basis of XML tags

2008-04-07 Thread bijeshn

pls disregard the above post

On Apr 7, 3:13 pm, bijeshn [EMAIL PROTECTED] wrote:
  What do you mean by written down to a separate file? Do you have a 
  specific
  format in mind?

 sorry, it should be extracted into separate  XML files. i.e. if i have an
 XML file containing 10 million records, i need to split the file to
 100 XML files containing 100,000 records each.

 i hope this is clearer...

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


Re: First Python project - comments welcome!

2008-04-07 Thread Steve Holden
Paul Scott wrote:
 I have started, and made some progress (OK it works, but needs some
 love) on my first real Python application.
 
 http://cvs2.uwc.ac.za/trac/python_tools/browser/podder
 
 I would love some feedback on what I have done. In total this has taken
 me 5 nights to do (I am working on it at night as PHP, not Python, is my
 day job), so it can probably do with *lots* of improvement. All code is
 GPL.
 
 If anyone on this list is willing/able, please do give me a few
 pointers, even if it is This is total crap - RTFM and come back when
 you are ready I would really appreciate it!
 
 Many thanks, and thank you to this community for helping me through the
 initial bumps of getting into Python - a great dev tool IMHO!
 
The code looks pretty good to someone that doesn't know Gtk graphics.

184: self.wTree2=gtk.glade.XML(globaldir+podder.glade,serverdialogue)

could really do with using os.path.join() if you want to be easily 
cross-platform. Similarly the other places you use globaldir+

At line 321 you loop while True over a Queue.Queue object until the 
QueueEmpty exception is raised, then break out of the loop. It would be 
easier to loop while not queue.empty(). I know the docs say that this 
function is not reliable due to multi-threading semantics, but I doubt 
it will make your program less responsive.

You even put docstrings on your code. WEll done, you are going to enjoy 
Python.

regards
  Steve
-- 
Steve Holden+1 571 484 6266   +1 800 494 3119
Holden Web LLC  http://www.holdenweb.com/

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


Re: splitting an XML file on the basis on basis of XML tags

2008-04-07 Thread bijeshn
the extracted files are to be XML too. ijust need to extract it raw
(tags and data just like it is in the parent XML file..)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: First Python project - comments welcome!

2008-04-07 Thread Paul Scott

On Mon, 2008-04-07 at 07:05 -0400, Steve Holden wrote:
 
 The code looks pretty good to someone that doesn't know Gtk graphics.
 

Err, neither do I, so I guess that means its OK? :)

 184: self.wTree2=gtk.glade.XML(globaldir+podder.glade,serverdialogue)
 
 could really do with using os.path.join() if you want to be easily 
 cross-platform. Similarly the other places you use globaldir+
 

Ah, OK, will take that into cognisance. Main use of the application will
be on Ubuntu based laptops in lecture theatres, so I am not overly
concerned, however, in the interests of writing better code, and maybe
even making it useful to others outside of my project, I will try and
fix it up.

 At line 321 you loop while True over a Queue.Queue object until the 
 QueueEmpty exception is raised, then break out of the loop. It would be 
 easier to loop while not queue.empty(). I know the docs say that this 
 function is not reliable due to multi-threading semantics, but I doubt 
 it will make your program less responsive.
 

That class is not yet even implemented. I put that code in there to do
an upload progress bar for the XML-RPC call, but can't yet figure out
how to do it properly. That being said, I will take your notes into
consideration when I get to it. Thanks!

 You even put docstrings on your code. WEll done, you are going to enjoy 
 Python.

Force of habit. :)

Thanks very much for your comments, I *really* appreciate it!

--Paul

All Email originating from UWC is covered by disclaimer 
http://www.uwc.ac.za/portal/public/portal_services/disclaimer.htm 
-- 
http://mail.python.org/mailman/listinfo/python-list

Wxpython. Is it possible to change layout in a running application? Selfmade listbox

2008-04-07 Thread Soren
Hi,

Id like to make my own special listbox.. I want to able (at the push
of a button) to add another item to my special listbox... each item is
a panel with a label, some buttons and maybe a text control.

I've tried adding a new panel object with the stuff i want to the
sizer i'm using for my listbox (which is a panel which can contain
other panels)... and then run update() and refresh() on everything...
But it doesn't work.. i see a panel appearing, but it's just a small
square in the corner of my listbox panel, and it only works the
first time... nothing new appears when I push the button again.

Is it at all possible to do this? Has anyone created something
similar? Does anyone know what i'm doing wrong?

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


Re: while-loops enter the last time after condition is filled?

2008-04-07 Thread [EMAIL PROTECTED]
On 6 avr, 01:53, [EMAIL PROTECTED] wrote:
 it seems to me from my results that when i use a while-loop it will
 execute once after the condition is met.

 ie the conditions is met the code executes one time more and then
 quits.

The problem is obviously in your code, but since you failed to post
the minimal code exhibiting the problem, we can't help.
-- 
http://mail.python.org/mailman/listinfo/python-list


Calling CVF-Fortran-dll with ctypes and simple structure

2008-04-07 Thread Michael Schäfer
Hi all,

I deal with the old problem passing characters from python to a
fortran dll build with CFV6.6c.
I reduced our complex structure to a simple one.  Here is the Fortran
code:

  SUBROUTINE DEMO2L(s)

C sample for calling CVF6.6c-DLLs from
C vb/vba/python with simple structure

!DEC$ ATTRIBUTES DLLEXPORT::DEMO2L

TYPE rcDEMO
   INTEGER a
   REAL b
   CHARACTER c*9
END TYPE

TYPE(rcDEMO) :: s
C
WRITE(*,*) s.a, s.b, s.c
C sample calculation:
s.a = s.a*10
s.b = s.b**2.3
s.c = 'Sample'

  RETURN
  END

From VB the calling is very simple:

Declare Sub DEMO2L Lib release\demo1l.dll (ByRef k As rcDEMO)

Type rcDEMO
  a As Long
  b As Single
  c As String * 9
End Type

Dim k As rcDEMO

Sub run()

k.a = 2
k.b = 3#
k.c = Test

Call DEMO2L(k)

Debug.Print k.a, k.b, k.c

End Sub

and result to:   2012,5135  Sample

When I try this from python:

from ctypes import *

class rcDemo(Structure):
  _fields_ = [
('a', c_int),
('b', c_float),
('c', c_char_p),
 ]

mydll = windll.LoadLibrary(release\DEMO1L.DLL)

rc = rcDemo()
rc.a = 2
rc.b = 3.
rc.c = Test56789

mydll.DEMO2L(byref(rc))

print rc.a
print rc.b
print  + rc.c + 

I got2   3.00 ♀Å╣ from the debug print in
Fortran and

20
12.513502121
Traceback (most recent call last):
  File run_demo.py, line 21, in ?
print  + rc.c + 
ValueError: invalid string pointer 0x706D6153

from Python. When passing only the string in a argument list instead
of the structure and considering to pass the length of the string as
2nd argument I am be able to send this characters to the dll and
receive a changed value back.

Have anyone an idea or perhaps a solution ;-) doing this in a
structure?

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

Re: ldap

2008-04-07 Thread Michael Ströder
[EMAIL PROTECTED] wrote:
 Searching on the web I know that exists PythonLdap, but I dont'know if
 this is best choise or not.

http://python-ldap.sf.net is the most complete implementation I know of. 
(Being the maintainer I might be biased.) It has the caveat of depending 
on the OpenLDAP client libs and possibly other libs (OpenSSL, 
cyrus-sasl). So generating a binary build can be heavy work. For which 
OSs are you developing and which kind of LDAP servers do you want to access?

Ciao, Michael.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: First Python project - comments welcome!

2008-04-07 Thread cokofreedom
Just a random check. Is __gsignals__ a builtin type? Else it would
probably be better not to include the postfix underscores. Though I
might be wrong here. Otherwise seems pretty good and well organised. I
hate it when people go comment mad, but you've kept them to the places
where an explanation is required. Good job :=)
-- 
http://mail.python.org/mailman/listinfo/python-list


Dependency Queue

2008-04-07 Thread Carl Banks
I'm looking for any information about a certain kind of dynamic data
structure.  Not knowing if it has some well-known name that I could
have Googled, I'll just call it a dependency queue.  It's like a
priority queue except instead of a strict ordering of items by
priority, there is only a topological ordering (like you would have in
a directed acyclic graph).

To date I've been generating a dependency graph in advance every
iteration through my main loop, doing a topsort, and executing the
values in order (the values are callable objects--this is a
scheduler).

However, I'd like a dynamic dependency queue for two reasons: it would
simplify things to not have to generate the whole graph in advance,
and it could improve performance to run some tasks of the next
iteration in the present one (this could potentially make better use
of the dual-core and graphics hardware).

I'm pretty sure I could hack out this structure on my own, but I'd
like to see any prior information if there is any, in case anyone's
figured out things like, Is there an easy way to detect cycles on
insertion? and so on.


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


Re: @x.setter property implementation

2008-04-07 Thread Floris Bruynooghe
On Apr 6, 6:41 pm, Daniel Fetchinson [EMAIL PROTECTED]
wrote:
  I found out about the new methods on properties, .setter()
  and .deleter(), in python 2.6.  Obviously that's a very tempting
  syntax and I don't want to wait for 2.6...

  It would seem this can be implemented entirely in python code, and I
  have seen hints in this directrion.  So before I go and try to invent
  this myself does anyone know if there is an official implementation
  of this somewhere that we can steal until we move to 2.6?

 The 2.6 source?

Have been grepping all over the place and failed to find it.  I found
the test module for them, but that doesn't get me very far...
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: splitting an XML file on the basis on basis of XML tags

2008-04-07 Thread Stefan Behnel
bijeshn wrote:
 the extracted files are to be XML too. ijust need to extract it raw
 (tags and data just like it is in the parent XML file..)

Ah, so then replace the print tostring() line in my example by

ET.ElementTree(element).write(outputfile.xml)

and you're done.

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


Re: Wxpython. Is it possible to change layout in a running application? Selfmade listbox

2008-04-07 Thread Iain King
On Apr 7, 12:50 pm, Soren [EMAIL PROTECTED] wrote:
 Hi,

 Id like to make my own special listbox.. I want to able (at the push
 of a button) to add another item to my special listbox... each item is
 a panel with a label, some buttons and maybe a text control.

 I've tried adding a new panel object with the stuff i want to the
 sizer i'm using for my listbox (which is a panel which can contain
 other panels)... and then run update() and refresh() on everything...
 But it doesn't work.. i see a panel appearing, but it's just a small
 square in the corner of my listbox panel, and it only works the
 first time... nothing new appears when I push the button again.

 Is it at all possible to do this? Has anyone created something
 similar? Does anyone know what i'm doing wrong?

 Thanks,
 Soren

Without your code can only really guess, but I'd check that the new
panel you are trying to add to the sizer has the listbox as a parent.

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


Re: Wxpython. Is it possible to change layout in a running application? Selfmade listbox

2008-04-07 Thread Mike Driscoll
On Apr 7, 6:50 am, Soren [EMAIL PROTECTED] wrote:
 Hi,

 Id like to make my own special listbox.. I want to able (at the push
 of a button) to add another item to my special listbox... each item is
 a panel with a label, some buttons and maybe a text control.

 I've tried adding a new panel object with the stuff i want to the
 sizer i'm using for my listbox (which is a panel which can contain
 other panels)... and then run update() and refresh() on everything...
 But it doesn't work.. i see a panel appearing, but it's just a small
 square in the corner of my listbox panel, and it only works the
 first time... nothing new appears when I push the button again.

 Is it at all possible to do this? Has anyone created something
 similar? Does anyone know what i'm doing wrong?

 Thanks,
 Soren

I'm pretty sure it's possible, but as Iain pointed out, it's hard to
guess what you're doing wrong without some code. Try making a sample
app that demonstrates the issue: http://wiki.wxpython.org/MakingSampleApps

Also, you will probably receive more help at the wxPython specific
list, found here:

http://wxpython.org/maillist.php

HTH

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


Re: Is there any way to say ignore case with in?

2008-04-07 Thread Mel
Paul McGuire wrote:
 On Apr 6, 8:53 am, Martin v. Löwis [EMAIL PROTECTED] wrote:
 I know I could use:-
 if lower(string1) in lower(string2):
 do something
 but it somehow feels there ought to be an easier (tidier?) way.
 Take, for example, U+017F, LATIN SMALL LETTER LONG S. It's .lower() is
 the same character, as the character is already in lower case.
 It's .upper() is U+0053, LATIN CAPITAL LETTER S. Notice that the LONG
 is gone - there is no upper-case version of a long s.
 It's .upper().lower() is U+0073, LATIN SMALL LETTER S.

 So should case-insensitive matching match the small s with the small
 long s, as they have the same upper-case letter?
[ ... ]
 [i for i in range(65536) if unichr(i).lower().upper() !=
 ... unichr(i).upper()]
 [304, 1012, 8486, 8490, 8491]
 
 Instead of 15 exceptions to the rule, conversion to upper has only 5
 exceptions.  So perhaps comparsion of upper's is, while not foolproof,
 less likely to encounter these exceptions?  Or at least, simpler to
 code explicit tests.

I don't know what meaning is carried by all those differences in 
lower-case glyphs.  Converting to upper seems to fold together a lot 
of variant pi's and rho's which I think would be roughly a good thing.
I seem to recall that the tiny iota (ypogegrammeni) has or had 
grammatical significance.  The other effect would be conflating 
physics' Angstron unit and Kelvin unit signs with ring-a and K. 
Applicaton programmers beware.

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


Re: Learning curve for new database program with Python?

2008-04-07 Thread Simon Brunning
On Sun, Apr 6, 2008 at 2:31 AM, John Nagle [EMAIL PROTECTED] wrote:

 Basic SQL isn't that hard.  Learn CREATE, SELECT, INSERT,
  UPDATE, and DELETE syntax.  That's enough for most simple
  applications.

Agreed. What's more, I've found SQL to be the single most transferable
skill in IT.. No matter what language and platform you find yourself
working on, you'll find an SQL driven relational database somewhere in
the mix. Learning SQL isn't a waste of time, I guarantee it.

-- 
Cheers,
Simon B.
[EMAIL PROTECTED]
http://www.brunningonline.net/simon/blog/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Presumably an import is no faster or slower than opening a file?

2008-04-07 Thread tinnews
Paul McGuire [EMAIL PROTECTED] wrote:
 On Apr 6, 8:41 am, [EMAIL PROTECTED] wrote:
  I'm trying to minimise the overheads of a small Python utility, I'm
  not really too fussed about how fast it is but I would like to
  minimise its loading effect on the system as it could be called lots
  of times (and, no, I don't think there's an easy way of keeping it
  running and using the same copy repeatedly).
 
  It needs a configuration file of some sort which I want to keep
  separate from the code, is there thus anything to choose between a
  configuration file that I read after:-
 
      f = open(configFile, 'r')
 
  ... and importing a configuration written as python dictionaries or
  whatever:-
 
      import myConfig
 
  --
  Chris Green
 
 Chris -
 
 The question is less an issue of the file overhead (both must open a
 file, read its contents, and then close it) than what is done with the
 file contents afterwards.
 
 A config file containing .INI-style or whatever content will need to
 be parsed into Python data/objects, and likely use Python code to do
 so.  An import will use the Python compiler itself, using optimized
 compiled C code to do the parsing and data/object construction.  But I
 think you would only see the distinction in a config file of
 substantial size or complexity.  If you think this will make a
 substantial difference in performance, then code up a test case and
 time it.
 
 In general, I'd say that splitting performance hairs to tip a design
 choice one way or another is a misguided premature optimization.
 
I quite agree (about the splitting hairs bit that is), as I said
before I just wanted to check that I wasn't missing anything really
obvious and, thus, that there probably isn't much to choose between
the two approaches.  Therefore I'll decide which way to do it on the
basis of 'usability'.

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

Re: A file iteration question/problem

2008-04-07 Thread tinnews
Arnaud Delobelle [EMAIL PROTECTED] wrote:
 On Apr 6, 4:40 pm, [EMAIL PROTECTED] wrote:
  I want to iterate through the lines of a file in a recursive function
  so I can't use:-
 
      f = open(listfile, 'r')
      for ln in f:
 
  because when the function calls itself it won't see any more lines in
  the file.  E.g. more fully I want to do somthing like:-
 
  def recfun(f)
      while True:
          str = readline(f)
          if (str == )
              break;
          #
          # do various tests
          #
          if something:
              recfun(f)
 
  Is there no more elegant way of doing this than that rather clumsy
  while True followed by a test?
 
  --
  Chris Green
 
 You could use an iterator over the lines of the file:
 
 def recfun(lines):
 for line in lines:
 # Do stuff
 if condition:
 recfun(lines)
 
 lines = iter(open(filename))
 recfun(lines)
 
Does that work though?  If you iterate through the file with the for
line in lines: in the first call of recfun(lines) you surely can't do
for line in lines: and get any sort of sensible result in recursive
calls of recfun(lines) can you?

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

Re: @x.setter property implementation

2008-04-07 Thread Andrii V. Mishkovskyi
2008/4/7, Floris Bruynooghe [EMAIL PROTECTED]:

  Have been grepping all over the place and failed to find it.  I found
  the test module for them, but that doesn't get me very far...


I think you should take a look at 'descrobject.c' file in 'Objects' directory.

-- 
Wbr, Andrii Mishkovskyi.

He's got a heart of a little child, and he keeps it in a jar on his desk.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: First Python project - comments welcome!

2008-04-07 Thread [EMAIL PROTECTED]
On 7 avr, 10:03, Paul Scott [EMAIL PROTECTED] wrote:
 I have started, and made some progress (OK it works, but needs some
 love) on my first real Python application.

 http://cvs2.uwc.ac.za/trac/python_tools/browser/podder

 I would love some feedback on what I have done. In total this has taken
 me 5 nights to do (I am working on it at night as PHP, not Python, is my
 day job), so it can probably do with *lots* of improvement. All code is
 GPL.

 If anyone on this list is willing/able, please do give me a few
 pointers, even if it is This is total crap - RTFM and come back when
 you are ready I would really appreciate it!

Ok, since you asked for it:

22  try:
23  import pygtk
24  #tell pyGTK, if possible, that we want GTKv2
25  pygtk.require(2.0)
26  except:

Don't use bare except clauses, always mention the exception class
you're expecting and let every other exception propagate. Else you may
shadow other unexpected errors (ie: what if the user has a pygtk.py
file in her pythonpath that is unrelated to the expected pygtk
module ? And yes, this kind of thing can and does happen, more often
than you may think).

27  print You need to install pyGTK or GTKv2 or set your
PYTHONPATH correctly

stdout is for normal program outputs. Error messages should go to
sys.stderr.

28  print try: export PYTHONPATH=/usr/local/lib/python2.2/site-
packages/
29  sys.exit(1)


40  class appgui:

1/ naming convention : should be Appgui or AppGui (cf pep08)
2/ unless you have very compelling reasons to stick with old-style
classes, make your class a newstyle one:

class AppGui(object):

41  def __init__(self):
42  
43  In this init we are going to display the main recorder
window
44  
45  global globaldir
46  globaldir=./

Since this doesn't depend on anything passed to the initializer, and
is initialized with a constant value, this should go to the top-level,
ie:

GLOBAL_DIR = './'

class AppGui(object):
   # code here


58  on_window1_destroy : (gtk.main_quit)}

This may not do what you think. If what you want is to pass a tuple,
the syntax is:

on_window1_destroy : (gtk.main_quit, )
 }

notice the trailing ','


59  self.wTree.signal_autoconnect (dic)
60  self.status = STOPPED
61  return

You don't need this return statement.

64  def record_click(self,widget):
(snip)
70  self.player = gst.Pipeline(recorder)
(snip)
87  def pause_click(self,widget):
(snip)
94  if widget.get_active():
95  # print paused recording...
96  self.player.set_state(gst.STATE_PAUSED)

This may be a bit of a personnal preference, but I never feel
confortable with attributes added in a method (I mean, else than the
initializer) and accessed in another. Specially when it's a very
important attribute... One reason being that I don't get the 'big
picture' just from browsing the __init__ and the methods names,
another being that now pause_click depends on record_click having been
called before - yet nothing mentions it, nothing documents it, you
have to read the whole code to find about it.



204 try:
205 f=open(globaldir+lecture.ogg, 'r')

Steve Holden already commented on using os.path.join here, and I
commented about using a top-level constant (GLOBAL_DIR), which will
makes thing more explicit (we know it's a constant, and we will look
for it at the top-level).  I'd recommend to also use top-level
symbolic constants for the file names, instead of hardcoding them in
the methods. Same thing for urls etc.

206 b=open(globaldir+basefile, 'w')
207 encoded = base64.encode(f,b)
208 b.close()
209 except:
210 print File could not be opened...

And what you get an exception in the call to base64.encode ? This is
*exactly* why you should *never* use bare except clauses.

(snip more bare except clauses...)

And while we're at it, you forget to close f.

283 if type(currentThread()) != _MainThread:

Since types are singletons, you can use the identity test here:

 if type(currentThread()) is not  _MainThread:

306 def __init__ (self, parrent, queue, signal,
sendPolicy):
(snip)
309 self.parrent = parrent

Don't you mean 'parent' ?-)

316 v = self.queue.get()
317 if v == None:

identity test again (more idiomatic, and a little bit faster)

318 break
319 threads_enter()
320 l = [v]

'v' is a very poor name, and 'l' is even worse.

431 # Get
stuff
#
432 def isCancelled (self):
433 return self.cancelled
434
435 def isDone (self):
436 return self.done

Re: Wxpython. Is it possible to change layout in a running application? Selfmade listbox

2008-04-07 Thread SPE - Stani's Python Editor
On Apr 7, 2:54 pm, Mike Driscoll [EMAIL PROTECTED] wrote:
 On Apr 7, 6:50 am, Soren [EMAIL PROTECTED] wrote:
  Hi,

  Id like to make my own special listbox.. I want to able (at the push
  of a button) to add another item to my special listbox... each item is
  a panel with a label, some buttons and maybe a text control.

  I've tried adding a new panel object with the stuff i want to the
  sizer i'm using for my listbox (which is a panel which can contain
  other panels)... and then run update() and refresh() on everything...
  But it doesn't work.. i see a panel appearing, but it's just a small
  square in the corner of my listbox panel, and it only works the
  first time... nothing new appears when I push the button again.

  Is it at all possible to do this? Has anyone created something
  similar? Does anyone know what i'm doing wrong?
To remove any doubt, yes this is possible. I guess you forgot to call
the Layout method of the sizer (only update or refresh won't help).

 Also, you will probably receive more help at the wxPython specific
 list, found here:

 http://wxpython.org/maillist.php
That is indeed the best list for wxpython related issues.

Good luck,
Stani
--
Phatch - Photo Batch Processor - http://photobatch.stani.be
SPE - Python Editor - http://pythonide.stani.be
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Learning curve for new database program with Python?

2008-04-07 Thread Greg Lindstrom
On Sun, Apr 6, 2008 at 2:31 AM, John Nagle [EMAIL PROTECTED] wrote:

 Basic SQL isn't that hard.  Learn CREATE, SELECT, INSERT,
  UPDATE, and DELETE syntax.  That's enough for most simple
  applications.

And then learn more advanced SQL: joins, nested selects, pivot tables and
stored procedures.  You can do a lot of processing inside the database
which cuts down on data running over the wire.

SQL is one of the areas I wish I had mastered (much) earlier in my career
--greg.
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: Help replacing os.system call with subprocess call

2008-04-07 Thread David Pratt
Hi David and Matt. I appreciate your help which has got me moving 
forward again so many thanks for your reply. I have been using 
subprocess.Popen a fair bit but this was the first time I had to use 
subprocess to capture large file output. The trouble I was having was 
with the process would just hang. Chunking was the solution. I guess I 
assumed this would be taken care of in the internals.

Overall, I wish subprocess had some better documentation since it is 
definitely not a drop in replacement for os.system. In other 
circumstances I am using subprocess.call() for simple calls which works 
fine.

The speed of this solution is slower than os.system. Would a queue of 
some kind be needed to speed this up? Has anyone implemented something 
like this? Many thanks.

Regards,
David

Matt Nordhoff wrote:
 David Pratt wrote:
 Hi. I am trying to replace a system call with a subprocess call. I have 
 tried subprocess.Popen and subprocess.call with but have not been 
 successful. The command line would be:

 svnadmin dump /my/repository  svndump.db

 This is what I am using currently:

 os.system('svnadmin dump %s  %s' % (svn_dir,
  os.path.join(backup_dir, 'svndump.db')))

 Many thanks.
 
 Try this:
 
 import os.path
 import subprocess
 
 p = subprocess.Popen(
 ['svnadmin', 'dump', svndir],
 stdout=subprocess.PIPE,
 )
 
 fh = open(os.path.join(backup_dir, 'svndump.db'), 'wb')
 
 while True:
 chunk = p.stdout.read(2**20) # 1 MB
 if not chunk:
 break
 fh.write(chunk)
 
 fh.close()
 
 It reads svnadmin's stdout in 1 MB chunks, in case it's large enough
 that reading the whole thing into RAM at once would be a bad idea.
 
 No error handling. For one, you might want to add a try...finally to
 ensure that fh will get closed. (Or if you have Python 2.5, use a with
 statement! :-) ) Also, Popen will raise an OSError if svnadmin can't be
 found or something. And this isn't even considering svnadmin erroring out...
 
 svnadmin's stderr will go to your stderr.
 
 I didn't test it, but I'm pretty sure it will work. (I spotted a syntax
 error while writing that though.) I don't have much experience with
 Popen's stdio objects, so it's possible you'd need to do something like
 call p.wait() to wait for it to exit before being able to read its stdout.
 
 It could be slower than the os.system version, since now Python is doing
 all of the I/O, instead of your shell, but I doubt that'll be a big problem.
 
 (Also, insert suggestion about using a good VCS. ;-) )
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: A file iteration question/problem

2008-04-07 Thread Gabriel Genellina
En Mon, 07 Apr 2008 10:09:13 -0300, [EMAIL PROTECTED] escribió:
 Arnaud Delobelle [EMAIL PROTECTED] wrote:

 def recfun(lines):
 for line in lines:
 # Do stuff
 if condition:
 recfun(lines)

 lines = iter(open(filename))
 recfun(lines)

 Does that work though?  If you iterate through the file with the for
 line in lines: in the first call of recfun(lines) you surely can't do
 for line in lines: and get any sort of sensible result in recursive
 calls of recfun(lines) can you?

Why not? Test and see what happens.

-- 
Gabriel Genellina

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


Re: Help replacing os.system call with subprocess call

2008-04-07 Thread Gabriel Genellina
 David Pratt wrote:
 Hi. I am trying to replace a system call with a subprocess call. I have
 tried subprocess.Popen and subprocess.call with but have not been
 successful. The command line would be:

 svnadmin dump /my/repository  svndump.db

En Mon, 07 Apr 2008 10:38:47 -0300, David Pratt [EMAIL PROTECTED]  
escribió:

 The speed of this solution is slower than os.system. Would a queue of
 some kind be needed to speed this up? Has anyone implemented something
 like this? Many thanks.

See the last post from Matt Nordhoff, where he calls Popen with  
stdout=an_open_file. This is the direct translation of outfile in a  
shell, and faster because it doesn't involve Python processing.

-- 
Gabriel Genellina

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


Re: A file iteration question/problem

2008-04-07 Thread Peter Otten
[EMAIL PROTECTED] wrote:

 Arnaud Delobelle [EMAIL PROTECTED] wrote:

 You could use an iterator over the lines of the file:
 
 def recfun(lines):
 for line in lines:
 # Do stuff
 if condition:
 recfun(lines)
 
 lines = iter(open(filename))
 recfun(lines)

 Does that work though?  If you iterate through the file with the for
 line in lines: in the first call of recfun(lines) you surely can't do
 for line in lines: and get any sort of sensible result in recursive
 calls of recfun(lines) can you?

Don't speculate, try it.

Peter 

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


Re: Please test Phatch on Windows (was Re: ANN: Phatch = PHoto bATCH processor and renamer based on PIL)

2008-04-07 Thread SPE - Stani's Python Editor
Hi Steve,
Thanks for the confirmation. It is indeed good news. Feel free to send
me privately some screenshots. BTW, I just released Phatch 0.1.3 which
is the final version for Ubuntu Hardy.

Stani

On Mar 31, 3:44 am, Steve Holden [EMAIL PROTECTED] wrote:
 Stani:

 You'll be happy to hear that it appears (after a quick test) to work on
 Vista, though I blush to admit I actually have a Python running on that
 platform.

 The font selection is much better than in previous versions - although
 the names aren't quite the full font names it's pretty easy to tell
 which one will be used.

 regards
   Steve

 SPE - Stani's Python Editor wrote:



  I have been working the last couple of days purely on bug fixing and
  to port the code ofPhatchfully to Windows as there were many issues.
  This has improved:
  -Phatchcan now create droplets on Windows (win32 extensions
  required)
  - Installed fonts are retrieved from the Windows registry
  - Image file dialogs are now working correctly
  - Missing icons are added (including aphatch.ico) and are now
  displayed in the windows titlebars
  - Image Inspector was missing a panel
  - Preview in Image Inspector now displays correctly
  - (...)

  Besides thatPhatchnow features for all platforms:
  - fonts can be defined with a nice dropdown autocomplete list
  - drop down lists with convenient values in all actions
  - the action masks now ships with some predefined masks (such as torn
  edges)
  - right click in the actions dialog box to see the source of an action
  - ViewDroplet nows shows the name of the action box rendered in the
  logo
  - Dutch translation is 100% complete

  As such no new features have been added, but the user experience feels
  much more polished now.

  Please read *carefully* the installation instructions first:
 http://photobatch.wikidot.com/install#toc6

  People who have been usingPhatchbefore should clear their font cache
  (if it exists). Simply delete the file:
  C:\Documents and Settings\Username\.phatch\fonts

  I did thePhatchport on a Windows 2000 machine, so I am curious to
  hear howPhatchworks on Windows XP and Vista. I will fix any bug (as
  far as possible) which is reported quickly in the next couple of days.

  You can help translatingPhatchhere:
 https://translations.launchpad.net/phatch/trunk/+pots/phatch

  Thanks in advance,

  Stani

  On 18 feb, 15:58, SPE - Stani's Python Editor
  [EMAIL PROTECTED] wrote:
  I'm pleased to announce the release ofPhatchwhich is a
  powerful batch processor and renamer.Phatchexposes a big part of the
  Python Imaging Library through an user friendly GUI. (It is using
  python-pyexiv2 to offer more extensive EXIF and IPTC support.)Phatch
  is not targeted at manipulating individual pictures (such as with
  Gimp), but repeating the same actions on hundreds or thousands of
  images.

  If you know PIL and have some nice recipes laying around, it is very
  easy to write plugins asPhatchgenerates the corresponding GUI
  automagically just like in Django. Any existings PIL scripts can be
  added very easily. Let me know if you want to contribute or have any
  questions.

  Homepage:http://photobatch.stani.be(freedownload link below)
  Tutorials:http://photobatch.wikidot.com/tutorials
  Translations:https://translations.launchpad.net/phatch/trunk/+pots/phatch
  License: GPLv3
  Screenshot:http://photobatch.wikidot.com/local--files/start/Screenshot-Phatch3d.jpg
  (the perspective and reflection is produced byPhatchitself)

  Phatchhas many features, like:
  - EXIF information inspector with thumbnail
  - limit jpeg file size when saving
  - tons of actions organized by tags (including perspective, round
  corners, shadow, reflection, ...)
  - console version (Phatchcan now run without a gui on servers)
  - batch rename and copy files based on exif metadata
  - data stamping (http://photobatch.wikidot.com)
  - online documentation wiki (http://photobatch.wikidot.com)

  Linux only features:
  - desktop or panel droplets on which images or folders can be dropped
  (will be ported to Windows  Mac)
  - Nautilus and desktop integration (with its own mime type and
  nautilus extension)
  - manpage with examples

  With python-pyexiv2 the following featues are added:
  - embedding the original EXIF and IPTC tags in the image

  All actions mostly have a separate pil function in their source code,
  so they could be read as a recipe book for PIL:
  * Auto Contrast - Maximize image contrast
  * Background - Put colour under transparent image
  * Border - Crop or add border to all sides
  * Brightness - Adjust brightness from black to white
  * Canvas - Crop the image or enlarge canvas without resizing the image
  * Colorize - Colorize grayscale image
  * Common - Copies the most common pixel value
  * Contrast - Adjust from grey to black  white
  * Convert Mode - Convert the color mode of an image (grayscale, RGB,
  RGBA or CMYK)
  * Copy - Copy image file
  * Effect - Blur, Sharpen, Emboss, Smooth, 

Re: A funnily inconsistent behavior of int and float

2008-04-07 Thread Mark Dickinson
On Apr 7, 6:43 am, Colin J. Williams [EMAIL PROTECTED] wrote:
 This is good but the documentation for
 3.0 is missing the syntax documentation
 from 2.5

Is

http://docs.python.org/dev/3.0/reference/lexical_analysis.html#integer-literals

the documentation that you're looking for?

But it seems to me that Lie's original point isn't really
about integer *literals* anyway---it's about the behaviour
of the built-in int() function when applied to a string.  So

http://docs.python.org/dev/3.0/library/functions.html#int

is probably the appropriate place in the documentation.  And
I agree that it could be made clearer exactly what strings are
acceptable here.

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


Re: Dependency Queue

2008-04-07 Thread Stefan Behnel
Carl Banks wrote:
 I'm looking for any information about a certain kind of dynamic data
 structure.  Not knowing if it has some well-known name that I could
 have Googled, I'll just call it a dependency queue.  It's like a
 priority queue except instead of a strict ordering of items by
 priority, there is only a topological ordering (like you would have in
 a directed acyclic graph).
 
 To date I've been generating a dependency graph in advance every
 iteration through my main loop, doing a topsort, and executing the
 values in order (the values are callable objects--this is a
 scheduler).
 
 However, I'd like a dynamic dependency queue for two reasons: it would
 simplify things to not have to generate the whole graph in advance,
 and it could improve performance to run some tasks of the next
 iteration in the present one (this could potentially make better use
 of the dual-core and graphics hardware).
 
 I'm pretty sure I could hack out this structure on my own, but I'd
 like to see any prior information if there is any, in case anyone's
 figured out things like, Is there an easy way to detect cycles on
 insertion? and so on.

You might consider flattening your graph to map it onto a heap (see the heapq
module). One way to do that might be to assign a different power of two to
each node and calculate the priority of each node as the sum of its parent's
numbers. That way, a child will always have a higher value (== lower priority)
than its parents, so the heap will return it after its parents. If you also
want a unique priority instead of the same one for all children of the same
set of parents, adding the number of the child itself will give you a
(possibly arbitrary) unique priority.

This (or a similar approach) may or may not solve your problem, depending on
how you determine the dependencies.

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


Re: Calling CVF-Fortran-dll with ctypes and simple structure

2008-04-07 Thread Gabriel Genellina
En Mon, 07 Apr 2008 09:19:03 -0300, Michael Schäfer [EMAIL PROTECTED]  
escribió:

 Hi all,

 I deal with the old problem passing characters from python to a
 fortran dll build with CFV6.6c.
 I reduced our complex structure to a simple one.  Here is the Fortran
 code:

   SUBROUTINE DEMO2L(s)

 C sample for calling CVF6.6c-DLLs from
 C vb/vba/python with simple structure

   !DEC$ ATTRIBUTES DLLEXPORT::DEMO2L

   TYPE rcDEMO
  INTEGER a
  REAL b
  CHARACTER c*9
   END TYPE

   TYPE(rcDEMO) :: s
 C
   WRITE(*,*) s.a, s.b, s.c
 C sample calculation:
   s.a = s.a*10
   s.b = s.b**2.3
 s.c = 'Sample'

   RETURN
   END

 From VB the calling is very simple:

 Declare Sub DEMO2L Lib release\demo1l.dll (ByRef k As rcDEMO)

 Type rcDEMO
   a As Long
   b As Single
   c As String * 9
 End Type

 Dim k As rcDEMO

 Sub run()

 k.a = 2
 k.b = 3#
 k.c = Test

 Call DEMO2L(k)

 Debug.Print k.a, k.b, k.c

 End Sub

 and result to:   2012,5135  Sample

 When I try this from python:

 from ctypes import *

 class rcDemo(Structure):
   _fields_ = [
   ('a', c_int),
   ('b', c_float),
   ('c', c_char_p),

Try with ('c', c_char*9). You may have alignment issues with such odd  
size, but in this case it doesnt matter so much as it's the last field in  
the struct.
(If both Fortran and VB say char*9, why did you choose a pointer here?)

-- 
Gabriel Genellina

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


Re: Help replacing os.system call with subprocess call

2008-04-07 Thread Matt Nordhoff
David Pratt wrote:
 Hi David and Matt. I appreciate your help which has got me moving
 forward again so many thanks for your reply. I have been using
 subprocess.Popen a fair bit but this was the first time I had to use
 subprocess to capture large file output. The trouble I was having was
 with the process would just hang. Chunking was the solution. I guess I
 assumed this would be taken care of in the internals.
 
 Overall, I wish subprocess had some better documentation since it is
 definitely not a drop in replacement for os.system. In other
 circumstances I am using subprocess.call() for simple calls which works
 fine.
 
 The speed of this solution is slower than os.system. Would a queue of
 some kind be needed to speed this up? Has anyone implemented something
 like this? Many thanks.
 
 Regards,
 David

Did you see my second message? That should help performance. If not, I'm
totally out of my depth and have no idea at all. Sorry.

(How much slower? 10%? 200%?)
-- 
-- 
http://mail.python.org/mailman/listinfo/python-list


Getting a value from a nested dictionary

2008-04-07 Thread Cunningham, Dan
Hi, My name is Dan and I'm a newb to python (and programming. Please
forgive)

 

I am trying to get a value from a nested dictionary. I would like to
pass in a parameter from a conf file, then compare it to a value in the
dictionary, and verify that it is a valid value. (The SSL_MODE Portion
of the below listed dictionary)

 

I have d1{key1: val1,

key2: val_2{key_a: val_a, key_b: val_b},

key3: val_3}

 

And In comes the value from the conf file key2: val_a

 

Any Ideas?

 

Dan C

 

#!/usr/local/bin/python2.5

# -*- coding: UTF-8 -*-

# File extractconf.py

# The file authn.conf must exist

 

import os

import sys

import re

 

CONF_FILE = authn.conf

 

#Use these defaults if none are provided in the .conf file

PARAMS_VALUES = {INSTANCE_NAME: ,

 CHASE_REFERRALS: False,

 DOMAIN_NAME: ,

 GROUP_CONTAINER: ,

 PASSWORD: ,

 SSL_MODE: {ssl1: NO_SSL, ssl2: SSL_TRUST_ALL,
ssl3: SSL_CERTIFICATE_MODE},

 USE_GC: False,

 USE_KERBEROS: False,

 USER_CONTAINER: ,

 USER_NAME: ,

 USER_NAME_TYPE: {'unt1': FULL_SAM, 'unt2':
PARTIAL_SAM, 'unt3': FULL_UPN, 'unt4': PARTIAL_UPN}}

 

def extractParams():

thedir = os.getcwd() #Parse the dir and get the file listing

filelist = os.listdir(thedir)

if CONF_FILE in filelist:

thefile = open(authn.conf).readlines()

thefile = [l.strip() for l in thefile] #Strip out the
whitespace

thefile = [l for l in thefile if l.find('=') = 0] #
Filters out non-conf lines

thefile = [re.split(r\s*=\s*, l) for l in thefile]
#Use regex and get out spaces

thefile = [(l[0], eval(l[1])) for l in thefile]
#Evaluate the str and bool values

thefile = dict(thefile) #Turn the file into a dictionary

for k in thefile.keys(): #For each entry in the file

if k == 'SSL_MODE': #If the key is equal to the
SSL_MODE key

 

##THIS IS WHERE I'M STUCK

 

print PARAMS_VALUES['SSL_MODE']



##else:

 

## THIS PART IS OK

for k in PARAMS_VALUES.keys(): #Replace values in
default dict with the values from the conf file

PARAMS_VALUES[k] = thefile[k]

else:

sys.exit(File authn.conf must exist)



if __name__ == __main__:

extractParams()

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

Python-URL! - weekly Python news and links (Apr 7)

2008-04-07 Thread Gabriel Genellina
QOTW:  Describing [Python] as a 'scripting language' is like describing a
fully-equipped professional kitchen as 'a left-over warming room'. - Steven
D'Aprano

[S]ocial measures are the only thing that *can* properly deal with these
issues [in this case, naming conflicts, functionality non-partitioning,
...--naming issues, really]. - Ben Finney


Python 2.6a2 and 3.0a4 have been released, two new
alpha versions of the next major releases:

http://groups.google.com/group/comp.lang.python/browse_thread/thread/6cf534b1163b627/

A long thread: Object-Relational Mappers (ORM), pros and cons:

http://groups.google.com/group/comp.lang.python/browse_thread/thread/a9b670f2a2b5be42/

Generator functions with recursive calls: why must a loop be explicit?

http://groups.google.com/group/comp.lang.python/browse_thread/thread/8923ccee2062473a/

Since 3.0 will be ready soon, why should anyone new to
the language bother to learn the old 2.X?

http://groups.google.com/group/comp.lang.python/browse_thread/thread/44ace1486d840678/

Adding methods to a single instance:

http://groups.google.com/group/comp.lang.python/browse_thread/thread/ba80ed8bf095b12f/

Teaching Python in high school:

http://groups.google.com/group/comp.lang.python/browse_thread/thread/846ca6453d396fe0/

Python-by-example, examples covering all the standard library modules.

http://groups.google.com/group/comp.lang.python/browse_thread/thread/d94853f357614b25/
http://www.lightbird.net/py-by-example/

Incorrect usage of the try/finally construct:

http://groups.google.com/group/comp.lang.python/browse_thread/thread/ac8d61438c4c00ca/

super() - when to use (and when not to use it):

http://groups.google.com/group/comp.lang.python/browse_thread/thread/22a35db06b0e9764/

Testing whether any string from a set is contained within another string:

http://groups.google.com/group/comp.lang.python/browse_thread/thread/5261983811a04956/



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
Mygale is a news-gathering webcrawler that specializes in (new)
World-Wide Web articles related to Python.
 http://www.awaretek.com/nowak/mygale.html
While cosmetically similar, Mygale and the Daily Python-URL
are utterly different in their technologies and generally in
their results.

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 enthusiats:
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/groups?oi=djqas_ugroup=comp.lang.python.announce

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

Steve Bethard continues the marvelous tradition early borne by
Andrew Kuchling, Michael Hudson, Brett Cannon, Tony Meyer, and Tim
Lesher of intelligently summarizing action on the python-dev mailing
list once every other week.
http://www.python.org/dev/summary/

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

The somewhat older Vaults of Parnassus ambitiously collects references
to all sorts of Python resources.
http://www.vex.net/~x/parnassus/

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/donate.html

Kurt B. Kaiser publishes a weekly report on faults and patches.
  

Orphaned child processes

2008-04-07 Thread rocco . rossi
I'm using the Python processing module. I've just run into a problem
though. Actually, it's a more general problem that isn't specific to
this module, but to the handling of Unix (Linux processes) in general.
Suppose for instance that for some reason or another, after forking
several child processes, the main process terminates or gets killed
(or segfaults or whatever) and the child processes are orphaned. Is
there any way to automatically arrange things so that they auto-
terminate or, in other words, is there a way to make the child
processes terminate when the parent terminates?

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


Re: Adherence to PEP 8 for published code

2008-04-07 Thread Ben Finney
Aldo Cortesi [EMAIL PROTECTED] writes:

 This is getting silly.

Agreed.

 Let's recap. You are upset

Not at all.

-- 
 \   We spend the first twelve months of our children's lives |
  `\  teaching them to walk and talk and the next twelve years |
_o__)telling them to sit down and shut up.  -- Phyllis Diller |
Ben Finney
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Welcome to the Python-list mailing list

2008-04-07 Thread Ronn Ross
This is my first post and I'm new to Python. How would someone go about
adding keywords to Python? It would be great to add support for Esperanto
keywords in the language instead of English being the only option.

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

Re: Welcome to the Python-list mailing list

2008-04-07 Thread Steve Holden
Ronn Ross wrote:
 This is my first post and I'm new to Python. How would someone go about 
 adding keywords to Python? It would be great to add support for 
 Esperanto keywords in the language instead of English being the only 
 option.
  
Unfortunately the resulting language would no longer be Python.

You need to consider software portability: Python has been very 
conservative about declaring words to be keywords in the language, 
though clearly words like def and class must necessarily be part of 
the syntax.

When you start to replace the keywords, though, your programs are no 
longer runnable on all Python installations, and simple transliteration 
fails because sometimes a keyword in one (natural) language will 
conflict with a programmer's choice of name(s) in another.

So it's a superficially attractive idea with some really bad downside 
consequences.

regards
  Steve
-- 
Steve Holden+1 571 484 6266   +1 800 494 3119
Holden Web LLC  http://www.holdenweb.com/

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


Re: Python Data Utils

2008-04-07 Thread Jesse Aldridge
 But then you introduced more.

oops.  old habits...

 mxTextTools.

This looks cool, so does the associated book - Text Processing in
Python.  I'll look into them.

 def normalise_whitespace(s):
     return ' '.join(s.split())

Ok, fixed.

 a.replace('\xA0', ' ') in there somewhere.

Added.

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


Re: Help replacing os.system call with subprocess call

2008-04-07 Thread David Pratt
Hi Matt. Many thanks. Sorry I had not seen your second post. I'll give 
this a try and time the completion to compare the differences and post 
back later today to show os.system, buffered imput and using a file 
directly for stdout.

Regards,
David

Matt Nordhoff wrote:
 David Pratt wrote:
 Hi David and Matt. I appreciate your help which has got me moving
 forward again so many thanks for your reply. I have been using
 subprocess.Popen a fair bit but this was the first time I had to use
 subprocess to capture large file output. The trouble I was having was
 with the process would just hang. Chunking was the solution. I guess I
 assumed this would be taken care of in the internals.

 Overall, I wish subprocess had some better documentation since it is
 definitely not a drop in replacement for os.system. In other
 circumstances I am using subprocess.call() for simple calls which works
 fine.

 The speed of this solution is slower than os.system. Would a queue of
 some kind be needed to speed this up? Has anyone implemented something
 like this? Many thanks.

 Regards,
 David
 
 Did you see my second message? That should help performance. If not, I'm
 totally out of my depth and have no idea at all. Sorry.
 
 (How much slower? 10%? 200%?)
-- 
http://mail.python.org/mailman/listinfo/python-list


WORLD TOURSIM WORLD TRAVEL WORLD PACKAGE

2008-04-07 Thread TAJMAHAL TEMPLE
Freee... Freee Fr
http://sai-tourism-package.blogspot.com/
-- 
http://mail.python.org/mailman/listinfo/python-list


Mathematical Python Library

2008-04-07 Thread mc
I'm looking for a library which can do mathematical stuff like
solving  equations. Or calculation the nulls of a function and so on.
Does anyone know one?

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


Re: Learning curve for new database program with Python?

2008-04-07 Thread M.-A. Lemburg
On 2008-04-07 15:30, Greg Lindstrom wrote:
 On Sun, Apr 6, 2008 at 2:31 AM, John Nagle [EMAIL PROTECTED] wrote:
 Basic SQL isn't that hard.  Learn CREATE, SELECT, INSERT,
  UPDATE, and DELETE syntax.  That's enough for most simple
  applications.
 
 And then learn more advanced SQL: joins, nested selects, pivot tables and
 stored procedures.  You can do a lot of processing inside the database
 which cuts down on data running over the wire.
 
 SQL is one of the areas I wish I had mastered (much) earlier in my career

Fully agree :-)

Interesting comments in a time where everyone seems to be obsessed
with ORMs.

-- 
Marc-Andre Lemburg
eGenix.com

Professional Python Services directly from the Source  (#1, Apr 07 2008)
  Python/Zope Consulting and Support ...http://www.egenix.com/
  mxODBC.Zope.Database.Adapter ... http://zope.egenix.com/
  mxODBC, mxDateTime, mxTextTools ...http://python.egenix.com/


 Try mxODBC.Zope.DA for Windows,Linux,Solaris,MacOSX for free ! 


eGenix.com Software, Skills and Services GmbH  Pastor-Loeh-Str.48
 D-40764 Langenfeld, Germany. CEO Dipl.-Math. Marc-Andre Lemburg
Registered at Amtsgericht Duesseldorf: HRB 46611
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Mathematical Python Library

2008-04-07 Thread Rob Clewley
The closest thing so far is probably going to be a combination of the
numpy, scipy, and sympy libraries. The latter is the one with the most
functionality for solving equations algebraically, but is also the
least mature package at the moment. The first two also provide the
basic tools for calculating the nulls of a function (for instance) as
numerical approximations, provided you are able to write small scripts
to use those tools.

-Rob

On Mon, Apr 7, 2008 at 12:05 PM, mc [EMAIL PROTECTED] wrote:
 I'm looking for a library which can do mathematical stuff like
  solving  equations. Or calculation the nulls of a function and so on.
  Does anyone know one?

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




-- 
Robert H. Clewley, Ph. D.
Assistant Professor
Department of Mathematics and Statistics
Georgia State University
720 COE, 30 Pryor St
Atlanta, GA 30303, USA

tel: 404-413-6420 fax: 404-651-2246
http://www.mathstat.gsu.edu/~matrhc
http://brainsbehavior.gsu.edu/
-- 
http://mail.python.org/mailman/listinfo/python-list


reading dictionary's (key,value) from file

2008-04-07 Thread ankitks . mital
Folks,
Is it possible to read hash values from txt file.
I have script which sets options. Hash table has key set to option,
and values are option values.

Way we have it, we set options in a different file (*.txt), and we
read from that file.
Is there easy way for just reading file and setting options instead of
parsing it.

so this is what my option files look like:

1opt.txt
{ '-cc': '12',
  '-I': r'/my/path/work/'}

2opt.txt
{  '-I': r/my/path/work2/'}

so my scipt how has dictionary
options = { '-cc' :'12'
'-I': r'/my/path/work/:/my/path/work2/'}

I am trying to avoid parsing
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: reading dictionary's (key,value) from file

2008-04-07 Thread Diez B. Roggisch
[EMAIL PROTECTED] wrote:

 Folks,
 Is it possible to read hash values from txt file.
 I have script which sets options. Hash table has key set to option,
 and values are option values.
 
 Way we have it, we set options in a different file (*.txt), and we
 read from that file.
 Is there easy way for just reading file and setting options instead of
 parsing it.
 
 so this is what my option files look like:
 
 1opt.txt
 { '-cc': '12',
   '-I': r'/my/path/work/'}
 
 2opt.txt
 {  '-I': r/my/path/work2/'}
 
 so my scipt how has dictionary
 options = { '-cc' :'12'
 '-I': r'/my/path/work/:/my/path/work2/'}
 
 I am trying to avoid parsing

Use a well-known config-file-format such as the module ConfigParser
supports. 

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


Re: reading dictionary's (key,value) from file

2008-04-07 Thread Robert Bossy
[EMAIL PROTECTED] wrote:
 Folks,
 Is it possible to read hash values from txt file.
 I have script which sets options. Hash table has key set to option,
 and values are option values.

 Way we have it, we set options in a different file (*.txt), and we
 read from that file.
 Is there easy way for just reading file and setting options instead of
 parsing it.

 so this is what my option files look like:

 1opt.txt
 { '-cc': '12',
   '-I': r'/my/path/work/'}

 2opt.txt
 {  '-I': r/my/path/work2/'}

 so my scipt how has dictionary
 options = { '-cc' :'12'
 '-I': r'/my/path/work/:/my/path/work2/'}

 I am trying to avoid parsing
   
For this particular case, you can use the optparse module:
http://docs.python.org/lib/module-optparse.html

Since you're obviously running commands with different set of options, I 
suggest you listen to Diez.

Cheers,
RB


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


Re: reading dictionary's (key,value) from file

2008-04-07 Thread Jeffrey Froman
[EMAIL PROTECTED] wrote:

 so this is what my option files look like:
 
 1opt.txt
 { '-cc': '12',
 '-I': r'/my/path/work/'}

You can turn these strings read from text files into actual dictionaries
using eval:

 d = eval({ '-cc': '12', '-I': r'/my/path/work/'})
 d
{'-I': '/my/path/work/', '-cc': '12'}
 type(d)
type 'dict'

Note that eval will happily execute all sorts of arbitrary code, so this is
not a good solution if you don't fully trust your option file creators.

It's also a bit clunky compared to simply importing. Since you already have
dictionary-literal syntax in your text file, why not add a
left-hand-operator and make it a module instead? For example:

# opt1.py
d = { '-cc': '12',
'-I': r'/my/path/work/'}

# main.py
from opt1 import d


--
Jeffrey

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


pylirc question: clearing the queue

2008-04-07 Thread jesse . k . rosenthal
Hi all,

Is there a way in the pylirc module to either (a) get it to stop
listening for a period of time, or (b) clear the queue of any stored
up commands? I have a script that starts mplayer, and I use my remote
while I'm running mplayer. The shell script waits
(subrpocess.Popen.wait()) for the mplayer process to complete, but
then it always runs through all the keypresses I've been sending
mplayer.

So i would like it to either stop listening until I give it a certain
command, or to simply clear the queue (I could tell it to that after I
return from wait()). Any ideas?

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


Re: First Python project - comments welcome!

2008-04-07 Thread Lie
On Apr 7, 3:03 pm, Paul Scott [EMAIL PROTECTED] wrote:
 I have started, and made some progress (OK it works, but needs some
 love) on my first real Python application.

 http://cvs2.uwc.ac.za/trac/python_tools/browser/podder

 I would love some feedback on what I have done. In total this has taken
 me 5 nights to do (I am working on it at night as PHP, not Python, is my
 day job), so it can probably do with *lots* of improvement. All code is
 GPL.

 If anyone on this list is willing/able, please do give me a few
 pointers, even if it is This is total crap - RTFM and come back when
 you are ready I would really appreciate it!

 Many thanks, and thank you to this community for helping me through the
 initial bumps of getting into Python - a great dev tool IMHO!

 --Paul

 All Email originating from UWC is covered by 
 disclaimerhttp://www.uwc.ac.za/portal/public/portal_services/disclaimer.htm

I don't know if it was just me, but I can't just scan through your
code briefly to know what it is about (as is with any non-trivial
codes), only after looking through the website's Roadmap I realized
it's something to do with audio and recording. Perhaps you should add
a short module-level docstring that explains in a brief what the code
is about, somewhat like an abstract.

And second, it's just my personal preference, but I usually like to
separate between GUI codes (codes that handle GUI events) and working
code (the real worker). It's just so that if one day you want to
revamp the GUI (e.g. unify the play and pause button into a single
morphing button), you could do it easily without touching the working
code or if you want to call pause() from somewhere else other than GUI
(from an error handler?), you don't call it by pause_click() while no
clicking is done. It's also helpful if someday you want to make a
command-line version of the program (for the same reason, so we don't
call play_click() while what we're doing is typing some commands) or
change the GUI engine. It's also helpful if we want to do something
fancy that is GUI-related, like clicking the play button will keep it
depressed until we click the stop button (like that ol' tape recorder)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Dependency Queue

2008-04-07 Thread Terry Reedy

Carl Banks [EMAIL PROTECTED] wrote in message 
news:[EMAIL PROTECTED]
| I'm looking for any information about a certain kind of dynamic data
| structure.  Not knowing if it has some well-known name that I could
| have Googled, I'll just call it a dependency queue.  It's like a
| priority queue except instead of a strict ordering of items by
| priority, there is only a topological ordering (like you would have in
| a directed acyclic graph).
|
| To date I've been generating a dependency graph in advance every
| iteration through my main loop, doing a topsort, and executing the
| values in order (the values are callable objects--this is a
| scheduler).
|
| However, I'd like a dynamic dependency queue for two reasons: it would
| simplify things to not have to generate the whole graph in advance,
| and it could improve performance to run some tasks of the next
| iteration in the present one (this could potentially make better use
| of the dual-core and graphics hardware).
|
| I'm pretty sure I could hack out this structure on my own, but I'd
| like to see any prior information if there is any, in case anyone's
| figured out things like, Is there an easy way to detect cycles on
| insertion? and so on.

Perhaps what you want is a dynamic DAG (directed acyclic graph) with 
ordered labels.  At any time, only the set of sources are eligible for 
execution, so there is no reason to flatten the whole thing.  I suspect 
insertion with cycle detection would be easier, but I don't remember 
actually seeing an algorithm.

tjr



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


Re: First Python project - comments welcome!

2008-04-07 Thread Paul Scott

On Mon, 2008-04-07 at 09:56 -0700, Lie wrote:
 I don't know if it was just me, but I can't just scan through your
 code briefly to know what it is about (as is with any non-trivial
 codes), only after looking through the website's Roadmap I realized
 it's something to do with audio and recording. Perhaps you should add
 a short module-level docstring that explains in a brief what the code
 is about, somewhat like an abstract.
 

Sure, will add that. It is a simple GUI based audio (and later video)
recorder that a user can record a audio stream from line in (mic) and
create an ogg vorbis file from it. It then allows the user to upload the
ogg file to a Chisimba (PHP5 - my day job) based server to be consumed
automagically as a podcast. The file is tagged and converted to MP3
server side and added to the Chisimba podcast module. It is really for
use in lecture halls so that lecturers can upload their audio files as
podcasts for the students to listen to almost immediately afterwards.

 And second, it's just my personal preference, but I usually like to
 separate between GUI codes (codes that handle GUI events) and working
 code (the real worker). 

Couldn't agree more! MVC architecture is how I do all of my code.
Unfortunately, this was my first stab at

1. Python
2. GUI applications
3. Audio apps

so I will need some more help in doing that (i.e. ramping up my skills
or getting someone that knows what they are doing onto the project to
help out).

Thanks for the feedback though, I will improve in time... :)

--Paul

All Email originating from UWC is covered by disclaimer 
http://www.uwc.ac.za/portal/public/portal_services/disclaimer.htm 
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: Learning curve for new database program with Python?

2008-04-07 Thread [EMAIL PROTECTED]
On 7 avr, 07:34, CM [EMAIL PROTECTED] wrote:
 On Apr 5, 11:50 am, Jetus [EMAIL PROTECTED] wrote:

  I have a need for a database program. I downloaded the db2 from ibm,
  and reviewed some of the documentation.

  My question is, what is the easiest program for me to try to learn. I
  will be creating a database of about 25,000 records, it will be
  relational. I am a beginner Python programmer, and need a database
  solution that is easy to grasp. I played with sql,
  and found that very difficult, if not overly cumbersome.

  A database that could work with Django would be very interesting to
  look at as well..

  Any suggestions out there?

 From the good people at Django:

 If you want to use Django with a database, which is probably the
 case, you'll also need a database engine. PostgreSQL is recommended,
 because we're PostgreSQL fans, and MySQL, SQLite 3, and Oracle are
 also supported.

 And if you want to make it a relational database,

Err... I may totally misunderstand you here, but I've the strong
impression that you missed the fact that the database systems
mentionned above are all (so-called) relational dabatases.

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


Re: Learning curve for new database program with Python?

2008-04-07 Thread [EMAIL PROTECTED]
On 5 avr, 17:50, Jetus [EMAIL PROTECTED] wrote:
 I have a need for a database program. I downloaded the db2 from ibm,
 and reviewed some of the documentation.

 My question is, what is the easiest program for me to try to learn. I
 will be creating a database of about 25,000 records, it will be
 relational. I am a beginner Python programmer, and need a database
 solution that is easy to grasp. I played with sql,
 and found that very difficult, if not overly cumbersome.

The point is that so far, relational database really means SQL
database. And believe me, trying to get away with a non-SQL database
only to avoid learning SQL is probably the worst possible move for
both your program and yourself.

 A database that could work with Django would be very interesting to
 look at as well..

The databases that the ORM part of Django can connect to are all SQL
databases.

 Any suggestions out there?

I can only second / third etc what everyone already told you : learn
SQL. And not only SQL, but also the theory that it builds upon (the
'relational model'), and the good practices wrt/ relational database
design. There's no shortage of good quality freely available
documentation on these topics, and you'll find help on quite a couple
of newsgroups / forums / whatever.

I'd strongly recommand you start without Django's ORM first, so you
get a chance to learn how it really works undercover. Else you might
end up doing things in a very inefficient way.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Welcome to the Python-list mailing list

2008-04-07 Thread Terry Reedy

Ronn Ross [EMAIL PROTECTED] wrote in message 
news:[EMAIL PROTECTED]
| This is my first post and I'm new to Python. How would someone go about
| adding keywords to Python? It would be great to add support for Esperanto
| keywords in the language instead of English being the only option.

If you want other-language keywords, you should either use a translator 
processor or an editor that will do keyword substitution.  I do not know of 
such but I would not be surprised if there is one.  I suspect this sort of 
thing will more likely happen with Python 3, which will allow unicode 
keywords.

PS. Subject lines should reflect the subject of the post. 



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


Tips for load balancing multiple Python apps on dual/quad core processors?

2008-04-07 Thread Malcolm Greene
I'm looking for tips on how to load balance running multiple Python
applications in multi-CPU environments. My understanding is that Python
applications and their threads are limited to a specific CPU.

Background: I have a Python utility that processes email messages. I
suspect there's a lot of idle time while this utility waits on a remote
email server. I would like to run as many simultaneous copies of this
utility as possible without overwhelming the server these utilities are
running on. My thought is that I should write a dispatcher that monitors
CPU load and launches/cancels multiple instances of my utility with
specific job queues to process. 

Is there a cross-platform way to monitor CPU load?

Is there a pre-existing Python module I should be looking at for
building (subclassing) my dispatcher?

Thanks!
Malcolm

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


Re: Adding Images To MySQL

2008-04-07 Thread Victor Subervi
in line...

On 4/5/08, Gabriel Genellina [EMAIL PROTECTED] wrote:

 En Sat, 05 Apr 2008 11:32:00 -0300, Victor Subervi
 [EMAIL PROTECTED] escribió:

  * *- You say Content-Type: image/jpeg but you emit HTML code. You're
  lucky
  if you see any
 
  * *text at all.
 
  Well, I tried Content-Type: text/html and that threw an HTTP 500 Error.

 If your script raised any exception, that's the expected code. (500 =
 internal error = your code has errors). But it's not very useful for
 debugging; using cgitb or wrapping the code in try/except as has already
 been suggested, lets you see the exception and traceback.


Yes, and I have employed your suggestion of cgtib, and I sent you personally
under separate cover the errors, since I forgot to include them in this
post.

 * *- HTTP 200 is not an error, it means the request was successful.
 
  When it doesn´t execute the code, how can it be called successful? If it
  doesn´t execute the code, how can you say it´s not an error? What is it,
  then?

 Well, your web server thinks all went ok... BTW, you did't provide details
 about it, I *guess* you're using CGI because of the print Content-Type
 line.


Yes, that is correct...

 * *- As a general advice, try to isolate the problems. Test the database
  stuff alone, in a local
  * *application. Test the cgi script alone, without database
 interaction.
  Test the database stuff in
  * *the web server (better if you have a shell account). Merge all and
  test
  again.
 
  Very good advice. Please help me understand how to do that.
 
  This is what I have done. I have tried these:
 
  sql = 'insert into products ( + col_names + ) values ( + val + )',
  ( +
  col_names + )
 
  cursor.execute(sql)
 
  and
 
  sql = 'insert into products ( + col_names + ) values ( + val + )'
 
  cursor.execute(sql, (col_names,))
 
  Neither work.

 You got a syntax error, I guess. What's that ' at the start?
 I'll try to explain it from the ground up. This would be a valid SQL
 statement::

 insert into PRODUCTS (PRODID, NAME, DESCRIPTION)
 values (123, 'Easter egg 80g', 'A longer description');

 In Python, you need the SQL text inside a string::

 sql = insert into PRODUCTS (PRODID, NAME, DESCRIPTION)  \
   values (123, 'Easter egg 80g', 'A longer description');

 and you can execute it with::

 cursor.execute(sql)

 That would be OK when you create the database for the first time. Later
 your boss comes in and says: We've got bigger eggs! Code 124, 150g each.
 We need them in the database. You write an sql statement similar to
 above. Some days later, they decide to sell bubble gum. Forty-two
 different sizes and flavors and brands. You don't want to write all that
 sql statements by hand. Your first thought is to build the sql text by
 pieces::

 sql = insert into PRODUCTS (PRODID, NAME, DESCRIPTION)  \
   values (+str(prodid)+, '+prodname+', '+description+');

 But then you remember to have read something about sql injection and you
 don't like that mess of  + ) ' ( anyway. After reading some articles
 about DBAPI 2, PEP 249, the MySQLdb module, you write this::

 sql = insert into PRODUCTS (PRODID, NAME, DESCRIPTION)  \
   values (%s,%s,%s);
 cursor.execute(sql, (prodid, prodname, description))

 and it works fine.

 Note that execute has two arguments: first, a string with the sql
 statement text; second, a tuple containing the values. The %s in the sql
 text are placeholders, they're replaced with the corresponding value from
 the second argument. And there is no ' anywhere.


Well, what I did, that now works, was essentially what you suggested, and
simply assigned null values to variables that accept null values in the
database. That works. What I was trying to do was build up just those
variables that were to be updated or entered, and supply only those
arguments. At this point it is rather academic, but can that be done?

 However, if I print what that code spits out:
 
  sql = 'insert into products ( + col_names + ) values ( + val + )',
  ( +
  col_names + )
 
  print sql
 
  then copy and paste it into a cursor.execute() statement, viola!
  Everything
  works _just_fine_. Go figure. Why??

 What you have done has no sense - why do you think it should work?


See above.

 pic1 = _mysql.escape_string(f)
 
  It does not like this (forgot error):
 
  pic1 = MySQLdb.Binary(f)

 You should make the above work. Look at the exception, read the error
 message, look at the traceback. There are a lot of info there.


Amazingly (because I thought I had tested this) both the escape string and
the db Binary work now.

 Escaping the string, I can successfully load this image into the
  database,
  along with all the other fields. Now, when I load an image from the form
  on
  the previous page with this code:
 
  input type='file' name='pic1' value=
 
  print '', MySQLdb.Binary(data[14]), ''
 
  and send the form off to the next page, when I process it on that page

 Why do you do *that*??? 

Re: Orphaned child processes

2008-04-07 Thread John Nagle
[EMAIL PROTECTED] wrote:
 I'm using the Python processing module. I've just run into a problem
 though. Actually, it's a more general problem that isn't specific to
 this module, but to the handling of Unix (Linux processes) in general.
 Suppose for instance that for some reason or another, after forking
 several child processes, the main process terminates or gets killed
 (or segfaults or whatever) and the child processes are orphaned. Is
 there any way to automatically arrange things so that they auto-
 terminate or, in other words, is there a way to make the child
 processes terminate when the parent terminates?
 
 Thank you.

Put a thread in the child which reads stdin, and make stdin
connect to a pipe from the parent.  When the parent terminates,
the child will get a SIGPIPE error and raise an exception.

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


Re: Tips for load balancing multiple Python apps on dual/quad core processors?

2008-04-07 Thread Jeffrey Froman
Malcolm Greene wrote:

 I'm looking for tips on how to load balance running multiple Python
 applications in multi-CPU environments. My understanding is that Python
 applications and their threads are limited to a specific CPU.
 
 Background: I have a Python utility that processes email messages. I
 suspect there's a lot of idle time while this utility waits on a remote
 email server.

While it's true that python's threads are limited to using a single CPU at a
time, it sounds like your bottleneck is network IO, not CPU power.

I imagine that your one CPU is doing a lot of idling, thumb-twiddling, etc.,
while waiting for the remote email server to respond. In such a scenario,
python's threads will work fine to speed your application. On the other
hand, adding CPUs to an IO-bound application isn't likely to speed it up at
all.


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


Re: Tips for load balancing multiple Python apps on dual/quad core processors?

2008-04-07 Thread Paul Rubin
Malcolm Greene [EMAIL PROTECTED] writes:
 Is there a cross-platform way to monitor CPU load?

Cross-platform: not that I know of. 

Linux: /proc/loadav (load average), 
/proc/cpuinfo (to figure out number of cpu's).  

You want the load average and # of cpu's to be about equal,
i.e. all cpu's should be kept busy but not overloaded.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Tips for load balancing multiple Python apps on dual/quad core processors?

2008-04-07 Thread Steve Holden
Malcolm Greene wrote:
 I'm looking for tips on how to load balance running multiple Python
 applications in multi-CPU environments. My understanding is that Python
 applications and their threads are limited to a specific CPU.
 
 Background: I have a Python utility that processes email messages. I
 suspect there's a lot of idle time while this utility waits on a remote
 email server. I would like to run as many simultaneous copies of this
 utility as possible without overwhelming the server these utilities are
 running on. My thought is that I should write a dispatcher that monitors
 CPU load and launches/cancels multiple instances of my utility with
 specific job queues to process. 
 
 Is there a cross-platform way to monitor CPU load?
 
 Is there a pre-existing Python module I should be looking at for
 building (subclassing) my dispatcher?
 
As a data point for you, I wrote a multi-threaded application that used 
100 threads to send about 45,000 emails in less than four hours. The 
single-CPU computer that processed this job wasn't using that much CPU 
(certainly under 50%).

regards
  Steve
-- 
Steve Holden+1 571 484 6266   +1 800 494 3119
Holden Web LLC  http://www.holdenweb.com/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: A file iteration question/problem

2008-04-07 Thread Arnaud Delobelle
On Apr 7, 2:09 pm, [EMAIL PROTECTED] wrote:
 Arnaud Delobelle [EMAIL PROTECTED] wrote:
  def recfun(lines):
      for line in lines:
          # Do stuff
          if condition:
              recfun(lines)

  lines = iter(open(filename))
  recfun(lines)

 Does that work though?  If you iterate through the file with the for
 line in lines: in the first call of recfun(lines) you surely can't do
 for line in lines: and get any sort of sensible result in recursive
 calls of recfun(lines) can you?

Try it!  The keyword is iterator.

Here is an example of how this would work, but since you didn't
believe me I changed the context (strings not files) and I didn't make
it as simple as possible ;)

def reclist(string):
chariter = iter(string + ' ')
def rec():
l = []
word = ''
for c in chariter:
if c.isalnum():
word += c
elif word and (c.isspace() or c in '[]'):
l.append(word)
word = ''
if c == ']':
return l
elif c == '[':
l.append(rec())
return l
return rec()

 reclist('40 and 2 eggs but no spam')
['40', 'and', '2', 'eggs', 'but', 'no', 'spam']
 reclist('[[40 and 2] eggs] but [no spam]')
[[['40', 'and', '2'], 'eggs'], 'but', ['no', 'spam']]


--
Arnaud

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


Re: Mathematical Python Library

2008-04-07 Thread Cameron Laird
In article [EMAIL PROTECTED],
Dennis Lee Bieber  [EMAIL PROTECTED] wrote:
On Mon, 7 Apr 2008 09:05:57 -0700 (PDT), mc [EMAIL PROTECTED]
declaimed the following in comp.lang.python:

 I'm looking for a library which can do mathematical stuff like
 solving  equations. Or calculation the nulls of a function and so on.
 Does anyone know one?

   Other than coding some serial/USB interface to an HP50g...

   Maybe SAGE? 
   sympy?

http://www.google.com/search?hl=enq=python+computer+algebra+systembtnG=Google+Search
.
.
.
While there are in fact several possible approaches to symbolic mani-
pulation of mathematical stuff in Python, I STRONGLY recommend that
beginners in the area look into SAGE URL: http://www.sagemath.org/ , 
already mentioned above by Dennis.  SAGE is life-altering software, for
those with a life focused on mathematics or related science or
engineering.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: A funnily inconsistent behavior of int and float

2008-04-07 Thread Terry Reedy

Mark Dickinson [EMAIL PROTECTED] wrote in message 
news:[EMAIL PROTECTED]
| On Apr 7, 6:43 am, Colin J. Williams [EMAIL PROTECTED] wrote:
|  This is good but the documentation for
|  3.0 is missing the syntax documentation
|  from 2.5
|
| Is
|
| 
http://docs.python.org/dev/3.0/reference/lexical_analysis.html#integer-literals
|
| the documentation that you're looking for?
|
| But it seems to me that Lie's original point isn't really
| about integer *literals* anyway---it's about the behaviour
| of the built-in int() function when applied to a string.  So
|
| http://docs.python.org/dev/3.0/library/functions.html#int
|
| is probably the appropriate place in the documentation.  And
| I agree that it could be made clearer exactly what strings are
| acceptable here.

Agreed.

It says If radix is zero, the interpretation is the same as for integer 
literals.
But integer literals are unsigned.  Is radix 0 any different from the 
default of radix 10?

It also says If the argument is a string, it must contain a possibly 
signed number of arbitrary size, possibly embedded in whitespace.  But 
only integers, not 'numbers' as some would understand that, are accepted.

My suggestions:
1. Change signature to: int([number | string[, radix]).
This makes it clear that radix can only follow a string without having to 
say so in the text.

2. Replace text with:
Convert a number or string to an integer.  If no arguments are given, 
return 0.  If a number is given, return number.__int__().  Conversion of 
floating point numbers to integers truncates towards zero.  A string must 
be a base-radix integer literal optionally preceded by '+' or '-' (with no 
space in between) and optionally surrounded by whitespace.  A base-n 
literal consists of the digits 0 to n-1, with 'a' to 'z' (or 'A' to 'Z') 
having values 10 to 35.  The default radix is 10. The allowed values are 0 
and 2-36, with 0 the same as 10.

If 0 is not the same as 10, the last would have to be changed, but I could 
not detect any difference in a quick test.

After looking at any comments here, I will consider submitting these to the 
tracker.

Terry Jan Reedy



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


Re: reading dictionary's (key,value) from file

2008-04-07 Thread ankitks . mital
On Apr 7, 11:55 am, Robert Bossy [EMAIL PROTECTED] wrote:
 [EMAIL PROTECTED] wrote:
  Folks,
  Is it possible to read hash values from txt file.
  I have script which sets options. Hash table has key set to option,
  and values are option values.

  Way we have it, we set options in a different file (*.txt), and we
  read from that file.
  Is there easy way for just reading file and setting options instead of
  parsing it.

  so this is what my option files look like:

  1opt.txt
  { '-cc': '12',
    '-I': r'/my/path/work/'}

  2opt.txt
  {  '-I': r/my/path/work2/'}

  so my scipt how has dictionary
  options = { '-cc' :'12'
                  '-I': r'/my/path/work/:/my/path/work2/'}

  I am trying to avoid parsing

 For this particular case, you can use the optparse 
 module:http://docs.python.org/lib/module-optparse.html

 Since you're obviously running commands with different set of options, I
 suggest you listen to Diez.

 Cheers,
 RB- Hide quoted text -

 - Show quoted text -

I think I am missing lot regarding optparser module. My only option is
to have option file, and I have couple of those..each user creates
it's own. How can optparser help me in this regard

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


Problem with smtplib and py2exe

2008-04-07 Thread Kevin
Hi everyone,

I'm running Python 2.5.1 on an XP-Pro platform, with all the updates
(SP2, etc) installed. I have a program (send_file.py) that sends a
file to a service provider, using an ftp connection.  The program
works properly, and I've created an 'exe' of it, using py2exe.  It was
distrubuted to my user base a couple of weeks ago and seems to be
working well.  None of the users have Python installed on their
machines, thus the need for an 'exe' for the program.

I now need to add an email function to the program, to automatically
send an email to a select user list when the program is completed.
I've made the appropriate modifications to my code, and the program
works properly when I run it from Python.  When I try to make an exe
out of my new program, however, I get the following error:

Traceback (most recent call last):
  File C:/Python25/send_ftp/setup.py, line 17, in module
console = [{script: 'send_file.py'}] )
  File C:\Python25\lib\distutils\core.py, line 168, in setup
raise SystemExit, error:  + str(msg)
SystemExit: error: command 'C:\Python25\pythonw.exe' failed with exit
status 1

The 'setup.py' script is the same one I used to generate the 'exe' of
the original program. The email-related code was added to my
'send_file.py' program as a function - it's not a separate module.  If
all of the changes are commented out, the py2exe function works. But
as soon as I activate even the line import smtplib, the py2exe
process spits out the error above.

If I put only the email portions of code in a test program, and run it
from Python, it works, but if I try make an 'exe' out of the test
program, I get the same error as above.

Is there an inherent incompatibility between smtplib and py2exe? Does
anyone have any ideas of how I can fix this problem?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: A funnily inconsistent behavior of int and float

2008-04-07 Thread Mark Dickinson
On Apr 7, 3:15 pm, Terry Reedy [EMAIL PROTECTED] wrote:

 My suggestions:
 1. Change signature to: int([number | string[, radix]).
 This makes it clear that radix can only follow a string without having to
 say so in the text.

 2. Replace text with:
 Convert a number or string to an integer.  If no arguments are given,
 return 0.  If a number is given, return number.__int__().  Conversion of
 floating point numbers to integers truncates towards zero.  A string must
 be a base-radix integer literal optionally preceded by '+' or '-' (with no
 space in between) and optionally surrounded by whitespace.  A base-n
 literal consists of the digits 0 to n-1, with 'a' to 'z' (or 'A' to 'Z')
 having values 10 to 35.  The default radix is 10. The allowed values are 0
 and 2-36, with 0 the same as 10.

 If 0 is not the same as 10, the last would have to be changed, but I could
 not detect any difference in a quick test.

 After looking at any comments here, I will consider submitting these to the
 tracker.

 Terry Jan Reedy

Looks good! The description should probably also mention the optional
'0b', '0o' or '0x' (or '0B', '0O', '0X') allowed between the sign and
the digits (or before the digits in the case of a missing sign) when
base=2, base=8 or base=16.

The only base 0 versus base 10 difference I could find was the
following:

 int('033', 0)
Traceback (most recent call last):
  File stdin, line 1, in module
ValueError: invalid literal for int() with base 0: '033'
[38720 refs]
 int('033')
33

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


Re: reading dictionary's (key,value) from file

2008-04-07 Thread Terry Reedy
You can use execfile (or exec, in 3.0) function to execute code in a file 
in the present context. 



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


Re: Mathematical Python Library

2008-04-07 Thread Jaap Spies
Cameron Laird wrote:
 In article [EMAIL PROTECTED],
 Dennis Lee Bieber  [EMAIL PROTECTED] wrote:
 On Mon, 7 Apr 2008 09:05:57 -0700 (PDT), mc [EMAIL PROTECTED]
 declaimed the following in comp.lang.python:

 I'm looking for a library which can do mathematical stuff like
 solving  equations. Or calculation the nulls of a function and so on.
 Does anyone know one?

  Other than coding some serial/USB interface to an HP50g...

  Maybe SAGE? 
  sympy?

 http://www.google.com/search?hl=enq=python+computer+algebra+systembtnG=Google+Search
   .
   .
   .
 While there are in fact several possible approaches to symbolic mani-
 pulation of mathematical stuff in Python, I STRONGLY recommend that
 beginners in the area look into SAGE URL: http://www.sagemath.org/ , 
 already mentioned above by Dennis.  SAGE is life-altering software, for
 those with a life focused on mathematics or related science or
 engineering.

+1

Jaap

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


Re: A funnily inconsistent behavior of int and float

2008-04-07 Thread Mark Dickinson
On Apr 7, 3:53 pm, Mark Dickinson [EMAIL PROTECTED] wrote:
 The only base 0 versus base 10 difference I could find was the
 following:

  int('033', 0)

 Traceback (most recent call last):
   File stdin, line 1, in module
 ValueError: invalid literal for int() with base 0: '033'
 [38720 refs] int('033')

 33

 Mark

And also things like:

 int('0x33')
Traceback (most recent call last):
  File stdin, line 1, in module
ValueError: invalid literal for int() with base 10: '0x33'
[38719 refs]
 int('0x33', 0)
51
[38719 refs]

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


Data structure recommendation?

2008-04-07 Thread Steven Clark
Hi all-

I'm looking for a data structure that is a bit like a dictionary or a
hash map. In particular, I want a mapping of floats to objects.
However, I want to map a RANGE of floats to an object.

This will be used for timestamped storage / lookup, where the float
represents the timestamp.
get(x) should return the object with the newest (biggest) timestamp
y = x, if it exists.
Example:

foo = Foo()

foo.get(1.5)
- None
foo.put(1.3, 'a')
foo.put(2.6, 'b')
foo.get(1.5)
- 'a'
foo.get(7.8)
- 'b'
foo.put(5.0, 'c')
foo.get(7.8)
- 'c'

In otherwords, by the end here, for foo.get(x),
x  1.3 maps to None,
1.3 = x  2.6 maps to 'a',
2.6 = x  5.0 maps to 'b',
5.0 = x maps to 'c'.

I know that foo.get() will be called many times for each foo.put(). Is
there any way to achieve O(1) performance for foo.get(), maybe via
some kind of hash function? Or is the best thing to use some kind of
binary search?

Thanks for any advice.

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


Re: Data structure recommendation?

2008-04-07 Thread Martin v. Löwis
 I know that foo.get() will be called many times for each foo.put(). Is
 there any way to achieve O(1) performance for foo.get(), maybe via
 some kind of hash function? Or is the best thing to use some kind of
 binary search?

If you know something about the density of the input values, O(1) is
possible. E.g if there is a guarantee that there will be between 1
and 10 values per unit of input, then truncate the event time to
the next-lower int, and use that as an index k into a list; the list
item will be a list of events between k and k+1. As you know that
there is an upper bound to the number of such events (10), you
know that searching the list will take bounded (i.e. constant) time.
Likewise, as you know that there will be atleast one event per
(k,k+1) interval, you know that you have to scan only one list.

If you know no such thing, you'll have to use a binary search.

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


Re: Data structure recommendation?

2008-04-07 Thread Steve Holden
Steven Clark wrote:
 Hi all-
 
 I'm looking for a data structure that is a bit like a dictionary or a
 hash map. In particular, I want a mapping of floats to objects.
 However, I want to map a RANGE of floats to an object.
 
 This will be used for timestamped storage / lookup, where the float
 represents the timestamp.
 get(x) should return the object with the newest (biggest) timestamp
 y = x, if it exists.
 Example:
 
 foo = Foo()
 
 foo.get(1.5)
 - None
 foo.put(1.3, 'a')
 foo.put(2.6, 'b')
 foo.get(1.5)
 - 'a'
 foo.get(7.8)
 - 'b'
 foo.put(5.0, 'c')
 foo.get(7.8)
 - 'c'
 
 In otherwords, by the end here, for foo.get(x),
 x  1.3 maps to None,
 1.3 = x  2.6 maps to 'a',
 2.6 = x  5.0 maps to 'b',
 5.0 = x maps to 'c'.
 
 I know that foo.get() will be called many times for each foo.put(). Is
 there any way to achieve O(1) performance for foo.get(), maybe via
 some kind of hash function? Or is the best thing to use some kind of
 binary search?
 
I believe the best way to implement this would be a binary search 
(bisect?) on the actual times, which would be O(log N). Though since 
they are timestamps they should be monotonically increasing, in which 
case at least you don't have to go to the expense of sorting them.

Some kind of hash function won't hack it, since the purpose of a hash 
function is to map a large number of (possibly) evenly-distributed 
(potential) keys as nearly as possible randomly across a much smaller 
set of actual values.

You might try messing around with reducing the precision of the numbers 
to home in on a gross region, but I am not convinced that does anything 
other than re-spell binary search if carried to extremes.

regards
  Steve
-- 
Steve Holden+1 571 484 6266   +1 800 494 3119
Holden Web LLC  http://www.holdenweb.com/

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


  1   2   3   >