Re: removing spaces between 2 names

2007-05-14 Thread half . italian
On May 14, 11:00 pm, [EMAIL PROTECTED] wrote:
> Hi,
>  Suppose i have a string stored in variable,how do i remove the
> space between them,like if i have the name:
> "USDT request" in a variable.i need "USDTrequest",without any space .
> Thanks

s = "jk hij ght"
print "".join(s.split(" "))

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


Re: Trying to choose between python and java

2007-05-14 Thread Marc 'BlackJack' Rintsch
In <[EMAIL PROTECTED]>, Anthony Irwin wrote:

> #1 Does python have something like javas .jar packages. A jar file 
> contains all the program files and you can execute the program with 
> java -jar program.jar

There are .egg files but usually distributing a program consisting of
several files isn't a big problem.  There is a mechanism to write a
`setup.py` that copies the files into the correct locations.  Look for
`distutils` in the library docs.

> #2 What database do people recommend for using with python that is 
> easy to distribute across linux, mac, windows.

>From Python 2.5 the standard library contains SQLite support.  There are
third party libraries to many DBMSs like MySQL, PostgreSQL, Oracle etc.

The situation with MySQL bindings under Windows was a bit troublesome
recently.  The author of the bindings doesn't use Windows and does not
provide pre-built binaries.

> #4 If I write a program a test it with python-wxgtk2.6 under linux are 
> the program windows likely to look right under windows and mac?

Likely yes, but you better check.  Same applies to Java GUIs.

> #5 someone said that they used to use python but stopped because the 
> language changed or made stuff depreciated (I can fully remember 
> which) and old code stopped working. Is code written today likely to 
> still work in 5+ years or do they depreciate stuff and you have to update?

That sounds odd because the language and standard library is very
backwards compatible.  There are some things deprecated with a comment in
the docs and in some cases runtime warnings, but the code still works.

With Python 3.0 some things will break, because there's some cruft in the
language and library that accumulated over time, just because backwards
compatibility was such a high priority.  The 2.x series will be supported
for some time parallel to 3.x, so there is enough time to migrate.

Ciao,
Marc 'BlackJack' Rintsch
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: removing spaces between 2 names

2007-05-14 Thread 7stud
On May 15, 12:14 am, Steven Howe <[EMAIL PROTECTED]> wrote:
> [EMAIL PROTECTED] wrote:
> > Hi,
> >  Suppose i have a string stored in variable,how do i remove the
> > space between them,like if i have the name:
> > "USDT request" in a variable.i need "USDTrequest",without any space .
> > Thanks
>
> from string import replace
> st = 'abcd acdfgxtit'
> st.replace(' ','')
> 'abcdacdfgxtit'
>
> sph
>
> --
> HEX: 09 F9 11 02 9D 74 E3 5B D8 41 56 C5 63 56 88 C0

The methods in the string module are deprecated.  Skip the import and
use a string's built in replace() method instead:

s = "hello world"
result = s.replace(" ", "")
print result

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


Re: Sorting troubles

2007-05-14 Thread Terry Reedy

<[EMAIL PROTECTED]> wrote in message 
news:[EMAIL PROTECTED]
| Teach said that the optimal threshold in hybrids is 14-16, but guess
| he wasn't so right after all =\\ The overhead of using insertion sort
| on a longer list turns out to be faster than just piling on
| recursions, when confronted with bigger lists.

The current list.sort (is C, of course, not Python) is a hybrid 
insert/merge sort with a threshhold, last I knew, of 64.  I believe there 
are explanatory comments in the source.

tjr



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


Re: PEP 3131: Supporting Non-ASCII Identifiers

2007-05-14 Thread Stefan Behnel
Paul Rubin wrote:
> Stefan Behnel <[EMAIL PROTECTED]> writes:
>> But then, where's the problem? Just stick to accepting only patches that are
>> plain ASCII *for your particular project*. 
> 
> There is no feature that has ever been proposed for Python, that cannot
> be supported with this argument.  If you don't like having a "go to"
> statement added to Python, where's the problem?  Just don't use it in
> your particular project.

"go to" is not meant for clarity, nor does it encourage code readability.

But that's what this PEP is about.

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


Re: PEP 3131: Supporting Non-ASCII Identifiers

2007-05-14 Thread Stefan Behnel
Paul Rubin wrote:
> Stefan Behnel <[EMAIL PROTECTED]> writes:
>> But then, where's the problem? Just stick to accepting only patches that are
>> plain ASCII *for your particular project*. 
> 
> There is no feature that has ever been proposed for Python, that cannot
> be supported with this argument.  If you don't like having a "go to"
> statement added to Python, where's the problem?  Just don't use it in
> your particular project.

"go to" is not meant for clarity, nor does it encourage code readability.

But that's what this PEP is about.

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


Re: removing spaces between 2 names

2007-05-14 Thread Steven Howe
[EMAIL PROTECTED] wrote:
> Hi,
>  Suppose i have a string stored in variable,how do i remove the
> space between them,like if i have the name:
> "USDT request" in a variable.i need "USDTrequest",without any space .
> Thanks
>
>   
from string import replace
st = 'abcd acdfgxtit'
st.replace(' ','')
'abcdacdfgxtit'

sph

-- 
HEX: 09 F9 11 02 9D 74 E3 5B D8 41 56 C5 63 56 88 C0

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


removing spaces between 2 names

2007-05-14 Thread saif . shakeel
Hi,
 Suppose i have a string stored in variable,how do i remove the
space between them,like if i have the name:
"USDT request" in a variable.i need "USDTrequest",without any space .
Thanks

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


Re: Generators in C code

2007-05-14 Thread Gabriel Genellina
En Tue, 15 May 2007 02:12:40 -0300, Raymond Hettinger <[EMAIL PROTECTED]>  
escribió:

>> I feel I'm out of luck, but if someone could point some way to write a
>> generator in C, I'be very grateful!
>
> Perhaps the code in the itertools module will provide a good example
> -- they behave like generators in many respects except that you are
> responsible for tracking state and jumping to an appropriate resume
> point.  Being C, it won't be as convenient as Python generators, but
> should be able to translate any generator into equivalent C.

Oh, thanks for pointing that! (I didn't know the itertools module was  
written in C - I supposed it was a Python module).
After a brief reading, I think I'll use something similar to how tee and  
teedataobject store current state.

-- 
Gabriel Genellina

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


Trying to choose between python and java

2007-05-14 Thread Anthony Irwin
Hi All,

I am currently trying to decide between using python or java and have 
a few quick questions about python that you may be able to help with.

#1 Does python have something like javas .jar packages. A jar file 
contains all the program files and you can execute the program with 
java -jar program.jar

I am sort of hoping python has something like this because I feel it 
makes it easier to distribute between platforms e.g. linux, mac 
windows etc.

#2 What database do people recommend for using with python that is 
easy to distribute across linux, mac, windows.

#3 Is there any equivalent to jfreechart and jfreereport 
(http://www.jfree.org for details) in python.

#4 If I write a program a test it with python-wxgtk2.6 under linux are 
the program windows likely to look right under windows and mac?

#5 someone said that they used to use python but stopped because the 
language changed or made stuff depreciated (I can fully remember 
which) and old code stopped working. Is code written today likely to 
still work in 5+ years or do they depreciate stuff and you have to update?

Anyway hopefully someone can help me out with these last few questions 
I have.

Also does anyone else have any useful comments about python vs java 
without starting a flame war.


-- 
Kind Regards,
Anthony Irwin

http://www.irwinresources.com
http://www.makehomebusiness.com
email: anthony at above domains, - www.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Interesting list Validity (True/False)

2007-05-14 Thread Gabriel Genellina
En Tue, 15 May 2007 01:37:07 -0300, [EMAIL PROTECTED]  
<[EMAIL PROTECTED]> escribió:

>> > 
>> > Sec 2.2.3:
>> > Objects of different types, *--->except<---* different numeric types
>> > and different string types, never compare equal;
>> > 
>>
>> The exceptions you mean are not exceptions to "'X==Y' means 'X equals
>> Y'".
>
> I never said they were. I said they were exceptions to
> "Obbjects of different types never compare equal".

This is an unfortunate wording, and perhaps should read: "For most builtin  
types, objects of different types never compare equal; such objects are  
ordered consistently but arbitrarily (so that sorting a heterogeneous  
sequence yields a consistent result). The exceptions being different  
numeric types and different string types, that have a special treatment;  
see section 5.9 in the Reference Manual for details."

And said section 5.9 should be updated too: "The objects need not have the  
same type. If both are numbers or strings, they are converted to a common  
type. Otherwise, objects of different builtin types always compare  
unequal, and are ordered consistently but arbitrarily. You can control  
comparison behavior of objects of non-builtin types by defining a __cmp__  
method or rich comparison methods like __gt__, described in section 3.4."

I hope this helps a bit. Your performance issues don't have to do with the  
*definition* of equal or not equal, only with how someone decided to write  
the mpz class.

-- 
Gabriel Genellina

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


Re: PEP 3131: Supporting Non-ASCII Identifiers

2007-05-14 Thread Martin v. Löwis
Paul Rubin schrieb:
>> Plenty of programming languages already support unicode identifiers, 
> 
> Could you name a few?  Thanks.

The GNU assembler also supports non-ASCII symbol names on object file
formats that support it; this includes at least ELF (not sure about
PE32). Higher-level programming languages can use that to encode symbols
in UTF-8.

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


How to calculate definite integral with python

2007-05-14 Thread [EMAIL PROTECTED]
I'm trying to do some integral calculation. I have searched the web, but 
haven't found any useful information. Will somebody point me to the 
right resources on the web for this job ?

Thanks a lot.

ps. Can numpy be used for this job?*
*
-- 
http://mail.python.org/mailman/listinfo/python-list


ClientForm .click() oddity

2007-05-14 Thread Gordon Airporte
I've written a script using ClientForm to automate opening and closing 
ports on my Linksys router. It works, but I wonder if there isn't a 
better way to do it.
The problem is that the list of arguments in the request generated by 
.click()ing the form is incomplete and I have to edit it manually. The 
Submit button on the form is created with the following code:

document.write("");

Which calls this function in the form source:

function to_submit(F)
{
 F.submit_button.value = "Forward";
 F.action.value = "Apply";
 F.submit();
}

Simply .click()ing on the form does not properly fill in 
submit_button=Forward&action=apply, however. The arguments are there but 
with no values.
Is this because ClientForm doesn't run javascript, or is there a way to 
determine and fix these values without manually editing the .data string 
of the Request with values I have to find on my own?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python Power Point Slides

2007-05-14 Thread Steven D'Aprano
On Tue, 15 May 2007 02:48:47 +0200, Irmen de Jong wrote:

> Krypto wrote:
>> Hi,
>> 
>> I want to give a short presentation in my group about benefits of
>> python, why should one use python and some basic starting information
>> about python, about its data type, etc.
>> 
>> Can somebody point me to the right references on the web. I have
>> searched a lot and I do get quite a few but I thought to check on
>> newsgroup for a better presentation, or if you have prepared any, can
>> you please share it.
>> 
>> Thanks
>> 
>> 
> Ahem, if you can't create one yourself, how could you ever give a
> convincing presentation about these subjects? You'll have to tell your
> own story... You know the benefits of Python etc. yourself, don't you?

Doesn't mean (s)he is articulate enough to explain them in his own words 
without help, AND familiar enough with Powerpoint or OpenOffice to drive 
them effectively, AND has an artistic flair to make the slides not suck, 
AND has the time to do all these things.

Asking for a good presentation is no worse than asking for a good code 
library. Maybe Krypto is like some actors or professional Masters of 
Ceremonies: excellent at giving the speech, lousy at writing it.



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


Re: PEP 3131: Supporting Non-ASCII Identifiers

2007-05-14 Thread ZeD
Neil Hodgson wrote:

> Ada 2005 allows Unicode identifiers and even includes the constant
> '?' in Ada.Numerics.

this. is. cool.

(oh, and +1 for the pep)

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


Re: Generators in C code

2007-05-14 Thread Raymond Hettinger
On May 14, 9:55 pm, "Gabriel Genellina" <[EMAIL PROTECTED]>
wrote:
> I feel I'm out of luck, but if someone could point some way to write a  
> generator in C, I'be very grateful!

Perhaps the code in the itertools module will provide a good example
-- they behave like generators in many respects except that you are
responsible for tracking state and jumping to an appropriate resume
point.  Being C, it won't be as convenient as Python generators, but
should be able to translate any generator into equivalent C.


Raymond Hettinger


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


Generators in C code

2007-05-14 Thread Gabriel Genellina
Hi

I'd like to write a generator in C, callable from Python.
The only way to create a generator object I can see, is using  
PyGen_New(frame) - and a frame object implies Python code, right? holding  
global state and local variables and stack and a lot of stuff, so perhaps  
there is no (easy) way I could write that in C code.
Or perhaps some way to execute a yield statement inside a C function?  
Being able to resume execution at the same point later?
I feel I'm out of luck, but if someone could point some way to write a  
generator in C, I'be very grateful!

-- 
Gabriel Genellina

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


Re: Sorting troubles

2007-05-14 Thread seyensubs
On May 15, 5:35 am, Steven D'Aprano
<[EMAIL PROTECTED]> wrote:
> On Mon, 14 May 2007 09:49:56 -0700, Thomas Nelson wrote:
> > The thing is that [x for x in List[1:]...] is a brand new list created
> > by iterating over the old one.
> > How about:
> > qSortHelp(List):
> > newlist = qSort(List)
> > for i, val in enumerate(newlist):
> > List[i] = val
> > You have to iterate over one more time, but this sorts the list in
> > place.
>
> A better way of spelling that would be:
>
> def qSortHelp(List):
> List[:] = qSort(List)
> return List
>
> but the helper function is redundant, as it is easy enough to make the
> qSort function behave the same way. We can also make the code a smidgen
> more concise by reversing the sense of the test at the start of the code:
>
> def qSort(List):
> if List:
> List[:] = qSort([x for x in List[1:] if x< List[0]]) \
> + List[0:1] + qSort([x for x in List[1:] if x>=List[0]])
> return List
>
> --
> Steven.

Ah, I see, just slicing it like that.. nice!
But after doing some timing tests, the version that's in place and
using partitions is about twice faster than the non hybrid qSort.
The hybrid one, with insertionsSort used for smaller lists works
faster, but in a weird way. When given lists of 2000, the best bet to
is to set the threshold to 14, but when given a list of 4, 14 is
slow, but a threshold of 200(less or more is slower, again) makes it
about 8 times faster than a normal qSort, and 4 times faster than an
in-place qSort, using a self -defined partitioning alg.

Making a hybrid out of the in-place partitioned qSort makes it a bit
faster, but not by much compared to the other hybrid which uses list
comprehensions.

Teach said that the optimal threshold in hybrids is 14-16, but guess
he wasn't so right after all =\\ The overhead of using insertion sort
on a longer list turns out to be faster than just piling on
recursions, when confronted with bigger lists.

I should probably try and make it iterative now, see how it goes.
Gonna need a stack though, I think.

Thanks for all the answers up to now! :)

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


