Re: s.split() on multiple separators

2007-10-04 Thread Lawrence D'Oliveiro
In message <[EMAIL PROTECTED]>, Antoon Pardon wrote:

> On 2007-10-01, Gabriel Genellina <[EMAIL PROTECTED]> wrote:
>
>> En Sun, 30 Sep 2007 16:16:30 -0300, <[EMAIL PROTECTED]> escribi?:
>>
 From my POV, if I want sequence from here to there, it should include
>>> both here and there.
>>>
>>> I do understand the consequences of making high bound exclusive, which
>>> is more elegant code: xrange(len(c)). But it does seem a bit
>>> illogical...
>>
>> See this note from E.W.Dijkstra in 1982 where he says that the Python
>> convention is the best choice.
>> http://www.cs.utexas.edu/users/EWD/transcriptions/EWD08xx/EWD831.html
> 
> It may be convincing if you only consider natural numbers in ascending
> order. Suppose you have the sequence a .. b and you want the reverse.
> If you work with included bounds the reverse is just b .. a. If you use
> the python convention, things become more complicated.

Nothing complicated about it:

>>> a = 1
>>> b = 5
>>> range(a, b)
[1, 2, 3, 4]
>>> range(b - 1, a - 1, -1)
[4, 3, 2, 1]

> Another problem is if you are working with floats. Suppose you have a
> set of floats. Now you want the subset of numbers that are between a and
> b included. If you want to follow the convention that means you have to
> find the smallest float that is bigger than b, not a trivial task.

Due to precision limitations, the set will probably not be what you think it
is, anyway.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Algebraic Modules For Python

2007-10-04 Thread Lawrence D'Oliveiro
In message <[EMAIL PROTECTED]>, Shawn
Milochik wrote:

> On 10/1/07, Brandon McGinty <[EMAIL PROTECTED]> wrote:
>>
> 
>> Brandon McGinty
>> McGinty Soft Ltd.
>> Website design, configuration, and maintenance
>> Python and PHP coder
> 
> So let me get this straight:
> 
> You label yourself as a coder for hire in Python, but you don't have
> time to search the Internet for an answer to your own Python question?

Yeah, but he's also a PHP coder, and that's probably worth a 20 IQ point
penalty right there. :)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: slice last 4 items from a list

2007-10-04 Thread Lawrence D'Oliveiro
In message <[EMAIL PROTECTED]>, John
Machin wrote:

> On Oct 2, 6:27 am, brad <[EMAIL PROTECTED]> wrote:
>> Is this the correct way to slice the last 4 items from a list?
>>
>> x = [1,2,3,4,5,6,7,8,9]
>> print x[-4:]
>>
>> It works, but is it Pythonic?
> 
> It's Pythonic. It's also unambiguous, unlike your specification, which
> could be interpreted as 'chop off the last 4 items from a list' ...

No, the OP is using "slice" in the technically correct CS sense.
-- 
http://mail.python.org/mailman/listinfo/python-list


Web service client using https

2007-10-04 Thread welcomestocontact
Hi All,

   I am trying to connect .NET web service using HTTPS. I wrote a
python script using https. For that need to send SOAP message to the
server. But it is giving error 401.3 execution access is denied.(SOAP
message not processing)
   I have a doubt can we access web services using HTTPS
only, or need to have any other.
  I am sending the code::
 [CODE]
import httplib
a=open('/root/Desktop/b.xml','r')

#SOAP message
Message=a.read()
h =httplib.HTTPS('hpc.msftlabs.com')
h.putrequest('PUT','/HPCBasicProfile/HPCBasicProfile.svc')
h.putheader('Accept','text/soap')
h.putheader('Content-type','text/jsl; charset="utf-8"')
h.putheader('Content-length','%s' % str(len(Message)))
h.putheader('SOAPAction','http://schemas.ggf.org/bes/2006/08/
besfactory/BESFactoryPortType/CreateActivity')
.endheaders()

h.send(Message)

errcode,errmsg, headers = h.getreply()
print errcode,errmsg, headers
f = h.getfile() # Get file object for reading data
data = f.read()
print data
f.close()
[/CODE]

Please guid me to access web service.

Thanks
Allavarapu

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


Re: Real time plot

2007-10-04 Thread Hendrik van Rooyen
 Jean-Francois Canac  wrote:

>I am reading a large amount of data from a COM port (or from a file) at a rate
of 20 records per second. It is about >positioning of a vehicle on a race track.
>In each record we have time, position (lat and long) speed, course all from GPS
equipment. I would like to Produce a >graph in real time with these records to
see the  vehicle moving on the track. The goal is to study the vehicle
>performance and to always have its position, the application would run around
24 hours.
 >
>I would like to write the application in Python and I am wondering which plot
interface would be the more appropriate, I >have seen matplotlib, but I do not
know how to make real time applications with big amount of data. Is hippodraw
more >suited to this use or an other interface?
>Many thanks

I would draw dots on a suitably sized Tkinter canvas, after drawing a schematic
of the race track (laborious).

20 per second will be no problem, provided the machine is half decent.

What is the speed at which the com port runs?

- Hendrik

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


Re: Web service client using https

2007-10-04 Thread Lawrence D'Oliveiro
In message <[EMAIL PROTECTED]>, 
[EMAIL PROTECTED] wrote:

>I am trying to connect .NET web service using HTTPS. I wrote a
> python script using https. For that need to send SOAP message to the
> server. But it is giving error 401.3 execution access is denied.(SOAP
> message not processing)

Does it work over non-secure HTTP, just for comparison? (I know, don't do it
for production use, only for testing.)

Are you able to compare your code with some other working code? You could
try concatenating the complete request into a text file and sending that
with wget, to see if it works.

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


Re: module confusion

2007-10-04 Thread Hendrik van Rooyen
"Steve Holden"  wrote:

> religious issues for me. It's more like "This problem has a cross head, 
> so I'll need a Philips screwdriver". 

As long as it is not a Pozidrive, that is a commendable attitude.

- Hendrik

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


Re: A question about subprocess

2007-10-04 Thread Lawrence D'Oliveiro
In message <[EMAIL PROTECTED]>, JD wrote:

> I want send my jobs over a whole bunch of machines (using ssh). The
> jobs will need to be run in the following pattern:
> 
> (Machine A)   (Machine B)  (Machine C)
> 
> Job A1 Job B1Job C1
> 
>  Job A2   Job B2etc
> 
>  Job A3  etc
> 
>  etc
> 
> Jobs runing on machine A, B, C should be in parallel, however, for
> each machine, jobs should run one after another.
> 
> How can I do it with the subprocess?

You could do it with SSH. A command like

ssh machine_a run_job_a1.py

will not terminate until the execution of run_job_a1.py on the remote
machine has terminated. So you end up with a lot of "proxy" subprocesses,
if you like, on the master machine, each one waiting for a remote process
on some master machine to terminate. As the controlling process notices the
termination of each proxy process, it looks to see which slave machine that
maps to, and sends another command to start the next job on that machine.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Convert on uppercase unaccentent unicode character

2007-10-04 Thread Lawrence D'Oliveiro
In message <[EMAIL PROTECTED]>, Duncan Booth wrote:

> Steve Holden <[EMAIL PROTECTED]> wrote:
> 
>>> No, that will uppercase the string, but it doesn't (and shouldn't)
>>> strip the accents:
>>> 
>> I can agree that is doesn't (though I am taking your word for it), but
>> a French person will definitely feel it's doing the wrong thing. Upper
>> case letters aren't accented in written French.
>> 
> I didn't know that, and I'm not sure I believe it: but then the French
> tend to have conventions honoured more in the breach than the observance.

Second most diabolical spelling system in the world ... after English.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: The Modernization of Emacs: terminology buffer and keybinding

2007-10-04 Thread Lawrence D'Oliveiro
In message <[EMAIL PROTECTED]>, Bent C Dalager wrote:

> Unfortunately, these days English almost always means American English...

North American or South American? Seems like USAmericans speak a little
different English from other Americans...
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: python autoconf macro for building ming extension

2007-10-04 Thread Lawrence D'Oliveiro
In message <[EMAIL PROTECTED]>, Daniel
Nogradi wrote:

> It might be slightly off topic here but couldn't find a more suitable
> place for this question:
> 
> I'm trying to build the python binding for ming -- http://ming.sf.net
> -- but for some reason the python macro for autoconf -- python.m4 --
> doesn't seem to detect my python installation correctly. The strange
> thing is that it seemingly detects everything correctly, but a final
> check still fails. I have the python 2.5 source distribution installed
> to /usr/local the standard location.
> 
> Configuring ming fails with:
> 
> checking for python... /usr/local/bin/python
> checking for python2.5... (cached) /usr/local/bin/python
> checking for a version of Python >= '2.1.0'... yes
> checking for the distutils Python package... yes
> checking for Python include path... -I/usr/local/include/python2.5
> checking for Python library path... -L/usr/local/lib/python2.5 -lpython2.5
> checking for Python site-packages path...
> /usr/local/lib/python2.5/site-packages checking python extra libraries...
> -lpthread -ldl -lutil checking python extra linking flags... -Xlinker
> -export-dynamic
> checking consistency of all components of python development
> environment... no

It's saying the components are not consistent. Perhaps the includes are not
consistent with the libraries or the Python executable. Have you managed to
build Python bindings for anything else?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: A question about subprocess

2007-10-04 Thread Lawrence D'Oliveiro
In message <[EMAIL PROTECTED]>, Lawrence D'Oliveiro wrote:

> ... each one waiting for a remote process
> on some master machine to terminate.

Of course, "master" there should be "slave". :)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: The Modernization of Emacs: terminology buffer and keybinding

2007-10-04 Thread Lawrence D'Oliveiro
In message <[EMAIL PROTECTED]>, George Neuner
wrote:

> The Christian Bible says "In the beginning was the Word..."

Which is an English mistranslation from the Greek "logos".
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Convert on uppercase unaccentent unicode character

2007-10-04 Thread JBJ
Steve Holden wrote:

> Duncan Booth wrote:
>> [EMAIL PROTECTED] wrote:
>> 
>>> On Oct 4, 7:35 am, JBJ >> [EMAIL PROTECTED]> wrote:
 Hi,
 I'am very newbie in Python.
 For the moment I'am trying to convert an unicode character to his
 uppercase unaccented character.
 By example with locale fr_FR:
 a,A,à,À should return A
 o,O,ô,Ô should return O
 ?,? should return ?
 i,I,î,Î should return I

 Have you some suggestions ?

 Thank.
>>> Unicode strings have an upper() method - try that.  I'm think it
>>> should work properly with your locale - it doesn't give the expected
>>> result for me with an english locale.
>>>
>> No, that will uppercase the string, but it doesn't (and shouldn't) strip
>> the accents:
>> 
> I can agree that is doesn't (though I am taking your word for it), but a
> French person will definitely feel it's doing the wrong thing. Upper
> case letters aren't accented in written French.
> 
> regards
>   Steve
http://www.academie-francaise.fr/langue/questions.html#accentuation
Regards
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: migrating to packages

2007-10-04 Thread Bruno Desthuilliers
Hrvoje Niksic a écrit :
> [EMAIL PROTECTED] writes:
> 
>> I will expose my case quicly.
>> The MYCLASES.py file contains the A class, so i can use
>> from MYCLASES import A
>> a = ()
>>
>> Using the "package mode" (wich looks fine BTW), having the simple
>> MYCLASES/
>>  __init__.py
>>  A.py
>>
>> forces my (i guess) to use the
>> from MYCLASES.A import A
> 
> Exactly.  Using mypackage.mymodule instead of just mymodule is the
> entire *point* of a package.

Nope. The "entire point" of packages is to let you organize your code 
and namespace. And it's quite common to use the __init__.py of the 
package (as explained by Ben) as a facade to the internal organization 
of the package, so you can change this internal organization without 
breaking client code.

>  That way, if someone creates another
> module with using the same name (mymodule), it won't conflict with
> yours.  If you don't want to change mymodule to mypackage.mymodule,
> why use a package in the first place?

Because you have too much code to keep it in a single file.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Convert on uppercase unaccentent unicode character

2007-10-04 Thread JBJ
John Machin wrote:

> On Oct 4, 4:35 am, JBJ  [EMAIL PROTECTED]> wrote:
>> Hi,
>> I'am very newbie in Python.
>> For the moment I'am trying to convert an unicode character to his
>> uppercase unaccented character.
>> By example with locale fr_FR:
>> a,A,à,À should return A
>> o,O,ô,Ô should return O
>> ?,? should return ?
>> i,I,î,Î should return I
>>
>> Have you some suggestions ?
>>
>> Thank.
> 
> Google in this newsgroup for a thread started by "bussiere" on or
> about 2006-03-25. The code snippet provided by Fredrik Lundh should
> help you.
Thanks
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: migrating to packages

