Re: Doc tests in Python

2008-06-19 Thread Gabriel Genellina
En Thu, 19 Jun 2008 02:46:15 -0300, J-Burns <[EMAIL PROTECTED]>  
escribió:



Hello. Im new to using doctests in python. Could some1 tel me how to
use doctests if i have a constructor in my code?


Just construct the desired objects inside the doctest. See the difflib  
module for a couple examples.
If it's hard/undesirable/annoying to construct the objects for every test,  
you may use the "globs" or "extraglobs" argument to doctest.testmod.  
Something like this:


class SomeClass:
def __init__(self, a, lot, of arguments, are, required):
...

def some_method(self, arg):
"""Does this and that...

In the test below, obj refers to the
already created instance (below, in _test)

>>> obj.some_method(self, 123)
True
>>> obj.some_method(self, "hi")
False
"""
...

def _test():
import doctest
obj = SomeClass(create, the instance, using, a, lot, of, arguments)
doctest.testmod(extraglobs={'obj': obj})

if __name__=='__main__':
_test()

But I prefer to keep the doctests self-contained whenever possible.

--
Gabriel Genellina

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


Re: why can i still able to reproduce the SimpleHTTPServer bug whichis said fixed 3 years ago?

2008-06-19 Thread Irmen de Jong


Terry Reedy wrote:
"Gabriel Genellina" <[EMAIL PROTECTED]> wrote in message 
news:[EMAIL PROTECTED]

En Fri, 13 Jun 2008 04:02:48 -0300, Leo Jay <[EMAIL PROTECTED]>
escribió:


http://bugs.python.org/issue1097597

in my python 2.5.2,  i still find these code in SimpleHTTPServer.py,
is that deliberate?


According to http://bugs.python.org/issue839496 it should have been
corrected, but apparently the patch was only applied to the 2.4
maintenance branch, not to the trunk. Both 2.5 and 2.6 have the same
problem. 3.0 doesn't have this problem but probably it was fixed
independently.
===

I reopened this so it will appear on the weekly bug report, in case the 
original committer does not see it.




Is jlgijsbers still around? :)

Seeing that Python 2.6 is now in beta phase, I'd love to see this 3 year old bug fixed 
before 2.6 is released.  The fix is extremely simple: just always open the file in 
binary mode (i.e. remove the test for the file type).


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


Re: How do i : Python Threads + KeyboardInterrupt exception

2008-06-19 Thread Brendon Costa
I tested this a bit more. My windows example was incorrect. It should
have used CTRL_C_EVENT. But even then, the problem is that the process
will also close the console window from which it was called because of
the 0. Also this requires that the process actually have a console and
is not a GUI application.

Is there some other method rather than a blocking "for line in fin:"
that i can use for reading from a file like device that plays nicely
with other threads asynchronously waking it up?

Sorry for all the posts. I am giving updates as i look further into
the problem.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Why doesnt PDB allow me to view the current line?

2008-06-19 Thread Diez B. Roggisch

hardcoreUFO schrieb:

I have some code that I am trying to debug (Python 2.5.2 on OSX) using
pdb. However, when the code reaches the pdb.set_trace(), it does not
allow me to view the current line:


/Users/chris/Research/ISEC/build/bdist.macosx-10.3-i386/egg/pyrl/reinforcement.py(943)__call__()

(Pdb) n

/Users/chris/Research/ISEC/build/bdist.macosx-10.3-i386/egg/pyrl/reinforcement.py(946)__call__()

(Pdb) l
[EOF]
(Pdb) l
[EOF]

It steps through the code fine, but for some reason returns end-of-
file when I want to look at the code.


It might be that the egg is installed as ZIP. Try either decompressing 
it, or re-install using


easy_install -Z 

If it is "your" egg, add zip_safe=False (or such) to the setup.py

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


Re: please critique my thread code

2008-06-19 Thread Roger Heathcote

MRAB wrote:

On Jun 15, 2:29 pm, [EMAIL PROTECTED] wrote:

I wrote a Python program (103 lines, below) to download developer data
from SourceForge for research about social networks.

Please critique the code and let me know how to improve it.

An example use of the program:

prompt> python download.py 1 24

The above command downloads data for the projects with IDs between 1
and 24, inclusive. As it runs, it prints status messages, with a
plus sign meaning that the project ID exists. Else, it prints a minus
sign.

Questions:

--- Are my setup and use of threads, the queue, and "while True" loop
correct or conventional?

--- Should the program sleep sometimes, to be nice to the SourceForge
servers, and so they don't think this is a denial-of-service attack?

--- Someone told me that popen is not thread-safe, and to use
mechanize. I installed it and followed an example on the web site.
There wasn't a good description of it on the web site, or I didn't
find it. Could someone explain what mechanize does?

--- How do I choose the number of threads? I am using a MacBook Pro
2.4GHz Intel Core 2 Duo with 4 GB 667 MHz DDR2 SDRAM, running OS
10.5.3.

Thank you.

Winston


[snip]
String methods are quicker than regular expressions, so don't use
regular expressions if string methods are perfectly adequate. For
example, you can replace:




Erm, shurely the bottleneck will be bandwidth not processor/memory?* If 
it isn't then - yes, you run the risk of actually DOSing their servers!


Your mac will run thousands of threads comfortably but your router may 
not handle the thousands of TCP/IP connections you throw at it very 
well, especially if it is a domestic model, and sure as hell sourceforge 
aren't going to want more than a handfull of concurrent connections from 
you.


Typical sourceforge page ~ 30K
Project pages to read = 24

= ~6.8 Gigabytes

Maybe send their sysadmin a box of chocolates if you want to grab all 
that in any less than a week and not get your IP blocked! :)



Roger Heathcote

* Of course, stylistically, MRAB is perfectly right about not wasting 
CPU on regexes where string methods will do, unless you are planning on 
making your searches more elaborate in the future.


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


SPAM

2008-06-19 Thread Aspersieman

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


BootCampArama Early Bird Registration Reminder

2008-06-19 Thread Chris Calloway
Just a reminder, we're at the two week warning on early bird 
registration for PyCamp:


http://trizpug.org/boot-camp/2008/

Registration is now open for:

PyCamp: Python Boot Camp, August 4 - 8

Plone Boot Camp: Customizing Plone, July 28 - August 1

Advanced Plone Boot Camp: Plone 3 Techniques, August 4 - 7

All of these take place on the campus of the University of North 
Carolina at Chapel Hill in state of the art high tech classrooms, with 
free mass transit, low-cost accommodations with free wireless, and 
convenient dining options.


Plone Boot Camp is taught by Joel Burton, twice chair of the Plone 
Foundation. Joel has logged more the 200 days at the head of Plone 
classrooms on four continents. See plonebootcamps.com for dozens of 
testimonials from Joel's students.


PyCamp is taught by Chris Calloway, facilitator for TriZPUG and 
application analyst for the Southeast Coastal Ocean Observing System. 
Chris has developed PyCamp for over 1500 hours on behalf of Python user 
groups. Early bird registration runs through June 30. So register today!


PyCamp is TriZPUG's Python Boot Camp, which takes a programmer familiar 
with basic programming concepts to the status of Python developer with 
one week of training. If you have previous scripting or programming 
experience and want to step into Python programming as quickly and 
painlessly as possible, this boot camp is for you. PyCamp is also the 
perfect follow-on to Plone Boot Camp: Customizing Plone the previous week.


At Plone Boot Camp: Customizing Plone you will learn the essentials you 
need to build your Plone site and deploy it. This course is the most 
popular in the Plone world--for a good reason: it teaches you practical 
skills in a friendly, hands-on format. This bootcamp is aimed at:

* people with HTML or web design experience
* people with some or no Python experience
* people with some or no Zope/Plone experience
It covers using Plone, customizing, and deploying Plone sites.

At Advanced Plone Boot Camp: Plone 3 Techniques you will learn to build 
a site using the best practices of Plone 3 as well as advance your 
skills in scripting and developing for Plone. The course covers the new 
technologies in Plone 3.0 and 3.1 intended for site integrators and 
developers: our new portlet infrastructure, viewlets, versioning, and a 
friendly introduction to Zope 3 component architecture. Now, updated for 
Plone 3.1! The course is intended for people who have experience with 
the basics of Plone site development and HTML/CSS. It will cover what 
you need to know to take advantage of these new technologies in Plone 3.


For more information contact: [EMAIL PROTECTED]

--
Sincerely,

Chris Calloway
http://www.secoora.org
office: 332 Chapman Hall   phone: (919) 599-3530
mail: Campus Box #3300, UNC-CH, Chapel Hill, NC 27599



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


Re: moyea flv to video converter keygen

2008-06-19 Thread George
got error on your page--
http://mail.python.org/mailman/listinfo/python-list

SPAM

2008-06-19 Thread Aspersieman

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


python socket programming

2008-06-19 Thread srinivasan srinivas
HI,
I want to know the different kind of exceptions may occur in client-server  
socket communication and the way to handle those scenarios.
1. What does the server do when a socket error occurs at any point: accepting a 
connection, sending data to a client, receiving data from a client, waiting for 
a client to shut down.
   
2. What does the client do when a socket error occurs at any point: connecting 
to the server, receiving data, sending data.
If anyone knows answer for this qns, Can you please explain me briefly about 
it??
Thanks,
Srini



  Unlimited freedom, unlimited storage. Get it now, on 
http://help.yahoo.com/l/in/yahoo/mail/yahoomail/tools/tools-08.html/
--
http://mail.python.org/mailman/listinfo/python-list


[SMTPLIB] how to send a "Multiline" mail with smtplib?

2008-06-19 Thread Evan
Hello -

I'm new with Python, I try to do a mail problem, the code likes below:

+

import smtplib
import mimetypes
from email.Encoders import encode_base64
from email.MIMEAudio import MIMEAudio
from email.MIMEBase import MIMEBase
from email.MIMEImage import MIMEImage
from email.MIMEMultipart import MIMEMultipart
from email.MIMEText import MIMEText


msg = MIMEMultipart()
msg['From'] = '[EMAIL PROTECTED]'
msg['To'] = '[EMAIL PROTECTED]'
msg['Subject'] = 'test subject'

body=MIMEText('hello,\r\n ok',_subtype='html',_charset='windows-1255')
msg.attach(body)

server = smtplib.SMTP('mail.xx.net')
server.sendmail('[EMAIL PROTECTED]', '[EMAIL PROTECTED]', msg.as_string())
server.quit()


+++

I try to use "\r\n" or "\n", but no luck, nothing with them, I still
get a Single-line text in the mail.

hello, ok


So how do I send a multiline mail? such as :
+++
Hello,
1,
2,
ok
+++

I would like to get help from you, thanks so much.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Function argument conformity check

2008-06-19 Thread Bruno Desthuilliers

[EMAIL PROTECTED] a écrit :

Hi. I am looking for a way to check if some given set of (*args,
**kwds) conforms to the argument specification of a given function,
without calling that function.


import inspect
help(inspect.getargspec)

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


Re: Looking for lots of words in lots of files

2008-06-19 Thread Bruno Desthuilliers

brad a écrit :
Just wondering if anyone has ever solved this efficiently... not looking 
for specific solutions tho... just ideas.


I have one thousand words and one thousand files. I need to read the 
files to see if some of the words are in the files. I can stop reading a 
file once I find 10 of the words in it. It's easy for me to do this with 
a few dozen words, but a thousand words is too large for an RE and too 
inefficient to loop, etc. Any suggestions?


Full text indexing.

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


Re: Annoying message when interrupting python scripts

2008-06-19 Thread geoffbache

As nobody decried the idea of this being a bug, it now is :)

http://bugs.python.org/issue3137

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


Re: please critique my thread code

2008-06-19 Thread Pau Freixes
>
> MRAB wrote:
>
> Erm, shurely the bottleneck will be bandwidth not processor/memory?* If it
> isn't then - yes, you run the risk of actually DOSing their servers!


>
> Your mac will run thousands of threads comfortably but your router may not
> handle the thousands of TCP/IP connections you throw at it very well,
> especially if it is a domestic model, and sure as hell sourceforge aren't
> going to want more than a handfull of concurrent connections from you.
>
> Typical sourceforge page ~ 30K
> Project pages to read = 24
>
> = ~6.8 Gigabytes


The best path for avoid congestion network problem and probably "DOS attack"
it's use a equilibrate number of parallel connection with a number of
threads. One router can handle hundred connections and Mac thread
implementation may be also - with a lot of memory or stack size profiling.
If you run hundred threads you will be fight with OS, Webserver, Router and
network starvation problems.

I believe use a 64 number of threads it's ok, but probably all 64 thread
connections will be performance for the same sourceforge web server -
balancing algorithm - and may be that this week up suspicion to the admin.

May be, you can use httplib [1] for do a persistent connection and reuse
same connection for same  thread.


[1] http://www.python.org/doc/2.4.2/lib/httplib-examples.html



-- 
Pau Freixes
Linux GNU/User
--
http://mail.python.org/mailman/listinfo/python-list

Re: Combining music or video files?

2008-06-19 Thread Roger Heathcote

John Salerno wrote:
"Dennis Lee Bieber" <[EMAIL PROTECTED]> wrote in message 
news:[EMAIL PROTECTED]

On Sun, 15 Jun 2008 22:53:19 -0400, John Salerno
<[EMAIL PROTECTED]> declaimed the following in comp.lang.python:
Even the simplest format -> WAV, which is normally uncompressed
audio samples, is wrapped in layers of informational packets.

snip other stuff!!!


Yikes! Then what I'm reading from your post (and others) is no, I can't do 
it my way. ;) It *did* seem a little too easy, after all! 





I can't speak for video (and I'd imagine it's a factor more difficult) 
but it's really not that hard to concatenate audio in python. What you 
need to do...


Import the right modules for the audio formats you want to read.
Decide on a master output format, say CD quality - PCM 16bit 44.1Khz Stereo.
Open a file for appending
Read through each of your source files loading them into memory
  Get the sample rate and format
  Run the sample data through a function to convert it to the master 
output format*

  Squirt it to disk

Finally take the resulting file, calculate a new header and munge the 
two together. Voila :)



*I'm sure several modules have functions/methods for this but it 
wouldn't be very hard to roll your own either.



Roger Heathcote

http://www.technicalbloke.com
--
http://mail.python.org/mailman/listinfo/python-list


Re: [Python-3000] RELEASED Python 2.6b1 and 3.0b1

2008-06-19 Thread Paul Moore
On 19/06/2008, Barry Warsaw <[EMAIL PROTECTED]> wrote:
> -BEGIN PGP SIGNED MESSAGE-
> Hash: SHA1
>
> On behalf of the Python development team and the Python community, I am
> happy to announce the first beta releases of Python 2.6 and Python 3.0.