Re: Interesting list Validity (True/False)

2007-05-14 Thread [EMAIL PROTECTED]
On May 14, 8:10?pm, Carsten Haese <[EMAIL PROTECTED]> wrote:
> On Mon, 2007-05-14 at 11:41 -0700, [EMAIL PROTECTED] wrote:
> > On May 13, 8:24 am, Steven D'Aprano
> > <[EMAIL PROTECTED]> wrote:
> > > On Sat, 12 May 2007 21:50:12 -0700, [EMAIL PROTECTED] wrote:
> > > >> > 
> > > >> > "if arg==True" tests whether the object known as arg is equal to the
> > > >> > object known as True.
> > > >> > 
>
> > > >> Not at all, it makes perfect sense. X == Y always tests whether the
> > > >> argument X is equal to the object Y regardless of what X and Y are.
>
> > > > Except for the exceptions, that's why the statement is wrong.
>
> > > But there are no exceptions.
>
> > 
> > Sec 2.2.3:
> > Objects of different types, *--->except<---* different numeric types
> > and different string types, never compare equal;
> > 
>
> The exceptions you mean are not exceptions to "'X==Y' means 'X equals
> Y'".

I never said they were. I said they were exceptions to
"Obbjects of different types never compare equal".

> They are exceptions to "'X equals Y' means 'X is mathematically the
> same as Y',"

Who's "they"?. (1,2) and [1,2] are mathematically equal but
the == comparison returns False. They are not an exception
to "mathematically equal", neither are they exceptions to
"different types never compare equal".

1 and mpz(1) compare equal so aren't an exception to
"mathematically equal" although they are an exception
to "different types never compare equal".

You need to be more explicit about what you're
talking about, as this last argument makes no sense.

> but that is not how equality is actually defined.

Ok, I'll bite. How is "equality" defined?

Are you implying that I can interchange 1 and mpz(1)
because the == comparison returns True?

Are you implying that I can't interchange (1,2) and [1,2]
because the == comparison returns False?

Please make sure your definition deals with these cases.

>
> --
> Carsten Haesehttp://informixdb.sourceforge.net

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


Re: Class name as argument

2007-05-14 Thread Gabriel Genellina
En Mon, 14 May 2007 19:34:52 -0300, HMS Surprise <[EMAIL PROTECTED]>  
escribió:

> Snippet 1 below doesn't do much but works (more code is inserted by a
> generator). In the next to last line the class name is also used as
> argument. I have seen this construct before and have had error
> messages tell me that the name is expected. Why is this so? In snippet
> 2 that I concocted is not required. Is it related to __init__ perhaps?

The arguments are those expected by the class constructor: __new__, and  
initializer: __init__.
It's up to the class designer to define which arguments are required -if  
any- and which ones are optional -if any-.
In your case, see the documentation for PyHttpTestCase.

-- 
Gabriel Genellina

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


Re: multi-line input?

2007-05-14 Thread Gabriel Genellina
En Mon, 14 May 2007 18:50:35 -0300, <[EMAIL PROTECTED]> escribió:

> I'm writing a C++ application with an embedded Python interpreter.
> Command text is captured and passed to the interpreter a single line
> at a time. My question is this: is there a simple way of determining
> whether a given input line of text will cause the prompt to change
> from the regular ">>>" to the multi-line "..." before sending the text
> to the interpreter? I suppose the completely correct solution would be
> tokenize and parse the entire string and then examine all the
> constituent parts, but that seems like a lot more work than I really
> want to do.

There is an emulation of the read-eval-print loop written in Python  
itself, see the code module. In particular, compile_command tries to  
determine whether the entered text is a complete Python statement,  
contains a syntax error, or requires more input.
If you want to stay with C code, you could use Py_CompileString and see if  
the already entered code can be compiled or not - but I'm not sure if you  
will actually be able to distinguish a SyntaxError from an incomplete  
statement.