2007-10-04 Thread Hrvoje Niksic
Bruno Desthuilliers <[EMAIL PROTECTED]> writes:

> it's quite common to use the __init__.py of the package (as
> explained by Ben) as a facade to the internal organization of the
> package, so you can change this internal organization without
> breaking client code.

We agree on that.  It is the OP who *wants* to access his modules
directly without ever naming the package.  That is why I think he is
missing the point of having a package in the first place.

>> That way, if someone creates another module with using the same
>> name (mymodule), it won't conflict with yours.  If you don't want
>> to change mymodule to mypackage.mymodule, why use a package in the
>> first place?
>
> Because you have too much code to keep it in a single file.

There is no "single file", the OP already has modules A and B.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: racism kontrol

2007-10-04 Thread Hendrik van Rooyen

 "Wildemar Wildenburger"  wrote:

> (By the way: Accusing a German of racism is almost too easy an insult. 
> Not that I had taken any, just saying.)

I always thought that it would be insulting to a German if you accused
him or her of not being a racist...

- Hendrik

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


Re: List of objects X Database

2007-10-04 Thread M.-A. Lemburg
MindMaster32 wrote:
> I am writing a script that has to read data from an ASCII file of
> about 50 Mb and do a lot of searches and calculations with that data.
> That would be a classic problem solved by the use of a database
> (SQLite would suit just fine), but that would require the user to
> install more packages other than python itself, and that I am trying
> to avoid.
>
> Since the data is not too large, I wonder if there is another way to
> store all data in memory and work with it more or less like a
> database, doing searches and working with datafields.
> 
> This is not clear to me how can be implemented. I thought of creating
> a class with the data structure, and creating a list of objects of
> that class, each one containing one line of data from the "database".
> 
> Any thoughts or suggestions?

Python 2.5 ships with SQLite and also supports in-memory
storage of the data.

-- 
Marc-Andre Lemburg
eGenix.com

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


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


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


Re: module confusion

2007-10-04 Thread Hendrik van Rooyen
"Lawrence D'Oliveiro" <[EMAIL PROTECTED]> wote:

> Honestly, why do people react to the word "pointer" as though computers have
> to wear underwear to conceal something shameful going on in their nether
> regions?

I think it is because a pointer is a variable containing as a value the address
of something.

So its a low level concept - useful to low-lifes like C and assembler
programmers, and as
such, capable of causing extreme mayhem in your nicely structured, high level
life.

So it boils down to fear - also known as: "once bitten, twice shy"

:-)- Hendrik


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


Re: A question about subprocess

2007-10-04 Thread Lawrence D'Oliveiro
In message <[EMAIL PROTECTED]>, Carl Banks wrote:

> On Wed, 03 Oct 2007 16:46:20 +, JD wrote:
>> 
>> I want send my jobs over a whole bunch of machines (using ssh). The jobs
>> will need to be run in the following pattern:
>> 
>> (Machine A)   (Machine B)  (Machine C)
>> 
>> Job A1 Job B1Job C1
>> 
>>  Job A2   Job B2etc
>> 
>>  Job A3  etc
>> 
>>  etc
>> 
>> Jobs runing on machine A, B, C should be in parallel, however, for each
>> machine, jobs should run one after another.
>> 
>> How can I do it with the subprocess?
> 
> 
> It's not too hard if the remote jobs exit gracefully, so that ssh knows
> when the remote job is done.

It's hard to see how an _ungraceful_ exit could stop SSH from knowing when
the remote job is done.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: module confusion

2007-10-04 Thread Steven D'Aprano
On Thu, 04 Oct 2007 11:11:03 +1300, Lawrence D'Oliveiro wrote:

> In Python, all names _are_ variables. They are not "bound" to objects.

The general convention among Python programmers is to describe names 
being bound to values. While the analogy to real life binding of objects, 
it's close enough to be useful.


> The value of os.path is a pointer. It's implemented as a pointer, it has
> all the semantics of a pointer.

Ah, I see you are a devotee of Humpty Dumpty:

"When I use a word," Humpty Dumpty said, in rather 
a scornful tone, "it means just what I choose it to 
mean-neither more nor less." 

"The question is," said Alice, "whether you can 
make words mean so many different things." 

"The question is," said Humpty Dumpty, "which is to 
be master -- that's all."


The rest of the world understands pointers to be in the sense of pointers 
in C, Pascal and similar: a low level construct that is to all extents 
and purposes a memory location whose content is itself a memory location.

Oh sure, I suppose there are a few pedants who insist that "pointer" just 
means "something which points to something else". There may even be a 
language or two whose users regularly use the term "pointer" to mean 
something other than the common usage, and may never have been exposed to 
the common usage.

And thus, satisfied in their own mind that *technically* they're right, 
or at least not provably wrong, the pedants insist on calling Python 
names "pointers" regardless of the confusion it confuses to the majority 
of programmers and despite the violence they have to do to the human 
language for it to work.

Of course, we can *easily* find out what the type of os.path is. Python 
allows us to interrogate any object and find out its type:

>>> import os
>>> type(os.path)


It's a module, not a pointer. End of story.


> Honestly, why do people react to the word "pointer" as though computers
> have to wear underwear to conceal something shameful going on in their
> nether regions?

The real question is why people insist on hammering the square peg of C 
terminology into the round holes of Python's object model.



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


Re: A question about subprocess

2007-10-04 Thread Carl Banks
On Oct 4, 4:55 am, Lawrence D'Oliveiro <[EMAIL PROTECTED]
central.gen.new_zealand> wrote:
> In message <[EMAIL PROTECTED]>, Carl Banks wrote:
>
>
>
> > On Wed, 03 Oct 2007 16:46:20 +, JD wrote:
>
> >> I want send my jobs over a whole bunch of machines (using ssh). The jobs
> >> will need to be run in the following pattern:
>
> >> (Machine A)   (Machine B)  (Machine C)
>
> >> Job A1 Job B1Job C1
>
> >>  Job A2   Job B2etc
>
> >>  Job A3  etc
>
> >>  etc
>
> >> Jobs runing on machine A, B, C should be in parallel, however, for each
> >> machine, jobs should run one after another.
>
> >> How can I do it with the subprocess?
>
> > It's not too hard if the remote jobs exit gracefully, so that ssh knows
> > when the remote job is done.
>
> It's hard to see how an _ungraceful_ exit could stop SSH from knowing when
> the remote job is done.

Clean exit might have been a better word.  Various things can cause
ssh to exit before the job is done; other things can make the process
hang around after the job is finished.  The OP needs to make sure the
job, and ssh, exit reliably enough for the given use before depending
on it.  Otherwise, resorting to things like lockfiles and timeouts may
be necessary to keep things sequential.


Carl Banks

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


Re: Using fractions instead of floats

2007-10-04 Thread Steven D'Aprano
On Mon, 01 Oct 2007 09:09:21 -0700, Arnaud Delobelle wrote:

> As pointed out by others, implementations of rationals in Python abound.
> Whereas there is a canonical representation of floats and ints (and even
> longints) in the machine, it is not the case for rationals. Moreover
> most programming tasks do not need rationals, so why burden the language
> with them? If one needs them, there are perfectly adequate modules to
> import (even though I, like many others I suspect, have my own
> implementation in pure Python).  Finally, arithmetic would become very
> confusing if there were three distinct numeric types; it already causes
> enough confusion with two!

Or, to put it another way:


As pointed out by others, implementations of sets in Python abound. 
Whereas there is a canonical representation of floats and ints in the 
machine, it is not the case for sets. Moreover most programming tasks do 
not need sets, so why burden the language with them? If one needs them, 
there are perfectly adequate modules to import (even though I, like many 
others I suspect, have my own implementation in pure Python).  Finally, 
programming would become very confusing if there were three distinct 
sequence types; it already causes enough confusion with two!



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


Re: Using fractions instead of floats

2007-10-04 Thread Paul Rubin
Steven D'Aprano <[EMAIL PROTECTED]> writes:
> > implementation in pure Python).  Finally, arithmetic would become very
> > confusing if there were three distinct numeric types; it already causes
> > enough confusion with two!

There's already ints, longs, floats, complexes, and decimals.  What's
the problem with one more?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: The Modernization of Emacs: terminology buffer and keybinding

2007-10-04 Thread Tim X
George Neuner  writes:

> On Wed, 3 Oct 2007 09:36:40 + (UTC), [EMAIL PROTECTED] (Bent C
> Dalager) wrote:
>
>>In article <[EMAIL PROTECTED]>, David Kastrup  <[EMAIL PROTECTED]> wrote:
>>>[EMAIL PROTECTED] (Bent C Dalager) writes:
>>>
 In article <[EMAIL PROTECTED]>,
 Frank Goenninger  <[EMAIL PROTECTED]> wrote:
>
>Well, I didn't start the discussion. So you should ask the OP about the 
>why. I jumped in when I came across the so often mentioned "hey, it's 
>all well defined" statement was brought in. I simply said that if that 
>"well-definedness" is against "common understanding" then I don't give 
>a damn about that clever definitions. Because I have to know that there 
>are such definitions - always also knowing that free is not really 
>free.

 "Liberated" is a valid meaning of the word "free".
>>>
>>>No.  It is a valid meaning of the word "freed".
>>
>>Only if you're being exceedingly pedantic and probably not even
>>then. Webster 1913 lists, among other meanings,
>>
>>Free
>>(...)
>>"Liberated, by arriving at a certain age, from the control
>>of parents, guardian, or master."
>>
>>The point presumably being that having been "liberated", you are now
>>"free".
>
> I don't think knowing the meaning of a word is being pedantic.
> "Freed" is derived from "free" but has a different, though associated,
> meaning.  Words have meaning despite the many attempts by Generation X
> to assert otherwise.  Symbolism over substance has become the mantra
> of the young.
>
> The English language has degenerated significantly in the last 30
> years.  People (marketers in particular) routinely coin ridiculous new
> words and hope they will catch on.  I remember seeing a documentary
> (circa 1990?) about changes in the English language.  One part of the
> program was about the BBC news and one of its editors, whom the staff
> called the "protector of language", who checked the pronunciation of
> words by the news anchors.  The thing that struck me about this story
> was the number of BBC newspeople who publicly admitted that they could
> hardly wait for this man to retire so they could write and speak the
> way they wanted rather than having to be "correct".
>
> Dictionaries used to be the arbiters of the language - any word or
> meaning of a word not found in the dictionary was considered a
> colloquial (slang) use.  Since the 1980's, an entry in the dictionary
> has become little more than evidence of popularity as the major
> dictionaries (OED, Webster, Cambridge, etc.) will now consider any
> word they can find used in print.
>

Language is not a static 'set in stone' thing. It changes and while some
may find the changes unwelcome, it will change anyway. Although I have no
evidence to support it, I suspect that 'free' wold have been more commonly
associated with meanings other than 'free of cost' pre-capitalism. Checking
a few dictionaries seems to indicate that its meaning along the lines of
free from restriction, control, freedom, liberated etc is more in keeping
with its origins than an interpretation of free of cost and that even in
that context, it meant free from the restriction of having to be paid for.

The bottom line is that free has different meanings and if a group decides
to use that term and at the same time specify which context it means it to
apply, then I think that is reasonable. Ask your wife what she thinks is
meant by a free variable and she may say that it is a variable that has no
cost (as in free beer), This doesn't mean that its use is wrong or
incorrect.

I once asked RMS why he chose free, given the ambiguity it would cause,
over alternatives, such as freedom, liberated or even unrestricted. His
response was that at the time, free as in freedom was the concious
association they had and other associations and resulting ambiguity did not
occur to them until it was too late. This seems reasonable enough. If your
focus was to ensure that software was free from what you perceived to be
restrictions that would ultimately reduce your individual freedom, then
free fits. The fact this has led to confusion amongst consumers in a
capitalist based economy probably says as much about modern values and the
changing balance between consumerism compared to freedom than anything
else. 

Tim

"The Americans are identical to the British in all respects except, of
course, language."  Oscar Wilde

Giving English to an American is like giving sex to a child.  He knows it's
important but he doesn't know what to do with it. Adam Cooper (19th
century)

"We (the British and Americans) are two countries separated by a common
language.  G.B. Shaw

The Englishman commented to the American about the "curious"
way in which he pronounced so many words, such as schedule
(pronounced shedule). The American thought about it for a few
moments, then replied, "Perhaps it's because we went to
different shools!"

Englishman: Its maths not math because it is short for mathematics

Re: module confusion

2007-10-04 Thread Lawrence D'Oliveiro
In message <[EMAIL PROTECTED]>, Steven D'Aprano wrote:

> ... pedants ...

When people use that word against me, it's generally a sign they're trying
not to admit I'm right.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: The Modernization of Emacs: terminology buffer and keybinding