Any ETA for Windows builds? The web pages still point to the alphas.
(I'd like to see the Windows builds more closely integrated with the
releases now we're in beta stage...)

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


Re: how to send a "Multiline" mail with smtplib?

2008-06-19 Thread Justin Ezequiel
perhaps change html

body=MIMEText('hello,\r\n
ok',_subtype='html',_charset='windows-1255')

to plain

body=MIMEText('hello,\r\n
ok',_subtype='plain',_charset='windows-1255')
--
http://mail.python.org/mailman/listinfo/python-list


Re: Combining music or video files?

2008-06-19 Thread Paul Boddie
On 16 Jun, 04:53, John Salerno <[EMAIL PROTECTED]> wrote:
> Before I try this and destroy my computer :) I just wanted to see if
> this would even work at all. Is it possible to read a binary file such
> as an mp3 or an avi, put its contents into a new file, then read another
> such file and append its contents to this same new file as well, thereby
> making, for example, a single long video instead of two smaller ones?

Probably not, as people have pointed out, but I imagine you could use
GStreamer and a few processing pipelines, as I pointed out in a
comment on the following article (for another task):

http://jessenoller.com/2008/05/06/lazyweb-question-python-video-manipulation-libraries/

This is probably as close as you can get to treating the files as if
they were simple things which can be concatenated.

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


Simple wxPython SetLabel question

2008-06-19 Thread dp_pearce
Hi All,

Apologies if this should be seriously obvious. But I am quite new to
Python and it is not quite so obvious yet.

I have a GUI which will eventually load and display database
information. I want the user to be able to browse for a database and
then load it. My problem relates to how I set the value of a TextCtrl
once the user has selected the database they wish to load.

Here is a snip of my code:

import wx
import os

class TestFrame(wx.Frame):
def __init__(self):
wx.Frame.__init__(self, None, -1, "Code Snip")
panel   = wx.Panel(self)

databaseLbl = wx.StaticText(panel, -1, "Database:")
database= wx.TextCtrl(panel, -1, "")
databaseBtn = wx.Button(panel, -1, "Browse")
self.Bind(wx.EVT_BUTTON, self.OnBrowse, databaseBtn)
fetchSizer  = wx.BoxSizer(wx.HORIZONTAL)
fetchSizer.Add(databaseLbl)
fetchSizer.Add(database, -1, wx.LEFT |wx.RIGHT, 5)
fetchSizer.Add(databaseBtn)

panel.SetSizer(fetchSizer)

def OnBrowse(self, event):
wildcard = "Access Database (*.mdb) | *.mdb | Access Database
(*.MDB) | *.MDB | All Files (*.*) | *.*"
dialog   = wx.FileDialog(None, "Choose an database",
os.getcwd(), "", wildcard, wx.OPEN)

if dialog.ShowModal() == wx.ID_OK:
path = dialog.GetPath()
#
# NOW SET TEXTCTRL "database" TO "path"
panel.database.SetLabel(path)
#
dialog.Destroy()

app = wx.PySimpleApp()
TestFrame().Show()
app.MainLoop()

The current code returns that "global name 'panel' is not defined" so
I must be referring to it in the wrong way. Can any body help? Any
directions towards any well recommended tutorials would also be
appreciated.

Thank you in advance for your time.

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


Re: Simple wxPython SetLabel question

2008-06-19 Thread Cédric Lucantis
Le Thursday 19 June 2008 11:48:54 dp_pearce, vous avez écrit :
> Hi All,
>
> Apologies if this should be seriously obvious. But I am quite new to
> Python and it is not quite so obvious yet.
>
> I have a GUI which will eventually load and display database
> information. I want the user to be able to browse for a database and
> then load it. My problem relates to how I set the value of a TextCtrl
> once the user has selected the database they wish to load.
>
> Here is a snip of my code:
>
> import wx
> import os
>
> class TestFrame(wx.Frame):
> def __init__(self):
> wx.Frame.__init__(self, None, -1, "Code Snip")
> panel   = wx.Panel(self)
>
> databaseLbl = wx.StaticText(panel, -1, "Database:")
> database= wx.TextCtrl(panel, -1, "")
> databaseBtn = wx.Button(panel, -1, "Browse")
> self.Bind(wx.EVT_BUTTON, self.OnBrowse, databaseBtn)
> fetchSizer  = wx.BoxSizer(wx.HORIZONTAL)
> fetchSizer.Add(databaseLbl)
> fetchSizer.Add(database, -1, wx.LEFT |wx.RIGHT, 5)
> fetchSizer.Add(databaseBtn)
>
> panel.SetSizer(fetchSizer)
>
> def OnBrowse(self, event):
> wildcard = "Access Database (*.mdb) | *.mdb | Access Database
> (*.MDB) | *.MDB | All Files (*.*) | *.*"
> dialog   = wx.FileDialog(None, "Choose an database",
> os.getcwd(), "", wildcard, wx.OPEN)
>
> if dialog.ShowModal() == wx.ID_OK:
> path = dialog.GetPath()
> #
> # NOW SET TEXTCTRL "database" TO "path"
> panel.database.SetLabel(path)
> #
> dialog.Destroy()
>
> app = wx.PySimpleApp()
> TestFrame().Show()
> app.MainLoop()
>
> The current code returns that "global name 'panel' is not defined" 

'panel' is local to your __init__ function, so it's not available elsewhere. 
You should store it as an instance attribute instead :

# in __init__:
self.panel = wx.Panel(self)

# in OnBrowse
self.panel.database.SetLabel(patrh)

note that unlike some other languages, panel and self.panel are two distinct 
variables, so you should replace _all_ references to panel by self.panel.

-- 
Cédric Lucantis
--
http://mail.python.org/mailman/listinfo/python-list


Python-3.0b1 build fails on Linux : _gestalt

2008-06-19 Thread Helmut Jarausch

Hi,

trying to build Python-3.0b1 on my Gentoo Linux box fails with

Failed to find the necessary bits to build these modules:
_gestalt

Looking at setup.py it seems that module '_gestalt'
is only needed on Darwin but my build on Linux fails
nevertheless.

Thanks for any hints,

Helmut Jarausch

Lehrstuhl fuer Numerische Mathematik
RWTH - Aachen University
D 52056 Aachen, Germany
--
http://mail.python.org/mailman/listinfo/python-list


Re: python/ruby question..

2008-06-19 Thread Matt Nordhoff
Mensanator wrote:
> On Jun 18, 10:33�pm, "bruce" <[EMAIL PROTECTED]> wrote:
>> hi...
>>
>> can someone point me to where/how i would go about calling a ruby app from a
>> python app, and having the python app being able to get a returned value
>> from the ruby script.
>>
>> something like
>>
>> test.py
>> �a = os.exec(testruby.rb)
>>
>> testruby.py
>> �foo = 9
>> �return foo
>>
>> i know this doesn't work... but i've been searching for hours on this with
>> no luck (and yeah, i'm relatively new to both ruby/python!!)
>>
>> thanks
> 
> Well, I don't know anything about Ruby, but here's
> how I do it for C programs (compiled to .exe that
> write to stdout).
> 
> 
> import os
> factor_program = 'factor! -d200 ' # factor!.exe from MIRACL
> 
> n =
> '50818429800343305993022114330311033271249313957919046352679206262204589342623811236647989889145173098650749'
> 
> # call external program and capture stdout
> the_output = os.popen(factor_program+n).readlines()
> 
> print 'n: %s' % n
> for i in the_output:
> print i,



You're supposed to use the subprocess module.

In this case, something like:

import subprocess
factor_program = ['factor!', '-d200']

...

p = subprocess.Popen(factor_program + [n], stdout=subprocess.PIPE)
p.wait() # wait for it to finish; not sure how necessary it is
the_output = p.stdout.readlines()

See subprocess's documentation [1], which includes guides on replacing
os.popen* and other functions with it.

[1] 
-- 
--
http://mail.python.org/mailman/listinfo/python-list

Re: how to send a "Multiline" mail with smtplib?

2008-06-19 Thread Lie
On Jun 19, 4:02 pm, Justin Ezequiel <[EMAIL PROTECTED]>
wrote:
> perhaps change html
>
> body=MIMEText('hello,\r\n
> ok',_subtype='html',_charset='windows-1255')
>
> to plain
>
> body=MIMEText('hello,\r\n
> ok',_subtype='plain',_charset='windows-1255')

If that was the case, and you needed a line break in html-mode, use
 or  tags.
--
http://mail.python.org/mailman/listinfo/python-list


Re: python string comparison oddity

2008-06-19 Thread Lie
On Jun 19, 5:13 am, Faheem Mitha <[EMAIL PROTECTED]> wrote:
> On Wed, 18 Jun 2008 12:57:44 -0700 (PDT), Lie <[EMAIL PROTECTED]> wrote:
> > On Jun 19, 2:26 am, Faheem Mitha <[EMAIL PROTECTED]> wrote:
> >> Hi everybody,
>
> >> I was wondering if anyone can explain this. My understanding is that 'is'
> >> checks if the object is the same. However, in that case, why this
> >> inconsistency for short strings? I would expect a 'False' for all three
> >> comparisons. This is reproducible across two different machines, so it is
> >> not just a local quirk. I'm running Debian etch with Python 2.4.4 (the
> >> default).
> >>                                                             Thanks, Faheem.
>
> >> In [1]: a = '--'
>
> >> In [2]: a is '--'
> >> Out[2]: False
>
> >> In [4]: a = '-'
>
> >> In [5]: a is '-'
> >> Out[5]: True
>
> >> In [6]: a = 'foo'
>
> >> In [7]: a is 'foo'
> >> Out[7]: True
>
> > Yes, this happens because of small objects caching. When small
> > integers or short strings are created, there are possibility that they
> > might refer to the same objects behind-the-scene. Don't rely on this
> > behavior.
>
> Yes, but why is '-' and 'foo' cached, and not '--'? Do you know what
> the basis of the choice is?
>                                                              Faheem.

Yes, but we're already warned not to rely on it since the basis of
what may be cached and what-not might be arbitrary. Personally, I'd
not delve deeply into them, they aren't a reliable behavior.
--
http://mail.python.org/mailman/listinfo/python-list


Re: [SPAM] ¡¶python in a nutshell¡·and¡ ¶programming python¡·

2008-06-19 Thread Tommy Nordgren


On 19 jun 2008, at 04.02, yps wrote:


as a new learner of python,which book in  and
 is more suitable?
and recommend several books?
thanks
best regards

   pase.Y


--
http://mail.python.org/mailman/listinfo/python-list
	programming Python is quite good for experienced programmers who want  
to learn Python.
It don't tutor on the Syntax, however, so it needs to be complemented  
with an introduction
to the syntax. Guidos ebook Introduction to Python, (available with  
the Python dist) helps here.

---
See the amazing new SF reel: Invasion of the man eating cucumbers from  
outer space.
On congratulations for a fantastic parody, the producer replies :  
"What parody?"


Tommy Nordgren
[EMAIL PROTECTED]



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


Re: Simple wxPython SetLabel question

2008-06-19 Thread dp_pearce
Thank you very much Cédric. I thought it would be something very
straight forward.
--
http://mail.python.org/mailman/listinfo/python-list


Pyparsing performance boost using Python 2.6b1

2008-06-19 Thread Paul McGuire
I just ran my pyparsing unit tests with the latest Python 2.6b1
(labeled internally as Python 2.6a3 - ???), and the current 1.5.0
version of pyparsing runs with no warnings or regressions.

I was pleasantly surprised by the improved performance.  The most
complex parser I have is the Verilog parser, and I have just under 300
sample input files, so the test gets a chance to run over a range of
code and source inputs.  Here are the lines/second parsing for the
Verilog data (higher numbers are better):

 Python V2.5.1   Python V2.6b1
base
 209.2307.0

with packrat optimization enabled
 349.8408.0

This is a huge percentage improvement, anywhere from 15-50%!  I do not
know what it is about 2.6 that runs so much faster, but given that
packratting achieves somewhat less improvement, I would guess that the
2.6 performance comes from some optimization in making function calls,
or in GC of local variables when functions are completed (since
packratting is a form of internal memoization of parse expressions,
which thereby avoids duplicate calls to parsing functions).

Using psyco typically gives another 30-50% performance improvement,
but there is no psyco available for 2.6 yet, so I skipped those tests
for now.

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


Re: python string comparison oddity

2008-06-19 Thread Duncan Booth
Faheem Mitha <[EMAIL PROTECTED]> wrote:

>>> In [1]: a = '--'
>>>
>>> In [2]: a is '--'
>>> Out[2]: False
>>>
>>> In [4]: a = '-'
>>>
>>> In [5]: a is '-'
>>> Out[5]: True
>>>
>>> In [6]: a = 'foo'
>>>
>>> In [7]: a is 'foo'
>>> Out[7]: True
>>
>> Yes, this happens because of small objects caching. When small
>> integers or short strings are created, there are possibility that they
>> might refer to the same objects behind-the-scene. Don't rely on this
>> behavior.
> 
> Yes, but why is '-' and 'foo' cached, and not '--'? Do you know what
> the basis of the choice is?

Also note that the behaviour you saw above changes if you put code into a 
script rather than running it interactively (the string '--' will be re-
used within a single compilation unit). So even if you understand all of 
the choices made in your particular release of Python (and they do vary 
between releases) it would be very unwise to rely on this behaviour.

-- 
Duncan Booth http://kupuguy.blogspot.com
--
http://mail.python.org/mailman/listinfo/python-list


py2exe & application add-ons

2008-06-19 Thread Alex Gusarov
Hello, I've met a problem - I want my program working without Python
installation but I have some add-on mechanism (add-ons represented by
separate .py files, and application auto-recognize such files on
start).

So, if I will using py2exe for main program and separate .py files for
add-ons, will I need Python installation on client machine?
Maybe other ways exist for such tasks?

--
Thx, Alex Gusarov
--
http://mail.python.org/mailman/listinfo/python-list


Re: python string comparison oddity

2008-06-19 Thread Hrvoje Niksic
Faheem Mitha <[EMAIL PROTECTED]> writes:

> Yes, but why is '-' and 'foo' cached, and not '--'? Do you know what
> the basis of the choice is?

Caches such as intern dictionary/set and one-character cache are
specific to the implementation (and also to its version version,
etc.).  In this case '-' is a 1-character string, all of which are
cached.  Python also interns strings that show up in Python source as
literals that can be interpreted as identifiers.  It also reuses
string literals within a single expression.  None of this should be
relied on, but it's interesting to get insight into the implementation
by examining the different cases:

>>> '--' is '--'
True  # string repeated within an expression is simply reused

>>> a = '--'
>>> b = '--'
>>> a is b
False # not cached

>>> a = '-'
>>> b = '-'
>>> a is b
False # all 1-character strings are cached

>>> a = 'flobozz'
>>> b = 'flobozz'
>>> a is b
True  # flobozz is a valid identifier, so it's cached

>>> a = 'flo-bozz'
>>> b = 'flo-bozz'
>>> a is b
False
--
http://mail.python.org/mailman/listinfo/python-list


Re: py2exe & application add-ons

2008-06-19 Thread Cédric Lucantis
Le Thursday 19 June 2008 13:00:32 Alex Gusarov, vous avez écrit :
> Hello, I've met a problem - I want my program working without Python
> installation but I have some add-on mechanism (add-ons represented by
> separate .py files, and application auto-recognize such files on
> start).
>
> So, if I will using py2exe for main program and separate .py files for
> add-ons, will I need Python installation on client machine?
> Maybe other ways exist for such tasks?
>

I guess you're reading these addons with the exec or execfile builtins ? I 
don't really know py2exe but I bet it can handle it without problem.

-- 
Cédric Lucantis
--
http://mail.python.org/mailman/listinfo/python-list


Re: PEP 372 -- Adding an ordered directory to collections

2008-06-19 Thread Armin Ronacher
Small Status update of the changes incorporated in the PEP:

  - The PEP Title was fixed.  Of course it's a dictionary not a
directory :-)

  - A questions and answers section was added that covers some
of the questions raised here and on the original thread on
python-devel.

  - Comparison behavor was documented

  - a note on Python 3 support was added (about keys-views)


Regards,
Armin

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


Re: Python-3.0b1 build fails on Linux : _gestalt

2008-06-19 Thread Tommy Nordgren


On 19 jun 2008, at 12.07, Helmut Jarausch wrote:


Hi,

trying to build Python-3.0b1 on my Gentoo Linux box fails with

Failed to find the necessary bits to build these modules:
_gestalt

Looking at setup.py it seems that module '_gestalt'
is only needed on Darwin but my build on Linux fails
nevertheless.

Thanks for any hints,

Helmut Jarausch

Lehrstuhl fuer Numerische Mathematik
RWTH - Aachen University
D 52056 Aachen, Germany
--
http://mail.python.org/mailman/listinfo/python-list

Have you run the configure script?
This might happen if you have copied the directory from a machine with  
Darwin/Mac OS X

---
See the amazing new SF reel: Invasion of the man eating cucumbers from  
outer space.
On congratulations for a fantastic parody, the producer replies :  
"What parody?"


Tommy Nordgren
[EMAIL PROTECTED]



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


Extending Python with C: Cannot find MPI library

2008-06-19 Thread Spectrum
  I am writing some Python code using the Message Passing Interface
(MPI), an API used in parallel computing. There exist a number of
Python implementations of MPI, but apparently they all rely on the
Numeric Python (numpy) package. I need to run my code on a particular
machine made available by my university, which does not have numpy and
will not be getting it.

  So I am trying to write my own mini-wrapper for MPI in C to extend
my Python program.

  There exists a special C compiler to use when compiling C programs
that use MPI, called mpicc.

  Here is what I have tried:

  I have written a minimal C program that uses MPI. It works correctly
when compiled with mpicc.

  Then I've written Python boilerplate code and a Python script to
compile my C program into a Python-includable module. This does not
work a priori because the Python compilation script uses gcc rather
than mpicc. So I have taken the exact gcc command that the script uses
and replaced "gcc" with "mpicc".

  This produces an *.so file that compiles without errors.
Unfortunately, it fails when I try to import it in Python. It can't
find the MPI library.

  My MPI code looks like this (plus some boilerplate code):



  /* Return the MPI rank of the current process. */
  int rank(){
int  argc;
char **argv;
int rank, size;
MPI_Init( &argc, &argv );
MPI_Comm_rank( MPI_COMM_WORLD, &rank );
MPI_Finalize();
return rank;
  }

  /* Main. A 'Hello World' function. */
  int hello() {
int rankNumber = rank();
printf ("Hello, World. I am process %d.\n", rankNumber);
return rankNumber;
  }



  My Python program that includes it looks like this:



  import ctest

  ctest.hello()




  My error message is this:



  [EMAIL PROTECTED] Opgave03]$ mpiexec -n 1 python ctest.py
  Traceback (most recent call last):
File "ctest.py", line 1, in 
  import ctest
  ImportError: /big/School/Cluster/Opgave03/ctest.so: undefined
symbol: ompi_mpi_comm_world
  [EMAIL PROTECTED] Opgave03]$



  Can anyone suggest anything? Can I get MPI to work in Python?

  Last time I asked a similar question, someone recommended that I
check out Cython instead of C. Do MPI bindings for Cython exist?

Thanks in advance.

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


Re: [Python-3000] RELEASED Python 2.6b1 and 3.0b1

2008-06-19 Thread Barry Warsaw

-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

On Jun 19, 2008, at 4:43 AM, Paul Moore wrote:


On 19/06/2008, Barry Warsaw <[EMAIL PROTECTED]> wrote:

-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

On behalf of the Python development team and the Python community,  
I am
happy to announce the first beta releases of Python 2.6 and Python  
3.0.


Any ETA for Windows builds? The web pages still point to the alphas.
(I'd like to see the Windows builds more closely integrated with the
releases now we're in beta stage...)


Martin usually fills these in pretty quickly.  I think the current  
situation works fine for the betas but we'll make sure the final  
release (and candidates) are better coordinated.


- -Barry

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

iQCVAwUBSFpIpnEjvBPtnXfVAQJyWQP9FSH8Ipg93UDM3nmH3UtN+i61YGsQPd0O
ypHlnz4yHpxeRkJm1zkppHHI0hKMou6JOeUf05QCnPzrAdsG/mkuv5aoBrBt3dDd
UncHLoQOvXEhGrrPzexmHKv3ehxUXPQOzkiWBWVv9e69GYH4e4HcqV6s2Ya2733T
zC/EyOgkyMg=
=5wM5
-END PGP SIGNATURE-
--
http://mail.python.org/mailman/listinfo/python-list


Simple Python class questions

2008-06-19 Thread John Dann
A Python newbie, but some basic understanding of how classes, objects
etc work in eg VB.Net. However, I'm struggling a little to translate
this knowledge into the Python context.

I'm trying to teach myself this aspect of Python by working up a trial
project, part of which calls for pulling in data from a serial data
connection at regular intervals. It looked sensible to place all the
comms procedures/functions in their own class and module and make
calls to those functions from an object instantiated in a main
controlling module. But I'm struggling to get this working - not sure
whether it's a fundamental misunderstanding of the use of classes in
Python, syntax errors pure and simple or, most likely, a combination
of both!

Maybe I could provide some outline code as an illustration:

Let's say I define the class in a module called comms.py. The class
isn't really going to inherit from any other class (except presumably
in the most primitive base-class sense, which is presumably automatic
and implicit in using the class keyword). Let's call the class
serial_link. So in comms.py I have:

class serial_link:
def __init__(self):
Try
Import serial # the pyserial library
Except ImportException
#Error handling

def openPort(self):
Try
#Code to try opening serial port
Return "Success"
Except SerialException
Return "Failure"

Then in my separate main calling module I might have:

Import comms
serlink=comms.seral_link #Create instance of serial_link class
print serlink.openPort


The last line I'm hoping would print Success or Failure. But I just
seem to get some internal reference to the openPort function enclosed
in <>.

So why doesn't it work please? I may be making multiple errors here
but as far as I can see the syntax seems right. For this particular
example, I don't need to pass any arguments from the
'seriallink.openPort' function so haven't included any parentheses (or
are they mandatory even if empty?) I could go on with the explanations
etc, but it may be simplest to see if anyone can spot a howler
straight out.