> As far as I can tell, there are only a few ways to trigger the multi-
> line input prompt:
>
> - if-statement, for-loop, function or class definition
> - line continuation (\)
> - block quote (""" or ''')

- Any expression involving an open group of () [] {}

-- 
Gabriel Genellina

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


Re: How to do basic CRUD apps with Python

2007-05-14 Thread James T. Dennis
Bruno Desthuilliers <[EMAIL PROTECTED]> wrote:
> walterbyrd a ?crit :

>> With PHP, libraries, apps, etc. to do basic CRUD are everywhere. Ajax
>> and non-Ajax solutions abound.

>> With Python, finding such library, or apps. seems to be much more
>> difficult to find.

>> I thought django might be a good way, but I can not seem to get an
>> answer on that board.

>> I would like to put together a CRUD grid with editable/deletable/
>> addable fields, click on the headers to sort. Something that would
>> sort-of looks like an online  spreadsheet. It would be nice if the
>> fields could be edited in-line, but it's not entirely necessary.

>> Are there any Python libraries to do that sort of thing? Can it be
>> done with django or cherrypy?

> You may want to have a look at turbogears's widgets.

 Admittedly I had to look up the meaning of CRUD in this context:
 (http://en.wikipedia.org/wiki/Create%2C_read%2C_update_and_delete
 create, read, update, and delete).

 I'm looking at Turbogears' Widgets in another window as I type
 this ... but it will be awhile before I can comment on how they
 might apply to the OP's needs.  Actually I'm wholly unqualified
 to comment on his or her needs ... but I can comment on how I
 interpreted the question.

 Even with the SQLAlchemy SQLSoup examples there's still an
 annoying about of boilerplate coding that has to be done in order
 to create a web application for doing CRUD on a database.

 The missing element seems to be the ability to autogenerate
 web forms and reports with the requisite controls in them.

 Imagine, for a moment, being able to do something like:

>>> import sqlalchemy.ext.webcrud as crud
>>> db = crud.open()
>>> db.displayTopForm()
''

 ... and having a default "top level" web page generated with
 options to query the database (or some specific table in the
 database to be more specific, add new entries, etc).

 I'm thinking of some sort of class/module that would generate
 various sorts of HTML forms by default, but also allow one to
 sub-class each of the form/query types to customize the contents.

 It would use introspection on the database columns and constraints
 to automatically generate input fields for each of the columns and
 even fields for required foreign keys (or links to the CRUD for those
 tables?).  Ideally it would also automatically hide autogenerated
 (index/key) fields, and map the table column IDs to form names (with
 gettext support for l10n of those).

 I think that's the sort of thing the OP was looking for.  Not the
 ORM ... the the glue between the web framework and the ORM.
  

-- 
Jim Dennis,
Starshine: Signed, Sealed, Delivered

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


Re: Sorting troubles

2007-05-14 Thread Steven D'Aprano
On Mon, 14 May 2007 09:49:56 -0700, Thomas Nelson wrote:

> The thing is that [x for x in List[1:]...] is a brand new list created
> by iterating over the old one.
> How about:
> qSortHelp(List):
> newlist = qSort(List)
> for i, val in enumerate(newlist):
> List[i] = val
> You have to iterate over one more time, but this sorts the list in
> place.

A better way of spelling that would be:

def qSortHelp(List):
List[:] = qSort(List)
return List


but the helper function is redundant, as it is easy enough to make the 
qSort function behave the same way. We can also make the code a smidgen 
more concise by reversing the sense of the test at the start of the code:


def qSort(List):
if List:
List[:] = qSort([x for x in List[1:] if x< List[0]]) \
+ List[0:1] + qSort([x for x in List[1:] if x>=List[0]])
return List



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


Subprocess with and without shell

2007-05-14 Thread George Sakkis
I'm trying to figure out why Popen captures the stderr of a specific
command when it runs through the shell but not without it. IOW:

cmd = [my_exe, arg1, arg2, ..., argN]
if 1: # this captures both stdout and stderr as expected
pipe = Popen(' '.join(cmd), shell=True, stderr=PIPE, stdout=PIPE)
else: # this captures only stdout
pipe = Popen(cmd, shell=False, stderr=PIPE, stdout=PIPE)

# this prints the empty string if not run through the shell
print "stderr:", pipe.stderr.read()
# this prints correctly in both cases
print "stdout:", pipe.stdout.read()

Any hints ?

George

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


Re: PEP 3131: Supporting Non-ASCII Identifiers

2007-05-14 Thread Paul Rubin
Stefan Behnel <[EMAIL PROTECTED]> writes:
> But then, where's the problem? Just stick to accepting only patches that are
> plain ASCII *for your particular project*. 

There is no feature that has ever been proposed for Python, that cannot
be supported with this argument.  If you don't like having a "go to"
statement added to Python, where's the problem?  Just don't use it in
your particular project.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Interesting list Validity (True/False)

2007-05-14 Thread Carsten Haese
On Mon, 2007-05-14 at 11:41 -0700, [EMAIL PROTECTED] wrote:
> On May 13, 8:24 am, Steven D'Aprano
> <[EMAIL PROTECTED]> wrote:
> > On Sat, 12 May 2007 21:50:12 -0700, [EMAIL PROTECTED] wrote:
> > >> > 
> > >> > "if arg==True" tests whether the object known as arg is equal to the
> > >> > object known as True.
> > >> > 
> >
> > >> Not at all, it makes perfect sense. X == Y always tests whether the
> > >> argument X is equal to the object Y regardless of what X and Y are.
> >
> > > Except for the exceptions, that's why the statement is wrong.
> >
> > But there are no exceptions.
> 
> 
> Sec 2.2.3:
> Objects of different types, *--->except<---* different numeric types
> and different string types, never compare equal;
> 

The exceptions you mean are not exceptions to "'X==Y' means 'X equals
Y'". They are exceptions to "'X equals Y' means 'X is mathematically the
same as Y'," but that is not how equality is actually defined.

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


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


Re: Hello gettext

2007-05-14 Thread James T. Dennis
James T. Dennis <[EMAIL PROTECTED]> wrote:

 ... just to follow-up my own posting --- as gauche as that is:

> You'd think that using things like gettext would be easy.  Superficially
> it seems well documented in the Library Reference(*).  However, it can
> be surprisingly difficult to get the external details right.

>* http://docs.python.org/lib/node738.html 

> Here's what I finally came up with as the simplest instructions, suitable
> for an "overview of Python programming" class:

> Start with the venerable "Hello, World!" program ... slightly modified
> to make it ever-so-slightly more "functional:"



>#!/usr/bin/env python
>import sys

>def hello(s="World"):
>print "Hello,", s

>if __name__ == "__main__":
>args = sys.argv[1:]
>if len(args):
>for each in args:
>hello(each)
>else:
>hello()

> ... and add gettext support (and a little os.path handling on the
> assumption that our message object files will not be readily
> installable into the system /usr/share/locale tree):

>#!/usr/bin/env python
>import sys, os, gettext

>_ = gettext.lgettext
>mydir = os.path.realpath(os.path.dirname(sys.argv[0]))
>localedir = os.path.join(mydir, "locale")
>gettext.bindtextdomain('HelloPython', localedir)
>gettext.textdomain('HelloPython')

>def hello(s=_("World")):
>print _("Hello,"), s

 Turns out this particular version is a Bad Idea(TM) if you ever
 try to import this into another script and use it after changing
 you os.environ['LANG'] value.

 I mentioned in another message awhile back that I have an aversion
 to using defaulted arguments other than by setting them as "None"
 and I hesitated this time and then thought: "Oh, it's fine in this
 case!"

 Here's my updated version of this script:

 ---

#!/usr/bin/env python
import gettext, os, sys

_ = gettext.lgettext
i18ndomain = 'HelloPython'
mydir = os.path.realpath(os.path.dirname(sys.argv[0]))
localedir = os.path.join(mydir, "locale")
gettext.install(i18ndomain, localedir=None, unicode=1)
gettext.bindtextdomain(i18ndomain, localedir)
gettext.textdomain(i18ndomain)

def hello(s=None):
"""Print "Hello, World" (or its equivalent in any supported language):

   Examples:
  >>> os.environ['LANG']=''
  >>> hello()
  Hello, World
  >>> os.environ['LANG']='es_ES'
  >>> hello()
  Hola, Mundo
  >>> os.environ['LANG']='fr_FR'
  >>> hello()
  Bonjour, Monde

"""
if s is None:
s = _("World")
print _("Hello,"), s

def test():
import doctest
doctest.testmod()

if __name__ == "__main__":
args = sys.argv[1:]
if 'PYDOCTEST' in os.environ and os.environ['PYDOCTEST']:
test()
elif len(args):
for each in args:
hello(each)
else:
hello()

 ---

 ... now with doctest support. :)

>if __name__ == "__main__":
>args = sys.argv[1:]
>if len(args):
>for each in args:
>hello(each)
>else:
>hello()


> Note that I've only added five lines, the two modules to my import
> line, and wrapped two strings with the conventional _() function.

> This part is easy, and well-documented.

> Running pygettext or GNU xgettext (-L or --language=Python) is
> also easy and gives us a file like:


># SOME DESCRIPTIVE TITLE.
># Copyright (C) YEAR ORGANIZATION
># FIRST AUTHOR <[EMAIL PROTECTED]>, YEAR.
>#
>msgid ""
>msgstr ""
>"Project-Id-Version: PACKAGE VERSION\n"
>"POT-Creation-Date: 2007-05-14 12:19+PDT\n"
>"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
>"Last-Translator: FULL NAME <[EMAIL PROTECTED]>\n"
>"Language-Team: LANGUAGE <[EMAIL PROTECTED]>\n"
>"MIME-Version: 1.0\n"
>"Content-Type: text/plain; charset=CHARSET\n"
>"Content-Transfer-Encoding: ENCODING\n"
>"Generated-By: pygettext.py 1.5\n"


>#: HelloWorld.py:10
>msgid "World"
>msgstr ""

>#: HelloWorld.py:11
>msgid "Hello,"
>msgstr ""

> ... I suppose I should add the appropriate magic package name,
> version, author and other values to my source.  Anyone remember
> where those are documented?  Does pygettext extract them from the
> sources and insert them into the .pot?

> Anyway, I minimally have to change one line thus:

>"Content-Type: text/plain; charset=utf-8\n"

> ... and I suppose there are other ways to do this more properly.
> (Documented where?)

> I did find that I could either change that in the .pot file or
> in the individual .po files.  However, if I failed to chan

Re: customary way of keeping your own Python and module directory in $HOME

2007-05-14 Thread jmg3000
On May 14, 6:00 pm, James Stroud <[EMAIL PROTECTED]> wrote:
> [EMAIL PROTECTED] wrote:
> [snip], but on *nix,
> you can compile python with the "--prefix=" option set to a directory in
> your home dir and install there.

Check.

> I recommend having your own python install if you want a comprehensive
> approach.

Yup. I dropped the src in ~/src/Python-2.5.1, created a ~/py-2.5.1
directory, and did

./configure --prefix=/home/me/py-2.5.1
make
make install

and it worked fine. The only other step after that was creating a
symlink:

cd
ln -s py-2.5.1 py

and adding /home/me/py/bin to my $PATH.

> Doesn't seem like hyper-paranoid sysadmining is all that efficient, does it?

Well, on a server with many other users, they've pretty much gotta
keep you confined to your home directory.

My issues have been with keeping a ~/pylib directory for extra
modules, and reconciling that with setuptools / Easy Install. I'm
curious to hear how other folks manage their own local module
directory.

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


Re: Python Power Point Slides

2007-05-14 Thread Irmen de Jong
Krypto wrote:
> Hi,
> 
> I want to give a short presentation in my group about benefits of
> python, why should one use python and some basic starting information
> about python, about its data type, etc.
> 
> Can somebody point me to the right references on the web. I have
> searched a lot and I do get quite a few but I thought to check on
> newsgroup for a better presentation, or if you have prepared any, can
> you please share it.
> 
> Thanks
> 

Ahem, if you can't create one yourself, how could you ever give
a convincing presentation about these subjects?
You'll have to tell your own story...
You know the benefits of Python etc. yourself, don't you?

--Irmen

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


Re: tkinter button state = DISABLED

2007-05-14 Thread James Stroud
[EMAIL PROTECTED] wrote:
> I have created a button widget with a button click binding. The button
> initially has a state=disabled. I can see the greyed out version of
> the button in the GUI. But If I click on the button it still invokes
> the callback/binding function.
> 
> Any suggestions as to why the callback is being invoked even though
> the button has a disabled state. It looks like-
> 
> b=Button(frame,  text = "Button", state = 'disabled')
> 
> b.bind("",
> lambda
> event :
>   function()
>   )
> 
> Thanks
> Rahul
> 

DISABLED refers to the whether the function supplied in the "command" 
parameter is called when the button is pressed, other bindings are 
irrelevant, so you will need code to re-bind any events you have bound 
when the button is "disabled". So its better to just use the "command" 
parameter rather than binding mouse events.

An exception is Checkbutton, where you might want to bind 
 and then query the button's state (or the state of an 
IntVar associated with it) to make a decision--if you want a GUI to 
respond real-time to user events.

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


Re: PEP 3131: Supporting Non-ASCII Identifiers

2007-05-14 Thread Neil Hodgson
Martin v. Löwis:

> Specification-wise, C99 and C++98 also support Unicode identifiers,
> although many compilers still don't.

Ada 2005 allows Unicode identifiers and even includes the constant 
'π' in Ada.Numerics.

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

Re: PEP 3131: Supporting Non-ASCII Identifiers

2007-05-14 Thread Martin v. Löwis
Neil Hodgson schrieb:
> Paul Rubin wrote:
>>> Plenty of programming languages already support unicode identifiers, 
>>
>> Could you name a few?  Thanks.
> 
>C#, Java, Ecmascript, Visual Basic.

Specification-wise, C99 and C++98 also support Unicode identifiers,
although many compilers still don't.

For dynamic languages, Groovy also supports it.

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


Python Power Point Slides

2007-05-14 Thread Krypto
Hi,

I want to give a short presentation in my group about benefits of
python, why should one use python and some basic starting information
about python, about its data type, etc.

Can somebody point me to the right references on the web. I have
searched a lot and I do get quite a few but I thought to check on
newsgroup for a better presentation, or if you have prepared any, can
you please share it.

Thanks

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


Class name as argument

2007-05-14 Thread HMS Surprise
Snippet 1 below doesn't do much but works (more code is inserted by a
generator). In the next to last line the class name is also used as
argument. I have seen this construct before and have had error
messages tell me that the name is expected. Why is this so? In snippet
2 that I concocted is not required. Is it related to __init__ perhaps?

Thanks,

jvh

# Snippet 1 ~~~

from PyHttpTestCase import PyHttpTestCase

# definition of test class
class MaxQTest(PyHttpTestCase):
def runTest(self):
self.msg('Test started')

# ^^^ Insert new recordings here.  (Do not remove this line.)

# Code to load and run the test
if __name__ == 'main':
test = MaxQTest("MaxQTest")
test.Run()


# Snippet 2 ~~~

class topClass():
str = 'abc'
def tcMsg(self):
print 'topClass tcMsg'

class one(topClass):
strOne = 'class one'

def classOneFun(self):
print 'this is classOneFun'
self.tcMsg()

if __name__ == 'main':
test = one()
test.classOneFun()

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


Re: deployment scripts

2007-05-14 Thread [EMAIL PROTECTED]
On May 14, 9:32 am, Erin <[EMAIL PROTECTED]> wrote:
> Does anyone have experience developing deployment scripts with Jython?

csound blue is open source and uses jython, ..  I don't have the url
on me though

http://www.stormpages.com/edexter/csound.html

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


Re: PEP 3131: Supporting Non-ASCII Identifiers

2007-05-14 Thread Martin v. Löwis
> Not providing an explicit listing of allowed characters is inexcusable
> sloppiness.

That is a deliberate part of the specification. It is intentional that
it does *not* specify a precise list, but instead defers that list
to the version of the Unicode standard used (in the unicodedata
module).

> The XML standard is an example of how listings of large parts of the
> Unicode character set can be provided clearly, exactly and (almost)
> concisely.

And, indeed, this is now recognized as one of the bigger mistakes
of the XML recommendation: they provide an explicit list, and fail
to consider characters that are unassigned. In XML 1.1, they try
to address this issue, by now allowing unassigned characters in
XML names even though it's not certain yet what those characters
mean (until they are assigned).

>> ``ID_Continue`` is defined as all characters in ``ID_Start``, plus
>> nonspacing marks (Mn), spacing combining marks (Mc), decimal number
>> (Nd), and connector punctuations (Pc).
> 
> Am I the first to notice how unsuitable these characters are?

Probably. Nobody in the Unicode consortium noticed, but what
do they know about suitability of Unicode characters...

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


Hello gettext

2007-05-14 Thread James T. Dennis

 You'd think that using things like gettext would be easy.  Superficially
 it seems well documented in the Library Reference(*).  However, it can
 be surprisingly difficult to get the external details right.

* http://docs.python.org/lib/node738.html 

 Here's what I finally came up with as the simplest instructions, suitable
 for an "overview of Python programming" class:

 Start with the venerable "Hello, World!" program ... slightly modified
 to make it ever-so-slightly more "functional:"



#!/usr/bin/env python
import sys

def hello(s="World"):
print "Hello,", s

if __name__ == "__main__":
args = sys.argv[1:]
if len(args):
for each in args:
hello(each)
else:
hello()

 ... and add gettext support (and a little os.path handling on the
 assumption that our message object files will not be readily
 installable into the system /usr/share/locale tree):

#!/usr/bin/env python
import sys, os, gettext

_ = gettext.lgettext
mydir = os.path.realpath(os.path.dirname(sys.argv[0]))
localedir = os.path.join(mydir, "locale")
gettext.bindtextdomain('HelloPython', localedir)
gettext.textdomain('HelloPython')

def hello(s=_("World")):
print _("Hello,"), s

if __name__ == "__main__":
args = sys.argv[1:]
if len(args):
for each in args:
hello(each)
else:
hello()

 Note that I've only added five lines, the two modules to my import
 line, and wrapped two strings with the conventional _() function.

 This part is easy, and well-documented.

 Running pygettext or GNU xgettext (-L or --language=Python) is
 also easy and gives us a file like:


# SOME DESCRIPTIVE TITLE.
# Copyright (C) YEAR ORGANIZATION
# FIRST AUTHOR <[EMAIL PROTECTED]>, YEAR.
#
msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"POT-Creation-Date: 2007-05-14 12:19+PDT\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <[EMAIL PROTECTED]>\n"
"Language-Team: LANGUAGE <[EMAIL PROTECTED]>\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=CHARSET\n"
"Content-Transfer-Encoding: ENCODING\n"
"Generated-By: pygettext.py 1.5\n"


#: HelloWorld.py:10
msgid "World"
msgstr ""

#: HelloWorld.py:11
msgid "Hello,"
msgstr ""

 ... I suppose I should add the appropriate magic package name,
 version, author and other values to my source.  Anyone remember
 where those are documented?  Does pygettext extract them from the
 sources and insert them into the .pot?

 Anyway, I minimally have to change one line thus:

"Content-Type: text/plain; charset=utf-8\n"

 ... and I suppose there are other ways to do this more properly.
 (Documented where?)

 I did find that I could either change that in the .pot file or
 in the individual .po files.  However, if I failed to change it
 then my translations would NOT work and would throw an exception.

 (Where is the setting to force the _() function to fail gracefully
 --- falling back to no-translation and NEVER raise exceptions?
 I seem to recall there is one somewhere --- but I just spent all
 evening reading the docs and various Google hits to get this far; so
 please excuse me if it's a blur right now).

 Now we just copy these templates to individual .po files and
 make our LC_MESSAGES directories:

mkdir locale && mv HelloPython.pot locale
cd locale

for i in es_ES fr_FR # ...
do
cp HelloPython.pot HelloPython_$i.po
mkdir -p $i/LC_MESSAGES
done

 ... and finally we can work on the translations.

 We edit each of the _*.po files inserting "Hola" and "Bonjour" and
 "Mundo" and "Monde" in the appropriate places.  And then process
 these into .mo files and move them into place as follows:

for i in *_*.po; do 
i=${i#*_} 
msgfmt -o ./${i%.po}/LC_MESSAGES/HelloPython.mo 
done

 ... in other words HelloPython_es_ES.po is written to 
 ./es_ES/LC_MESSAGES/HelloPython.mo, etc.

 This last part was the hardest to get right. 

 To test this we simply run:

$HELLO_PATH/HelloPython.py
Hello, World

export LANG=es_ES
$HELLO_PATH/HelloPython.py
Hola, Mundo

export LANG=fr_FR
$HELLO_PATH/HelloPython.py
Bonjour, Monde

export LANG=zh_ZH
$HELLO_PATH/HelloPython.py
Hello, World

 ... and we find that our Spanish and French translations work. (With
 apologies if my translations are technically wrong).

 Of course I realize this only barely scratches the surface of I18n and
 L10n issues.  Also I don't know, offhand, how

Re: Time

2007-05-14 Thread HMS Surprise

>
> Do you mean 12 Noon or 12 Midnight?   12AM and 12PM don't exist,
> do they?
>


>>> t = (2007, 5, 14, 12, 0,0,0,0,0)
>>> strftime('%p', t)
'PM'
>>> t = (2007, 5, 14, 0,0,0,0,0,0)
>>> strftime('%p', t)
'AM'
>>>

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


Re: PEP 3131: Supporting Non-ASCII Identifiers

2007-05-14 Thread Martin v. Löwis
> In <[EMAIL PROTECTED]>, Nick Craig-Wood
> wrote:
> 
>> My initial reaction is that it would be cool to use all those great
>> symbols.  A variable called OHM etc!
> 
> This is a nice candidate for homoglyph confusion.  There's the Greek
> letter omega (U+03A9) Ω and the SI unit symbol (U+2126) Ω, and I think
> some omegas in the mathematical symbols area too.

Under the PEP, identifiers are converted to normal form NFC, and
we have

py> unicodedata.normalize("NFC", u"\u2126")
u'\u03a9'

So, OHM SIGN compares equal to GREEK CAPITAL LETTER OMEGA. It can't
be confused with it - it is equal to it by the proposed language
semantics.

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

Re: file uploader

2007-05-14 Thread James T. Dennis
Gabriel Genellina <[EMAIL PROTECTED]> wrote:
> En Sun, 13 May 2007 18:41:16 -0300, Sick Monkey <[EMAIL PROTECTED]>  
> escribi?:

>> If anyone has a simpler way of checking to see if
>> a file already exists (prior to uploading to a server) and renaming it,
>> please let me know.

> I will ignore the "server" part...

>> Here is the code that I am using (it runs exactly the same as the linux  
>> app
>> 'arcgen').
>>  [...]
>>  t = i-1
>>  filename=string.replace(filename,".-%s" % (t),".-%s" % (i))

> If the original filename contained .-1 somewhere, you're modifying it.  
> This is safer and shorter:

> import os,string
> filename = "whoa.mp3"
> dir_path = "/u01/"
> ofilename = filename
> i = 0
> while os.path.exists(dir_path+filename):
>  filename = "%s.-%s" % (ofilename,i)
>  i += 1
> req.write(filename)


 Is it really safer?  Couldn't their still be a race condition
 (if some hostile process has write access to the directory in
 which this is being attempted)?  

 Wouldn't it be safer to import tempfile, use the t=NamedTemporaryFile()
 function therein and then use try: os.link(t.name, ...) except OSError:
 to safely rename it?

 Something like:

import os, tempfile
tdir = "/u01/"
tf = tempfile.NamedTemporaryFile(dir="/u01/"

i = 0
while 1:
try:
os.link(tf.name, os.path.join(tdir, filename)
except OSError:
i += 1
filename = "%s.-%s" % (filename, i)
else:
break

 ...???


-- 
Jim Dennis,
Starshine: Signed, Sealed, Delivered

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


Re: customary way of keeping your own Python and module directory in $HOME

2007-05-14 Thread James Stroud
[EMAIL PROTECTED] wrote:
> What's the customary way to keep your own local Python and package
> directory? For example, when you're on a server where you don't have
> root access, and everything must go in your home directory.
> 
> * What directories do you create?
> * What environment variables do you set?
> * What config files do you keep?
> * Does that setup work with distutils and setuptools? What special
> options do you need to pass to these tools when installing modules for
> everything to work right?
> 
> Please, share your tips.
> 

You can do more than you can imagine as non-root even if you have 
hyper-paranoid sysadmins who don't know how to protect infrastructure 
without shackling the users.

I don't know about windoze (pro-windoze complainers: yep, I'm spelling 
it wrong on purpose, please complain elsewhere about my anti-windoze 
spelling :P -- If you want to be a pro-windoze speller, take the time to 
give your own answers instead of complaining all the time), but on *nix, 
you can compile python with the "--prefix=" option set to a directory in 
your home dir and install there. Because python is compiled with the 
prefix, you will not need to adjust the path if you add modules to the 
site-packages directory. If you have your own modules, but they aren't 
ready for site-packages, you can alter PYTHONPATH to point at your 
staging directory.

I recommend having your own python install if you want a comprehensive 
approach. Sometimes you need to build your own Tcl/Tk and blt-wish if 
you have a linux version that predates the python dependency 
requirements, though. If you know the dependencies, its all very 
"configure --prefix= ; make ; make install", with proper settings of 
LD_LIBRARY path.

Doesn't seem like hyper-paranoid sysadmining is all that efficient, does it?

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


multi-line input?

2007-05-14 Thread joshusdog
I'm writing a C++ application with an embedded Python interpreter.
Command text is captured and passed to the interpreter a single line
at a time. My question is this: is there a simple way of determining
whether a given input line of text will cause the prompt to change
from the regular ">>>" to the multi-line "..." before sending the text
to the interpreter? I suppose the completely correct solution would be
tokenize and parse the entire string and then examine all the
constituent parts, but that seems like a lot more work than I really
want to do.

As far as I can tell, there are only a few ways to trigger the multi-
line input prompt:

- if-statement, for-loop, function or class definition
- line continuation (\)
- block quote (""" or ''')

Any help would be greatly appreciated.

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


RE: os.listdir() doesn't work ??

2007-05-14 Thread Looney, James B
The case sensitivity has to do with the OS you're on.  So, using glob
from Un*x is case sensitive, but from Windows it isn't.
 

-Original Message-
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] On
Behalf Of Stef Mientki
Sent: Monday, May 14, 2007 3:39 PM
To: python-list@python.org
Subject: Re: os.listdir() doesn't work ??

Michel Claveau wrote:
> Hi!
> 
> 
>> You want the glob module
> 
> Warning: glob has "unix like behavior"; just a little different with 
> windows's DIR

Don't know the details of "Unix"
but I thought "unix" was case-sensitive,
and glob.glob doesn't seem to be,
at least not on windows systems ;-)

cheers,
Stef Mientki
-- 
http://mail.python.org/mailman/listinfo/python-list
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: os.listdir() doesn't work ??

2007-05-14 Thread Stef Mientki
Michel Claveau wrote:
> Hi!
> 
> 
>> You want the glob module
> 
> Warning: glob has "unix like behavior"; just a little different with 
> windows's DIR

Don't know the details of "Unix"
but I thought "unix" was case-sensitive,
and glob.glob doesn't seem to be,
at least not on windows systems ;-)

cheers,
Stef Mientki
-- 
http://mail.python.org/mailman/listinfo/python-list


swig %typemap generated list typeerror

2007-05-14 Thread txtoth
I'm trying to map a security_context_t ** to a python list. After
calling the method that returns this type when I process the returned
list in a for loop I get:
TypeError: expected string or Unicode object, NoneType found
after processing the last list entry. Can anyone see what I'm doing
wrong? Do I need to do something else to the list to somehow terminate
it?

%typemap(argout) security_context_t ** {
   PyObject *list_security_context = PyList_New(0); // Create the
list.
   if (list_security_context) {
   security_context_t **p_p_security_context_t = arg3;
   while (*p_p_security_context_t) { // Move each string
into the list.
   security_context_t *p_security_context_t =
*p_p_security_context_t;
   if (PyList_Append(list_security_context,
PyString_FromString((char
*)*p_security_context_t)) < 0) {
   fprintf(stderr, "Fail to insert item in
list.\n");
   $result = -1;
   break;
   }
   p_p_security_context_t++;
   }
   }
   else {
   fprintf(stderr, "Fail to create list.\n");
   $result = -1;
   }

   $result = SWIG_Python_AppendOutput($result,
list_security_context);

}

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


Re: os.listdir() doesn't work ??

2007-05-14 Thread Gabriel Genellina
En Mon, 14 May 2007 18:24:23 -0300, Stef Mientki  
<[EMAIL PROTECTED]> escribió:

>>>files = os.listdir('D:\\akto_yk\\yk_controle\\*.txt')
>>>
>>> I get an error message
>>>
>>>WindowsError: [Errno 123] The filename, directory name, or volume  
>>> label syntax is incorrect:
>>>'D:\\akto_yk\\yk_controle\\*.txt/*.*'

> Still don't know why it's not allowed through listdir ;-)

Because listir expects a single directory as parameter, not a wildcard  
specification.
That is, you could do:
files = os.listdir("D:\\akto_yk\\yk_controle")
to get ALL the filenames in that directory, and then filter them using  
fnmatch. But that's exactly what the glob module does internally.

-- 
Gabriel Genellina

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


Re: tkinter button state = DISABLED

2007-05-14 Thread Gabriel Genellina
En Mon, 14 May 2007 17:46:32 -0300, <[EMAIL PROTECTED]> escribió:

> On May 14, 12:01 pm, Peter Otten <[EMAIL PROTECTED]> wrote:
>> [EMAIL PROTECTED] wrote:
>> > b=Button(frame,  text = "Button", state = 'disabled')
>> > b.bind("",
>> > lambda
>> > event :
>> > function()
>> > )
>>
>> Well, the /mouse/ button /was/ released. Do you know about the  
>> alternative?
>>
>> b = Button(..., command=function) # no bind(), no lambda
>> It behaves like you expect.
>
> So, then is it right to say that for a widget like button widget on
> occurance of a 'event' the function which is bound to this event is
> invoked, even if the button widget has its 'state' option set to
> 'disabled'. I was assuming that if the button widget has state =
> 'disabled' then even on a button event the binding function wont be
> invoked.
> I will take a look at the alternative code you suggested above too.

Maybe there is a confusion here. You code above means that, when the event  
"The leftmost MOUSE BUTTON was released" happens over your BUTTON WIDGET  
b, your function will be called.
The "alternative code" suggested is the right way; the "command" is fired  
when the mouse button is pressed inside the widget AND then released  
inside the SAME widget (and the button is not disabled).

-- 
Gabriel Genellina

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


Re: os.listdir() doesn't work ??

2007-05-14 Thread Michel Claveau
Hi!


> You want the glob module

Warning: glob has "unix like behavior"; just a little different with 
windows's DIR






-- 
@-salutations

Michel Claveau


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


Re: os.listdir() doesn't work ??

2007-05-14 Thread Stef Mientki
timw.google wrote:
> On May 14, 4:09 pm, Stef Mientki <[EMAIL PROTECTED]>
> wrote:
>> hello,
>>
>> I want to find all files with the extension "*.txt".
>>  From the examples in "Learning Python, Lutz and Asher" and
>> from the website I see examples where you also may specify a wildcard 
>> filegroup.
>>
>> But when I try this
>>files = os.listdir('D:\\akto_yk\\yk_controle\\*.txt')
>>
>> I get an error message
>>
>>WindowsError: [Errno 123] The filename, directory name, or volume label 
>> syntax is incorrect:
>>'D:\\akto_yk\\yk_controle\\*.txt/*.*'
>>
>> What am I doing wrong ?
>>
>> thanks,
>> Stef Mientki
> 
> You want the glob module
> 
> http://docs.python.org/lib/module-glob.html
> 
> import glob
> glob.glob('*.txt')

thanks that works !
Still don't know why it's not allowed through listdir ;-)

cheers,
Stef Mientki
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: os.listdir() doesn't work ??

2007-05-14 Thread Steven Howe

Stef Mientki wrote:

hello,

I want to find all files with the extension "*.txt".
 From the examples in "Learning Python, Lutz and Asher" and
from the website I see examples where you also may specify a wildcard filegroup.

But when I try this
   files = os.listdir('D:\\akto_yk\\yk_controle\\*.txt')

I get an error message

   WindowsError: [Errno 123] The filename, directory name, or volume label syntax is incorrect: 
   'D:\\akto_yk\\yk_controle\\*.txt/*.*'	


What am I doing wrong ?

thanks,
Stef Mientki
  

Hi Stef,
Like that name; from a passing thought, I think the os.listdir command 
will resolve the slash/backslash. You might try using the unix method 
which I think would be 'd:/akto_yk/yk_controls/*.txt'. I'm sorry, but I 
can't test this knowledge, as I don't have access to Windows.


Alternatively you could use glob.glob, after changing directory ( via 
os.chdir) to get a listing.


   from os import chdir, getcwd
   from glob import glob

   CWD = getcwd()
   chdir( 'd:/akto_yk/yk_controls')
   filelist = glob.glob('*.txt')
   chdir( CWD )


Steven Howe

--
HEX: 09 F9 11 02 9D 74 E3 5B D8 41 56 C5 63 56 88 C0

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

Re: PEP 3131: Supporting Non-ASCII Identifiers

2007-05-14 Thread Michel Claveau
Hi!

;-)))

In whitespace-programming-language, only three characters are used : 
Space - Tab - RC

No parasitic characters in listings ; economy of ink ; ecological 
behavior ; LOL programming...

Must, Python, follow this way?






-- 
@-salutations

Michel Claveau


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


Re: track cpu usage of linux application

2007-05-14 Thread James T. Dennis
Fabian Braennstroem <[EMAIL PROTECTED]> wrote:
> Hi,

>I would like to track the cpu usage of a couple of
>programs using python. Maybe it works somehow with
>piping 'top' to python read the cpu load for a greped
>application and clocking the the first and last
>appearence. Is that a good approach or does anyone have
>a more elegant way to do that?

> Greetings!
> Fabian

 If you're on a Linux system you might be far better accessing
 the /proc/$PID/stat files directly. The values you'd find therein
 are documented:

http://www.die.net/doc/linux/man/man5/proc.5.html

 (among other places).

 Of course you could write you code to look for file and fall back
 to use the 'ps' command if it fails.  In addition you can supply
 arguments to the 'ps' command to limit it to reporting just on the
 process(es) in which you are interested ... and to eliminate the
 header line and irrelevant columns of output.


-- 
Jim Dennis,
Starshine: Signed, Sealed, Delivered

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


Re: Creating a function to make checkbutton with information from a list?

2007-05-14 Thread Thomas Jansson
On 13 Maj, 08:45, Peter Otten <[EMAIL PROTECTED]> wrote:
> Thomas Jansson wrote:
> > Dear all
>
> > I am writing a program with tkinter where I have to create a lot of
> > checkbuttons. They should have the same format but should have
> > different names. My intention is to run the functions and the create
> > all the buttons with the names from the list.
>
> > I now the lines below doesn't work, but this is what I have so far. I
> > don't really know how call the element in the dict use in the for
> > loop. I tried to call +'item'+ but this doesn't work.
>
> > def create_checkbox(self):
> >self.checkbutton = ["LNCOL", "LFORM", "LPOT", "LGRID",  "LERR",
> > "LCOMP"]
> >for item in self.checkbutton:
> >   self.+'item'+Checkbutton = Chekcbutton(frame, onvalue='t',
> > offvalue='f', variable=self.+'item'+)
> >   self.+'item'+Checkbutton.grid()
>
> > How should I do this?
>
> You /could/ use setattr()/getattr(), but for a clean design putting the
> buttons (or associated variables) into a dictionary is preferrable.
>
> def create_checkbuttons(self):
> button_names = ["LNCOL", "LFORM", "LPOT", "LGRID",  "LERR", "LCOMP"]
> self.cbvalues = {}
> for row, name in enumerate(button_names):
> v = self.cbvalues[name] = IntVar()
> cb = Checkbutton(self.frame, variable=v)
> label = Label(self.frame, text=name)
> cb.grid(row=row, column=0)
> label.grid(row=row, column=1)
>
> You can then find out a checkbutton's state with
>
> self.cbvalues[name].get()
>
> Peter

Both of you for your answers I ended up using the last one since it
seemed least complicated to new python programmer as my self. In the
case that anyone should ever read the post again and would like to see
what I ended up with:

self.button_names = ["LPOT", "LNCOL", "LFORM", "LGRID", "LERR",
"LCOMP", "LMAP", "LPUNCH", "LMEAN"]
button_state =  ["t", "t", "t"   , "t", "f"   ,
"f", "f"   , "t" , "f"]
self.cbvalues = {}
for row, name in enumerate(self.button_names):
  v = self.cbvalues[name] = StringVar() # It is a string variable so,
t or f can be store here
  self.cb = Checkbutton(frame, onvalue="t", offvalue="f", variable=v)
  label = Label(frame, text=name)
  label.grid(row=row+15, column=0, sticky=W)
  self.cb.grid(row=row+15, column=1, sticky=W)
  if button_state[row] == "t":
self.cb.select()
  else:
self.cb.deselect()

Kind regards
Thomas Jansson

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


Re: Time

2007-05-14 Thread Gabriel Genellina
En Mon, 14 May 2007 16:20:27 -0300, Grant Edwards <[EMAIL PROTECTED]>  
escribió:

 On May 14, 9:22 am, HMS Surprise <[EMAIL PROTECTED]> wrote:

 Oops +=1, should be:
  hrMn[0] = int(hrMn[0]
  if t[2] == 'PM':
  hrMn[0] += 12

 Need more starter fluid, coffee please!!!
>>>
>>> Still won't work for 12 AM nor 12 PM...
>>
>> Do you mean 12 Noon or 12 Midnight?   12AM and 12PM don't exist,
>> do they?
>
> http://www.astronomy.net/articles/13/

No. Even ignoring that exact instant at Noon or Midnight, 12:01 PM  
translates into itself, 12:01, on a 24 hr clock; and 12:01 AM becomes 0:01  
on a 24 hr clock. For hours between 01 PM and 11 PM, yes, you can follow  
the rule "add 12".

-- 
Gabriel Genellina

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


Re: Path python versions and Macosx

2007-05-14 Thread half . italian
On May 14, 4:46 am, andrea <[EMAIL PROTECTED]> wrote:
> On 12 Mag, 01:09, [EMAIL PROTECTED] wrote:
>
>
>
> > On May 11, 1:36 pm, andrea <[EMAIL PROTECTED]> wrote:
>
> > > Hi everyone,
> > > I use python on macosx with textmate as editor (great program).
>
> > > I also use macport to install unix programs from the command line and
> > > I find it great too.
> > > Well I would like to have all my modules in the path when I'm using
> > > textmate AND when I use the commandline (ipython), but because
> > > textmate and the command line use different python versions they also
> > > search in different places..
>
> > > I found somewhere to write .pythonrc.py like this
>
> > > #!/usr/bin/env python
> > > import sys
> > > PATH='/opt/local/lib/python2.4/site-packages/'
> > > sys.path.append(PATH)
> > > del sys
>
> > > But it doesn't work either, I also tried to append this
> > > PATH="/Library/Frameworks/Python.framework/Versions/Current/bin:/opt/
> > > local/lib/python2.4/site-packages:${PATH}
> > > to .bash_profile but nothing.
>
> > > Where should I set this variables??
>
> > > Thanks a lot
>
> > You can set environment variables for gui apps with this 
> > freeware:http://www.versiontracker.com/dyn/moreinfo/macosx/15073
>
> > You can edit some text files as well, but this thing just makes it
> > much easier.
>
> > ~Sean
>
> Ok thanks, but why it doesn't work setting the .bash_profile?? What
> should I set manually theorically?? The problem is also that I have
> many modules for python 2.4 and trying to import them from the 2.5 of
> course gives errors..
> I installed them with macports (compiling), how can I make them switch
> to 2.5???
> thanks

Gui applications are not launched through the bash shell.
The .bash_profile never gets read.

You can accomplish the same thing as the freewware app I mentioned by
editing the xml file at ~/.MacOSX/environment.plist.  Its a simple xml
file with keys and their corresponding values.

Not sure about the modules.  You can force a script to look for libs
in a given directory like you mentioned, but that needs to go at the
top of each python file instead of a .pythonrc file.  Maybe the
modules will work with 2.5, maybe not.

~Sean

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


Re: tkinter button state = DISABLED

2007-05-14 Thread rahulnag22
On May 14, 12:01 pm, Peter Otten <[EMAIL PROTECTED]> wrote:
> [EMAIL PROTECTED] wrote:
> > I have created a button widget with a button click binding. The button
> > initially has a state=disabled. I can see the greyed out version of
> > the button in the GUI. But If I click on the button it still invokes
> > the callback/binding function.
>
> > Any suggestions as to why the callback is being invoked even though
> > the button has a disabled state. It looks like-
>
> > b=Button(frame,  text = "Button", state = 'disabled')
>
> > b.bind("",
> > lambda
> > event :
> > function()
> > )
>
> Well, the /mouse/ button /was/ released. Do you know about the alternative?
>
> b = Button(..., command=function) # no bind(), no lambda
>
> It behaves like you expect.
>
> Peter


So, then is it right to say that for a widget like button widget on
occurance of a 'event' the function which is bound to this event is
invoked, even if the button widget has its 'state' option set to
'disabled'. I was assuming that if the button widget has state =
'disabled' then even on a button event the binding function wont be
invoked.
I will take a look at the alternative code you suggested above too.

Thanks
Rahul

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


customary way of keeping your own Python and module directory in $HOME

2007-05-14 Thread jmg3000
What's the customary way to keep your own local Python and package
directory? For example, when you're on a server where you don't have
root access, and everything must go in your home directory.

* What directories do you create?
* What environment variables do you set?
* What config files do you keep?
* Does that setup work with distutils and setuptools? What special
options do you need to pass to these tools when installing modules for
everything to work right?

Please, share your tips.

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


Re: Bug? import cp1252

2007-05-14 Thread M�ta-MCI
Hi!

>>> I suspect that's there's some invisible character in the file

No ; because I reproduce the problem, on another CPU, with typing from 
scratch.



>>> I can't reproduce this -- Python 2.5.1, Windows XP Pro SP2

I'm sorry. Perhaps my "french" windows is a co-factor?
Perhaps my locale has Or my local influence?

I had try on four computer, with the same problem.



Fortunately, write in UTF-8 delete the problem...


-- 
Michel Claveau


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


Re: PEP 3131: Supporting Non-ASCII Identifiers

2007-05-14 Thread Jakub Stolarski
On May 14, 9:49 pm, Méta-MCI <[EMAIL PROTECTED]> wrote:
> Hi!
>
> - should non-ASCII identifiers be supported? why?
> - would you use them if it was possible to do so? in what cases?
>
> Yes.
>
> JScript  can use letters with accents in identifiers
> XML (1.1)  can use letters with accents in tags
> C# can use letters with accents in variables
> SQL: MySQL/MS-Sql/Oralcle/etc. can use accents in fields or request
> etc.
> etc.
>
> Python MUST make up for its lost time.
>
> MCI

And generally nobody use it.
It sounds like "are for art's sake".

But OK. Maybe it'll be some impulse to learn some new languages.

+1 for this PEP

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


Re: Simulating simple electric circuits

2007-05-14 Thread Bjoern Schliessmann
Arnaud Delobelle wrote:

> I'm interested! I was tempted to have a go at it after your
> initial post, it sounded like a nice little project :)

Here you go, see below (quite long). It works from Python 2.5
and above and should be straightly executable from command line.

(It'll work with lower Python versions if you backtranslate the
few "A if (condition) else B" parts.)

We have:
- class CurrentController which does the main work
- classes Source and Ground for convenience when creating circuits
- class Relay for the realisation of logic

Please have a look at the example at the end. It's taken from my
actual project. A relay "ZT" is brought up if an outside key is
pressed. This forces the normally-"up" latching relay "ZTS" down.
This in turn causes relay "FTS" to go "up" (which causes many
other complicated stuff).

I'm open for questions and/or suggestions. :) The names used and
docstrings may sound a bit strange since I hastily translated the
source from german (we have some very special terms regarding relay
technology).

I suspect that this is a dead end though, because in more complex 
designs the creation of circuits becomes cumbersome. Also, for the 
system I want to model, the circuits are OOH very complex and OTOH 
I don't have access to all circuit diagrams. :( So I think I'll try 
next to transfer my problem to digital two-level logic. 

I'll go with Dave Baum's suggestion with the event queue and post 
again here soon with report of my achievements ...

Regards,


Björn

---snip---
#!/usr/bin/env python

class CurrentController(object):

def __init__(self):
self.currentSources = {} 
# Contents: {ID1: source1, ID2: source2, ...}
self.circuits = {} 
# Contents: {ID1: [all circuits starting at source 1],
 ID2: [...], ...}

def newID(self):
ID = 0
while ID in self.currentSources:
ID += 1
return ID

def newSource(self, func = None):
id = self.newID()
s = Source(id, func)
self.currentSources[id] = s
return s

def newGround(self):
e = Ground()
return e

def newRelay(self, name, **argv):
r = Relay(name, **argv)
return r

def changed(self, relay):
"""
Relay relay changed. Re-try all circuits containing it.
"""
print "CurrentController: changed:", relay.name, "up" if relay.up else 
"down"
for ID, circuits in self.circuits.items():
for circuit in circuits:
if circuit.contains(relay):
circuit.test()

def showCircuits(self, activeOnly = False):
"""
Show all circuits.

If activeOnly is True, show only active ones.
"""
print "| Circuits: "
for ID, circuits in self.circuits.items():
print "| ID: %i" % ID
for circuit in circuits:
if (not activeOnly) or circuit.active:
print circuit


def start(self):
"""
All circuits are defined -- try them out and start
monitoring changes.
"""
for ID, source in self.currentSources.items():
source.start()

for ID, circuits in self.circuits.items():
for circuit in circuits:
circuit.test()



def toGround(self, telegram):
"""
Save telegram as valid circuit and monitor it.

Called from the outside if a telegram reaches "ground"
(i. e., circuit closed).
"""
try:
self.circuits[telegram.ID].append(telegram)
except KeyError:
self.circuits[telegram.ID] = [telegram]

class CurrentTelegram(object):
"""
Class for recording and managing a circuit.
"""
usedIDs = []

def __init__(self, id):
self.relays = [] 
# Contents: [(group name, relay object, coil function), ...]
self.switches = [] 
# Format: [(group name, relay object, switch function), ...]

self.ID = id   # ID of the source of this telegram
self.circuitID = self.newID() # unique telegram ID
 
# default priority is 1. Should always be > 0.
# It's used for weighing of multiple currents, see Relay class.
self.prio = 1
self.active = False

def newID(self):
ID = 0
while ID in self.usedIDs:
ID += 1
self.usedIDs.append(ID)
return ID

def __str__(self):
relays = [""]  # for an extra newline at the beginning of the string to 
return
for group, r, f in self.relays:
type = repr(f)
temp = "||| Group %s, Relay %s %s" % (group, r.name, type)
relays.append(temp)
relays = "\n".join(relays)

switches = [""]
for group, r, f in self.switches:
type = repr(f)
 

Re: os.listdir() doesn't work ??

2007-05-14 Thread timw.google
On May 14, 4:09 pm, Stef Mientki <[EMAIL PROTECTED]>
wrote:
> hello,
>
> I want to find all files with the extension "*.txt".
>  From the examples in "Learning Python, Lutz and Asher" and
> from the website I see examples where you also may specify a wildcard 
> filegroup.
>
> But when I try this
>files = os.listdir('D:\\akto_yk\\yk_controle\\*.txt')
>
> I get an error message
>
>WindowsError: [Errno 123] The filename, directory name, or volume label 
> syntax is incorrect:
>'D:\\akto_yk\\yk_controle\\*.txt/*.*'
>
> What am I doing wrong ?
>
> thanks,
> Stef Mientki

You want the glob module

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

import glob
glob.glob('*.txt')


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


os.listdir() doesn't work ??

2007-05-14 Thread Stef Mientki
hello,

I want to find all files with the extension "*.txt".
 From the examples in "Learning Python, Lutz and Asher" and
from the website I see examples where you also may specify a wildcard filegroup.

But when I try this
   files = os.listdir('D:\\akto_yk\\yk_controle\\*.txt')

I get an error message

   WindowsError: [Errno 123] The filename, directory name, or volume label 
syntax is incorrect: 
   'D:\\akto_yk\\yk_controle\\*.txt/*.*'

What am I doing wrong ?

thanks,
Stef Mientki
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: PEP 3131: Supporting Non-ASCII Identifiers

2007-05-14 Thread Méta-MCI
Hi!

- should non-ASCII identifiers be supported? why?
- would you use them if it was possible to do so? in what cases?

Yes.

JScript  can use letters with accents in identifiers
XML (1.1)  can use letters with accents in tags
C# can use letters with accents in variables
SQL: MySQL/MS-Sql/Oralcle/etc. can use accents in fields or request
etc.
etc.

Python MUST make up for its lost time.


MCI




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


Re: Sorting troubles

2007-05-14 Thread Anton Vredegoor
[EMAIL PROTECTED] wrote:
> I see. I figured that list comprehensions made another list(duh), but
> I thought I could relink the object(List) to the new list and keep it
> once the function ended.
> 
> Is it possible to pass a reference(to an object.. Like 'List',
> basically) to a function and change the reference to point to
> something created inside a function? Or all data unreturned from a
> function is lost and no references kept?(The second, I'd guess, since
> it's local temporary scope, but you never know, maybe Python can :) )

Maybe this (untested):

def qsort(seq):
 if seq:
 pivot = seq.pop()
 Q = L,R = [],[]
 for x in seq:
 Q[x>=pivot].append(x)
 qsort(R)
 seq[:] = L+[pivot]+R

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


Re: PEP 3131: Supporting Non-ASCII Identifiers

2007-05-14 Thread Grant Edwards
On 2007-05-14, Grant Edwards <[EMAIL PROTECTED]> wrote:
> On 2007-05-14, Michael Yanowitz <[EMAIL PROTECTED]> wrote:
>
>> Let me guess - the next step will be to restrict the identifiers
>> to be at most 6 characters long.
>
> Of course. If they're any longer than that then you can't fit
> an entire identifier into a 26-bit CDC 6600 machine register so
  36-bit
  
> you can do a compare with a single machine instruction.

-- 
Grant Edwards   grante Yow! If our behavior is
  at   strict, we do not need fun!
   visi.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Time

2007-05-14 Thread Grant Edwards
On 2007-05-14, Grant Edwards <[EMAIL PROTECTED]> wrote:
> On 2007-05-14, Gabriel Genellina <[EMAIL PROTECTED]> wrote:
>> En Mon, 14 May 2007 11:27:35 -0300, HMS Surprise <[EMAIL PROTECTED]>  
>> escribió:
>>
>>> On May 14, 9:22 am, HMS Surprise <[EMAIL PROTECTED]> wrote:
>>>
>>> Oops +=1, should be:
>>>  hrMn[0] = int(hrMn[0]
>>>  if t[2] == 'PM':
>>>  hrMn[0] += 12
>>>
>>> Need more starter fluid, coffee please!!!
>>
>> Still won't work for 12 AM nor 12 PM...
>
> Do you mean 12 Noon or 12 Midnight?   12AM and 12PM don't exist,
> do they?

http://www.astronomy.net/articles/13/


-- 
Grant Edwards   grante Yow! I am a jelly donut.
  at   I am a jelly donut.
   visi.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Time

2007-05-14 Thread Grant Edwards
On 2007-05-14, Gabriel Genellina <[EMAIL PROTECTED]> wrote:
> En Mon, 14 May 2007 11:27:35 -0300, HMS Surprise <[EMAIL PROTECTED]>  
> escribió:
>
>> On May 14, 9:22 am, HMS Surprise <[EMAIL PROTECTED]> wrote:
>>
>> Oops +=1, should be:
>>  hrMn[0] = int(hrMn[0]
>>  if t[2] == 'PM':
>>  hrMn[0] += 12
>>
>> Need more starter fluid, coffee please!!!
>
> Still won't work for 12 AM nor 12 PM...

Do you mean 12 Noon or 12 Midnight?   12AM and 12PM don't exist,
do they?

-- 
Grant Edwards   grante Yow! HELLO, everybody,
  at   I'm a HUMAN!!
   visi.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: PEP 3131: Supporting Non-ASCII Identifiers

2007-05-14 Thread Grant Edwards
On 2007-05-14, Michael Yanowitz <[EMAIL PROTECTED]> wrote:

> Let me guess - the next step will be to restrict the identifiers
> to be at most 6 characters long.

Of course. If they're any longer than that then you can't fit
an entire identifier into a 26-bit CDC 6600 machine register so
you can do a compare with a single machine instruction.

-- 
Grant Edwards   grante Yow! CHUBBY CHECKER just
  at   had a CHICKEN SANDWICH in
   visi.comdowntown DULUTH!
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: track cpu usage of linux application

2007-05-14 Thread Zed A. Shaw
On Mon, 14 May 2007 20:56:20 +
Fabian Braennstroem <[EMAIL PROTECTED]> wrote:

> Hi,
> 
> I would like to track the cpu usage of a couple of
> programs using python. Maybe it works somehow with
> piping 'top' to python read the cpu load for a greped
> application and clocking the the first and last
> appearence. Is that a good approach or does anyone have
> a more elegant way to do that?

Look at the /proc filesystem instead.  For example, you can do this:

cat /proc/49595/status

To get information about that process.  Using this you can find out
anything you need with just basic file operations.

Use: man proc to find our more.

-- 
Zed A. Shaw
- Hate: http://savingtheinternetwithhate.com/
- Good: http://www.zedshaw.com/
- Evil: http://yearofevil.com/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: PEP 3131: Supporting Non-ASCII Identifiers

2007-05-14 Thread Grant Edwards
On 2007-05-14, Stefan Behnel <[EMAIL PROTECTED]> wrote:
> Marc 'BlackJack' Rintsch schrieb:
>> In <[EMAIL PROTECTED]>, Michel Claveau
>> wrote:
>> 
>>> And  Il1 O0 ?
>> 
>> Hm, we should ban digits from identifier names.  :-)
>
> Ah, good idea - and capital letters also. After all, they are
> rare enough in English to just plain ignore their existance.

And I don't really see any need for using more than two
characters.  With just two letters (ignoring case, of course),
you can create 676 identifiers in any namespace.  That's
certainly got to be enough.  If not, adding a special caracter
suffix (e.g. $,%,#) to denote the data type should sufficient
expand the namespace.

So, let's just silently ignore anything past the first two.
That way we'd be compatible with Commodor PET Basic.

[You don't want to know how long it took me to find all of the
name-collision bugs after porting a basic program from a CP/M
system which had a fairly sophisticated Basic compiler (no line
numbers, all the normal structured programming flow control
constructs) to a Commodore PET which had a really crappy BASIC
interpreter.]

-- 
Grant Edwards   grante Yow! Am I having fun yet?
  at   
   visi.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Recursion limit problems

2007-05-14 Thread elventear
On May 14, 2:03 pm, "Gabriel Genellina" <[EMAIL PROTECTED]>
wrote:
>
> Dicts and sets use the key's hash value to determine the "bucket" where  
> the key will be placed, and == to distingish between different objects  
> with the same hash value.
> That is, you should define __hash__ and one of (__cmp__ or __eq__).  
> __neq__ (inequality) isn't required nor used by dict/set implementation.  
> (Anyway, Python will transform a!=b into not(a==b), if __neq__ isn't  
> defined). Neither <, <=, >, >= are used.
> The important thing is that, if two objects compare equal, they must have  
> the same hash value. That is: (a==b) => (hash(a)==hash(b)) (the reciprocal  
> is not true).

Cool! I think this answers my last question.

Thanks!

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


Re: Recursion limit problems

2007-05-14 Thread elventear
On May 14, 1:20 pm, "Terry Reedy" <[EMAIL PROTECTED]> wrote:
>
> Dicts first compare hashes and if they are equal, then check equality.  If
> two unequal strings have the same hash value, as is possible of course
> (given only 2**32 possible hashes and many more possible strings), both can
> still be used as different keys.  Ditto for unequal numbers.  Or for a
> number and string with equal hashes.  And so on.  The first quoted
> sentence, about mixing, is directed at minimizing such hash collisions.

Now my question is, since the definition mentions __cmp__ explicity.
Is that the only function it uses? What if __ne__, __eq__ are defined,
but not __cmp__?

Finally I am still confused about the inequality. Does dict only care
about the __cmp__ ouput being 0 and ignore the rest, or does it make
use of -1,1 as well? Could I just say that 0 defines equality in my
object and 1 otherwise, without regard of it being less than or
greater than?

Thanks!

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


Re: Recursion limit problems

2007-05-14 Thread Gabriel Genellina
En Mon, 14 May 2007 12:35:16 -0300, elventear <[EMAIL PROTECTED]>  
escribió:

> Since I am defining a hash for my object, it makes sense that I should
> be able to define equality. But I am not sure about inequality, in my
> specific case. The paragraph above mentions that __cmp__ should be
> defined if I define a __hash__, but in the default behaviour of
> __cmp__ inequality is included. So what should I do? Also why is
> equality necessary to be defined? Do dicts only use __hash__ or do
> they use equality as well?

Dicts and sets use the key's hash value to determine the "bucket" where  
the key will be placed, and == to distingish between different objects  
with the same hash value.
That is, you should define __hash__ and one of (__cmp__ or __eq__).  
__neq__ (inequality) isn't required nor used by dict/set implementation.  
(Anyway, Python will transform a!=b into not(a==b), if __neq__ isn't  
defined). Neither <, <=, >, >= are used.
The important thing is that, if two objects compare equal, they must have  
the same hash value. That is: (a==b) => (hash(a)==hash(b)) (the reciprocal  
is not true).

-- 
Gabriel Genellina

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


RE: PEP 3131: Supporting Non-ASCII Identifiers

2007-05-14 Thread Michael Yanowitz
Let me guess - the next step will be to restrict the identifiers
to be at most 6 characters long.

-Original Message-
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] Behalf
Of Stefan Behnel
Sent: Monday, May 14, 2007 2:53 PM
To: python-list@python.org
Subject: Re: PEP 3131: Supporting Non-ASCII Identifiers


Marc 'BlackJack' Rintsch schrieb:
> In <[EMAIL PROTECTED]>, Michel Claveau
> wrote:
>
>> And  Il1 O0 ?
>
> Hm, we should ban digits from identifier names.  :-)

Ah, good idea - and capital letters also. After all, they are rare enough in
English to just plain ignore their existance.

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


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


Re: PEP 3131: Supporting Non-ASCII Identifiers

2007-05-14 Thread Stefan Behnel
Marc 'BlackJack' Rintsch schrieb:
> In <[EMAIL PROTECTED]>, Michel Claveau
> wrote:
> 
>> And  Il1 O0 ?
> 
> Hm, we should ban digits from identifier names.  :-)

Ah, good idea - and capital letters also. After all, they are rare enough in
English to just plain ignore their existance.

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


track cpu usage of linux application

2007-05-14 Thread Fabian Braennstroem
Hi,

I would like to track the cpu usage of a couple of
programs using python. Maybe it works somehow with
piping 'top' to python read the cpu load for a greped
application and clocking the the first and last
appearence. Is that a good approach or does anyone have
a more elegant way to do that?

Greetings!
 Fabian

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


Re: Interesting list Validity (True/False)

2007-05-14 Thread [EMAIL PROTECTED]
On May 13, 8:24 am, Steven D'Aprano
<[EMAIL PROTECTED]> wrote:
> On Sat, 12 May 2007 21:50:12 -0700, [EMAIL PROTECTED] wrote:

I intended to reply to this yesterday, but circumstances
(see timeit results) prevented it.

> >> > Actually, it's this statement that's non-sensical.
>
> >> > 
> >> > "if arg==True" tests whether the object known as arg is equal to the
> >> > object known as True.
> >> > 
>
> >> Not at all, it makes perfect sense. X == Y always tests whether the
> >> argument X is equal to the object Y regardless of what X and Y are.
>
> > Except for the exceptions, that's why the statement is wrong.
>
> But there are no exceptions.


Sec 2.2.3:
Objects of different types, *--->except<---* different numeric types
and different string types, never compare equal;



> X == Y tests for equality. If it returns
> True, then the objects are equal by definition. That's what equal means in
> Python.
>
> One can abuse the technology to give nonsensical results:
>
> class EqualToEverything(object):
> def __eq__(self, other):
> return True
>
> >>> x = EqualToEverything()
> >>> x == 1.0
> True
> >>> x == [2.9, "hello world"]
>
> True
>
> but that's no different from any language that allows you to override
> operators.
>
> >> > None of these four examples are "equal" to any other.
>
> >> That's actually wrong, as you show further down.
>
> > No, it's not, as I show further down.
>
> But you show no such thing.
>
> Or, to put it another way:
>
> Did! Did not! Did! Did not! Did! Did not! ...
>
> >>  a = 1
> >>  b = (1,)
> >>  c = [1]
> >>  d = gmpy.mpz(1)
>
> [snip]
>
> >>  a==d
> >> > True
>
> >> See, a and d are equal.
>
> > No, they are not "equal".
>
> Of course they are. It says so right there: "a equals d" is true.

Ok, but they are an exception to the rule "different types compare
False".

>
> > Ints and mpzs should NEVER
> > be used together in loops, even though it's legal.
>
> Why ever not? If you need an mpz value in order to do something, and no
> other data type will do, what would you suggest? Just give up and say
> "Don't do this, because it is Bad, m'kay?"

It's not the mpzs you shouldn't use, its the ints. I also stessed
"in loops". Replacing an integer literal with a variable still
requires a coercion, so it doesn't matter if n + 1 occurs outside
a loop.

>
> > The ints
> > ALWAYS have to be coerced to mpzs to perform arithmetic
> > and this takes time...LOTS of it.
>
> Really? Just how much time?

Can't say, had to abort the following.
Returns the count of n/2 and 3n+1 operations [1531812, 854697].

import gmpy

def collatz(a):
ONE = gmpy.mpz(1)
TWO = gmpy.mpz(2)
TWE = gmpy.mpz(3)
a = gmpy.mpz(a)
t = 0
u = 0
done = 0
while done==0:
f = gmpy.scan1(a,0)
if f>0:
a = a >> f
u += f
else:
if a==1:
done = 1
else:
a = a*TWE + ONE
t += 1
return [u,t]

def collatz2(a):
t = 0
u = 0
done = 0
while done==0:
f = gmpy.scan1(a,0)
if f>0:
a = a >> f
u += f
else:
if a==1:
done = 1
else:
a = a*3 + 1
t += 1
return [u,t]

def test():
collatz(2**177149-1)

def test2():
collatz2(2**177149-1)

if __name__=='__main__':
from timeit import Timer
t = Timer("a = test()", "from __main__ import test")
u = Timer("b = test2()", "from __main__ import test2")
print t.timeit(10)
print u.timeit(10)

##723.430377542
##*ABORTED after 20 hours*


>
> timeit.Timer("x == y", "import gmpy; x = 1; y = gmpy.mpz(1)").repeat()
> timeit.Timer("x == y", "x = 1; y = 1").repeat()
>
> I don't have gmpy installed here,

Good Lord! How do you solve a Linear Congruence? :-)

> so I can't time it, but I look forward
> to seeing the results, if you would be so kind.

I had a lot of trouble with this, but I think I finally got a
handle on it. I had to abort the previous test after 20+ hours
and abort a second test (once I figured out to do your example)
on another machine after 14+ hours. I had forgotten just how
significant the difference is.

import timeit

##t = timeit.Timer("a == b", "a = 1; b = 1")
##u = timeit.Timer("c == d", "import gmpy; c = 1; d =
gmpy.mpz(1)")
##t.repeat()
##[0.22317417437132372, 0.22519314605627253, 0.22474588250741367]
##u.repeat()
##[0.59943819675405763, 0.5962260566636246, 0.60122920650529466]

Unfortunately, this is not a very useful test, since mpz
coercion appears to vary ny the size of the number involved.
Although changing t to

##t = timeit.Timer("a == b", "a = 2**177149-1; b = 2**177149-1")

still produces tractable results
##t.repeat()
##[36.323597552202841, 34.727026758987506, 34.574566320579862]

the same can't be said for mpz coercion:

##u = timeit.Timer("c == d", "import gmpy; c = 2**177149-1; d =
gmpy.mpz(2**

Re: Time

2007-05-14 Thread Gabriel Genellina
En Mon, 14 May 2007 11:27:35 -0300, HMS Surprise <[EMAIL PROTECTED]>  
escribió:

> On May 14, 9:22 am, HMS Surprise <[EMAIL PROTECTED]> wrote:
>
> Oops +=1, should be:
>  hrMn[0] = int(hrMn[0]
>  if t[2] == 'PM':
>  hrMn[0] += 12
>
> Need more starter fluid, coffee please!!!

Still won't work for 12 AM nor 12 PM...

-- 
Gabriel Genellina

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


Re: Sorting troubles

2007-05-14 Thread Terry Reedy

<[EMAIL PROTECTED]> wrote in message 
news:[EMAIL PROTECTED]
|I have the following implementations of quicksort and insertion sort:
|
| def qSort(List):
|if List == []: return []
|return qSort([x for x in List[1:] if x< List[0]]) + List[0:1] + \
|   qSort([x for x in List[1:] if x>=List[0]])
|
| def insertSort(List):
|for i in range(1,len(List)):
|value=List[i]
|j=i
|while List[j-1]>value and j>0:
|List[j]=List[j-1]
|j-=1
|List[j]=value
|
| Now, the quickSort does not modify the original list, mostly because
| it works on products and concatenations, rather than alterations.
| The insertion sort, however, does modify the list. Now, to give
| results, they should be called in such a way( A is an unsorted list)
| A=qSort(A)
| # the insertion sort does not require this,
| insertSort(A)
|
| I would like to know how can I modify the qSort function such that it
| affects the list directly inside
| I have tried doing it like this
|
| def qSort(List):
|if List == []: return []
|List = qSort([x for x in List[1:] if x< List[0]]) + List[0:1] + \
|   qSort([x for x in List[1:] if x>=List[0]])
|return List
|
| while processing, the list changes, but those changes remain inside
| the function, so that once it's over, if nothis catches the return,
| the original List remains unchanged.
|
| If not a solution, I would like to at least know why it does what it
| does. I so understand that List(above) is only a reference to the
| actual data(a list), but I'm not passing a copy of the data to the
| function, but the actual reference(hence, insertSort does
| modifications). But then how can I change, inside the function, the
| object List is referencing to? If I can't modify the original list,
| maybe I can make the variable List point to another list? But changes
| inside the function are local. Sorry if this is a bit confusing.

The traditional way to do qsort in place (ignoring possible variations):

def  qsort(List, start=0, stop=None):
  if start >= stop: return
  if stop == None: stop = len(List)
  p = partition(List, start, stop) # p = index of pivot/partition item
  qsort(List, start, p)
  qsort(List, p+1, stop)

where partition puts elements less that pivot value before the pivot value 
and greater values after.

You could instead call your function qSorted to indicate that it returns a 
sorted copy ;-)

Terry Jan Reedy



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


Re: PEP 3131: Supporting Non-ASCII Identifiers

2007-05-14 Thread Marc 'BlackJack' Rintsch
In <[EMAIL PROTECTED]>, Michel Claveau
wrote:

> And  Il1 O0 ?

Hm, we should ban digits from identifier names.  :-)

Ciao,
Marc 'BlackJack' Rintsch

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


Re: Recursion limit problems

2007-05-14 Thread Terry Reedy

"elventear" <[EMAIL PROTECTED]> wrote in message 
news:[EMAIL PROTECTED]
On May 12, 12:25 am, "Gabriel Genellina" <[EMAIL PROTECTED]>
wrote:
> En Fri, 11 May 2007 19:17:57 -0300, elventear <[EMAIL PROTECTED]>
> escribió:
> "The only required property is that objects which compare equal have the
> same hash value; it is advised to somehow mix together (e.g., using
> exclusive or) the hash values for the components of the object that also
> play a part in comparison of objects. If a class does not define a
> __cmp__() method it should not define a __hash__() operation either; if 
> it

I suspect/believe that the above should be __cmp__() or __eq__() both for 
uniformity with the usage below and also because objects do not need to be 
ordered (__cmp__) to be used as dict keys.

> defines __cmp__() or __eq__() but not __hash__(), its instances will not
> be usable as dictionary keys. If a class defines mutable objects and
> implements a __cmp__() or __eq__() method, it should not implement
> __hash__(), since the dictionary implementation requires that a key's 
> hash
> value is immutable (if the object's hash value changes, it will be in the
> wrong hash bucket)."

Thanks for the information. I have a doubt regarding the wording in
the paragraph on top.

Since I am defining a hash for my object, it makes sense that I should
be able to define equality. But I am not sure about inequality, in my
specific case. The paragraph above mentions that __cmp__ should be
defined if I define a __hash__, but in the default behaviour of
__cmp__ inequality is included. So what should I do? Also why is
equality necessary to be defined? Do dicts only use __hash__ or do
they use equality as well?
===

Dicts first compare hashes and if they are equal, then check equality.  If 
two unequal strings have the same hash value, as is possible of course 
(given only 2**32 possible hashes and many more possible strings), both can 
still be used as different keys.  Ditto for unequal numbers.  Or for a 
number and string with equal hashes.  And so on.  The first quoted 
sentence, about mixing, is directed at minimizing such hash collisions.

Terry Jan Reedy



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

Re: PEP 3131: Supporting Non-ASCII Identifiers

2007-05-14 Thread Michel Claveau
And  Il1 O0 ?

-- 
@-salutations

Michel Claveau


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


=// Homeland Security on High Alert!!

2007-05-14 Thread ready . or . special3
http://freewindowsvista.blogspot.com/ - With a class action lawsuit
looming, three politicians question the head of the Department of
Homeland Security about the lost hard drive. The laptop was never
found...

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


Re: tkinter button state = DISABLED

2007-05-14 Thread Peter Otten
[EMAIL PROTECTED] wrote:

> I have created a button widget with a button click binding. The button
> initially has a state=disabled. I can see the greyed out version of
> the button in the GUI. But If I click on the button it still invokes
> the callback/binding function.
> 
> Any suggestions as to why the callback is being invoked even though
> the button has a disabled state. It looks like-
> 
> b=Button(frame,  text = "Button", state = 'disabled')
> 
> b.bind("",
> lambda
> event :
> function()
> )

Well, the /mouse/ button /was/ released. Do you know about the alternative?

b = Button(..., command=function) # no bind(), no lambda

It behaves like you expect. 

Peter

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


Re: PEP 3131: Supporting Non-ASCII Identifiers

2007-05-14 Thread Terry Reedy

"Stefan Behnel" <[EMAIL PROTECTED]> wrote in message 
news:[EMAIL PROTECTED]
| Sounds like CPython would better follow IronPython here.

One could also turn the argument around and say that there is no need to 
follow IronPython; people who want non-ASCII identifiers can just juse 
IronPython.




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


Re: Jessica Simpson Sports new "Boob Job"!!!@

2007-05-14 Thread wb
On May 14, 2:09 am, [EMAIL PROTECTED] wrote:


If her boobs getting any bigger she won't be able to stand up.

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


Re: Sorting troubles

2007-05-14 Thread seyensubs
I see. I figured that list comprehensions made another list(duh), but
I thought I could relink the object(List) to the new list and keep it
once the function ended.

Is it possible to pass a reference(to an object.. Like 'List',
basically) to a function and change the reference to point to
something created inside a function? Or all data unreturned from a
function is lost and no references kept?(The second, I'd guess, since
it's local temporary scope, but you never know, maybe Python can :) )

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


tkinter button state = DISABLED

2007-05-14 Thread rahulnag22
I have created a button widget with a button click binding. The button
initially has a state=disabled. I can see the greyed out version of
the button in the GUI. But If I click on the button it still invokes
the callback/binding function.

Any suggestions as to why the callback is being invoked even though
the button has a disabled state. It looks like-

b=Button(frame,  text = "Button", state = 'disabled')

b.bind("",
lambda
event :
function()
)

Thanks
Rahul

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


Re: GUI tutorial

2007-05-14 Thread John K Masters
On 15:03 Mon 14 May , Jarek Zgoda wrote:
> John K Masters napisał(a):
> 
> > Can someone point me in the direction of a good tutorial on programming
> > python with a GUI? I'm just starting out with python and have written a
> > few scripts successfully but would like to add a graphical front end to
> > them to make it easier for my work colleagues, most of whom have never
> > used a command line, to use.
> 
> Each of GUI frameworks/libraries has its own tutorial and some even more
> than one... The choice is directly related to what library you would use.

Thanks to all for the advice. I shall start with Py-GTK and see how it
goes.

Regards, John
-- 
War is God's way of teaching Americans geography
Ambrose Bierce (1842 - 1914)
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: deployment scripts

2007-05-14 Thread kyosohma
On May 14, 9:32 am, Erin <[EMAIL PROTECTED]> wrote:
> Does anyone have experience developing deployment scripts with Jython?

What do you mean by "deployment scripts"? What do you want to deploy?
Jython? A different program from Jython? Or do you mean packaging a
Jython program you wrote?

We need more info to be more helpful!

Mike

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


Re: Sorting troubles

2007-05-14 Thread Nick Vatamaniuc
On May 14, 12:05 pm, [EMAIL PROTECTED] wrote:
> I have the following implementations of quicksort and insertion sort:
>
> def qSort(List):
> if List == []: return []
> return qSort([x for x in List[1:] if x< List[0]]) + List[0:1] + \
>qSort([x for x in List[1:] if x>=List[0]])
>
> def insertSort(List):
> for i in range(1,len(List)):
> value=List[i]
> j=i
> while List[j-1]>value and j>0:
> List[j]=List[j-1]
> j-=1
> List[j]=value
>
> Now, the quickSort does not modify the original list, mostly because
> it works on products and concatenations, rather than alterations.
> The insertion sort, however, does modify the list. Now, to give
> results, they should be called in such a way( A is an unsorted list)
> A=qSort(A)
> # the insertion sort does not require this,
> insertSort(A)
>
> I would like to know how can I modify the qSort function such that it
> affects the list directly inside
> I have tried doing it like this
>
> def qSort(List):
> if List == []: return []
> List = qSort([x for x in List[1:] if x< List[0]]) + List[0:1] + \
>qSort([x for x in List[1:] if x>=List[0]])
> return List
>
> while processing, the list changes, but those changes remain inside
> the function, so that once it's over, if nothis catches the return,
> the original List remains unchanged.
>
> If not a solution, I would like to at least know why it does what it
> does. I so understand that List(above) is only a reference to the
> actual data(a list), but I'm not passing a copy of the data to the
> function, but the actual reference(hence, insertSort does
> modifications). But then how can I change, inside the function, the
> object List is referencing to? If I can't modify the original list,
> maybe I can make the variable List point to another list? But changes
> inside the function are local. Sorry if this is a bit confusing.

It does what it does because in the return statement when you
concatenate qsort(...x<..)+List[0:1]+qsort(...x>=..) you create a new
list. In the insertion sort you modify the values of the list directly
by doing List[j]=List[j-1] or List[j]=value.

If you just have to have the list modified in place, create another
wrapper function that calls your qsort and then will copy all data
from the result into the original list and you are done. Something
like:
def qsort_in_place(L):
   sortedL=qsort(L)
   for (i,x) in enumerate(sortedL):
 L[i]=x

Cheers,
-Nick Vatamaniuc

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


PEP 3131: Ascii-English is like coca-cola!

2007-05-14 Thread Pierre Hanser
This pep is not technical, or at least not only. It has
larger implications about society model we want.

Let me explain with an analogy:
let's compare 'ascii english' to coca-cola.

It's available nearly everywhere.

It does not taste good at first try, and is especially
repulsive to young children.

It's cheap and you don't expect much of it.

You know you can drink some in case of real need.

It's imperialist connotation is widely accepted(?)

But it's not good as your favorite beverage, beer, wine, ...

The world is full of other possibilities. Think, in case
of necessity you could even have to drink tea with yack
butter in himalaya! in normal circonstances, you should
never see any, but in extreme situation you may have to!

Were is freedom in such a world you could only drink coca?

I DON'T WANT TO HAVE TO DRINK COCA AT HOME ALL THE TIME.

and this pep is a glorious occasion to get free from it.


[disclaimer: coca is used here as the generic name it became,
and no real offense is intended]

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


Re: Sorting troubles

2007-05-14 Thread Thomas Nelson
On May 14, 11:05 am, [EMAIL PROTECTED] wrote:
> I have the following implementations of quicksort and insertion sort:
>
> def qSort(List):
> if List == []: return []
> return qSort([x for x in List[1:] if x< List[0]]) + List[0:1] + \
>qSort([x for x in List[1:] if x>=List[0]])
>
> def insertSort(List):
> for i in range(1,len(List)):
> value=List[i]
> j=i
> while List[j-1]>value and j>0:
> List[j]=List[j-1]
> j-=1
> List[j]=value
>
> Now, the quickSort does not modify the original list, mostly because
> it works on products and concatenations, rather than alterations.
> The insertion sort, however, does modify the list. Now, to give
> results, they should be called in such a way( A is an unsorted list)
> A=qSort(A)
> # the insertion sort does not require this,
> insertSort(A)
>
> I would like to know how can I modify the qSort function such that it
> affects the list directly inside
> I have tried doing it like this
>
> def qSort(List):
> if List == []: return []
> List = qSort([x for x in List[1:] if x< List[0]]) + List[0:1] + \
>qSort([x for x in List[1:] if x>=List[0]])
> return List
>
> while processing, the list changes, but those changes remain inside
> the function, so that once it's over, if nothis catches the return,
> the original List remains unchanged.
>
> If not a solution, I would like to at least know why it does what it
> does. I so understand that List(above) is only a reference to the
> actual data(a list), but I'm not passing a copy of the data to the
> function, but the actual reference(hence, insertSort does
> modifications). But then how can I change, inside the function, the
> object List is referencing to? If I can't modify the original list,
> maybe I can make the variable List point to another list? But changes
> inside the function are local. Sorry if this is a bit confusing.

The thing is that [x for x in List[1:]...] is a brand new list created
by iterating over the old one.
How about:
qSortHelp(List):
newlist = qSort(List)
for i, val in enumerate(newlist):
List[i] = val
You have to iterate over one more time, but this sorts the list in
place.
HTH,
Tom

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


Re: PEP 3131: Supporting Non-ASCII Identifiers

2007-05-14 Thread Jakub Stolarski
On May 13, 5:44 pm, "Martin v. Löwis" <[EMAIL PROTECTED]> wrote:
> - should non-ASCII identifiers be supported? why?
No. It's good convention to stick with english. And if we stick with
english, why we should need non-ASCII characters? Any non-ASCII
character makes code less readable. We never know if our code became
public.

> - would you use them if it was possible to do so? in what cases?
No. I don't see any uses. I'm Polish. Polish-english mix looks funny.

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


Re: PEP 3131: Supporting Non-ASCII Identifiers

2007-05-14 Thread Stefan Behnel
Jarek Zgoda schrieb:
> Stefan Behnel napisał(a):
> 
>>> While I can read the code with Hebrew, Russian or Greek names
>>> transliterated to ASCII, I would not be able to read such code in native.
>> Then maybe it was code that was not meant to be read by you?
> 
> OK, then. As a code obfuscation measure this would fit perfectly.

I actually meant it as a measure for clarity and readability for those who are
actually meant to *read* the code.

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

Re: PEP 3131: Supporting Non-ASCII Identifiers

2007-05-14 Thread Anton Vredegoor
Neil Hodgson wrote:
> Anton Vredegoor:
> 
>> Ouch! Now I seem to be disagreeing with the one who writes my editor. 
>> What will become of me now?
> 
> It should be OK. I try to keep my anger under control and not cut 
> off the pixel supply at the first stirrings of dissent.

Thanks! I guess I won't have to make the obligatory Sovjet Russia joke 
now :-)

> It may be an idea to provide some more help for multilingual text 
> such as allowing ranges of characters to be represented as hex escapes 
> or character names automatically. Then someone who only normally uses 
> ASCII can more easily audit patches that could contain non-ASCII characters.

Now that I read about IronPython already supporting some larger 
character set I feel like I'm somewhat caught in a side effect of an 
embrace and extend scheme.

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


Re: PEP 3131: Supporting Non-ASCII Identifiers

2007-05-14 Thread rurpy
On May 14, 9:53 am, Michel Claveau
<[EMAIL PROTECTED]> wrote:
> > - should non-ASCII identifiers be supported? why?
> > - would you use them if it was possible to do so? in what cases?
>
> Yes.
> And, more: yes yes yes
>
> Because:
>
> 1) when I connect Python to j(ava)Script, if the pages "connected"
> contains objects with non-ascii characters, I can't use it ; snif...
>
> 2) when I connect Python to databases, if there are fields (columns)
> with emphatic letters, I can't use class properties for drive these
> fields.  Exemples:
>  "cité" (french translate of "city")
>  "téléphone"  (for phone)
>
> And, because non-ASCII characters are possible, they are no-obligatory
> ; consequently guys (snobs?) want stay in pure-ASCII dimension will
> can.
>
> * sorry for my bad english *

Can a discussion about support for non-english identifiers (1)
conducted in a group where 99.9% of the posters are fluent
speakers of english (2), have any chance of being objective
or fair?

Although probably not-sufficient to overcome this built-in
bias, it would be interesting if some bi-lingual readers would
raise this issue in some non-english Python discussion
groups to see if the opposition to this idea is as strong
there as it is here.

(1) No quibbles about the distintion between non-english
and non-ascii please.
(2) Several posters have claimed non-native english speaker
status to bolster their position, but since they are clearly at
or near native-speaker levels of fluency, that english is not
their native language is really irrelevant.

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


Re: Asyncore Help?

2007-05-14 Thread Bjoern Schliessmann
Nick Craig-Wood wrote:

>   http://twistedmatrix.com/trac/
> 
> The learning curve of twisted is rather brutal, 

NACK, the tutorial is -- IMHO -- rather easy if you are used to
writing Python code and doing asynchronous programming. 



> but it will do everything you want and a whole lot more!

That's true. More Twisted, less work (and less headache). IMHO.

Regards,


Björn

-- 
BOFH excuse #242:

Software uses US measurements, but the OS is in metric...

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


Re: which is more pythonic/faster append or +=[]

2007-05-14 Thread 7stud
On May 10, 2:39 pm, Steven Bethard <[EMAIL PROTECTED]> wrote:
> 7studwrote:
> >> Is there any documentation for the syntax you used with timeit?
>
> > This is the syntax the docs describe:
> [snip
> > python timeit.py [-n N] [-r N] [-s S] [-t] [-c] [-h] [statement ...]
> [snip]
> > Then in the examples in section 10.10.2
> [snip]
> > timeit.py 'try:' '  str.__nonzero__' 'except AttributeError:' '  pass'
> [snip]
> > and then there is Alex Martelli's syntax:
> [snip]
> > python -mtimeit 'L=range(3); n=23' 'x=L[:]; x.append(n)'
>
> The following three things are equivalent:
>  python /path/to/.py
>  /path/to/.py # assuming the OS knows how to exec it
>  python -m# assuming  is on sys.path
>
> So that just leaves the differences between:
>  [-n N] [-r N] [-s S] [-t] [-c] [-h] [statement ...]
>  'try:' '  str.__nonzero__' 'except AttributeError:' '  pass'
>  'L=range(3); n=23' 'x=L[:]; x.append(n)'
>
> Those look pretty similar to me (aside from the fact that they're
> testing different things). Each argument in single quotes is a line of
> the code you want timed.
>

Thanks.

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


  1   2   >