2007-10-04 Thread Steve Holden
Lawrence D'Oliveiro wrote:
> In message <[EMAIL PROTECTED]>, Bent C Dalager wrote:
> 
>> Unfortunately, these days English almost always means American English...
> 
> North American or South American? Seems like USAmericans speak a little
> different English from other Americans...

Leave him be in his sea of ignorance. He's American ...

regards
  Steve
-- 
Steve Holden+1 571 484 6266   +1 800 494 3119
Holden Web LLC/Ltd   http://www.holdenweb.com
Skype: holdenweb  http://del.icio.us/steve.holden

Sorry, the dog ate my .sigline so I couldn't cat it

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


Re: module confusion

2007-10-04 Thread Steve Holden
Hendrik van Rooyen wrote:
> "Steve Holden"  wrote:
> 
>> religious issues for me. It's more like "This problem has a cross head, 
>> so I'll need a Philips screwdriver". 
> 
> As long as it is not a Pozidrive, that is a commendable attitude.
> 
I said cross head, not Pozidriv (tm). But then I have been nown to use a 
Manchester screwdriver[1] on occasion.

regards
  Steve

[1]: http://www.urbandictionary.com/define.php?term=manchester+screwdriver
-- 
Steve Holden+1 571 484 6266   +1 800 494 3119
Holden Web LLC/Ltd   http://www.holdenweb.com
Skype: holdenweb  http://del.icio.us/steve.holden

Sorry, the dog ate my .sigline so I couldn't cat it

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


Re: Convert on uppercase unaccentent unicode character

2007-10-04 Thread Steve Holden
JBJ wrote:
> Steve Holden wrote:
> 
>> Duncan Booth wrote:
>>> [EMAIL PROTECTED] wrote:
>>>
 On Oct 4, 7:35 am, JBJ >>> [EMAIL PROTECTED]> wrote:
> Hi,
> I'am very newbie in Python.
> For the moment I'am trying to convert an unicode character to his
> uppercase unaccented character.
> By example with locale fr_FR:
> a,A,à,À should return A
> o,O,ô,Ô should return O
> ?,? should return ?
> i,I,î,Î should return I
>
> Have you some suggestions ?
>
> Thank.
 Unicode strings have an upper() method - try that.  I'm think it
 should work properly with your locale - it doesn't give the expected
 result for me with an english locale.

>>> No, that will uppercase the string, but it doesn't (and shouldn't) strip
>>> the accents:
>>>
>> I can agree that is doesn't (though I am taking your word for it), but a
>> French person will definitely feel it's doing the wrong thing. Upper
>> case letters aren't accented in written French.
>>
>> regards
>>   Steve
> http://www.academie-francaise.fr/langue/questions.html#accentuation

Malheureusement, I see that absence of accented capitals is a modern 
phenomenon that is regarded as an impediment to the language mostly 
stemming from laziness of individual authors and inadequacy of low-end 
typesetting software. I hadn't realised I was so up-to-date ;-)

So I will have to stop propagating this misinformation.

regards
  Steve
-- 
Steve Holden+1 571 484 6266   +1 800 494 3119
Holden Web LLC/Ltd   http://www.holdenweb.com
Skype: holdenweb  http://del.icio.us/steve.holden

Sorry, the dog ate my .sigline so I couldn't cat it

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


Re: The Modernization of Emacs: terminology buffer and keybinding

2007-10-04 Thread Steve Holden
Lawrence D'Oliveiro wrote:
> In message <[EMAIL PROTECTED]>, George Neuner
> wrote:
> 
>> The Christian Bible says "In the beginning was the Word..."
> 
> Which is an English mistranslation from the Greek "logos".

So, now you're telling me that the Garden of Eden was actually a 
*marketing campaign*?

regards
  Steve
-- 
Steve Holden+1 571 484 6266   +1 800 494 3119
Holden Web LLC/Ltd   http://www.holdenweb.com
Skype: holdenweb  http://del.icio.us/steve.holden

Sorry, the dog ate my .sigline so I couldn't cat it

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


Re: module confusion

2007-10-04 Thread Steve Holden
Lawrence D'Oliveiro wrote:
> In message <[EMAIL PROTECTED]>, Steven D'Aprano wrote:
> 
>> ... pedants ...
> 
> When people use that word against me, it's generally a sign they're trying
> not to admit I'm right.

If it were less important to be right and more important to be 
considerate this thread could end without a further contribution from 
you ...

regards
  Steve
-- 
Steve Holden+1 571 484 6266   +1 800 494 3119
Holden Web LLC/Ltd   http://www.holdenweb.com
Skype: holdenweb  http://del.icio.us/steve.holden

Sorry, the dog ate my .sigline so I couldn't cat it

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


Re: module confusion

2007-10-04 Thread Bruno Desthuilliers
Lawrence D'Oliveiro a écrit :
> In message <[EMAIL PROTECTED]>, Carsten
> Haese wrote:
> 
>> On Thu, 2007-10-04 at 11:11 +1300, Lawrence D'Oliveiro wrote:
>>
>>> In Python, all names _are_ variables. They are not "bound" to objects.
>>> The value of os.path is a pointer.
>> No. "os.path" refers to the object that's known as the "path" attribute
>> of the object known as "os". That object, in turn, is a module.
> 
> No, it's a variable. It just happens to contain a pointer to a module.

Lawrence, you should have a look at CPython's source code. And at other 
implementations too. Python's "variables" *really* are name/object pairs 
- most of the time key/value pairs in a dict. The name itself is just 
that : a name. It doesn't "contains" anything, it's *not* a label for a 
memory address, it's *only* a name.

>>>  It's implemented as a pointer,
>> While it is true that namespaces are implemented in CPython as
>> collections of pointers to PyObject structures, that's an irrelevant
>> implementation detail. I doubt that they are implemented as pointers in
>> Jython, PyPy, or IronPython.
> 
> I'll bet they are.

Since Java doesn't have pointers, you lost your bet.

>>>  it has all the semantics of a pointer.
>> No, it doesn't. A pointer means the physical address of a memory
>> location, which implies that you can overwrite that memory location. Can
>> you do that in Python?
> 
> Yes. Look up the definition of "mutable objects".

I think Carsten knows this definition. But it has nothing to do with 
"overwriting a memory location" - like you could do in C using pointers.

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


Re: migrating to packages

2007-10-04 Thread Bruno Desthuilliers
Hrvoje Niksic a écrit :
> Bruno Desthuilliers <[EMAIL PROTECTED]> writes:
> 
>> it's quite common to use the __init__.py of the package (as
>> explained by Ben) as a facade to the internal organization of the
>> package, so you can change this internal organization without
>> breaking client code.
> 
> We agree on that.  It is the OP who *wants* to access his modules
> directly without ever naming the package.  

To be exact, he wants to reorganize it's source code (splitting a file 
that's getting too big AFAICT) without impacting client code. And this 
is a common use case for a package - which package is given the same 
name as the to-be-reorganized module, and uses imports in the 
__init__.py to expose the same API as the module did.

> That is why I think he is
> missing the point of having a package in the first place.

MHO opinion is that *you* are missing *one* of the point*s* of having 
packages.

>>> That way, if someone creates another module with using the same
>>> name (mymodule), it won't conflict with yours.  If you don't want
>>> to change mymodule to mypackage.mymodule, why use a package in the
>>> first place?
>> Because you have too much code to keep it in a single file.
> 
> There is no "single file", the OP already has modules A and B.

Let's see:
"""I have a single file with several classes, wich i want to separate"""

"""We have been using this MYCLASES in the from MYCLASES import B syntax"""

So the starting point is a single module. The OP already splitted it 
indeed, and now asks how to *not* change client code's import 
statements, ie how to make the newly created package exposing the same 
API as the single-module did.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: The Modernization of Emacs: terminology buffer and keybinding

2007-10-04 Thread Lawrence D'Oliveiro
In message <[EMAIL PROTECTED]>, Steve
Holden wrote:

> Lawrence D'Oliveiro wrote:
>
>> In message <[EMAIL PROTECTED]>, George Neuner
>> wrote:
>> 
>>> The Christian Bible says "In the beginning was the Word..."
>> 
>> Which is an English mistranslation from the Greek "logos".
> 
> So, now you're telling me that the Garden of Eden was actually a
> *marketing campaign*?

Different Bible book, different author, different original language.
-- 
http://mail.python.org/mailman/listinfo/python-list


Program with wx in Linux and Windows

2007-10-04 Thread marcpp
Hi I've developed a program (WXpython GUI). In Linux the GUI is correct 
(various distributions), but in Windows all appears disordered.
Any recomendations?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: The Modernization of Emacs: terminology buffer and keybinding

2007-10-04 Thread Steve Holden
Lawrence D'Oliveiro wrote:
> In message <[EMAIL PROTECTED]>, Steve
> Holden wrote:
> 
>> Lawrence D'Oliveiro wrote:
>>
>>> In message <[EMAIL PROTECTED]>, George Neuner
>>> wrote:
>>>
 The Christian Bible says "In the beginning was the Word..."
>>> Which is an English mistranslation from the Greek "logos".
>> So, now you're telling me that the Garden of Eden was actually a
>> *marketing campaign*?
> 
> Different Bible book, different author, different original language.

So Genesis was written in Hebrew? I have no clue as to where the 
manuscripts were found.

regards
  Steve
-- 
Steve Holden+1 571 484 6266   +1 800 494 3119
Holden Web LLC/Ltd   http://www.holdenweb.com
Skype: holdenweb  http://del.icio.us/steve.holden

Sorry, the dog ate my .sigline so I couldn't cat it

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


open(.xls file, 'w') so that hyperlinks appear

2007-10-04 Thread Verroen
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: HELP me Am very new one To python

2007-10-04 Thread David
>
> how to configure apache where i want to configure .
> if any files want to copy in to apache folder, wahts the procedure to
> start the coding pls help me am very very beginner pls spend some time
> to teach how to do that.please plaes
>

Unlike PHP, Python is not primarily a web programming language. What
you installed was the standard interpreter which allows you to run
scripts outside of a web server. It won't integrate into apache
automatically.

What you're probably looking for is an apache module that lets you run
python scripts.

This link may be useful: http://sourceforge.net/projects/spyce/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: HELP me Am very new one To python

2007-10-04 Thread Amit Khemka
On 10/4/07, Damodhar <[EMAIL PROTECTED]> wrote:
> hi,
>
> Am working in PHP MYSQL. I am very very interest to learn Python but i
> don't Know Little Bit,
> am using windows Xp, Ialready download from
> http://www.python.org/ftp/python/2.5.1/python-2.5.1.ia64.msi
>
> and install into C:\Python25
>
> whats the next step . i UsedApache 2.0  run as a local server..
>
> whats the next step . please say one by one i already read the
> documentation but i cant get clearer.
>
> how to configure apache where i want to configure .
> if any files want to copy in to apache folder, wahts the procedure to
> start the coding pls help me am very very beginner pls spend some time
> to teach how to do that.please plaes

I presume that you want to do web programming using python.

Have a look at following:

Using mod_python: http://webpython.codepoint.net/mod_python
CGI: http://docs.python.org/lib/module-cgi.html
FastCGI: http://www.fastcgi.com/

You can also explore some of existing web frameworks. Search web for
"python web frameworks", some popular ones are django, pylons etc.

Try to play with one of the above that you like and suits your needs.
If you still get struck , please post specific issues.

I wish and hope learning python would be a pleasing experience !

Cheers,
amit.


-- 

Amit Khemka
website: www.onyomo.com
wap-site: www.owap.in
-- 
http://mail.python.org/mailman/listinfo/python-list


Check it out:Very good online resources, tons of cool men and beautiful women eager for lovers....:

2007-10-04 Thread jack
Check it out:Very good online resources,tons of cool men and beautiful
women eager for lovers:

1.Buy tickets online:
http://groups.google.com/group/all-good-things/web/want-to-buy-tickets-online-come-here

2.No 1 social network:
http://groups.google.com/group/all-good-things/web/1-social-network

3.Very good online resources:
http://groups.google.com/group/all-good-things/web/very-useful-websites

4.cool men and beautiful women eager for lovers
http://groups.google.com/group/all-good-things/web/tons-of-men-and-women-are-looking-lovers

5.Best affiliate programs:
http://www.apsense.com/abc/ymapsense/business.html

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


HELP me Am very new one To python

2007-10-04 Thread Damodhar
hi,

Am working in PHP MYSQL. I am very very interest to learn Python but i
don't Know Little Bit,
am using windows Xp, Ialready download from
http://www.python.org/ftp/python/2.5.1/python-2.5.1.ia64.msi

and install into C:\Python25

whats the next step . i UsedApache 2.0  run as a local server..