TIA for anyone willing to help
--
http://mail.python.org/mailman/listinfo/python-list


Re: Extending Python with C: Cannot find MPI library

2008-06-19 Thread Jeroen Ruigrok van der Werven
-On [20080619 13:53], Spectrum ([EMAIL PROTECTED]) wrote:
>  ImportError: /big/School/Cluster/Opgave03/ctest.so: undefined
>symbol: ompi_mpi_comm_world
>  [EMAIL PROTECTED] Opgave03]$
>
>  Can anyone suggest anything? Can I get MPI to work in Python?

Sounds like a typical case of not specifying any -L and/or -l options. In
this case the ctest.so module has an undefined reference to the symbol
ompi_mpi_comm_world and cannot resolve it. So either it was not linked
properly or the loader cannot find the required library.

Apply nm -D and ldd to the .so and see what ails.

-- 
Jeroen Ruigrok van der Werven  / asmodai
イェルーン ラウフロック ヴァン デル ウェルヴェン
http://www.in-nomine.org/ | http://www.rangaku.org/ | GPG: 2EAC625B
Under this standard shalt thou conquer...
--
http://mail.python.org/mailman/listinfo/python-list

Re: Simple Python class questions

2008-06-19 Thread Cédric Lucantis
Le Thursday 19 June 2008 13:54:03 John Dann, vous avez écrit :
> A Python newbie, but some basic understanding of how classes, objects
> etc work in eg VB.Net. However, I'm struggling a little to translate
> this knowledge into the Python context.
>
> Maybe I could provide some outline code as an illustration:
>
> Let's say I define the class in a module called comms.py. The class
> isn't really going to inherit from any other class (except presumably
> in the most primitive base-class sense, which is presumably automatic
> and implicit in using the class keyword).

No it's not :) It is recommended to always use new-style classes, and thus to 
give the object base explicitely :

class serial_link (object) :
...

see http://docs.python.org/ref/node33.html

> print serlink.openPort
>

You just forgot the (), so you're printing the method object itself without 
calling it : print serlink.openPort()

-- 
Cédric Lucantis
--
http://mail.python.org/mailman/listinfo/python-list


Re: advanced listcomprehenions?

2008-06-19 Thread Mark Wooding
Gabriel Genellina <[EMAIL PROTECTED]> wrote:

> [(not x%3 and not x%5 and "FizzBuzz") or (not x%3 and "Fizz") or (not x%5  
> and "Buzz") or x for x in xrange(1,101)]

Rather unpleasant.  Note that a number is zero mod both 3 and 5 if and
only if it's zero mod 15.  But we can do better.  

A simple application of Fermat's Little Theorem (to distinguish units
mod 3 and 5 from non-units) gives us this:

  [['FizzBuzz', 'Buzz', 'Fizz', False][pow(i, 2, 3) + 2*pow(i, 4, 5)] or
   str(i) for i in xrange(1, 101)]

This is still inelegant, though.  We can glue the results mod 3 and 5
together using the Chinese Remainder Theorem and working mod 15
instead.  For example,

  [['Fizz', 'FizzBuzz', False, None, 'Buzz'][(pow(i, 4, 15) + 1)%7] or
   str(i) for i in xrange(1, 101)]

(A less mathematical approach would just use i%15 to index a table.  But
that's not interesting. ;-) )

-- [mdw]
--
http://mail.python.org/mailman/listinfo/python-list


Re: Simple Python class questions

2008-06-19 Thread Lie
On Jun 19, 6:54 pm, John Dann <[EMAIL PROTECTED]> wrote:
> A Python newbie, but some basic understanding of how classes, objects
> etc work in eg VB.Net. However, I'm struggling a little to translate
> this knowledge into the Python context.
>
> I'm trying to teach myself this aspect of Python by working up a trial
> project, part of which calls for pulling in data from a serial data
> connection at regular intervals. It looked sensible to place all the
> comms procedures/functions in their own class and module and make
> calls to those functions from an object instantiated in a main
> controlling module. But I'm struggling to get this working - not sure
> whether it's a fundamental misunderstanding of the use of classes in
> Python, syntax errors pure and simple or, most likely, a combination
> of both!
>
> Maybe I could provide some outline code as an illustration:
>
> Let's say I define the class in a module called comms.py. The class
> isn't really going to inherit from any other class (except presumably
> in the most primitive base-class sense, which is presumably automatic
> and implicit in using the class keyword). Let's call the class
> serial_link. So in comms.py I have:
>
> class serial_link:
>         def __init__(self):
>                 Try
>                         Import serial # the pyserial library
>                 Except ImportException
>                         #Error handling
>
>         def openPort(self):
>                 Try
>                         #Code to try opening serial port
>                         Return "Success"
>                 Except SerialException
>                         Return "Failure"
>
> Then in my separate main calling module I might have:
>
> Import comms
> serlink=comms.seral_link     #Create instance of serial_link class
> print serlink.openPort
>
> The last line I'm hoping would print Success or Failure. But I just
> seem to get some internal reference to the openPort function enclosed
> in <>.
>
> So why doesn't it work please? I may be making multiple errors here
> but as far as I can see the syntax seems right. For this particular
> example, I don't need to pass any arguments from the
> 'seriallink.openPort' function so haven't included any parentheses (or
> are they mandatory even if empty?) I could go on with the explanations
> etc, but it may be simplest to see if anyone can spot a howler
> straight out.

Yes they're mandatory even if there is no arguments, this is needed so
python can differentiate between calling function and passing function
objects.

> TIA for anyone willing to help

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


Re: Simple Python class questions

2008-06-19 Thread Ulrich Eckhardt
John Dann wrote:
> Let's say I define the class in a module called comms.py. The class
> isn't really going to inherit from any other class (except presumably
> in the most primitive base-class sense, which is presumably automatic
> and implicit in using the class keyword). Let's call the class
> serial_link. So in comms.py I have:
> 
> class serial_link:
> def __init__(self):
> Try
> Import serial # the pyserial library

Stop, this can't work. Other than VB, Python actually is case sensitive, so
you must write 'try' and not 'Try' and also 'import' and not 'Import'.
Further, many (all?) statements that cause an indention are usually
terminated with a colon, so like with 'class ..:' and 'def ..:' you also
must use 'try:' and not just 'try'. Fix all these and try again, I guess
this will already help a lot.

One more thing: you are abusing exceptions. Typically, in such a short
program you only have one try-except pair in the main entry function and
all other code only throws the exceptions. In particular the __init__
function of a class should always signal errors using exceptions. However,
this is not a strict yes/no question but rather a stylistic one.


Uli

-- 
Sator Laser GmbH
Geschäftsführer: Thorsten Föcking, Amtsgericht Hamburg HR B62 932

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