whats the next step . please say one by one i already read the
documentation but i cant get clearer.

how to configure apache where i want to configure .
if any files want to copy in to apache folder, wahts the procedure to
start the coding pls help me am very very beginner pls spend some time
to teach how to do that.please plaes

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


Re: The Modernization of Emacs: terminology buffer and keybinding

2007-10-04 Thread Lew
Tim X wrote:
> "The Americans are identical to the British in all respects except, of
> course, language."  Oscar Wilde

> "We (the British and Americans) are two countries separated by a common
> language.  G.B. Shaw


>  There is a well-known saying: Two nations separated by a common language. 
> However, this phrase doesn't seem to have been positively recorded in this 
> form by anyone.
> 
> In The Canterville Ghost Oscar Wilde wrote:
> 
>  /We have really everything in common with America nowadays except, of 
> course, language/
> 
> In a 1951 book of quotations, and without attributing a source, George 
> Bernard Shaw was credited with saying:
> 
>  /England and America are two countries separated by the same language/
> 
> Even Dylan Thomas had his say in a radio talk in the early 50s:
> 
>  /[European writers and scholars in America are] up against the barrier of a 
> common language/
> 
> But where the original phrase came from, nobody knows, and it is probably 
> simply incorrectly quoted.


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


Re: Program with wx in Linux and Windows

2007-10-04 Thread Steve Holden
marcpp wrote:
> Hi I've developed a program (WXpython GUI). In Linux the GUI is correct 
> (various distributions), but in Windows all appears disordered.
> Any recomendations?

A slightly unhelpful one might be "learn to use sizers", as they are the 
key to ordered layouts. Unfortunately the learning materials available 
aren't for everyone (to the extent that I am considering producing some 
more).

But with sizers you can certainly ease cross-platform issues considerably.

If you have an existing interface layout you might want to try just 
dropping all the components into a GridSizer to start with, then add 
more layout sophistication as you get into it.

regards
  Steve
-- 
Steve Holden+1 571 484 6266   +1 800 494 3119
Holden Web LLC/Ltd   http://www.holdenweb.com
Skype: holdenweb  http://del.icio.us/steve.holden

Sorry, the dog ate my .sigline so I couldn't cat it

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


Re: migrating to packages

2007-10-04 Thread Hrvoje Niksic
Bruno Desthuilliers <[EMAIL PROTECTED]> writes:

>> We agree on that.  It is the OP who *wants* to access his modules
>> directly without ever naming the package.
>
> To be exact, he wants to reorganize it's source code (splitting a
> file that's getting too big AFAICT)

You're right, I misread his original problem statement (as you also
correctly pointed out later in the post).  So yes, a package will do
what he wants, simply by arranging the necessary imports in
__init__.py.  Sorry about the misunderstanding.

>> That is why I think he is missing the point of having a package in
>> the first place.
>
> MHO opinion is that *you* are missing *one* of the point*s* of having
> packages.

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


Re: Looking for volunteer to help debug SpamBayes problem

2007-10-04 Thread Larry Bates
[EMAIL PROTECTED] wrote:
> We've had some reports of a UnicodeDecodeError in SpamBayes by people using
> its IMAP filter.  I'm unable to reproduce it with other SpamBayes
> applications I use and don't have a suitable IMAP setup in which to test it.
> This problem is holding up the 1.1 release of SpamBayes.  If you always
> wanted to give SpamBayes a try and have access to IMAP, this could be the
> chance you've been waiting for.  Just reply to me ([EMAIL PROTECTED]) and I'll
> help you get set up.
> 
> Thanks,
> 
Skip,

I've been using SpamBayes with Outlook/IMAP for about 6 months without any
problems.  One "issue" is that it doesn't seem to filter my mail when I first 
start up each morning.  I have to manually run the filtering process.  I've 
never seen UnicodeDecodeError.  I'd be happy to test something for you.

FYI, Larry
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: module confusion

2007-10-04 Thread Neil Cerutti
On 2007-10-03, Lawrence D'Oliveiro <[EMAIL PROTECTED]> wrote:
> In message <[EMAIL PROTECTED]>, Ben Finney wrote:
>
>> Lawrence D'Oliveiro <[EMAIL PROTECTED]> writes:
>> 
>>> On my Gentoo system:
>>> 
>>> >>> import os
>>> >>> os.path
>>> 
>>> 
>>> It's just a variable that happens to point to the posixpath module.
>> 
>> There's no "pointing" going on. It's another name bound to the
>> same object, of equal status to the 'posixpath' name.
>> 
>> Python doesn't have pointers, and even "variable" is a
>> misleading term in Python. Best to stick to "name" and "bound
>> to".
>
> In Python, all names _are_ variables. They are not "bound" to
> objects. The value of os.path is a pointer. It's implemented as
> a pointer, it has all the semantics of a pointer.

No. A pointer is also an iterator.

void duplicate(char *d, const char *s)
{
  while (*d++ = *s++)
;
}

What does that look like implemented with Python names?

def duplicate(d, s):
  raise AbstractionViolationError("Python identifiers aren't pointers.")

Moreover, it seems difficult to promote the concept of a pointers
in a language which doesn't provide a "take the address of an
object" operation.

> Honestly, why do people react to the word "pointer" as though
> computers have to wear underwear to conceal something shameful
> going on in their nether regions?

Refraining from thinking about pointers (unless I have to) saves
wear and tear on the old bean.  I also like to think of 5 as an
integer most of the time.

-- 
Neil Cerutti
Will the last person to leave please see that the perpetual light is
extinguished --sign at New England church
-- 
http://mail.python.org/mailman/listinfo/python-list


Auction/Bidding system for AdWords/AdSense functionality

2007-10-04 Thread bruce
Hi...

Looking for an app that provides bidding/auction functionality, for a system
similar to what Google provides.

Anybody have any expertise with any system like this, or any kind of app
that could be modified to get this kind of functionality.

Thanks



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


Re: The Modernization of Emacs: terminology buffer and keybinding

2007-10-04 Thread Wildemar Wildenburger
Steve Holden wrote:
> Lawrence D'Oliveiro wrote:
>> In message <[EMAIL PROTECTED]>, Steve
>> Holden wrote:
>>
>>> Lawrence D'Oliveiro wrote:
>>>
 In message <[EMAIL PROTECTED]>, George Neuner
 wrote:

> The Christian Bible says "In the beginning was the Word..."
 Which is an English mistranslation from the Greek "logos".
>>> So, now you're telling me that the Garden of Eden was actually a
>>> *marketing campaign*?
>>
>> Different Bible book, different author, different original language.
> 
> So Genesis was written in Hebrew? I have no clue as to where the 
> manuscripts were found.
> 
Am I missing a joke here? What are you talking about?

Different book? From what book would the first sentence in the Bible be, 
if not from the first book (yeah yeah, from the publisher, haw-haw :-|)?

And Genesis and all other of Moe's books where written in Hebrew. No 
doubt about that. Its (part of) the /Hebrew/ Bible, after all. 
http://en.wikipedia.org/wiki/Torah>

I can't program with discussions like this going on ;)
/W
-- 
http://mail.python.org/mailman/listinfo/python-list


What does the syntax [::-1] really mean?

2007-10-04 Thread Casey
I've used [::-1] as a shorthand for reverse on several occasions, but
it occurred to me yesterday I never really thought about why it
works.  First, I checked out the documentation.

>From section 3.6 of the Python Library Reference:

"The slice of s from i to j with step k is defined as the sequence of
items with index x = i + n*k such that 0 <= n < (j-i)/k. In other
words, the indices are i, i+k, i+2*k, i+3*k and so on, stopping when j
is reached (but never including j). If i or j  is greater than len(s),
use len(s). If i or j are omitted or None, they become ``end'' values
(which end depends on the sign of k). Note, k cannot be zero. If k is
None, it is treated like 1."

>From Section 5.3.3 of the Python Language Reference (x[::-1] is a
"proper slice" in the BNF, hence the excerpt):

"The conversion of a proper slice is a slice object (see section 3.2)
whose start, stop and step attributes are the values of the
expressions given as lower bound, upper bound and stride,
respectively, substituting None for missing expressions."

Following the reference to section 3.2 provides a (non-rigorous)
description of what a slice object is, in terms of the extended
slicing semantics.  But it doesn't shed any additional light on the
meaning of [::-1].

>From this, I would expect that x[::-1] would be identical to x[n:0:-1]
(n and 0 being the "end" values, with the order switched due to the
negative step value).  But the clause that "(but never including j)"
means that x[n:0:-1] excludes the 1st element of x, x[0].  A quick
test in ipython confirms that "abc"[3:0:-1] => "cb", not "cba".
Changing the "end" value  to x[n:-1:-1] results in an empty string.

So my question is: "what exactly is [::-1] shorthand for"?  Or is it a
special case, in which case why isn't it  defined as such in the
library?

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


Python "implements " equivalent?

2007-10-04 Thread Wojciech Gryc
Hi,

I recently started using Python and am extremely happy with how
productive it's made me, even as a new user. I'm hoping to continue
using the language for my research, and have come across a bit of a
stumbling block.

I'm a seasoned Java programmer and quite a big fan of interfaces...
i.e. The idea that if I make a number of distinct classes that
implement interface X, I can pass them all as parameters to functions
or whatnot that require an X object.

Is there something similar in Python?

What I'd like to do is create a feature detection system for my work
-- specifically, a general class / interface called "Feature" and then
subclasses that implement functions like isFeaturePresent() in all of
their different and unique ways. I'd love to hear how I can do this in
Python.

Thanks,
Wojciech

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


Re: Python "implements " equivalent?

2007-10-04 Thread Jarek Zgoda
Wojciech Gryc napisał(a):

> I'm a seasoned Java programmer and quite a big fan of interfaces...
> i.e. The idea that if I make a number of distinct classes that
> implement interface X, I can pass them all as parameters to functions
> or whatnot that require an X object.
> 
> Is there something similar in Python?

The closest thing I saw is zope.interface.

> What I'd like to do is create a feature detection system for my work
> -- specifically, a general class / interface called "Feature" and then
> subclasses that implement functions like isFeaturePresent() in all of
> their different and unique ways. I'd love to hear how I can do this in
> Python.

I am sure you wouldn't need interfaces to do such things in Python.
"Duck typing" is how we call this feature. :)

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

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


Need help to find origin of a memory leakage

2007-10-04 Thread David Tremouilles
hello,

 I'm struggling with a memory leakage of my  app for quite some
time. Could somebody help?

I join a demo program in attachment.
The problem is that the memory consumption keeps on increasing while
opening and closing tabs.
In the demo attached a click on "button" will open a new tab. If, for
example, you open ten new tabs, then close ten tabs, and open again
ten tab, and repeat this many times you will see the memory
consumption increases after each 10 close-10 open cycles.
Could somebody help me on finding the origin of this leak?

Note: I already post on pygtk list and did not get any useful help at
this point in time.
I use
Python 2.5.1
GTK: (2, 12, 0)
 pyGTK: (2, 12, 0)
I already observed the same issue with older versions...
It's been a long time I try to solve it...

Thanks in advance,


mem_leak.py
Description: Binary data


fenetre.glade
Description: Binary data


element.glade
Description: Binary data
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: Python "implements " equivalent?

2007-10-04 Thread Carl Banks
On Oct 4, 11:11 am, Wojciech Gryc <[EMAIL PROTECTED]> wrote:
> Hi,
>
> I recently started using Python and am extremely happy with how
> productive it's made me, even as a new user. I'm hoping to continue
> using the language for my research, and have come across a bit of a
> stumbling block.
>
> I'm a seasoned Java programmer and quite a big fan of interfaces...
> i.e. The idea that if I make a number of distinct classes that
> implement interface X, I can pass them all as parameters to functions
> or whatnot that require an X object.
>
> Is there something similar in Python?


Yes: you do it pretty much the same way you'd do it in Java, except
for two differences:
* leave out the "implements Interface" part
* don't actually create an Interface class

And then, voila!, you can write functions that can accept any class
that implements your interface.


> What I'd like to do is create a feature detection system for my work
> -- specifically, a general class / interface called "Feature" and then
> subclasses that implement functions like isFeaturePresent() in all of
> their different and unique ways. I'd love to hear how I can do this in
> Python.

Just define isFeaturePresent() in any class you want.  That's all you
have to do; any class that defines this method can be passed to any
function that invokes it, without having to "implement" or "subclass"
anything.

This is known as "duck typing" in Python lingo.


Carl Banks

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


Re: Python "implements " equivalent?

2007-10-04 Thread Wojciech Gryc
Thank you Carl and thank you Jarek. This makes me feel much better --
on to coding, I shall go. :)

Thanks again,
Wojciech

On Oct 4, 11:27 am, Carl Banks <[EMAIL PROTECTED]> wrote:
> On Oct 4, 11:11 am, Wojciech Gryc <[EMAIL PROTECTED]> wrote:
>
> > Hi,
>
> > I recently started using Python and am extremely happy with how
> > productive it's made me, even as a new user. I'm hoping to continue
> > using the language for my research, and have come across a bit of a
> > stumbling block.
>
> > I'm a seasoned Java programmer and quite a big fan of interfaces...
> > i.e. The idea that if I make a number of distinct classes that
> > implement interface X, I can pass them all as parameters to functions
> > or whatnot that require an X object.
>
> > Is there something similar in Python?
>
> Yes: you do it pretty much the same way you'd do it in Java, except
> for two differences:
> * leave out the "implements Interface" part
> * don't actually create an Interface class
>
> And then, voila!, you can write functions that can accept any class
> that implements your interface.
>
> > What I'd like to do is create a feature detection system for my work
> > -- specifically, a general class / interface called "Feature" and then
> > subclasses that implement functions like isFeaturePresent() in all of
> > their different and unique ways. I'd love to hear how I can do this in
> > Python.
>
> Just define isFeaturePresent() in any class you want.  That's all you
> have to do; any class that defines this method can be passed to any
> function that invokes it, without having to "implement" or "subclass"
> anything.
>
> This is known as "duck typing" in Python lingo.
>
> Carl Banks


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


Re: Combine two dictionary...

2007-10-04 Thread Paul Hankin
On Oct 4, 4:35 pm, Gary Coulbourne <[EMAIL PROTECTED]> wrote:
> >>> dict1={1: 4,  3: 5}... and 2 millions element
> >>> dict2={3: 3,  8: 6}... and 3 millions element
>
> If you don't mind doing some kind of lazy evaluation, you could do
> something like...
>
> --
> dict1={1:4, 3:5}
> dict2={3:3, 8:6}
>
> import UserDict
>
> class Merge(UserDict.DictMixin):
>
>def __init__(self,d1,d2):
>self.dict1 = d1
>self.dict2 = d2
>
>keyset = set(d1.keys())
>keyset.update(d2.keys())
>
>self.dkeys = list(keyset)
>
>def keys(self):
>return self.dkeys
>
>def __getitem__(self,key):
>v1 = 0
>v2 = 0
>if key in self.dict1:
>   v1 = self.dict1[key]
>if key in self.dict2:
>   v2 = self.dict2[key]
>return v1+v2

Generalising to support any number of dicts reduces the amount of code
somewhat:

import UserDict

class Merge(UserDict.DictMixin):
def __init__(self, *args):
self._dicts = args
self._keys = list(set(k for d in self._dicts for k in d))
def keys(self):
return self._keys
def __getitem__(self, key):
return sum(d.get(key, 0) for d in self._dicts)

--
Paul Hankin

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


Re: Convert on uppercase unaccentent unicode character

2007-10-04 Thread Wildemar Wildenburger
Steve Holden wrote:
> Malheureusement, I see that absence of accented capitals is a modern 
> phenomenon that is regarded as an impediment to the language mostly 
> stemming from laziness of individual authors and inadequacy of low-end 
> typesetting software. I hadn't realised I was so up-to-date ;-)
> 
> So I will have to stop propagating this misinformation.
> 

Thats really weird, because I was taught in school that caps are not to 
be accented. In school! Big Brother is an idiot.

I'm equally ammused by the part of JBJ's link where it says that a 
missing acccent "fait hésiter sur la prononciation". Yeah, AS IF written 
French had anything to do with the way it is pronounced. Not that I 
don't like french, mind you. Everywhere outside action movies its pretty 
cool.

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


Re: Combine two dictionary...

2007-10-04 Thread Gary Coulbourne
>>> dict1={1: 4,  3: 5}... and 2 millions element
>>> dict2={3: 3,  8: 6}... and 3 millions element

If you don't mind doing some kind of lazy evaluation, you could do
something like...

--
dict1={1:4, 3:5}
dict2={3:3, 8:6}

import UserDict

class Merge(UserDict.DictMixin):

   def __init__(self,d1,d2):
   self.dict1 = d1
   self.dict2 = d2

   keyset = set(d1.keys())
   keyset.update(d2.keys())

   self.dkeys = list(keyset)


   def keys(self):
   return self.dkeys

   def __getitem__(self,key):
   v1 = 0
   v2 = 0
   if key in self.dict1:
  v1 = self.dict1[key]
   if key in self.dict2:
  v2 = self.dict2[key]
   return v1+v2

m = Merge(dict1,dict2)

print m
--

This basically does a sort of "virtual merge"... only merging when you
actually ask for an element in the list.

-- 

Gary CoulbourneSoftware Developer
   C/C++, Java, Perl, Python
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: racism kontrol

2007-10-04 Thread Wildemar Wildenburger
Hendrik van Rooyen wrote:
>  "Wildemar Wildenburger"  wrote:
> 
>> (By the way: Accusing a German of racism is almost too easy an insult. 
>> Not that I had taken any, just saying.)
> 
> I always thought that it would be insulting to a German if you accused
> him or her of not being a racist...
> 
Very funny, Herr Dutsh-Mann. Dude, hailing from South Africa with a 
Dutch name, I'd be careful with the word racist. That of course being 
based on the fact that in South Africa the term never had relevance and 
thus meaning. Hence I understand that you probably have as much 
understanding of the term "racism", as we have of "a welcome Jew". Or, 
for that matter, a "a Dutchman that is pleasant to listen to". Burn! ;)

Sidenote: Its funny that everybody calls the Dutch "Dutch" (when 
speaking English), which pretty much is the word "deutsch", which, guess 
what, means "German" (cf. Pennsylvania Dutch). That has always baffled 
me --- do Dutch people refer to themselves as "Dutch" when speaking 
dutch? The term for "Dutch" is "Nederlands" or "Hollands", isn't it?

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


pickle and __slots__

2007-10-04 Thread JL
Hello,

I am trying to pickle an object, and I get:

TypeError: a class that defines __slots__ without defining
__getstate__ cannot be pickled

I didn't find __slots__ in the object or the class. Is there a way to
find it, or to to know which object or class causes the problem?

Thanks

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


RegEx question

2007-10-04 Thread Robert Dailey
Hi,

The following regex (Not including the end quotes):

"@param\[in|out\] \w+ "

Should match any of the following:

@param[in] variable
@param[out] state
@param[in] foo
@param[out] bar


Correct? (Note the trailing whitespace in the regex as well as in the
examples)
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: RegEx question

2007-10-04 Thread Robert Dailey
It should also match:

@param[out] state Some description of this variable


On 10/4/07, Robert Dailey <[EMAIL PROTECTED]> wrote:
>
> Hi,
>
> The following regex (Not including the end quotes):
>
> "@param\[in|out\] \w+ "
>
> Should match any of the following:
>
> @param[in] variable
> @param[out] state
> @param[in] foo
> @param[out] bar
>
>
> Correct? (Note the trailing whitespace in the regex as well as in the
> examples)
>
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: The Modernization of Emacs: terminology buffer and keybinding

2007-10-04 Thread J. Clifford Dyer
On Thu, Oct 04, 2007 at 04:49:50PM +0200, Wildemar Wildenburger wrote regarding 
Re: The Modernization of Emacs: terminology buffer and keybinding:
> 
> Steve Holden wrote:
> > Lawrence D'Oliveiro wrote:
> >> In message <[EMAIL PROTECTED]>, Steve
> >> Holden wrote:
> >>
> >>> Lawrence D'Oliveiro wrote:
> >>>
>  In message <[EMAIL PROTECTED]>, George Neuner
>  wrote:
> 
> > The Christian Bible says "In the beginning was the Word..."
>  Which is an English mistranslation from the Greek "logos".
> >>> So, now you're telling me that the Garden of Eden was actually a
> >>> *marketing campaign*?
> >>
> >> Different Bible book, different author, different original language.
> > 
> > So Genesis was written in Hebrew? I have no clue as to where the 
> > manuscripts were found.
> > 
> Am I missing a joke here? What are you talking about?
> 
I'm trying to figure that out myself...

> Different book? From what book would the first sentence in the Bible be, 
> if not from the first book (yeah yeah, from the publisher, haw-haw :-|)?
> 

Yeah, different book.  "In the beginning was the Word" is John's cosmology.  
Written in Greek long after Genesis, and a couple decades after Jesus was 
executed. 

Also, I wouldn't so much say that "word" is a mistranslation.  Logos does 
indeed mean "word" in common usage, it just also carries along the baggage of 
reason, "logic" (for a loose definintion of which), rationality, and so forth.  
So it's not so much inaccurate as inadequate.

> And Genesis and all other of Moe's books where written in Hebrew. No 
> doubt about that. Its (part of) the /Hebrew/ Bible, after all. 
> http://en.wikipedia.org/wiki/Torah>
> 
> I can't program with discussions like this going on ;)
> /W

For real.  Not much python in this thread.  And yet, here I am, sucked into 
posting to a thread that I've spent the past three or four days wishing would 
die

Sigh.

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


Re: racism kontrol

2007-10-04 Thread Carsten Haese
On Thu, 2007-10-04 at 17:30 +0200, Wildemar Wildenburger wrote:
> Sidenote: Its funny that everybody calls the Dutch "Dutch" (when 
> speaking English), which pretty much is the word "deutsch", which, guess 
> what, means "German" (cf. Pennsylvania Dutch). That has always baffled 
> me --- do Dutch people refer to themselves as "Dutch" when speaking 
> dutch? The term for "Dutch" is "Nederlands" or "Hollands", isn't it?

It is fairly common that people are referred to by others by a different
name than what they call themselves in their native language. Germans
call themselves Deutsch, Chinese call themselves Zhong-guo-ren (I
think), Iroquois call themselves Haudenosaunee, and so on.

The reason for this, I'm guessing, is that visitors and/or invaders
either didn't bother to ask what the people call themselves, or they
misunderstood the answer, or they can't pronounce the answer, or they
didn't ask an authoritative source, or a combination of the above. (For
example, if you ask my neighbor what my name is, he might say "The guy
that doesn't mow his lawn often enough.")

Anyway, I believe this thread has gone on far enough off-topic...

-- 
Carsten Haese
http://informixdb.sourceforge.net


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


Re: Why doesn't Python's "robotparser" like Wikipedia's "robots.txt" file?

2007-10-04 Thread Nikita the Spider
In article <[EMAIL PROTECTED]>,
 John Nagle <[EMAIL PROTECTED]> wrote:

> Filip Salomonsson wrote:
> > On 02/10/2007, John Nagle <[EMAIL PROTECTED]> wrote:
> >> But there's something in there now that robotparser doesn't like.
> >> Any ideas?
> > 
> > Wikipedia denies _all_ access for the standard urllib user agent, and
> > when the robotparser gets a 401 or 403 response when trying to fetch
> > robots.txt, it is equivalent to "Disallow: *".
> > 
> > http://infix.se/2006/05/17/robotparser
> 
>  That explains it.  It's an undocumented feature of "robotparser",
> as is the 'errcode' variable.  The documentation of "robotparser" is
> silent on error handling (can it raise an exception?) and should be
> updated.

Hi John,
Robotparser is probably following the never-approved RFC for robots.txt 
which is the closest thing there is to a standard. It says, "On server 
response indicating access restrictions (HTTP Status Code 401 or 403) a 
robot should regard access to the site completely restricted."
http://www.robotstxt.org/wc/norobots-rfc.html

If you're interested, I have a replacement for the robotparser module 
that works a little better (IMHO) and which you might also find better 
documented. I'm using it in production code:
http://nikitathespider.com/python/rerp/

Happy spidering

-- 
Philip
http://NikitaTheSpider.com/
Whole-site HTML validation, link checking and more
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: pickle and __slots__

2007-10-04 Thread John Nagle
JL wrote:
> Hello,
> 
> I am trying to pickle an object, and I get:
> 
> TypeError: a class that defines __slots__ without defining
> __getstate__ cannot be pickled
> 
> I didn't find __slots__ in the object or the class. Is there a way to
> find it, or to to know which object or class causes the problem?
> 
> Thanks
> 
Is this a subclass?  Look at the parent classes.

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


Re: RegEx question

2007-10-04 Thread Adam Lanier
On Thu, 2007-10-04 at 10:58 -0500, Robert Dailey wrote:
> It should also match:
> 
> @param[out] state Some description of this variable
> 
> 
> On 10/4/07, Robert Dailey <[EMAIL PROTECTED]> wrote:
> Hi,
> 
> The following regex (Not including the end quotes):
> 
> "@param\[in|out\] \w+ "
> 
> Should match any of the following:
> 
> @param[in] variable 
> @param[out] state 
> @param[in] foo 
> @param[out] bar 
> 
> 
> Correct? (Note the trailing whitespace in the regex as well as
> in the examples)
> 
> -- 
> http://mail.python.org/mailman/listinfo/python-list