Re: PEP 372 -- Adding an ordered directory to collections

2008-06-19 Thread bearophileHUGS
dbpoko...:
> Which should be 12 bytes on a 32-bit machine. I thought the space for
> growth factor for dicts was about 12% but it is really 100%.

(Please ignore the trailing ".2" in my number in my last post, such
precision is silly).
My memory value comes from experiments, I have created a little
program like this:

from memory import memory

def main(N):
m1 = memory()
print m1

d = {}
for i in xrange(N):
d[i] = None

m2 = memory()
print m2
print float((m2 - m1) * 1024) / N
main(2000)

Where memory is a small module of mine that calls a little known
program that tells how much memory is used by the current Python
process. The results for that run n=2000 are (first two numbers
are kilobytes, the third number is byte/pair):

1876
633932
32.3612672

It means to store 20_000_000 pairs it requires about 647_000_000
bytes, Python 2.5.2, on Win.

Bye,
bearophile
--
http://mail.python.org/mailman/listinfo/python-list


Re: advanced listcomprehenions?

2008-06-19 Thread Duncan Booth
Mark Wooding <[EMAIL PROTECTED]> wrote:

> This is still inelegant, though.  We can glue the results mod 3 and 5
> together using the Chinese Remainder Theorem and working mod 15
> instead.  For example,
> 
>   [['Fizz', 'FizzBuzz', False, None, 'Buzz'][(pow(i, 4, 15) + 1)%7] or
>str(i) for i in xrange(1, 101)]
> 
> (A less mathematical approach would just use i%15 to index a table.  But
> that's not interesting. ;-) )
> 

Ooh. Doesn't having 5 elements make you shudder? (Even though you did 
change one to avoid a repeated value.) You have 4 options for output, so 
for elegance that list should also have 4 elements:

[[str(i), 'FizzBuzz', 'Fizz', 'Buzz'][25/(pow(i, 4, 15) + 1)%4] for i in 
xrange(1, 101)]

I feel it is even more elegant with the lookup table in its natural order:

[['Fizz', 'Buzz', 'FizzBuzz', str(i)][62/(pow(i, 4, 15) + 1)%4] for i in 
xrange(1, 101)]

:)

-- 
Duncan Booth http://kupuguy.blogspot.com
--
http://mail.python.org/mailman/listinfo/python-list


Re: PEP 372 -- Adding an ordered directory to collections

2008-06-19 Thread Duncan Booth
[EMAIL PROTECTED] wrote:

> My memory value comes from experiments, I have created a little
> program like this:
> 
> from memory import memory
> 
> def main(N):
> m1 = memory()
> print m1
> 
> d = {}
> for i in xrange(N):
> d[i] = None
> 
> m2 = memory()
> print m2
> print float((m2 - m1) * 1024) / N
> main(2000)
> 
> Where memory is a small module of mine that calls a little known
> program that tells how much memory is used by the current Python
> process. The results for that run n=2000 are (first two numbers
> are kilobytes, the third number is byte/pair):
> 
> 1876
> 633932
> 32.3612672
> 
> It means to store 20_000_000 pairs it requires about 647_000_000
> bytes, Python 2.5.2, on Win.
> 

What do you get if you change the output to exclude the integers from 
the memory calculation so you are only looking at the dictionary 
elements themselves? e.g.

def main(N):
keys = range(N)
m1 = memory()
print m1

d = {}
for i in keys:
d[i] = None

m2 = memory()
print m2
print float((m2 - m1) * 1024) / N
main(2000)


-- 
Duncan Booth http://kupuguy.blogspot.com
--
http://mail.python.org/mailman/listinfo/python-list


Re: Multiprecision arithmetic library question.

2008-06-19 Thread duncan smith

Michael Press wrote:

In article <[EMAIL PROTECTED]>,
 Mark Wooding <[EMAIL PROTECTED]> wrote:


Michael Press <[EMAIL PROTECTED]> wrote:


I already compiled and installed the GNU multiprecision library
on Mac OS X, and link to it in C programs. 
How do I link to the library from Python? 

You know that Python already supports multiprecision integer arithmetic,
right?  If you desperately want GMP, though, there's the gmpy module
(q.g.).


No, I do not know that. Define desperate. 
Does Python support the extended Euclidean algorithm

and other number theory functions?
How fast does Python multiply?
Not that the latter is particularly important,
as C is built for speed.

I've been fooling around. Ran dir(gmpy), and 
it does not show the full complement of GMP

library functions, such as the various division
functions. e.g. mpz_tdiv_qr.



There's also 
http://www.egenix.com/products/python/mxExperimental/mxNumber/.  I'm not 
sure how the functionality compares to GMPY.


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


python script for tortoise cvs

2008-06-19 Thread sandeep
hi

we are using tortoise cvs and putty. i want to write a python script
to whom i can provide a tag and module.now what this script will do is
look for this specific tag and checks for whether its a individual tag
or its inside a branch.if its inside a branch then find out what is
the branch tag and then check out that branch for me else it checks
out that module with that tag.

Actually the thing is i am not able to find the way how i will do it
and for where i have to look for the info.so any help will be
appreciated.

thanks and regards
sandeep kumar sharma
--
http://mail.python.org/mailman/listinfo/python-list


Re: Simple Python class questions

2008-06-19 Thread John Dann
Many thanks for the speedy replies.

On Thu, 19 Jun 2008 14:14:02 +0200, Cédric Lucantis <[EMAIL PROTECTED]>
wrote:

>Le Thursday 19 June 2008 13:54:03 John Dann, vous avez écrit :
>> Let's say I define the class in a module called comms.py. The class
>> isn't really going to inherit from any other class (except presumably
>> in the most primitive base-class sense, which is presumably automatic
>> and implicit in using the class keyword).
>
>No it's not :) It is recommended to always use new-style classes, and thus to 
>give the object base explicitely :
>
>class serial_link (object) :
>   ...

Can I just confirm: between the parentheses should be the literal
'object' - ie (object) - you're not just using 'object' as a
placeholder where there should be a more specific class name or
object?

--

On Thu, 19 Jun 2008 14:21:46 +0200, Ulrich Eckhardt
<[EMAIL PROTECTED]> wrote:

>Stop, this can't work. Other than VB, Python actually is case sensitive, so
>you must write 'try' and not 'Try' and also 'import' and not 'Import'.
>Further, many (all?) statements that cause an indention are usually
>terminated with a colon, so like with 'class ..:' and 'def ..:' you also
>must use 'try:' and not just 'try'. Fix all these and try again, I guess
>this will already help a lot.

Sorry - the original code was syntactically correct - I just re-keyed
it rather quickly for the original newsgroup post here, rather than
copy/paste a larger chunk. I'll try to be more careful with any future
posts.

>One more thing: you are abusing exceptions. Typically, in such a short
>program you only have one try-except pair in the main entry function and
>all other code only throws the exceptions. In particular the __init__
>function of a class should always signal errors using exceptions. However,
>this is not a strict yes/no question but rather a stylistic one.

Thanks - I need to think more clearly about the best way of doing
this.

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


Re: python script for tortoise cvs

2008-06-19 Thread Simon Brunning
On Thu, Jun 19, 2008 at 2:14 PM, sandeep <[EMAIL PROTECTED]> wrote:
> hi
>
> we are using tortoise cvs and putty. i want to write a python script
> to whom i can provide a tag and module.now what this script will do is
> look for this specific tag and checks for whether its a individual tag
> or its inside a branch.if its inside a branch then find out what is
> the branch tag and then check out that branch for me else it checks
> out that module with that tag.
>
> Actually the thing is i am not able to find the way how i will do it
> and for where i have to look for the info.so any help will be
> appreciated.

I don't know if Tortoise is scriptable, but Subversion certainly is -
 - and nothing you mention is Tortoise
specific.

-- 
Cheers,
Simon B.
[EMAIL PROTECTED]
http://www.brunningonline.net/simon/blog/
GTalk: simon.brunning | MSN: small_values | Yahoo: smallvalues | Twitter: brunns
--
http://mail.python.org/mailman/listinfo/python-list


Re: Simple Python class questions

2008-06-19 Thread Cédric Lucantis
Le Thursday 19 June 2008 15:13:39 John Dann, vous avez écrit :
> Many thanks for the speedy replies.
>
> On Thu, 19 Jun 2008 14:14:02 +0200, Cédric Lucantis <[EMAIL PROTECTED]>
>
> wrote:
> >Le Thursday 19 June 2008 13:54:03 John Dann, vous avez écrit :
> >> Let's say I define the class in a module called comms.py. The class
> >> isn't really going to inherit from any other class (except presumably
> >> in the most primitive base-class sense, which is presumably automatic
> >> and implicit in using the class keyword).
> >
> >No it's not :) It is recommended to always use new-style classes, and thus
> > to give the object base explicitely :
> >
> >class serial_link (object) :
> > ...
>
> Can I just confirm: between the parentheses should be the literal
> 'object' - ie (object) - you're not just using 'object' as a
> placeholder where there should be a more specific class name or
> object?

Right. 'object' is a builtin python class, used as a base for all classes as 
in many OO languages.

-- 
Cédric Lucantis
--
http://mail.python.org/mailman/listinfo/python-list


Re: Extending Python with C: Cannot find MPI library

2008-06-19 Thread Spectrum
On Jun 19, 2:10 pm, Jeroen Ruigrok van der Werven <[EMAIL PROTECTED]
nomine.org> wrote:
> -On [20080619 13:53], Spectrum ([EMAIL PROTECTED]) wrote:
>
> >  ImportError: /big/School/Cluster/Opgave03/ctest.so: undefined
> >symbol: ompi_mpi_comm_world
> > [EMAIL PROTECTED] Opgave03]$
>
> >  Can anyone suggest anything? Can I get MPI to work in Python?
>
> Sounds like a typical case of not specifying any -L and/or -l options. In
> this case the ctest.so module has an undefined reference to the symbol
> ompi_mpi_comm_world and cannot resolve it. So either it was not linked
> properly or the loader cannot find the required library.
>
> Apply nm -D and ldd to the .so and see what ails.

  Thanks for the reply.

  It is very likely that I am not compiling properly. I am a sucky C
programmer.

  The commands you recommended give the following output:

  [EMAIL PROTECTED] Opgave03]$ nm -D ctest.so
  U MPI_Comm_rank
  U MPI_Finalize
  U MPI_Init
  w _Jv_RegisterClasses
  18cc A __bss_start
  w __cxa_finalize
  w __gmon_start__
  U __printf_chk
  18cc A _edata
  18d4 A _end
  06c4 T _fini
  0414 T _init
  0600 T hello
  0650 T main
  U ompi_mpi_comm_world
  05b0 T rank
  [EMAIL PROTECTED] Opgave03]$
  [EMAIL PROTECTED] Opgave03]$
  [EMAIL PROTECTED] Opgave03]$ ldd ctest.so
  linux-gate.so.1 =>  (0x0011)
  libpython2.5.so.1.0 => /usr/lib/libpython2.5.so.1.0
(0x00113000)
  libpthread.so.0 => /lib/libpthread.so.0 (0x0025a000)
  libc.so.6 => /lib/libc.so.6 (0x00342000)
  libdl.so.2 => /lib/libdl.so.2 (0x00273000)
  libutil.so.1 => /lib/libutil.so.1 (0x00278000)
  libm.so.6 => /lib/libm.so.6 (0x0027c000)
  /lib/ld-linux.so.2 (0x00325000)
  [EMAIL PROTECTED] Opgave03]$



  The same commands, when applied to the mpicc-compiled, correctly-
functioning C program (in this case just named 'a.out') give this:



  [EMAIL PROTECTED] Opgave03]$ ./a.out
  Hello, World. I am process 0.
  [EMAIL PROTECTED] Opgave03]$ nm -D a.out
  U MPI_Comm_rank
  U MPI_Finalize
  U MPI_Init
  08048818 R _IO_stdin_used
  w _Jv_RegisterClasses
  080499fc A __bss_start
  080499f8 D __data_start
  w __gmon_start__
  08048750 T __libc_csu_fini
  08048760 T __libc_csu_init
  U __libc_start_main
  080499fc A _edata
  08049b10 A _end
  080487f8 T _fini
  08048814 R _fp_hw
  08048560 T _init
  080485f0 T _start
  080499f8 W data_start
  080486f9 T hello
  0804871f T main
  08049a00 B ompi_mpi_comm_world
  U printf
  080486c4 T rank
  [EMAIL PROTECTED] Opgave03]$ ldd a.out
  linux-gate.so.1 =>  (0x0011)
  libmpi.so.0 => /usr/lib/openmpi/1.2.4-gcc/libmpi.so.0
(0x0042f000)
  libopen-rte.so.0 => /usr/lib/openmpi/1.2.4-gcc/libopen-
rte.so.0 (0x003d4000)
  libopen-pal.so.0 => /usr/lib/openmpi/1.2.4-gcc/libopen-
pal.so.0 (0x00344000)
  libdl.so.2 => /lib/libdl.so.2 (0x00df)
  libnsl.so.1 => /lib/libnsl.so.1 (0x003b9000)
  libutil.so.1 => /lib/libutil.so.1 (0x004d8000)
  libm.so.6 => /lib/libm.so.6 (0x0025c000)
  libpthread.so.0 => /lib/libpthread.so.0 (0x00287000)
  libc.so.6 => /lib/libc.so.6 (0x004dc000)
  /lib/ld-linux.so.2 (0x00325000)
  [EMAIL PROTECTED] Opgave03]$



  I don't know how to interpret these, so can I get some more advice?

  Thanks in advance.

  - Claus Appel

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


Re: python/ruby question..

2008-06-19 Thread Michael Mabin
The commands module might help you out as well.
import commands as c
output = c.getoutput('testruby.rb')



On Thu, Jun 19, 2008 at 5:14 AM, Matt Nordhoff <[EMAIL PROTECTED]>
wrote:

> Mensanator wrote:
> > On Jun 18, 10:33�pm, "bruce" <[EMAIL PROTECTED]> wrote:
> >> hi...
> >>
> >> can someone point me to where/how i would go about calling a ruby app
> from a
> >> python app, and having the python app being able to get a returned value
> >> from the ruby script.
> >>
> >> something like
> >>
> >> test.py
> >> �a = os.exec(testruby.rb)
> >>
> >> testruby.py
> >> �foo = 9
> >> �return foo
> >>
> >> i know this doesn't work... but i've been searching for hours on this
> with
> >> no luck (and yeah, i'm relatively new to both ruby/python!!)
> >>
> >> thanks
> >
> > Well, I don't know anything about Ruby, but here's
> > how I do it for C programs (compiled to .exe that
> > write to stdout).
> >
> >
> > import os
> > factor_program = 'factor! -d200 ' # factor!.exe from MIRACL
> >
> > n =
> >
> '50818429800343305993022114330311033271249313957919046352679206262204589342623811236647989889145173098650749'
> >
> > # call external program and capture stdout
> > the_output = os.popen(factor_program+n).readlines()
> >
> > print 'n: %s' % n
> > for i in the_output:
> > print i,
>
> 
>
> You're supposed to use the subprocess module.
>
> In this case, something like:
>
> import subprocess
> factor_program = ['factor!', '-d200']
>
> ...
>
> p = subprocess.Popen(factor_program + [n], stdout=subprocess.PIPE)
> p.wait() # wait for it to finish; not sure how necessary it is
> the_output = p.stdout.readlines()
>
> See subprocess's documentation [1], which includes guides on replacing
> os.popen* and other functions with it.
>
> [1] 
> --
> --
> http://mail.python.org/mailman/listinfo/python-list
>



-- 
| _ | * | _ |
| _ | _ | * |
| * | * | * |
--
http://mail.python.org/mailman/listinfo/python-list

Re: PEP 372 -- Adding an ordered directory to collections

2008-06-19 Thread bearophileHUGS
Duncan Booth:
> What do you get if you change the output to exclude the integers from
> the memory calculation so you are only looking at the dictionary
> elements themselves? e.g.

The results:

318512 (kbytes)
712124 (kbytes)
20.1529344 (bytes)

Bye,
bearophile
--
http://mail.python.org/mailman/listinfo/python-list


Re: How do i : Python Threads + KeyboardInterrupt exception

2008-06-19 Thread MRAB
On Jun 19, 7:54 am, Dennis Lee Bieber <[EMAIL PROTECTED]> wrote:
> On Wed, 18 Jun 2008 21:33:42 -0700 (PDT), Brendon Costa
> <[EMAIL PROTECTED]> declaimed the following in comp.lang.python:
>
> > Unfortunately that is the problem. It is blocking in a IO system call
> > and i want to force it to exit that with an error, hopefully causing a
> > Python exception. I looked at what you mentioned and it is described a
> > bit here too:http://sebulba.wikispaces.com/recipe+thread2
>
>         There is no "safe" means of forcing a Python thread to exit... Heck,
> I believe the MSDN is full of warnings that killing a thread at the
> Windows OS level is fraught with danger.
>
>         Unfortunately, Windows doesn't allow for use of select() on anything
> other than sockets -- otherwise you could code a wait that included a
> "die" object and "write" to that object to break the blocking wait.
>
>         If your blocking call has no time-out variant, you may be stuck...
>
If only the main thread can receive KeyboardInterrupt, is there any
reason why you couldn't move the functionality of the Read thread into
the main thread? It looks like it's not doing any work, just waiting
for the Proc thread to finish.

You could start the Proc thread, do the current Read thread
functionality until the interrupt occurs, put the apporpriate message
in the queue, and then wait for the Proc thread to finish.
--
http://mail.python.org/mailman/listinfo/python-list


Simple Python implementation of bag/multiset

2008-06-19 Thread MRAB
While another thread is talking about an ordered dict, I thought I'd
try a simple implementation of a bag/multiset in Python. Comments/
suggestions welcome, etc.

class bag(object):
def __add__(self, other):
result = self.copy()
for item, count in other.iteritems():
result._items[item] = result._items.get(item, 0) + count
return result
def __and__(self, other):
result = bag()
for item, count in other.iteritems():
new_count = min(self._items.get(item, 0), count)
if new_count > 0:
result._items[item] = new_count
return result
def __contains__(self, item):
return item in self._items
def __eq__(self, other):
return self._items == other._items
def __getitem__(self, item):
return self._items[item]
def __iadd__(self, other):
self._items = self.__add__(other)._items
return self
def __iand__(self, other):
self._items = self.__and__(other)._items
return self
def __init__(self, iterable=None):
self._items = {}
if iterable is not None:
for item in iterable:
self._items[item] = self._items.get(item, 0) + 1
def __ior__(self, other):
self._items = self.__or__(other)._items
return self
def __isub__(self, other):
self._items = self.__sub__(other)._items
return self
def __iter__(self):
for item, count in self.iteritems():
for counter in xrange(count):
yield item
def __ixor__(self, other):
self._items = self.__xor__(other)._items
return self
def __len__(self):
return sum(self._items.itervalues())
def __ne__(self, other):
return self._items != other._items
def __or__(self, other):
result = self.copy()
for item, count in other.iteritems():
result._items[item] = max(result._items.get(item, 0),
count)
return result
def __repr__(self):
result = []
for item, count in self.iteritems():
result += [repr(item)] * count
return 'bag([%s])' % ', '.join(result)
def __setitem__(self, item, count):
if not isinstance(count, int) or count < 0:
raise ValueError
if count > 0:
self._items[item] = count
elif item in self._items:
del self._items[item]
def __sub__(self, other):
result = bag()
for item, count in self.iteritems():
new_count = count - other._items.get(item, 0)
if new_count > 0:
result._items[item] = new_count
return result
def __xor__(self, other):
result = self.copy()
for item, count in other.iteritems():
new_count = abs(result._items.get(item, 0) - count)
if new_count > 0:
result._items[item] = new_count
elif item in result._item:
del result._items[item]
return result
def add(self, item):
self._items[item] = self._items.get(item, 0) + 1
def discard(self, item):
new_count = self._items.get(item, 0) - 1
if new_count > 0:
self._items[item] = new_count
elif new_count == 0:
del self._items[item]
def clear(self):
self._items = {}
def copy(self):
result = bag()
result._items = self._items.copy()
return result
def difference(self, other):
return self.__sub__(other)
def difference_update(self, other):
self._items = self.__sub__(other)._items
def get(self, item, default=0):
return self._items.get(item, default)
def intersection(self, other):
return self.__and__(other)
def intersection_update(self, other):
self.__iand__(other)
def items(self):
return self._items.items()
def iteritems(self):
return self._items.iteritems()
def iterkeys(self):
return self._items.iterkeys()
def itervalues(self):
return self._items.itervalues()
def keys(self):
return self._items.keys()
def pop(self):
item = self._items.keys()[0]
self._items[item] -= 1
if self._items[item] == 0:
del self._items[item]
return item
def remove(self, item):
new_count = self._items[item] - 1
if new_count > 0:
self._items[item] = new_count
else:
del self._items[item]
def symmetric_difference(self, other):
return self.__xor__(other)
def symmetric_difference_update(self, other):
self.__ixor__(other)
def union(self, other):
return self.__or__(other)
def update(self, other):
self.__ior__(other)
def values(self):
return self._items.values()
--
http://mail.python.org/mailman/listinfo/python-list


Re: Extending Python with C: Cannot find MPI library

2008-06-19 Thread Jeroen Ruigrok van der Werven
-On [20080619 16:21], Spectrum ([EMAIL PROTECTED]) wrote:
>  libmpi.so.0 => /usr/lib/openmpi/1.2.4-gcc/libmpi.so.0
>(0x0042f000)
>  libopen-rte.so.0 => /usr/lib/openmpi/1.2.4-gcc/libopen-
>rte.so.0 (0x003d4000)
>  libopen-pal.so.0 => /usr/lib/openmpi/1.2.4-gcc/libopen-
>pal.so.0 (0x00344000)

These libraries are what your binaries (.so and such) needs to link against
as well. I am not sure if you have to add a flag (-mpi) to your compiler or
if you need to add a -L/usr/lib/openmpi/1.2.4-gcc -lmpi -lopen-rte
-lopen-pal to the incantations.

-- 
Jeroen Ruigrok van der Werven  / asmodai
イェルーン ラウフロック ヴァン デル ウェルヴェン
http://www.in-nomine.org/ | http://www.rangaku.org/ | GPG: 2EAC625B
The distance to here is infinite...
--
http://mail.python.org/mailman/listinfo/python-list

Re: Extending Python with C: Cannot find MPI library

2008-06-19 Thread Spectrum
On Jun 19, 4:39 pm, Jeroen Ruigrok van der Werven <[EMAIL PROTECTED]
nomine.org> wrote:
> -On [20080619 16:21], Spectrum ([EMAIL PROTECTED]) wrote:
>
> >          libmpi.so.0 => /usr/lib/openmpi/1.2.4-gcc/libmpi.so.0
> >(0x0042f000)
> >          libopen-rte.so.0 => /usr/lib/openmpi/1.2.4-gcc/libopen-
> >rte.so.0 (0x003d4000)
> >          libopen-pal.so.0 => /usr/lib/openmpi/1.2.4-gcc/libopen-
> >pal.so.0 (0x00344000)
>
> These libraries are what your binaries (.so and such) needs to link against
> as well. I am not sure if you have to add a flag (-mpi) to your compiler or
> if you need to add a -L/usr/lib/openmpi/1.2.4-gcc -lmpi -lopen-rte
> -lopen-pal to the incantations.

  Thanks for the reply.

  I did some more experimentation. The compiling commands I use are:

  mpicc -fno-strict-aliasing -DNDEBUG -O2 -g -pipe -Wall -Wp,-
D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector --param=ssp-buffer-
size=4 -m32 -march=i386 -mtune=generic -fasynchronous-unwind-tables -
D_GNU_SOURCE -fPIC -fPIC -I/usr/include/python2.5 -c ctest.c -o
ctest.o
  gcc -pthread -shared build/temp.linux-i686-2.5/ctest.o -L/usr/lib -
lpython2.5 -o ctest.so

  It turns out that changing the second "gcc" to "mpicc" causes the
module to no longer be includable. Python will give this error
message:

  [EMAIL PROTECTED] Opgave03]$ python ctest.py
  Traceback (most recent call last):
File "ctest.py", line 1, in 
  import ctest
  ImportError: dynamic module does not define init function
(initctest)
  [EMAIL PROTECTED] Opgave03]$

  The same happens if I try to add "-L/usr/lib/openmpi/1.2.4-gcc -lmpi
-lopen-rte -lopen-pal" as options to the second compilation command,
as you recommended.

  Looks like MPI doesn't like Python...
--
http://mail.python.org/mailman/listinfo/python-list


Convert string to array of floats

2008-06-19 Thread Jonno
Hi,

I'm very new to programming and python.

I need to convert a string like this:
'   0.906366 2.276152   0.01336980.773141
0.002836  -107.335197   0.01146286.846290\n'
to an array of floats.

Any pointers to the simplest way of doing this?

Thanks.

-- 
"If a theory can't produce hypotheses, can't be tested, can't be disproven,
and can't make predictions, then it's not a theory and certainly not
science." by spisska on Slashdot, Monday April 21, 2008
--
http://mail.python.org/mailman/listinfo/python-list

Re: Simple Python class questions

2008-06-19 Thread Lie
On Jun 19, 7:21 pm, Ulrich Eckhardt <[EMAIL PROTECTED]> wrote:
> John Dann wrote:
> > Let's say I define the class in a module called comms.py. The class
> > isn't really going to inherit from any other class (except presumably
> > in the most primitive base-class sense, which is presumably automatic
> > and implicit in using the class keyword). Let's call the class
> > serial_link. So in comms.py I have:
>
> > class serial_link:
> >     def __init__(self):
> >         Try
> >             Import serial # the pyserial library
>
> Stop, this can't work. Other than VB, Python actually is case sensitive, so
> you must write 'try' and not 'Try' and also 'import' and not 'Import'.
> Further, many (all?) statements that cause an indention are usually
> terminated with a colon, so like with 'class ..:' and 'def ..:' you also
> must use 'try:' and not just 'try'. Fix all these and try again, I guess
> this will already help a lot.
>
> One more thing: you are abusing exceptions. Typically, in such a short
> program you only have one try-except pair in the main entry function and
> all other code only throws the exceptions. In particular the __init__
> function of a class should always signal errors using exceptions. However,
> this is not a strict yes/no question but rather a stylistic one.
>
> Uli
>
> --
> Sator Laser GmbH
> Geschäftsführer: Thorsten Föcking, Amtsgericht Hamburg HR B62 932

I think it's not that hard to see that it's just a pseudo code
--
http://mail.python.org/mailman/listinfo/python-list


Installing Python 3.0 no probs running 2.5 at the same time?

2008-06-19 Thread cirfu
Can I install 3.0 without breaking 2.5? Meaning does it overwrite some
bindings or something or it just installs 3.0 in a different folder as
a completely separate program?
--
http://mail.python.org/mailman/listinfo/python-list


Re: advanced listcomprehenions?

2008-06-19 Thread Mark Wooding
Duncan Booth <[EMAIL PROTECTED]> wrote:

> [['Fizz', 'Buzz', 'FizzBuzz', str(i)][62/(pow(i, 4, 15) + 1)%4] for i in 
> xrange(1, 101)]

Cute! ;-)

-- [mdw]
--
http://mail.python.org/mailman/listinfo/python-list


Re: Simple Python class questions

2008-06-19 Thread Ulrich Eckhardt
Lie wrote:
> I think it's not that hard to see that it's just a pseudo code

"...in comms.py I have: ..." actually explicitly says that it is actual code
from a file.

*shrug*

Uli


-- 
Sator Laser GmbH
Geschäftsführer: Thorsten Föcking, Amtsgericht Hamburg HR B62 932

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

regex \b behaviour in python

2008-06-19 Thread Walter Cruz
Hi all!

Just a simple question about the behaviour of a regex in python. (I
discussed this on IRC, and they suggest me to post here).

I tried to split the string  "walter ' cruz" using \b .

In ruby, it returns:

irb(main):001:0>"walter ' cruz".split(/\b/)
=> ["walter", " ' ", "cruz"]

and in php:

Array
(
[0] =>
[1] => walter
[2] =>  '
[3] => cruz
[4] =>
)


But in python the behaviour of \b is differente from ruby or php.

The guys on the IRC pointed me a way to do that: [m.span() for m in
re.finditer(r'\b',"walter ' cruz")], but if fact there's some
differente as it strips the spaces :)

My question is: why \b behaves like this on python? Why it's different
from ruby or php (or even perl, I believe)?

(For the sake of curiosity, I was trying to solve the
http://www.rubyquiz.com/quiz76.html in python. But the question to not
to solve the quiz, but understand why python is different)

[]'s
- Walter
--
http://mail.python.org/mailman/listinfo/python-list


Re: Convert string to array of floats

2008-06-19 Thread Cédric Lucantis
Le Thursday 19 June 2008 17:12:08 Jonno, vous avez écrit :
> Hi,
>
> I'm very new to programming and python.
>
> I need to convert a string like this:
> '   0.906366 2.276152   0.01336980.773141
> 0.002836  -107.335197   0.01146286.846290\n'
> to an array of floats.
>

string = '0.906366 2.276152   0.01336980.773141'
array = [float(s) for s in string.split()]

-- 
Cédric Lucantis
--
http://mail.python.org/mailman/listinfo/python-list

Re: Installing Python 3.0 no probs running 2.5 at the same time?

2008-06-19 Thread Cédric Lucantis
Le Thursday 19 June 2008 17:32:10 cirfu, vous avez écrit :
> Can I install 3.0 without breaking 2.5? Meaning does it overwrite some
> bindings or something or it just installs 3.0 in a different folder as
> a completely separate program?

It's OK for any version having different major/minor version numbers (so 2.4 + 
2.5 is OK, but _not_ 2.4.2 + 2.4.4). Everything go in different directories, 
and a version specific executable is also installed (python2.5, 
python3.0...). The main one (python) is just a link to one of them. 

-- 
Cédric Lucantis
--
http://mail.python.org/mailman/listinfo/python-list


Pydev 1.3.18 Released

2008-06-19 Thread Fabio Zadrozny
Hi All,

Pydev and Pydev Extensions 1.3.18 have been released

Details on Pydev Extensions: http://www.fabioz.com/pydev
Details on Pydev: http://pydev.sf.net
Details on its development: http://pydev.blogspot.com

Release Highlights in Pydev Extensions:
-

* Auto-import: Groups imports when possible.
* Auto-import: Doesn't bring imports for completions already in the
document even if a parse is not successful.
* Organize Imports (ctrl+shift+O): Suggests imports to the undefined
tokens in the editor.
* Import quick-fix: Icons correspondent to the element being imported.


Release Highlights in Pydev:
--

* Executing external programs: Using Runtime.exec(String[] cmdargs)
instead of a string with the generated command (fixes problems
regarding having spaces in the installation).
* Organize Imports (ctrl+shift+O): Imports can be grouped.
* Cygwin: sys.executable in cygwin was not returning '.exe' in the end
of the executable as it should.
* Additional paths for PYTHONPATH (Patch from Eric Wittmann):
extension point allows plugins to contribute paths to the PYTHONPATH.
* Code-completion: typing '.' won't apply the selected completion, but
will still request a new one with the current contents.
* Pydev Package Explorer: Problem while trying to show active editor
on the pydev package explorer.


What is PyDev?
---

PyDev is a plugin that enables users to use Eclipse for Python and
Jython development -- making Eclipse a first class Python IDE -- It
comes with many goodies such as code completion, syntax highlighting,
syntax analysis, refactor, debug and many others.


Cheers,

-- 
Fabio Zadrozny
--
Software Developer

ESSS - Engineering Simulation and Scientific Software
http://www.esss.com.br

Pydev Extensions
http://www.fabioz.com/pydev

Pydev - Python Development Enviroment for Eclipse
http://pydev.sf.net
http://pydev.blogspot.com
--
http://mail.python.org/mailman/listinfo/python-list


Re: Convert string to array of floats

2008-06-19 Thread Jonno
Brilliant! Thanks.

On Thu, Jun 19, 2008 at 10:00 AM, Cédric Lucantis <[EMAIL PROTECTED]> wrote:

> Le Thursday 19 June 2008 17:12:08 Jonno, vous avez écrit :
> > Hi,
> >
> > I'm very new to programming and python.
> >
> > I need to convert a string like this:
> > '   0.906366 2.276152   0.01336980.773141
> > 0.002836  -107.335197   0.01146286.846290\n'
> > to an array of floats.
> >
>
> string = '0.906366 2.276152   0.01336980.773141'
> array = [float(s) for s in string.split()]
>
> --
> Cédric Lucantis
> --
> http://mail.python.org/mailman/listinfo/python-list




-- 
"If a theory can't produce hypotheses, can't be tested, can't be disproven,
and can't make predictions, then it's not a theory and certainly not
science." by spisska on Slashdot, Monday April 21, 2008
--
http://mail.python.org/mailman/listinfo/python-list

Getting Python to run Python Scripts in cygwin

2008-06-19 Thread Calvin Cheng
Hi guys,

This may be a cygwin issue but I was hoping to get some answers here
as well if someone has fixed this problem before.

Basically, I am able to run "python .py" python files in
command prompt.  Unfortunately, I can't seem to get it to work in
cygwin.  I always get an error that says:
python: can't open file '.py': [Errno 2] No such file or directory

I have looked at my environment variables and it seems to be correct.

Would be grateful if someone who has gotten python to work correctly
on cygwin could point me in the right direction.

It is very cumbersome switching back-and-forth between command prompt
and cygwin just to run python scripts.

Thank you in advance,
Calvin
--
http://mail.python.org/mailman/listinfo/python-list


Re: dict order

2008-06-19 Thread Aahz
In article <[EMAIL PROTECTED]>,
 <[EMAIL PROTECTED]> wrote:
>
>Whoops
>
>for keys, values in dict_one.items():
>  if keys in dict_two:
>if values == dict_two[keys]:

Except that "keys" implies a plural (meaning more than one thing); in a
for loop, each iteration will have only one key.
-- 
Aahz ([EMAIL PROTECTED])   <*> http://www.pythoncraft.com/

"as long as we like the same operating system, things are cool." --piranha
--
http://mail.python.org/mailman/listinfo/python-list


Re: Getting Python to run Python Scripts in cygwin

2008-06-19 Thread Cédric Lucantis
Le Thursday 19 June 2008 18:14:03 Calvin Cheng, vous avez écrit :
> Hi guys,
>
> This may be a cygwin issue but I was hoping to get some answers here
> as well if someone has fixed this problem before.
>
> Basically, I am able to run "python .py" python files in
> command prompt.  Unfortunately, I can't seem to get it to work in
> cygwin.  I always get an error that says:
> python: can't open file '.py': [Errno 2] No such file or
> directory

I don't think this is a python problem. Unlike dos, unix (and cygwin) dont 
look for executables in the current dir by default. Do you correctly 
type './yourscript.py' rather than 'yourcript.py' ?
If it doesn't help it might be an end-line problem : python doesn't care about 
them, but the shebang line is parsed by cygwin and should match the end-line 
style you've chosen at cygwin installation time. (See 
http://en.wikipedia.org/wiki/Newline#Common_problems)

-- 
Cédric Lucantis
--
http://mail.python.org/mailman/listinfo/python-list


Re: py2exe & application add-ons

2008-06-19 Thread Matthew Woodcraft
Alex Gusarov <[EMAIL PROTECTED]> wrote:
> Hello, I've met a problem - I want my program working without Python
> installation but I have some add-on mechanism (add-ons represented by
> separate .py files, and application auto-recognize such files on
> start).

> So, if I will using py2exe for main program and separate .py files for
> add-ons, will I need Python installation on client machine?
> Maybe other ways exist for such tasks?

py2exe's output includes a complete Python interpreter, so it should
work just fine.

If you want to load the .py files using 'import' you might have to
fiddle a bit, but if you just open the files and use 'exec' it should
be very easy indeed.

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


Re: python/ruby question..

2008-06-19 Thread Aahz
In article <[EMAIL PROTECTED]>,
Matt Nordhoff  <[EMAIL PROTECTED]> wrote:
>
>You're supposed to use the subprocess module.

Really?  Sez who?

$ python
Python 2.3.4 (#1, Feb  2 2005, 12:11:53) 
[GCC 3.4.2 20041017 (Red Hat 3.4.2-6.fc3)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import subprocess
Traceback (most recent call last):
  File "", line 1, in ?
ImportError: No module named subprocess
-- 
Aahz ([EMAIL PROTECTED])   <*> http://www.pythoncraft.com/

"as long as we like the same operating system, things are cool." --piranha
--
http://mail.python.org/mailman/listinfo/python-list


Re: Getting Python to run Python Scripts in cygwin

2008-06-19 Thread kretik
You do have Python installed in Cygwin, right? It's an optional 
component, IIRC?


If it is then it should have set the symlink in /usr/bin to wherever 
it's installed.


Calvin Cheng wrote:

Hi guys,

This may be a cygwin issue but I was hoping to get some answers here
as well if someone has fixed this problem before.

Basically, I am able to run "python .py" python files in
command prompt.  Unfortunately, I can't seem to get it to work in
cygwin.  I always get an error that says:
python: can't open file '.py': [Errno 2] No such file or directory

I have looked at my environment variables and it seems to be correct.

Would be grateful if someone who has gotten python to work correctly
on cygwin could point me in the right direction.

It is very cumbersome switching back-and-forth between command prompt
and cygwin just to run python scripts.

Thank you in advance,
Calvin

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


Re: py2exe & application add-ons

2008-06-19 Thread Mike Driscoll
On Jun 19, 6:00 am, "Alex Gusarov" <[EMAIL PROTECTED]> wrote:
> Hello, I've met a problem - I want my program working without Python
> installation but I have some add-on mechanism (add-ons represented by
> separate .py files, and application auto-recognize such files on
> start).
>
> So, if I will using py2exe for main program and separate .py files for
> add-ons, will I need Python installation on client machine?
> Maybe other ways exist for such tasks?
>
> --
> Thx, Alex Gusarov

I know some of the people here swear by the "freeze" modules. As I
understand it, you can use them to just distribute your pyc files.
This makes updates very small, or so I've heard. I haven't tried it
yet.

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


Re: Simple wxPython SetLabel question

2008-06-19 Thread Mike Driscoll
On Jun 19, 5:25 am, dp_pearce <[EMAIL PROTECTED]> wrote:
> Thank you very much Cédric. I thought it would be something very
> straight forward.

Just an FYI. There's also a wxPython specific mailing list that I
highly recommend. You can learn a lot just reading other people issues
and how they get them fixed.

Here's the link: http://wxpython.org/maillist.php

---
Mike Driscoll

Blog:   http://blog.pythonlibrary.org
Python Extension Building Network: http://www.pythonlibrary.org
--
http://mail.python.org/mailman/listinfo/python-list


Re: Getting Python to run Python Scripts in cygwin

2008-06-19 Thread Jason Tishler
Calvin,

On Fri, Jun 20, 2008 at 12:14:03AM +0800, Calvin Cheng wrote:
> This may be a cygwin issue but I was hoping to get some answers here
> as well if someone has fixed this problem before.
> 
> Basically, I am able to run "python .py" python files in
> command prompt.  Unfortunately, I can't seem to get it to work in
> cygwin.  I always get an error that says:
> python: can't open file '.py': [Errno 2] No such file or directory

Are you executing python in the same directory in Cygwin as you are in
the command prompt?  If not, then python will not be able to find
".py" unless you specify a (relative or absolute) path to
it.

Jason

-- 
PGP/GPG Key: http://www.tishler.net/jason/pubkey.asc or key servers
Fingerprint: 7A73 1405 7F2B E669 C19D  8784 1AFD E4CC ECF4 8EF6
--
http://mail.python.org/mailman/listinfo/python-list


Re: python/ruby question..

2008-06-19 Thread Giampaolo Rodola'
On 19 Giu, 18:49, [EMAIL PROTECTED] (Aahz) wrote:
> In article <[EMAIL PROTECTED]>,
> Matt Nordhoff  <[EMAIL PROTECTED]> wrote:
>
>
>
> >You're supposed to use the subprocess module.
>
> Really?  Sez who?
>
> $ python
> Python 2.3.4 (#1, Feb  2 2005, 12:11:53)
> [GCC 3.4.2 20041017 (Red Hat 3.4.2-6.fc3)] on linux2
> Type "help", "copyright", "credits" or "license" for more information.>>> 
> import subprocess
>
> Traceback (most recent call last):
>   File "", line 1, in ?
> ImportError: No module named subprocess
> --
> Aahz ([EMAIL PROTECTED])           <*>        http://www.pythoncraft.com/
>
> "as long as we like the same operating system, things are cool." --piranha

That's because you're using a too old python version.


--- Giampaolo
http://code.google.com/p/pyftpdlib/
--
http://mail.python.org/mailman/listinfo/python-list


Checking for network connectivity

2008-06-19 Thread felciano
Hi --

Is there a clean pythonic way to check for network connectivity? I
have a script that needs to run periodically on a laptop to create a
local cache of some network files. I would like it to fail gracefully
when disconnected, as well as issue a warning if it hasn't been able
to connect for X minutes / hours.

I currently just use try / except to catch the network errors when the
first call times out, but the timeout takes a while, and this doesn't
feel like the right design because technically this isn't an exception
-- it is expected behavior. Is there a better way to do this (and
still be reasonably portable)?

Thanks,

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


Re: python/ruby question..

2008-06-19 Thread Mike Driscoll
On Jun 19, 11:49 am, [EMAIL PROTECTED] (Aahz) wrote:
> In article <[EMAIL PROTECTED]>,
> Matt Nordhoff  <[EMAIL PROTECTED]> wrote:
>
>
>
> >You're supposed to use the subprocess module.
>
> Really?  Sez who?
>
> $ python
> Python 2.3.4 (#1, Feb  2 2005, 12:11:53)
> [GCC 3.4.2 20041017 (Red Hat 3.4.2-6.fc3)] on linux2
> Type "help", "copyright", "credits" or "license" for more information.>>> 
> import subprocess
>
> Traceback (most recent call last):
>   File "", line 1, in ?
> ImportError: No module named subprocess
> --
> Aahz ([EMAIL PROTECTED])           <*>        http://www.pythoncraft.com/
>
> "as long as we like the same operating system, things are cool." --piranha

The subprocess module supercedes os.popen*, os.system, commands and a
few others in Python 2.4+. Thus, those others are deprecated. See the
docs here:

http://docs.python.org/lib/module-subprocess.html

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


Python Package Construction

2008-06-19 Thread Tim Cook
Hi All,

I would like feedback on the proper/best 'Pythonic' approach.

This is a rather subjective question. Where is the trade-off between
package name lengths and faithfulness to the specifications?

[Discussion follows]

I am implementing a set of specifications for healthcare IT for Python
programmers to be able to develop interoperable healthcare applications.
I am using ZCA (aka.Zope3) extensively.  

My desire is to implement the specs as faithfully as possible for two
reasons:
1) teachability -  how easy/difficult is it to teach the framework and
specifications to new developers?
2) maintainability - which approach, if either, will make it easier to
maintain the framework if/when the specifications change?

My first pass was to develop a skeleton of the specs using Interfaces
from the ZCA approach and then the implementations following the
document structure of the specs.  

The specs are available via SVN at:
http://www.openehr.org/svn/specification/TRUNK/publishing/architecture/ 

It is best to probably use real examples. Following the document
structure for packaging AND using the ZCA convention of having a
sub-directory for interfaces caused massive circular import issues due
to some classes being used in the interface definition of classes inside
the same interface file being imported into the implementation file.  If
that sounds confusing; it is.  It was confusing to write too. :-)  If
anyone has questions I'll try to expand.

It is best to probably use specific, real examples.
http://www.openehr.org/svn/specification/TRUNK/publishing/architecture/rm/data_types_im.pdf

(note class names are converted from the upper case, underscore
separated style to CamelCase)

The package openehr.rm.datatypes.text defines the implementation class
CodePhrase.  The associated interface file
openehr.rm.datatypes.interfaces.text needed CodePhrase as an attribute
type in  DvCodedText and TermMapping needs both CodePhrase and
DvCodedText.  This quickly got out of control.

So my solution to solving the circular imports is to take each interface
and implementation and put them into one file. Research tells me that
this is probably the second mostly popular ZCA approach.  So,
ICodePhrase and CodePhrase are now in
openehr/rm/datatypes/codephrase.py, DvCodeText and IDvCodedText in
openehr/rm/datatypes/dvcodedtext.py, etc.  

But wait, now I don't have a 'text package'.  So if codephrase.py and
dvcodedtext.py were in openehr/rm/datatypes/text/ that would solve the
problem.  BUT! Throughout the specs many of the names are VERY long
already.  Adding another package name that is from 4 - 15 (or more)
characters long adds to the length of already long import statements,
i.e.

(sorry for the email line wraps)

from openehr.am.archetype.creferenceobject import
ICReferenceObject,CReferenceObject

should really be

from openehr.am.archetype.constraintmodel.creferenceobject import
ICReferenceObject,CReferenceObject

Thoughts, opinions and jeers all gratefully accepted.  :-)