try @param\[(in|out)\] \w+ 

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


Re: Real time plot

2007-10-04 Thread Jean-Francois Canac

"Hendrik van Rooyen" <[EMAIL PROTECTED]> a écrit dans le message de news: 
[EMAIL PROTECTED]
> Jean-Francois Canac  wrote:
>
>>I am reading a large amount of data from a COM port (or from a file) at a 
>>rate
> of 20 records per second. It is about >positioning of a vehicle on a race 
> track.
>>In each record we have time, position (lat and long) speed, course all 
>>from GPS
> equipment. I would like to Produce a >graph in real time with these 
> records to
> see the  vehicle moving on the track. The goal is to study the vehicle
>>performance and to always have its position, the application would run 
>>around
> 24 hours.
> >
>>I would like to write the application in Python and I am wondering which 
>>plot
> interface would be the more appropriate, I >have seen matplotlib, but I do 
> not
> know how to make real time applications with big amount of data. Is 
> hippodraw
> more >suited to this use or an other interface?
>>Many thanks
>
> I would draw dots on a suitably sized Tkinter canvas, after drawing a 
> schematic
> of the race track (laborious).
>
> 20 per second will be no problem, provided the machine is half decent.
>
> What is the speed at which the com port runs?
>
> - Hendrik
>
The com port run at 19.2 kb/s.
My pb is more the real time aspect: to see the plot changing in real time 
than the com aspect as the installation is already running with programs in 
c++.
The PC on which it is running is good enought
For me the interest is to migrate all taht on python to be able to make fast 
changes when it is of interest
Jean-Francois
> 


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

Starting a thread before wxPython bootup ... interesting.

2007-10-04 Thread Shafik
Hello folks,

I'm having an issue with mixing wxPython and threading ... I realize
multi-threading always introduces subtle bugs, but the following
scenario is just odd:

I start a dummy thread, that does nothing but increment a counter and
print its value to the screen, then afterwards, I start the wxPython
application. I get nothing but weird behavior: sometimes the gui just
crashes, sometimes I get an exception, sometimes it runs for a little
but very slowly ...

Anyone know whats going on? I have a dual-core T5500, so multi
threading is piece of cake for it hardware -wise.


Cheers,
--Shafik

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


Re: RegEx question

2007-10-04 Thread J. Clifford Dyer
You *are* talking about python regular expressions, right?  There are a number 
of different dialects.  Also, there could be issues with the quoting method 
(are you using raw strings?)  

The more specific you can get, the more we can help you.

Cheers,
Cliff
On Thu, Oct 04, 2007 at 11:54:32AM -0500, Robert Dailey wrote regarding Re: 
RegEx question:
> 
>On 10/4/07, Adam Lanier <[EMAIL PROTECTED]> wrote:
> 
>  try @param\[(in|out)\] \w+
> 
>This didn't work either :(
>The tool using this regular expression (Comment Reflower for VS2005)
>May be broken...
> 
> References
> 
>1. mailto:[EMAIL PROTECTED]

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


using regular express to analyze lisp code

2007-10-04 Thread Kelie
hello,

i've spent couple of hours trying to figure out the correct regular
expression to catch a VisualLisp (it is for AutoCAD and has a syntax
that's similar to common lisp) function body. VisualLisp is case-
insensitive. Any line beginning with ";" is for comment (can have
space(s) before ";").

here is an example of VisualLisp function:

(defun get_obj_app_names (obj / rv)
  (foreach app (get_registered_apps (vla-get-document obj))
(if (get_xdata obj app)
  (setq rv (cons app rv))
)
  )
  (if rv
;;"This line is comment (comment)"
;;) This line is also comment
(acad_strlsort rv)
nil
  )
)

for a function named foo, it is easy to find the beginning part of the
function
"(defun foo", but it is hard to find the ")" at the end of code block.
if eventually i can't come up with the solution using regular
expression only, what i was thinking is after finding the beginning
part, which is "(defun foo" in this case, i can count the parenthesis,
ignoring anything inside "" and any line for comment, until i find the
closing ")".

not sure if i've made myself understood. thanks for reading.

kelie

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


Re: pickle and __slots__

2007-10-04 Thread JL
> Is this a subclass?  Look at the parent classes.

Its class is a subclass of a similar class, but it indirectly
references instances of subclasses of asyncore.dispatcher or
asynchat.async_chat. I don't think there are other particular classes.
If I remove the first references, pickle works. Anyway it seems that I
will have to mask the asyncore.dispatcher and asynchat.async_chat
subclass instances which will not be relevant at unpickle time.

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


Import PY file not included in py2exe executable

2007-10-04 Thread ward . david
I am using py2exe to generate an executable so that I can deliver my
scripts as a EXE. I have a couple of file that are needed by the
program that I do not want to include in the EXE because they are used
for program configuration (similar to the way an INI file is used.)
These file may change per installation, so I may need to edit them.
Having them wrapped up in the EXE just won't work for my needs.

I've used the 'exclude' option to keep them from being included in the
EXE. I'm also using 'zipfile=None' so that all of the other pys are
included in the EXE. So, when I deliver the EXE all I should have in
my installation directory is:

MyProgram.exe
config1.py
config2.py


Is this possible? What is the setup.py configuration for this?

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


Re: RegEx question

2007-10-04 Thread Robert Dailey
On 10/4/07, Adam Lanier <[EMAIL PROTECTED]> wrote:
>
>
> try @param\[(in|out)\] \w+
>

This didn't work either :(

The tool using this regular expression (Comment Reflower for VS2005) May be
broken...
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: Python "implements " equivalent?

2007-10-04 Thread Bruno Desthuilliers
Wojciech Gryc a écrit :
> Hi,
> 
> I recently started using Python and am extremely happy with how
> productive it's made me, even as a new user. I'm hoping to continue
> using the language for my research, and have come across a bit of a
> stumbling block.
> 
> I'm a seasoned Java programmer

So you may want to read this:

http://dirtsimple.org/2004/12/python-is-not-java.html

http://dirtsimple.org/2004/12/java-is-not-python-either.html

> and quite a big fan of interfaces...
> i.e. The idea that if I make a number of distinct classes that
> implement interface X, I can pass them all as parameters to functions
> or whatnot that require an X object.
> 
> Is there something similar in Python?

Yes, and it's even simpler : just pass your object. If it effectively 
implements the desired interface, everything will work fine !-)

IOW : Python is dynamically typed, there's no parameters type 
declaration and no parameters type checking at compile time - so you 
just don't need to tell the compiler that your class implements a given 
interface. Anyway, this would be a waste of time since you can 
add/delete/replace attributes and methods at runtime either on a 
per-class or per-instance basis.

> What I'd like to do is create a feature detection system for my work
> -- specifically, a general class / interface called "Feature" and then
> subclasses that implement functions like isFeaturePresent() in all of
> their different and unique ways. I'd love to hear how I can do this in
> Python.

I'm not sure about what you exactly want to do, but FWIW, checking if an 
object has a given attribute is quite simple:

if has_attr(obj, 'attribute_name'):
   print "Hurray"
else:
   print "D'oh"

Note that in Python, methods are attributes too - only they are callable.



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


Re: pickle and __slots__

2007-10-04 Thread JL
I added the following method to the 2 subclasses of
asyncore.dispatcher and asynchat.async_chat and now pickle works:

def __getstate__(self):
return

Later I will probably modify this method so it returns something more
interesting.
Thanks for your help! I was confused because I am not sure what can be
pickled or not.

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


Re: using regular express to analyze lisp code

2007-10-04 Thread Dan
On Oct 4, 1:13 pm, Kelie <[EMAIL PROTECTED]> wrote:
> hello,
>
> i've spent couple of hours trying to figure out the correct regular
> expression to catch a VisualLisp (it is for AutoCAD and has a syntax
> that's similar to common lisp) function body. VisualLisp is case-
> insensitive. Any line beginning with ";" is for comment (can have
> space(s) before ";").
>
> here is an example of VisualLisp function:
>
> (defun get_obj_app_names (obj / rv)
>   (foreach app (get_registered_apps (vla-get-document obj))
> (if (get_xdata obj app)
>   (setq rv (cons app rv))
> )
>   )
>   (if rv
> ;;"This line is comment (comment)"
> ;;) This line is also comment
> (acad_strlsort rv)
> nil
>   )
> )
>
> for a function named foo, it is easy to find the beginning part of the
> function
> "(defun foo", but it is hard to find the ")" at the end of code block.
> if eventually i can't come up with the solution using regular
> expression only, what i was thinking is after finding the beginning
> part, which is "(defun foo" in this case, i can count the parenthesis,
> ignoring anything inside "" and any line for comment, until i find the
> closing ")".
>
> not sure if i've made myself understood. thanks for reading.
>
> kelie

So, paren matching is a canonical context-sensitive algorithm. Now,
many regex libraries have *some* not-purely-regular features, but I
doubt your going to find anything to match parens in a single regex.
If you want to go all out you can use a parser generator (for python
parser generators, see http://python.fyxm.net/topics/parsing.html).
Otherwise, you can go about it the quick-and-dirty way you describe:
scan for matching open and close parens, and ignore things in quotes
and comments.

-Dan

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


Re: Import PY file not included in py2exe executable

2007-10-04 Thread Larry Bates
[EMAIL PROTECTED] wrote:
> I am using py2exe to generate an executable so that I can deliver my
> scripts as a EXE. I have a couple of file that are needed by the
> program that I do not want to include in the EXE because they are used
> for program configuration (similar to the way an INI file is used.)
> These file may change per installation, so I may need to edit them.
> Having them wrapped up in the EXE just won't work for my needs.
> 
> I've used the 'exclude' option to keep them from being included in the
> EXE. I'm also using 'zipfile=None' so that all of the other pys are
> included in the EXE. So, when I deliver the EXE all I should have in
> my installation directory is:
> 
> MyProgram.exe
> config1.py
> config2.py
> 
> 
> Is this possible? What is the setup.py configuration for this?
> 
I've found that using Inno Installer to package all the "other" stuff that I 
need works EXTREMELY well.  I almost always need .INI file, HISTORY.TXT, 
README.TXT, icons, etc.  Inno also allows me to ship a single setup.exe file 
that can install my program, make registry entries (if needed), create 
shortcuts, etc.  The time I spend installing and learning Inno has paid for 
itself many times over.

FYI, Larry
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python "implements " equivalent?

2007-10-04 Thread Grant Edwards
On 2007-10-04, Bruno Desthuilliers <[EMAIL PROTECTED]> wrote:

> Yes, and it's even simpler : just pass your object. If it effectively 
> implements the desired interface, everything will work fine !-)
[...]

>> What I'd like to do is create a feature detection system for
>> my work -- specifically, a general class / interface called
>> "Feature" and then subclasses that implement functions like
>> isFeaturePresent() in all of their different and unique ways.
>> I'd love to hear how I can do this in Python.
>
> I'm not sure about what you exactly want to do, but FWIW, checking if an 
> object has a given attribute is quite simple:
>
> if has_attr(obj, 'attribute_name'):
>print "Hurray"
> else:
>print "D'oh"
>
> Note that in Python, methods are attributes too - only they
> are callable.

On a slight tangent

The "Pythonic" way to handle things like that is often just
to call the method you want to call.  If the object doesn't
have that method, then you catch the exception and do whatever
it is you do in the case where the object doesn't have the
feature in question.  

The tricky bit is only catching the AttributeError exception
generated by the attempt to access the non-existant method, and
not catching AttributeError exceptions generated by bugs in the
method when it does exist.

Once you've added code to make sure you only catch exceptions
you care about, it's simpler to just call has_attr

the obvious method

   try:
   myobj.feature1()
   except AttributeError:
   print "object doesn't implement feature1"

isn't correct, since an unhandled AttributeError generated by
the feature1 method will print "object doesn't implement
feature1".  Attempting to isolate the attributeError we care
about looks like this:

   try:
   m = myobj.feature1
   except AttributeError:
   print "object doesn't implement feature1"
   else:
   m()

That's just too messy compared with the has_attr method that
goes like this:
   
   if has_attr(myobj,'feature1'):
   myobj.feature1()
   else:
   print "object doesn't implement feature1"   

However, I don't like that alot because you've got to supply
the method name twice: once as a string and once as the method
name.

What's the cleanest way to call a method that might not be
there?

-- 
Grant Edwards   grante Yow! My haircut is totally
  at   traditional!
   visi.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: using regular express to analyze lisp code