--Tim



 


 


-- 
Timothy Cook, MSc
Health Informatics Research & Development Services
LinkedIn Profile:http://www.linkedin.com/in/timothywaynecook 
Skype ID == timothy.cook 
**
*You may get my Public GPG key from  popular keyservers or   *
*from this link http://timothywayne.cook.googlepages.com/home*
**


signature.asc
Description: This is a digitally signed message part
--
http://mail.python.org/mailman/listinfo/python-list

Re: Checking for network connectivity

2008-06-19 Thread Jefferson Kirkland
>From the socket module, you could use the s.connect(address) function.   It
returns a 0 on success or the value of errno on failure.

Regards,

Jeff

On Thu, Jun 19, 2008 at 2:36 PM, felciano <[EMAIL PROTECTED]> wrote:

> Hi --
>
> Is there a clean pythonic way to check for network connectivity? I
> have a script that needs to run periodically on a laptop to create a
> local cache of some network files. I would like it to fail gracefully
> when disconnected, as well as issue a warning if it hasn't been able
> to connect for X minutes / hours.
>
> I currently just use try / except to catch the network errors when the
> first call times out, but the timeout takes a while, and this doesn't
> feel like the right design because technically this isn't an exception
> -- it is expected behavior. Is there a better way to do this (and
> still be reasonably portable)?
>
> Thanks,
>
> Ramon
> --
> http://mail.python.org/mailman/listinfo/python-list
>
--
http://mail.python.org/mailman/listinfo/python-list

Re: Python-3.0b1 build fails on Linux : _gestalt

2008-06-19 Thread Martin v. Löwis
> Failed to find the necessary bits to build these modules:
> _gestalt
> 
> Looking at setup.py it seems that module '_gestalt'
> is only needed on Darwin but my build on Linux fails
> nevertheless.

Why do you think the build fails (i.e. what specific
error message makes you believe it failed)?

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


Re: regex \b behaviour in python

2008-06-19 Thread André Malo
* Walter Cruz wrote:

> irb(main):001:0>"walter ' cruz".split(/\b/)
> => ["walter", " ' ", "cruz"]
> 
> and in php:
> 
> Array
> (
> [0] =>
> [1] => walter
> [2] =>  '
> [3] => cruz
> [4] =>
> )
> 
> 
> But in python the behaviour of \b is differente from ruby or php.

My python here does the same, actually:

$ cat foo.py
import re

x = "walter ' cruz"
s = 0
r = []
for m in re.finditer(r'\b', x):
p = m.start()
if s != p:
r.append(x[s:p])
s = p

print r

$ python2.4 foo.py
['walter', " ' ", 'cruz']
$ python2.5 foo.py
['walter', " ' ", 'cruz']
$

nd
-- 
$_=q?tvc!uif)%*|#Bopuifs!A`#~tvc!Xibu)%*|qsjou#Kvtu!A`#~tvc!KBQI!)*|~
tvc!ifmm)%*|#Qfsm!A`#~tvc!jt)%*|(Ibdlfs(~  # What the hell is JAPH? ;
@_=split/\s\s+#/;$_=(join''=>map{chr(ord(  # André Malo ;
$_)-1)}split//=>$_[0]).$_[1];s s.*s$_see;  #  http://pub.perlig.de/ ;
--
http://mail.python.org/mailman/listinfo/python-list

[xlwt] Changing Cell Background Color

2008-06-19 Thread Chanman
I've posted this on the python-excel group, but perhaps people here
know what to do.

How does one change the cell background color using the xlwt module?
I've looked at several tutorials but none show how to change the
background color.  I've tried the following:

badBG = xlwt.Pattern()
badBG.SOLID_PATTERN = 0x34
badBG.NO_PATTERN = 0x34
badBG.pattern_fore_colour = 0x34
badBG.pattern_back_colour = 0x34

badFontStyle = xlwt.XFStyle()
badFontStyle.Pattern = badBG

sheet1.write(1,1,'hello world', badFontStyle)

However, the background cell color still remains white.  Any help
appreciated.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Extending Python with C: Cannot find MPI library

2008-06-19 Thread Jeroen Ruigrok van der Werven
-On [20080619 17:11], Spectrum ([EMAIL PROTECTED]) wrote:
>  ImportError: dynamic module does not define init function

Might be it's looking, but not finding, something like crti.S or the likes,
the C runtime files that specify stuff like _init and _fini.

-- 
Jeroen Ruigrok van der Werven  / asmodai
イェルーン ラウフロック ヴァン デル ウェルヴェン
http://www.in-nomine.org/ | http://www.rangaku.org/ | GPG: 2EAC625B
If you understand, things are as they are; if not, things are as they are...
--
http://mail.python.org/mailman/listinfo/python-list

Re: Installing Python 3.0 no probs running 2.5 at the same time?

2008-06-19 Thread Martin v. Löwis
> Can I install 3.0 without breaking 2.5? Meaning does it overwrite some
> bindings or something or it just installs 3.0 in a different folder as
> a completely separate program?

You can install both simultaneously, however, by default, .py will get
associated with the last installation. If you don't want this,
deselect "Register Extension".

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


Re: Extending Python with C: Cannot find MPI library

2008-06-19 Thread André Malo
* Jeroen Ruigrok van der Werven wrote:

> -On [20080619 17:11], Spectrum ([EMAIL PROTECTED]) wrote:
>>  ImportError: dynamic module does not define init function
> 
> Might be it's looking, but not finding, something like crti.S or the
> likes, the C runtime files that specify stuff like _init and _fini.

Nah. It's just looking for the init function required by the python module
loader. See: http://docs.python.org/ext/methodTable.html

nd
-- 
die (eval q-qq:Just Another Perl Hacker
:-)

# André Malo, <http://www.perlig.de/> #
--
http://mail.python.org/mailman/listinfo/python-list

Simple Class/Variable passing question

2008-06-19 Thread monkeyboy
Hello,

I'm new to python, and PythonCard. In the code below, I'm trying to
create a member variable (self.currValue) of the class, then just pass
it to a simple function (MainOutputRoutine) to increment it. I thought
Python "passed by reference" all variables, but the member variable
doesn't seem to be incremented. If I make the function just increment
the member variable directly, without passing it in, it works fine?

In the code below, "self.currValue" stays at 5, and value evaluates to
1? Any insight would be appreciated...


class TestModel(model.Background):

def on_initialize(self,event):
self.currValue = 5

def on_startBtn_mouseClick(self, event):
self.MainOutputRoutine(self.currValue)
self.OutputRoutine(self.currValue)

def OutputRoutine(self,value):
self.components.txtBox1.text = str(value)

def MainOutputRoutine(self,value):
value = value + 1
--
http://mail.python.org/mailman/listinfo/python-list


Re: python/ruby question..

2008-06-19 Thread Mensanator
On Jun 19, 5:14 am, Matt Nordhoff <[EMAIL PROTECTED]> wrote:
> Mensanator wrote:

> You're supposed to use the subprocess module.

Yeah, I know, but I couldn't get it to work the last
time I tried it.

>
> In this case, something like:
>
> import subprocess
> factor_program = ['factor!', '-d200']
>
> ...
>
> p = subprocess.Popen(factor_program + [n], stdout=subprocess.PIPE)
> p.wait() # wait for it to finish; not sure how necessary it is
> the_output = p.stdout.readlines()

Just like how this doesn't work either:

Traceback (most recent call last):
  File "C:\Program Files\PyGTK\Python\user\factor_timing.py", line 26,
in 
p = subprocess.Popen(factor_program + [the_comp[1]],
stdout=subprocess.PIPE)
  File "C:\Program Files\PyGTK\Python\lib\subprocess.py", line 586, in
__init__
errread, errwrite) = self._get_handles(stdin, stdout, stderr)
  File "C:\Program Files\PyGTK\Python\lib\subprocess.py", line 681, in
_get_handles
p2cread = self._make_inheritable(p2cread)
  File "C:\Program Files\PyGTK\Python\lib\subprocess.py", line 722, in
_make_inheritable
DUPLICATE_SAME_ACCESS)
TypeError: an integer is required

>
> See subprocess's documentation [1], which includes guides on replacing
> os.popen* and other functions with it.

I have seen it - it's utterly incomprehensible.

What do you suppose you did wrong?

The complete program (with the deprecated code commented out -
which works, BTW):


#import os
import time
import subprocess

#factor_program = 'factor! -d200 '
factor_program = ['factor!','-d200']

the_composites =
[['COMPOSITE_FACTOR','50818429800343305993022114330311033271249313957919046352679206262204589342623811236647989889145173098650749']]

the_primes = []
the_intractables = []

phase = 1
the_times = []
while the_composites:
  print "="*40
  print 'Phase',phase
  the_comp = the_composites.pop(0)
  print the_comp
  print
  the_times.append(time.time())  # time how long it takes to run
factor!.exe

  #the_output = os.popen(factor_program+the_comp[1]).readlines()
  #  change to subprocess
  p = subprocess.Popen(factor_program + [the_comp[1]],
stdout=subprocess.PIPE)
  p.wait()
  the_output = p.stdout.readlines()

  the_times.append(time.time())
  new_factors = [i.split() for i in the_output]
  for i in new_factors: print i
  print
  if len(new_factors) == 1:
if new_factors[0][0] == 'PRIME_FACTOR':
  the_primes.append([new_factors[0][0],long(new_factors[0][1])])
else:
  the_intractables.append([new_factors[0][0],long(new_factors[0]
[1])])
new_factors.pop()
  while new_factors:
j = new_factors.pop(0)
if j[0] == 'PRIME_FACTOR':
  the_primes.append([j[0],long(j[1])])
else:
  the_composites.append(j)
  print the_times[phase] - the_times[phase-1],'seconds'
  phase += 1

print "="*40
print
print 'Factoring complete'
print

the_primes.sort()
the_intractables.sort()
the_primes.extend(the_intractables)

for i in the_primes:
  print i[0],i[1]
print
print "="*40





When working, it produces:


##  
##  Phase 1
##  ['COMPOSITE_FACTOR',
'50818429800343305993022114330311033271249313957919046352679206262204589342623811236647989889145173098650749']
##
##  ['PRIME_FACTOR', '37']
##  ['PRIME_FACTOR', '43']
##  ['PRIME_FACTOR', '167']
##  ['COMPOSITE_FACTOR', '507787751']
##  ['PRIME_FACTOR', '69847']
##  ['PRIME_FACTOR', '30697']
##  ['PRIME_FACTOR', '89017']
##  ['PRIME_FACTOR', '3478697']
##  ['PRIME_FACTOR', '434593']
##  ['PRIME_FACTOR', '49998841']
##  ['PRIME_FACTOR', '161610704597143']
##  ['PRIME_FACTOR', '14064370273']
##  ['COMPOSITE_FACTOR', '963039394703598565337297']
##  ['PRIME_FACTOR', '11927295803']
##
##  0.86133514 seconds
##  
##  Phase 2
##  ['COMPOSITE_FACTOR', '507787751']
##
##  ['PRIME_FACTOR', '29819']
##  ['PRIME_FACTOR', '17029']
##
##  0.078686646 seconds
##  
##  Phase 3
##  ['COMPOSITE_FACTOR', '963039394703598565337297']
##
##  ['PRIME_FACTOR', '518069464441']
##  ['PRIME_FACTOR', '1858900129817']
##
##  0.046313354 seconds
##  
##
##  Factoring complete
##
##  PRIME_FACTOR 37
##  PRIME_FACTOR 43
##  PRIME_FACTOR 167
##  PRIME_FACTOR 17029
##  PRIME_FACTOR 29819
##  PRIME_FACTOR 30697
##  PRIME_FACTOR 69847
##  PRIME_FACTOR 89017
##  PRIME_FACTOR 434593
##  PRIME_FACTOR 3478697
##  PRIME_FACTOR 49998841
##  PRIME_FACTOR 11927295803
##  PRIME_FACTOR 14064370273
##  PRIME_FACTOR 518069464441
##  PRIME_FACTOR 1858900129817
##  PRIME_FACTOR 161610704597143
##
##  



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


Noob: finding my way around the docs...

2008-06-19 Thread kj



I'm a Python noob, and haven't yet figured out my way around the
Python documentation.

For example, suppose I learn about some great module foo.bar.baz,
and when I run the python interpreter and type "import foo.bar.baz",
lo and behold, it is already installed on our system, which means
that (knowing that our system is pretty bare-bones as far as python
goes) most likely foo.bar.baz is part of the standard python
installation.

So, if I were an experienced Pythonista, how would I go about
finding the documentation for foo.bar.baz?

This situation happened most recently to me, if we replace foo.bar.baz
with xml.dom.ext.  It was indeed installed on our system, but I
could find no mention of it in docs.python.org.

Somehow I have the feeling that there's some major stash of
documentation that I haven't learned about yet...

FWIW, I'm a Perlhead, and I'm very used (maybe too used) to the
fact that if the Perl module Foo::Bar::Baz is installed on our
system, all I need to do to read its full-blown documentation in
all its glory is to type "perldoc Foo::Bar::Baz" at the command
line.  Is there anything like this in Python?

TIA!

kj
-- 
NOTE: In my address everything before the first period is backwards;
and the last period, and everything after it, should be discarded.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Noob: finding my way around the docs...

2008-06-19 Thread Benjamin Kaplan
On Thu, Jun 19, 2008 at 5:06 PM, kj <[EMAIL PROTECTED]> wrote:

>
>
>
> I'm a Python noob, and haven't yet figured out my way around the
> Python documentation.
>
> For example, suppose I learn about some great module foo.bar.baz,
> and when I run the python interpreter and type "import foo.bar.baz",
> lo and behold, it is already installed on our system, which means
> that (knowing that our system is pretty bare-bones as far as python
> goes) most likely foo.bar.baz is part of the standard python
> installation.
>
> So, if I were an experienced Pythonista, how would I go about
> finding the documentation for foo.bar.baz?
>
> This situation happened most recently to me, if we replace foo.bar.baz
> with xml.dom.ext.  It was indeed installed on our system, but I
> could find no mention of it in docs.python.org.
>
> Somehow I have the feeling that there's some major stash of
> documentation that I haven't learned about yet...
>
> FWIW, I'm a Perlhead, and I'm very used (maybe too used) to the
> fact that if the Perl module Foo::Bar::Baz is installed on our
> system, all I need to do to read its full-blown documentation in
> all its glory is to type "perldoc Foo::Bar::Baz" at the command
> line.  Is there anything like this in Python?
>
> TIA!
>
> kj
> --
> NOTE: In my address everything before the first period is backwards;
> and the last period, and everything after it, should be discarded.
> --
> http://mail.python.org/mailman/listinfo/python-list
>

To get the docs, just open up the shell and type:

>>> import module
>>> help(module)
--
http://mail.python.org/mailman/listinfo/python-list

Docutils rst2html.py gives Unknown Directive type "toctree"

2008-06-19 Thread Calvin Cheng
Hi,

I am attempting to convert a bunch of .txt files into html using the
docutils package.

It works for most of the txt files except for the index.txt file which
gives 2 errors:
(1)  Unknown Directive type "toctree"
(2) (ERROR/3) Unknown interpreted text role "ref".

Any idea how I can fix this?

Would be glad if someone who is familiar with docutils could point me
in the right direction.

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


Why no output from xml.dom.ext.PrettyPrint?

2008-06-19 Thread kj



OK, the following should work but doesn't, and I can't figure out
why:

>>> from xml.marshal.generic import dumps
>>> dumps( ( 1, 2.0, 'foo', [3,4,5] ) )
'12.0foo345'
>>> from xml.dom.ext import PrettyPrint
>>> PrettyPrint( dumps( ( 1, 2.0, 'foo', [3,4,5] ) ) )
>>> import sys
>>> PrettyPrint( dumps( ( 1, 2.0, 'foo', [3,4,5] ) ), sys.stdout )
>>> 

Why am I seeing no output from PrettyPrint?

TIA!

kynn

-- 
NOTE: In my address everything before the first period is backwards;
and the last period, and everything after it, should be discarded.
--
http://mail.python.org/mailman/listinfo/python-list


AW: [Zope3-Users] Python Package Construction

2008-06-19 Thread Roger Ineichen
Hi Tim

> Betreff: [Zope3-Users] Python Package Construction
> 
> Hi All,
> 
> I would like feedback on the proper/best 'Pythonic' approach.
> 
> This is a rather subjective question. Where is the trade-off 
> between package name lengths and faithfulness to the specifications?
> 
> [Discussion follows]
> 
> I am implementing a set of specifications for healthcare IT 
> for Python programmers to be able to develop interoperable 
> healthcare applications.
> I am using ZCA (aka.Zope3) extensively.  
> 
> My desire is to implement the specs as faithfully as possible for two
> reasons:
> 1) teachability -  how easy/difficult is it to teach the 
> framework and specifications to new developers?
> 2) maintainability - which approach, if either, will make it 
> easier to maintain the framework if/when the specifications change?
> 
> My first pass was to develop a skeleton of the specs using 
> Interfaces from the ZCA approach and then the implementations 
> following the document structure of the specs.  
> 
> The specs are available via SVN at:
> http://www.openehr.org/svn/specification/TRUNK/publishing/arch
> itecture/ 
> 
> It is best to probably use real examples. Following the 
> document structure for packaging AND using the ZCA convention 
> of having a sub-directory for interfaces caused massive 
> circular import issues due to some classes being used in the 
> interface definition of classes inside the same interface 
> file being imported into the implementation file.  If that 
> sounds confusing; it is.  It was confusing to write too. :-)  
> If anyone has questions I'll try to expand.
> 
> It is best to probably use specific, real examples.
> http://www.openehr.org/svn/specification/TRUNK/publishing/arch
> itecture/rm/data_types_im.pdf
> 
> (note class names are converted from the upper case, 
> underscore separated style to CamelCase)
> 
> The package openehr.rm.datatypes.text defines the 
> implementation class CodePhrase.  The associated interface 
> file openehr.rm.datatypes.interfaces.text needed CodePhrase 
> as an attribute type in  DvCodedText and TermMapping needs 
> both CodePhrase and DvCodedText.  This quickly got out of control.
> 
> So my solution to solving the circular imports is to take 
> each interface and implementation and put them into one file. 
> Research tells me that this is probably the second mostly 
> popular ZCA approach.  So, ICodePhrase and CodePhrase are now 
> in openehr/rm/datatypes/codephrase.py, DvCodeText and 
> IDvCodedText in openehr/rm/datatypes/dvcodedtext.py, etc.  
> 
> But wait, now I don't have a 'text package'.  So if 
> codephrase.py and dvcodedtext.py were in 
> openehr/rm/datatypes/text/ that would solve the problem.  
> BUT! Throughout the specs many of the names are VERY long 
> already.  Adding another package name that is from 4 - 15 (or 
> more) characters long adds to the length of already long 
> import statements, i.e.
> 
> (sorry for the email line wraps)
> 
> from openehr.am.archetype.creferenceobject import 
> ICReferenceObject,CReferenceObject
> 
> should really be
> 
> from openehr.am.archetype.constraintmodel.creferenceobject 
> import ICReferenceObject,CReferenceObject
> 
> Thoughts, opinions and jeers all gratefully accepted.  :-)

For a usecase like this, I personaly recommend to 
defina all interfaces in one module which probably
is a namespace if you need alot of interfaces to define.

e.g.

openehr.interfaces.foobar.IFooBar

the reason why:

- spearate interface from implementation. That's an 
  important aspect in a component architecture. If you
  define your implementation and interfaces in one file,
  then you don't need a component architecture.

- interfaces are separated in a well know place.

This means if you define a module and you like to import 
an interface you can import just one line:

from openehr import interfaces

Which makes it very simple.


Regards
Roger Ineichen

> --Tim
> 
> 
> 
>  
> 
> 
>  
> 
> 
> --
> Timothy Cook, MSc
> Health Informatics Research & Development Services LinkedIn 
> Profile:http://www.linkedin.com/in/timothywaynecook
> Skype ID == timothy.cook
> **
> *You may get my Public GPG key from  popular keyservers or   *
> *from this link http://timothywayne.cook.googlepages.com/home*
> **
> 

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


Re: [Python-Dev] C API for gc.enable() and gc.disable()

2008-06-19 Thread Pau Freixes
Sorry for my ignorance, gc it's garbage collector ?

On Thu, Jun 19, 2008 at 11:23 PM, Alexandre Vassalotti <
[EMAIL PROTECTED]> wrote:

> On Sun, Jun 1, 2008 at 12:28 AM, Adam Olsen <[EMAIL PROTECTED]> wrote:
> > On Sat, May 31, 2008 at 10:11 PM, Alexandre Vassalotti
> > <[EMAIL PROTECTED]> wrote:
> >> Would anyone mind if I did add a public C API for gc.disable() and
> >> gc.enable()? I would like to use it as an optimization for the pickle
> >> module (I found out that I get a good 2x speedup just by disabling the
> >> GC while loading large pickles). Of course, I could simply import the
> >> gc module and call the functions there, but that seems overkill to me.
> >> I included the patch below for review.
> >
> > I'd rather see it fixed.  It behaves quadratically if you load enough
> > to trigger full collection a few times.
> >
>
> Do you have any idea how this behavior could be fixed? I am not a GC
> expert, but I could try to fix this.
>
> -- Alexandre
> ___
> Python-Dev mailing list
> [EMAIL PROTECTED]
> http://mail.python.org/mailman/listinfo/python-dev
> Unsubscribe:
> http://mail.python.org/mailman/options/python-dev/pfreixes%40gmail.com
>



-- 
Pau Freixes
Linux GNU/User
--
http://mail.python.org/mailman/listinfo/python-list

Re: Extending Python with C: Cannot find MPI library

2008-06-19 Thread John Machin
On Jun 20, 5:56 am, Jeroen Ruigrok van der Werven <[EMAIL PROTECTED]
nomine.org> wrote:
> -On [20080619 17:11], Spectrum ([EMAIL PROTECTED]) wrote:
>
> >  ImportError: dynamic module does not define init function
>
> Might be it's looking, but not finding, something like crti.S or the likes,
> the C runtime files that specify stuff like _init and _fini.
>

No, it means what it says. The OP seems to have stumbled past all the
hurdles imposed by using the mpicc compiler and by his C code calling
other code. Now he needs to put in the glue code so that his
blahblah.so acts like a Python module that defines a python function.
 He (inter alia) needs to read http://docs.python.org/ext/ext.html --
starting at the beginning, not at the section that addresses the init
function.

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


Re: Multiprecision arithmetic library question.

2008-06-19 Thread casevh
> No, I do not know that. Define desperate.
> Does Python support the extended Euclidean algorithm
> and other number theory functions?

No.

> How fast does Python multiply?

Python uses the Karatsuba algorithm which O(n^1.585). Division is
still O(n^2).

> Not that the latter is particularly important,
> as C is built for speed.
>
> I've been fooling around. Ran dir(gmpy), and
> it does not show the full complement of GMP
> library functions, such as the various division
> functions. e.g. mpz_tdiv_qr.

gmpy implements the Python numeric model using GMP and exposes some of
the high-level functions. Are you looking for low-level wrapper that
exposes all the GMP library functions?

> --
> Michael Press

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


Re: python script for tortoise cvs

2008-06-19 Thread Gabriel Genellina
En Thu, 19 Jun 2008 10:26:09 -0300, Simon Brunning <[EMAIL PROTECTED]> escribió:

> On Thu, Jun 19, 2008 at 2:14 PM, sandeep <[EMAIL PROTECTED]> wrote:
>> hi
>>
>> we are using tortoise cvs and putty. i want to write a python script
>> to whom i can provide a tag and module.now what this script will do is
>> look for this specific tag and checks for whether its a individual tag
>> or its inside a branch.if its inside a branch then find out what is
>> the branch tag and then check out that branch for me else it checks
>> out that module with that tag.
>>
>> Actually the thing is i am not able to find the way how i will do it
>> and for where i have to look for the info.so any help will be
>> appreciated.
>
> I don't know if Tortoise is scriptable, but Subversion certainly is -
>  - and nothing you mention is Tortoise
> specific.

(Note that he said Tortoise CVS - not Tortoise SVN)
To Sandeep: You should divide the question in two parts:
- how to obtain the info you want from cvs. This has nothing to do with Python; 
better ask in a CVS group related to your server. Suppose the answer is "use 
the status command with the -lv options", then you'll be able to obtain the 
info you want "by hand", executing said cvs command from the cmd prompt.
- the next task is to automate the execution using Python. You have to run the 
command, capture its output and extract the info you want. How to do that *is* 
a Python question, but you'll have to formulate it very precisely: "I want to 
read the output coming from this command, locate the line that contains the 
word XXX starting at column 12, and take the last word on the third line below 
it"
For that second part you can get some help here, but first you have to know 
*what* to execute and *what* to look for in the output.

(Anyway, I think the question is not well formulated - what is an "individual 
tag", as opposed to "inside a branch"? Every tag applied on a file marks a 
certain revision in a certain branch, - if you consider the trunk as a branch 
too. Do you want to know if the tag was applied directly over a file on the 
trunk? Or do you want to know if the tag is a "branch tag"?)


-- 
Gabriel Genellina

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


Re: Noob: finding my way around the docs...

2008-06-19 Thread Matimus
On Jun 19, 2:06 pm, kj <[EMAIL PROTECTED]> wrote:
> I'm a Python noob, and haven't yet figured out my way around the
> Python documentation.
>
> For example, suppose I learn about some great module foo.bar.baz,
> and when I run the python interpreter and type "import foo.bar.baz",
> lo and behold, it is already installed on our system, which means
> that (knowing that our system is pretty bare-bones as far as python
> goes) most likely foo.bar.baz is part of the standard python
> installation.
>
> So, if I were an experienced Pythonista, how would I go about
> finding the documentation for foo.bar.baz?
>
> This situation happened most recently to me, if we replace foo.bar.baz
> with xml.dom.ext.  It was indeed installed on our system, but I
> could find no mention of it in docs.python.org.
>
> Somehow I have the feeling that there's some major stash of
> documentation that I haven't learned about yet...
>
> FWIW, I'm a Perlhead, and I'm very used (maybe too used) to the
> fact that if the Perl module Foo::Bar::Baz is installed on our
> system, all I need to do to read its full-blown documentation in
> all its glory is to type "perldoc Foo::Bar::Baz" at the command
> line.  Is there anything like this in Python?
>
> TIA!
>
> kj
> --
> NOTE: In my address everything before the first period is backwards;
> and the last period, and everything after it, should be discarded.

If you are in the interpreter and you type: help(foo.bar.baz) you get
the embeded documentation.

I usually go straight to the `global module index` 
http://docs.python.org/modindex.html

I don't seem to have a module named "xml.dom.ext", so I don't think it
is standard.

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


Google-like "Did you mean... ?" search algorithm

2008-06-19 Thread miller . paul . w
This is a wee bit OT, but I am looking for algorithms to implement
search suggestions, similar to Google's "Did you mean... ?" feature.
Can anyone point me to web pages, journal articles, implementations
(preferably in Python!), or any other resources in this area?

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


  1   2   >