2007-10-04 Thread Tim Chase
> i've spent couple of hours trying to figure out the correct regular
> expression to catch a VisualLisp 
[snipped]
> "(defun foo", but it is hard to find the ")" at the end of code block.
> if eventually i can't come up with the solution using regular
> expression only, what i was thinking is after finding the beginning
> part, which is "(defun foo" in this case, i can count the parenthesis,
> ignoring anything inside "" and any line for comment, until i find the
> closing ")".


"""
Some people, when confronted with a problem, think
"I know, I'll use regular expressions!"
Now they have two problems
"""


Regular expressions are a wonderful tool when the domain is 
correct.  However, when your domain involves processing 
arbitrarily nested syntax, regexps are not your friend.  It is 
sometimes feasible to mung them into a fixed-depth-nesting 
parser, but it's always fairly painful, and the fixed-depth is an 
annoying limitation.

Use a parsing lib.  I've tinkered a bit with PyParsing[1] which 
is fairly easy to pick up, but powerful enough that you're not 
banging your head against limitations.  There are a number of 
other parsing libraries[2] with various domain-specific features 
and audiences, but I'd go browsing through them only if PyParsing 
doesn't fill the bill.

As you don't detail what you want to do with the content or how 
pathological the input can be, but you might be able to get away 
with just skimming through the input and counting open-parens and 
close-parens, stopping when they've been balanced, skipping lines 
with comments.

-tkc

[1] http://pyparsing.wikispaces.com/
[2] http://nedbatchelder.com/text/python-parsers.html
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: What does the syntax [::-1] really mean?

2007-10-04 Thread Kurt Smith
On 10/4/07, Casey <[EMAIL PROTECTED]> wrote:
[snippage]
>
> Following the reference to section 3.2 provides a (non-rigorous)
> description of what a slice object is, in terms of the extended
> slicing semantics.  But it doesn't shed any additional light on the
> meaning of [::-1].
>
> >From this, I would expect that x[::-1] would be identical to x[n:0:-1]
> (n and 0 being the "end" values, with the order switched due to the
> negative step value).  But the clause that "(but never including j)"
> means that x[n:0:-1] excludes the 1st element of x, x[0].  A quick
> test in ipython confirms that "abc"[3:0:-1] => "cb", not "cba".
> Changing the "end" value  to x[n:-1:-1] results in an empty string.

Check it out:

>>> 'abc'[3:None:-1]
'cba'
>>>

The second argument to the slice object, if negative, will convert
this index to (len(x)+j), which is why 'abc'[3:-1:-1] == 'abc'[2:2:-1]
== ''.  If you pass in None for the 1st or second index, the slice
object will compute the right bounds based on the __len__ of the
object, and do the right thing.  When there is no value specified,
None is assumed.


>
> So my question is: "what exactly is [::-1] shorthand for"?  Or is it a
> special case, in which case why isn't it  defined as such in the
> library?

obj[::-1] == obj[None:None:-1] == obj[slice(None,None,-1)]

>>> 'abc'[::-1]
'cba'
>>> 'abc'[None:None:-1]
'cba'
>>> 'abc'[slice(None,None,-1)]
'cba'

Taking a look at the slice class:

 |  indices(...)
 |  S.indices(len) -> (start, stop, stride)
 |
 |  Assuming a sequence of length len, calculate the start and stop
 |  indices, and the stride length of the extended slice described by
 |  S. Out of bounds indices are clipped in a manner consistent with the
 |  handling of normal slices.

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


Re: A question about subprocess

2007-10-04 Thread Dan Stromberg

You don't necessarily need the subprocess module to do this, though you
could use it.

I've done this sort of thing in the past with fork and exec.

To serialize the jobs on the machines, the easiest thing is to just send
the commands all at once to a given machine, like "command1; command2;
command3".

You can use waitpid or similar to check if a series of jobs has finished
on a particular machine.

An example of something similar can be found at
http://stromberg.dnsalias.org/~strombrg/loop.html

(If you look at the code, be kind.  I wrote it long ago :)

There's a benefit to saving the output from each machine into a single
file for that machine.  If you think some machines will produce the same
output, and you don't want to see it over and over, you can analyze the
files with something like
http://stromberg.dnsalias.org/~strombrg/equivalence-classes.html .


 On Wed, 03 Oct 2007 16:46:20 +, JD wrote:

> Hi,
> 
> I want send my jobs over a whole bunch of machines (using ssh). The
> jobs will need to be run in the following pattern:
> 
> (Machine A)   (Machine B)  (Machine C)
> 
> Job A1 Job B1Job C1
> 
>  Job A2   Job B2etc
> 
>  Job A3  etc
> 
>  etc
> 
> Jobs runing on machine A, B, C should be in parallel, however, for
> each machine, jobs should run one after another.
> 
> How can I do it with the subprocess?
> 
> 
> Thanks,
> 
> JD


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


Re: Python "implements " equivalent?

2007-10-04 Thread Jeff McNeil
I don't know how "clean" it is, but there are a few situations in which I do
something like this:

getattr(obj, "method", default_method)(*original_method_args)

The default_method is a base implementation or a simple error handler. For
example, when a client hits one of our XMLRPC servers and passes a method
name that's not defined, I've got a default catch-all that logs that and
handles the error accordingly.

-Jeff

On 10/4/07, Grant Edwards <[EMAIL PROTECTED]> wrote:
>
> On 2007-10-04, Bruno Desthuilliers <
> [EMAIL PROTECTED]> wrote:
>
> > Yes, and it's even simpler : just pass your object. If it effectively
> > implements the desired interface, everything will work fine !-)
> [...]
>
> >> What I'd like to do is create a feature detection system for
> >> my work -- specifically, a general class / interface called
> >> "Feature" and then subclasses that implement functions like
> >> isFeaturePresent() in all of their different and unique ways.
> >> I'd love to hear how I can do this in Python.
> >
> > I'm not sure about what you exactly want to do, but FWIW, checking if an
> > object has a given attribute is quite simple:
> >
> > if has_attr(obj, 'attribute_name'):
> >print "Hurray"
> > else:
> >print "D'oh"
> >
> > Note that in Python, methods are attributes too - only they
> > are callable.
>
> On a slight tangent
>
> The "Pythonic" way to handle things like that is often just
> to call the method you want to call.  If the object doesn't
> have that method, then you catch the exception and do whatever
> it is you do in the case where the object doesn't have the
> feature in question.
>
> The tricky bit is only catching the AttributeError exception
> generated by the attempt to access the non-existant method, and
> not catching AttributeError exceptions generated by bugs in the
> method when it does exist.
>
> Once you've added code to make sure you only catch exceptions
> you care about, it's simpler to just call has_attr
>
> the obvious method
>
>try:
>myobj.feature1()
>except AttributeError:
>print "object doesn't implement feature1"
>
> isn't correct, since an unhandled AttributeError generated by
> the feature1 method will print "object doesn't implement
> feature1".  Attempting to isolate the attributeError we care
> about looks like this:
>
>try:
>m = myobj.feature1
>except AttributeError:
>print "object doesn't implement feature1"
>else:
>m()
>
> That's just too messy compared with the has_attr method that
> goes like this:
>
>if has_attr(myobj,'feature1'):
>myobj.feature1()
>else:
>print "object doesn't implement feature1"
>
> However, I don't like that alot because you've got to supply
> the method name twice: once as a string and once as the method
> name.
>
> What's the cleanest way to call a method that might not be
> there?
>
> --
> Grant Edwards   grante Yow! My haircut is
> totally
>   at   traditional!
>visi.com
> --
> http://mail.python.org/mailman/listinfo/python-list
>
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: Import PY file not included in py2exe executable

2007-10-04 Thread Florian Schmidt
On Thu, Oct 04, 2007 at 10:15:59AM -0700, [EMAIL PROTECTED] wrote:
> ... because they are used for program configuration ...

not sure if i completely understood but i guess you do something like
that:

my_config.py:
db_host = "mydbserver"
db_user = "root"
...

and in your program.py you have:
import my_config
...
DB.Connect(my_config.db_host, my_config.db_user...)

and your problem is that py2exe will package that my_config.py so that
"noone" can change it afterwards...

one possibility i often use is execfile:
same my_config as above, but:
program.py:
class config_class:
  pass
my_config = config_class()
my_config.db_host = "localhost" # default config...

def read_config():
execfile("my_config.py", globals(), my_config.__dict__)
...
DB.Connect(my_config.db_host, my_config.db_user...)  

so you can always call read_config() to re-read the configuration and have
all python features in that config file. (additionally you can catch
exceptions and check the config files' mtime if it has changed...)

that way py2exe won't care about your config file...

hope it helps...

-- 

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


Re: What does the syntax [::-1] really mean?

2007-10-04 Thread Neil Cerutti
On 2007-10-04, Casey <[EMAIL PROTECTED]> wrote:
> I've used [::-1] as a shorthand for reverse on several occasions, but
> it occurred to me yesterday I never really thought about why it
> works.  First, I checked out the documentation.
>
>>From section 3.6 of the Python Library Reference:
>
> "The slice of s from i to j with step k is defined as the
> sequence of items with index x = i + n*k such that 0 <= n <
> (j-i)/k. In other words, the indices are i, i+k, i+2*k, i+3*k
> and so on, stopping when j is reached (but never including j).
> If i or j  is greater than len(s), use len(s). If i or j are
> omitted or None, they become ``end'' values (which end depends
> on the sign of k). Note, k cannot be zero. If k is None, it is
> treated like 1."

You just have to choose the right value for the end arguments.
With k negative, the result might be:

  [-1:-len(s)-1:k]

I.e., from -1 (the last element) to one beyond the first element
(-len(s)-1). A negative index seems to be the only way to refer
to the element before the first element.

In that case the forumula given above does yield the reverse
sequence.

For example, for len(s) of 3, you get, you would get the
following sequence of indices:

  i = -1, j = -4, k = -1

  -1 + -1 = -2
  -1 + 2*(-1) = -3
  -1 + 3*(-1) = -4

-4 is equal to j, so the sequence ends with s[-3].

> From this, I would expect that x[::-1] would be identical to
> x[n:0:-1] (n and 0 being the "end" values, with the order
> switched due to the negative step value).  But the clause that
> "(but never including j)" means that x[n:0:-1] excludes the 1st
> element of x, x[0].  A quick test in ipython confirms that
> "abc"[3:0:-1] => "cb", not "cba". Changing the "end" value  to
> x[n:-1:-1] results in an empty string.

Your proposed sequence, x[n:0:-1] is half-open on the wrong end.
When k is -1 then j must also be negative. This is because
there's no way to refer to the element one before the first
element without using a negative index value for j.

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


Don't understand module search path...

2007-10-04 Thread mhearne808[insert-at-sign-here]gmail[insert-dot-here]com
I think I don't understand how the module search path works...

Let's say I have a folders called 'test'.  Underneath it, I create two
more folders called 'foo' and 'bar'.

In 'foo', I create an empty '__init__.py' file, indicating that this
folder is a package 'foo'.  I then create a simple python script
'foo.py' consisting of the following code:


#!/usr/bin/python

def printhello():
print 'Hello world!'


Then in test/bar, I create 'bar.py' consisting of the following code:

#!/usr/bin/python
import sys
import os
(curpath,thisdir) = os.path.split(os.getcwd())
foopath = os.path.join(curpath,'foo')
sys.path.append(foopath)
print sys.path
os.chdir(os.path.join(os.getcwd(),'..'))
print os.getcwd()
from foo.foo import printhello


When I try to run bar.py, I get the following:


[sys.path search path, including full path to 'foo' folder]
path/to/test
Traceback (most recent call last):
  File "/path/to/test/bar/testfoo.py", line 16, in 
from foo.foo import printhello
ImportError: No module named foo


Why?  If 'foo' is in sys.path, shouldn't it appear when I try to
import the foo module from it?  Incidentally, when I move the script
up to 'test' and modify it so that it just says:

#!/usr/bin/python

from foo.foo import printhello


I get no errors.  I don't understand the difference...

Incidentally, my platform info:
Python 2.5.1
Darwin Kernel Version 8.10.1 (Mac OS X)

Help!

--Mike

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


Re: using regular express to analyze lisp code

2007-10-04 Thread Kelie
On Oct 4, 7:50 am, Tim Chase <[EMAIL PROTECTED]> wrote:
> Use a parsing lib.  I've tinkered a bit with PyParsing[1] which
> is fairly easy to pick up, but powerful enough that you're not
> banging your head against limitations.  There are a number of
> other parsing libraries[2] with various domain-specific features
> and audiences, but I'd go browsing through them only if PyParsing
> doesn't fill the bill.
>
> As you don't detail what you want to do with the content or how
> pathological the input can be, but you might be able to get away
> with just skimming through the input and counting open-parens and
> close-parens, stopping when they've been balanced, skipping lines
> with comments.

thanks Tim. following you and Dan's advice i visited
http://python.fyxm.net/topics/parsing.html and i picked up pyparsing
after brief reading of descriptions for couple of packages. now that
you recommended it, seems that i made a good choice.

btw, the content found will be copied to a new text file.




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


Re: using regular express to analyze lisp code

2007-10-04 Thread Kelie
On Oct 4, 7:28 am, Dan <[EMAIL PROTECTED]> wrote:
> So, paren matching is a canonical context-sensitive algorithm. Now,
> many regex libraries have *some* not-purely-regular features, but I
> doubt your going to find anything to match parens in a single regex.
> If you want to go all out you can use a parser generator (for python
> parser generators, seehttp://python.fyxm.net/topics/parsing.html).
> Otherwise, you can go about it the quick-and-dirty way you describe:
> scan for matching open and close parens, and ignore things in quotes
> and comments.
>
> -Dan

Dan, thanks for suggesting parser generators.

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


Re: Starting a thread before wxPython bootup ... interesting.

2007-10-04 Thread Chris Mellon
On 10/4/07, Shafik <[EMAIL PROTECTED]> wrote:
> Hello folks,
>
> I'm having an issue with mixing wxPython and threading ... I realize
> multi-threading always introduces subtle bugs, but the following
> scenario is just odd:
>
> I start a dummy thread, that does nothing but increment a counter and
> print its value to the screen, then afterwards, I start the wxPython
> application. I get nothing but weird behavior: sometimes the gui just
> crashes, sometimes I get an exception, sometimes it runs for a little
> but very slowly ...
>
> Anyone know whats going on? I have a dual-core T5500, so multi
> threading is piece of cake for it hardware -wise.
>

That's quite a broad and poorly specified problem to ask people to
solve with no code. You get double minus points for mentioning an
exception without saying what it was.

Below is a script that has no demonstrable problems on my machine:

import wx
import threading

if __name__ == '__main__':
run = True
def count():
counter = 0
while run:
print counter
counter += 1
thread = threading.Thread(target=count)
thread.start()
app = wx.App(False)
f = wx.Frame(None)
f.Show()
app.MainLoop()
run = False



Since the counter loop spins tightly, this causes some CPU contention
and could quite possibly cause a non-trivial GUI to respond poorly,
but that's to be expected.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Don't understand module search path...

2007-10-04 Thread Chris Mellon
On 10/4/07, mhearne808[insert-at-sign-here]gmail[insert-dot-here]com
<[EMAIL PROTECTED]> wrote:
> I think I don't understand how the module search path works...
>
> Let's say I have a folders called 'test'.  Underneath it, I create two
> more folders called 'foo' and 'bar'.
>
> In 'foo', I create an empty '__init__.py' file, indicating that this
> folder is a package 'foo'.  I then create a simple python script
> 'foo.py' consisting of the following code:
>
> 
> #!/usr/bin/python
>
> def printhello():
> print 'Hello world!'
> 
>
> Then in test/bar, I create 'bar.py' consisting of the following code:
> 
> #!/usr/bin/python
> import sys
> import os
> (curpath,thisdir) = os.path.split(os.getcwd())
> foopath = os.path.join(curpath,'foo')
> sys.path.append(foopath)
> print sys.path
> os.chdir(os.path.join(os.getcwd(),'..'))
> print os.getcwd()
> from foo.foo import printhello
> 
>
> When I try to run bar.py, I get the following:
>
> 
> [sys.path search path, including full path to 'foo' folder]
> path/to/test
> Traceback (most recent call last):
>   File "/path/to/test/bar/testfoo.py", line 16, in 
> from foo.foo import printhello
> ImportError: No module named foo
> 
>
> Why?  If 'foo' is in sys.path, shouldn't it appear when I try to
> import the foo module from it?

No. foo will be searched for modules, but foo itself won't be found
(because it's looking *inside* foo). You want "test" to be on sys.path
for this to work.

>Incidentally, when I move the script
> up to 'test' and modify it so that it just says:
> 
> #!/usr/bin/python
>
> from foo.foo import printhello
> 
>
> I get no errors.  I don't understand the difference...
>

The directory that the executing script is in is implicitly on
sys.path, so when you do this you place "test" in sys.path, and foo is
found.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: win32com COMAdminCatalogObject Value method

2007-10-04 Thread rc
On Oct 2, 11:11 pm, "Gabriel Genellina" <[EMAIL PROTECTED]>
wrote:
> En Tue, 02 Oct 2007 12:12:09 -0300, rc <[EMAIL PROTECTED]> escribi?:
>
> >> Try objCOMAdminCatalogObject.SetValue("ID", AppID).
> > When I try that I get exception:
> > AttributeError: Add.SetValue
>
> I think you would get more help asking in [EMAIL PROTECTED]
>
> --
> Gabriel Genellina

Thank you, python-win32 was able to help.
makepy needed to be run on the COM object allowing SetValue to be
called:
win32com.client.gencache.EnsureModule(pywintypes.IID('{F618C513-
DFB8-11D1-A2CF-00805FC79235}'), 0x0, 1, 0)

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


Re: What does the syntax [::-1] really mean?

2007-10-04 Thread Casey
On Oct 4, 1:41 pm, "Kurt Smith" <[EMAIL PROTECTED]> wrote:
> >>> 'abc'[None:None:-1]
> 'cba'
> Kurt

Thanks!

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


Re: Python and SSL

2007-10-04 Thread Johny
Martin and John,
Thank you both for your replies
 Must I  have OpenSSL imported in my Python program?
So far I have been using only SSL  support.
Built-in SSL support works OK if I connect from my Python program
directly to SSL server ( but not via proxy).
L.

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


Re: RegEx question

2007-10-04 Thread Robert Dailey
On 10/4/07, J. Clifford Dyer <[EMAIL PROTECTED]> wrote:
>
> You *are* talking about python regular expressions, right?  There are a
> number of different dialects.  Also, there could be issues with the quoting
> method (are you using raw strings?)
>
> The more specific you can get, the more we can help you.


As far as the dialect, I can't be sure. I am unable to find documentation
for Comment Reflower and thus cannot figure out what type of regex it is
using. What exactly do you mean by your question, "are you using raw
strings?". Thanks for your response and I apologize for the lack of detail.
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: What does the syntax [::-1] really mean?

2007-10-04 Thread Robert Kern
Casey wrote:
> I've used [::-1] as a shorthand for reverse on several occasions, but
> it occurred to me yesterday I never really thought about why it
> works.  First, I checked out the documentation.
> 
>>From section 3.6 of the Python Library Reference:
> 
> "The slice of s from i to j with step k is defined as the sequence of
> items with index x = i + n*k such that 0 <= n < (j-i)/k. In other
> words, the indices are i, i+k, i+2*k, i+3*k and so on, stopping when j
> is reached (but never including j). If i or j  is greater than len(s),
> use len(s). If i or j are omitted or None, they become ``end'' values
> (which end depends on the sign of k). Note, k cannot be zero. If k is
> None, it is treated like 1."
> 
>>From Section 5.3.3 of the Python Language Reference (x[::-1] is a
> "proper slice" in the BNF, hence the excerpt):
> 
> "The conversion of a proper slice is a slice object (see section 3.2)
> whose start, stop and step attributes are the values of the
> expressions given as lower bound, upper bound and stride,
> respectively, substituting None for missing expressions."
> 
> Following the reference to section 3.2 provides a (non-rigorous)
> description of what a slice object is, in terms of the extended
> slicing semantics.  But it doesn't shed any additional light on the
> meaning of [::-1].
> 
>>From this, I would expect that x[::-1] would be identical to x[n:0:-1]
> (n and 0 being the "end" values, with the order switched due to the
> negative step value).  But the clause that "(but never including j)"
> means that x[n:0:-1] excludes the 1st element of x, x[0].  A quick
> test in ipython confirms that "abc"[3:0:-1] => "cb", not "cba".
> Changing the "end" value  to x[n:-1:-1] results in an empty string.
> 
> So my question is: "what exactly is [::-1] shorthand for"?  Or is it a
> special case, in which case why isn't it  defined as such in the
> library?

It's a shorthand for [None:None:-1].

I think you're misinterpreting the sentence, "If i or j are omitted or None,
they become ``end'' values (which end depends on the sign of k)." The end values
*aren't* 0 and n except by happenstance. None (or omission) is a special marker
that says "go to the end".

-- 
Robert Kern

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

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


Off Topic: Gmail hates newsgroups!!!

2007-10-04 Thread Robert Dailey
I don't know how many other people subscribe to the python mailing list and
use the mailing list using the web-based interface for Gmail, but I do. I
use it mainly because Gmail doesn't support IMAP and I use my email from
multiple locations. Gmail web based works fine except that it starts your
caret off BEFORE the reply instead of AFTER it. They don't even have an
option to change this either. I'm just ranting this because it upsets me :)

If anyone might know of a firefox plugin or something to fix this I'd be
more than willing to use it. I've looked a bit myself for such an extension
and I've been unsuccessful in finding one.
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: unit testing

2007-10-04 Thread Chris Mellon
On 10/4/07, brad <[EMAIL PROTECTED]> wrote:
> Does anyone else feel that unittesting is too much work? Not in general,
> just the official unittest module for small to medium sized projects?
>
> It seems easier to write some quick methods that are used when needed
> rather than building a program with integrated unittesting. I see the
> value of it (the official unittest that is)... especially when there's a
> lot of source code. But this...
>
> if len(x) != y:
> sys.exit('...')
>
> is a hell of a lot easier and quicker that subclassing unittest.TestCase
> on small projects :)
>
> Do others do their own "informal" unit testing?
>


Doctest is commonly given as the alternative to people who feel this
way. Personally, I find that anything worth testing is worth having a
test directory and independent unit tests for.
-- 
http://mail.python.org/mailman/listinfo/python-list


unit testing

2007-10-04 Thread brad
Does anyone else feel that unittesting is too much work? Not in general, 
just the official unittest module for small to medium sized projects?

It seems easier to write some quick methods that are used when needed 
rather than building a program with integrated unittesting. I see the 
value of it (the official unittest that is)... especially when there's a 
lot of source code. But this...

if len(x) != y:
sys.exit('...')

is a hell of a lot easier and quicker that subclassing unittest.TestCase 
on small projects :)

Do others do their own "informal" unit testing?

Just curious,

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


Re: RegEx question

2007-10-04 Thread Jerry Hill
> As far as the dialect, I can't be sure. I am unable to find documentation
> for Comment Reflower and thus cannot figure out what type of regex it is
> using. What exactly do you mean by your question, "are you using raw
> strings?". Thanks for your response and I apologize for the lack of detail.

Comment Reflower appears to be a plugin for Visual Studio written in
C#.  As far as I can tell, it has nothing to do with Python at all.

A quick look at their sourceforge page
(http://sourceforge.net/projects/commentreflower/) doesn't show any
mailing lists or discussion groups.  Maybe try emailing the author
directly, or asking a C# language group about whatever the standard C#
regular expression library is.

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


Re: migrating to packages

2007-10-04 Thread Gerardo Herzig

>
>  
>
>>>On Oct 3, 2007, at 11:42 AM, Gerardo Herzig wrote:
>>>
>>>  
>>>
Hi all. I have a single file with several classes, wich i want to
separate into several packages.
The big file is named, say MYCLASES, and contains a class named
A(object), and B(A).

We have been using this MYCLASES in the from MYCLASES import B syntax,
but i cant reproduce this syntax using packages. Im forced to write
from PACKAGE.B import *, and if that means
i have to touch so many files, that would really be a problem to me.
There is (i cant find it yet) a place where i can read about that kind
of package 'migration' situation?

Because i *really* want to keep the FROM PACKAGE import B syntax.


>>>http://www.python.org/doc/current/tut/
>>>node8.html#SECTION00840
>>>  
>>>
>>I have already read those files (and i just read it again), but still
>>cant find the solution. Maybe i just do not explain myself in the
>>correct way (or  i am very very stupid :)
>>I will expose my case quicly.
>>The MYCLASES.py file contains the A class, so i can use from MYCLASES
>>import A
>>a = ()
>>
>>Using the "package mode" (wich looks fine BTW), having the simple
>>MYCLASES/
>> __init__.py
>> A.py
>>
>>forces my (i guess) to use the
>>from MYCLASES.A import A
>>
>>which is not what i want, because the big amount of files i will have to
>>modify (and im not alones, there is a group of dudes who use this
>>MYCLASES)
>>
>>Im i missing something in that docs you post? Thanks!!
>>
>>
>
>Add these lines in __init__.py:
>
>from MYCLASSES.A import A
>from MYCLASSES.B import B
>  
>
Ummm, that works indeed, but forces me to import all (more than A and B) 
classes, rigth?
Gerardo.
-- 
http://mail.python.org/mailman/listinfo/python-list


  1   2   >