Re: re.findall() hangs in python

2007-03-31 Thread Gabriel Genellina
En Sun, 01 Apr 2007 03:58:51 -0300, Peter Otten <[EMAIL PROTECTED]>  
escribió:

> [EMAIL PROTECTED] wrote:
>
>> I have the following regular expression.
>> It works when 'data' contains the pattern and I see 'match2' get print
>> out.
>> But when 'data' does not contain pattern, it just hangs at
>> 're.findall'
>>
>> pattern = re.compile("(.*)> re.S)
>
> Could it be that it is just slow? If not, post a small example of data  
> that
> provokes findall() to hang.

I bet it is very slooow!
To the OP: do you actually need all those groups? Specially the first and  
last (.*), they match all the surrounding text.

-- 
Gabriel Genellina

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


Re: shelf membership

2007-03-31 Thread Gabriel Genellina
En Sat, 31 Mar 2007 21:22:20 -0300, John Machin <[EMAIL PROTECTED]>  
escribió:

> On Apr 1, 8:02 am, Aaron Brady <[EMAIL PROTECTED]> wrote:
>> can you shelve objects with membership?
>>
>> this gives you:
>>
>> TypeError: object does not support item assignment
>> dict 0 True
>> Exception exceptions.TypeError: 'object does not support item  
>> assignment'
>> in  ignored
>>
>> > ignored is a bit mysterious.  tx in advance.
>>
>
> Please supply the *full* traceback, using copy/paste.

Not this time. Exceptions in __del__ are ignored and all you got is that  
message.

To the OP: This comes from Shelf.__del__, which in turn calls close(),  
which tries to set the internal dict to 0 (?!). You may try overriding  
close() - but what do you want to achieve, exactly?

-- 
Gabriel Genellina

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


Re: Shed Skin Python-to-C++ Compiler 0.0.21, Help needed

2007-03-31 Thread Kay Schluehr
On Mar 31, 11:26 pm, "Luis M. González" <[EMAIL PROTECTED]> wrote:
> On Mar 31, 8:38 am, Bjoern Schliessmann 
>
>
> [EMAIL PROTECTED]> wrote:
> > Mark Dufour wrote:
> > > Shed Skin allows for translation of pure (unmodified), implicitly
> > > statically typed Python programs into optimized C++, and hence,
>
> >^> highly 
> > optimized machine language.
>
> >   
>
> > Wow, I bet all C++ compiler manufacturers would want you to work for
> > them.
>
> > Regards,
>
> > Björn
>
> > --
> > BOFH excuse #23:
>
> > improperly oriented keyboard
>
> Mark has been doing an heroic job so far.
> Shedskin is an impressive piece of software and, if pypy hadn't been
> started some time ago, it should have gotten more attention from the
> community.
> I think he should be taken very seriously.

Indeed. The only serious problem from an acceptance point of view is
that Mark tried to solve the more difficult problem first and hung on
it. Instead of integrating a translator/compiler early with CPython,
doing some factorization of Python module code into compilable and
interpretable functions ( which can be quite rudimentary at first )
together with some automatically generated glue code and *always have
a running system* with monotone benefit for all Python code he seemed
to stem an impossible task, namely translating the whole Python to C++
and created therefore a "lesser Python". I do think this is now a well
identified anti-pattern but nothing that can't be repaired in this
case - from what I understand. However, speaking on my part, I don't
make my hands dirty with C++ code unless I get paid *well* for it.
This is like duplicating my job in my sparetime. No go. Otherwise it
wouldn't be a big deal to do what is necessary here and even extend
the system with perspective on Py3K annotations or other means to ship
typed Python code into the compiler.


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


Re: saving Python process state for later debugging

2007-03-31 Thread yossi . kreinin
On Apr 1, 2:07 am, "aspineux" <[EMAIL PROTECTED]> wrote:
>
> Pylon has something like 
> that.http://pylonshq.com/docs/0.9.4.1/interactive_debugger.html
>
> Turbogears has the same with option tg.fancy_exception
>

I could get it wrong, but these things seem to be about debugging
crashed processes "online", not saving snapshots to files for later
inspection. Can you e-mail a process snapshot to a different machine
with them, for example? I understood that you are supposed to debug
the original process, which is kept alive, via the web. I'm talking
about a situation where you have a Python program deployed to a user
who is not running a web server, and have the user send you a snapshot
as a bug report.

-- Yossi

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


Re: re.findall() hangs in python

2007-03-31 Thread 7stud
On Mar 31, 9:12 pm, "[EMAIL PROTECTED]"
<[EMAIL PROTECTED]> wrote:
> Hi,
>
> I have the following regular expression.
> It works when 'data' contains the pattern and I see 'match2' get print
> out.
> But when 'data' does not contain pattern, it just hangs at
> 're.findall'
>
> pattern = re.compile("(.*) re.S)
>
> print "before find all"
>
> match = re.findall(pattern, data)
>
> if (match):
>print "match2"
>
> Can you please tell me why it that?

It doesn't hang when I try it.  Why don't you post a complete example
that hangs.

Also, you might consider using exterior single quotes around your
string so that you don't have to escape double quotes inside the
string.

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


Re: re.findall() hangs in python

2007-03-31 Thread Peter Otten
[EMAIL PROTECTED] wrote:

> I have the following regular expression.
> It works when 'data' contains the pattern and I see 'match2' get print
> out.
> But when 'data' does not contain pattern, it just hangs at
> 're.findall'
> 
> pattern = re.compile("(.*) re.S)
> 
> print "before find all"
> 
> match = re.findall(pattern, data)
> 
> if (match):
>print "match2"
> 
> 
> 
> Can you please tell me why it that?

Could it be that it is just slow? If not, post a small example of data that
provokes findall() to hang.

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


Re: Unicode list

2007-03-31 Thread Martin v. Löwis
> Like this, the program prints some characters as strange escape 
> sequences, which is due to the input file being encoded in utf-8: When I 
> convert "re.findall..." to a string and wrap an "unicode()" around it, 
> the matches get printed correctly. Is it possible to make "matches" 
> unicode without saving it as a single string first? The function "unicode
> ()" seems only to work for strings. Or is there a general way of telling 
> Python to abandon the ancient and evil land of iso-8859 for good and use 
> utf-8 only?

Python does not live in the ancient and evi land of iso-8859; it lives
in the ancient and evil land of ASCII.

When printing a list, the individual elements are converted with repr(),
not with str(). For a string object, repr() adds escape codes for all
bytes that are not printable ASCII characters. To avoid this call to
repr, you need to iterate over the list yourself, and print it:

if matches:
for m in matches:
print m,
print

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


Re: CRC CCITT UPDATE in Python

2007-03-31 Thread Martin v. Löwis

>   Please, is there here some good soul that understand this
> functions hi8 and lo8 (from GCC AVR) and can help me to port it to
> Python?
> 
> uint16_t
> crc_ccitt_update (uint16_t crc, uint8_t data)
> {
>data ˆ= lo8 (crc);
>data ˆ= data << 4;
>return uint16_t)data << 8) | hi8 (crc)) ˆ (uint8_t)(data >> 4)
> ˆ ((uint16_t)data << 3));
> }

Most likely, lo8(crc) == crc & 0xFF, and hi8(crc) == (crc >> 8) & 0xFF
(the last bit masking might be redundant, as crc should not occupy more
than 16 bits, anyway).

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

Re: Shed Skin Python-to-C++ Compiler 0.0.21, Help needed

2007-03-31 Thread John Nagle
Mark Dufour wrote:
> Hi all,
> 
> I have recently released version 0.0.20 and 0.0.21 of Shed Skin, an
> optimizing Python-to-C++ compiler. Shed Skin allows for translation of
> pure (unmodified), implicitly statically typed Python programs into
> optimized C++, and hence, highly optimized machine language. Besides
> many bug fixes and optimizations, these releases add the following
> changes:
 >
> I'm also
> hoping someone else would like to deal with integration with CPython
> (so Shed Skin can generate extension modules, and it becomes easier to
> use 'arbitrary' external CPython modules such as 're' and 'pygame'.)

Reusing precompiled external modules will be tough.  Even
CPython has trouble with that.  But that's just a conversion
problem.  Maybe SWIG (yuck, but it exists) could be persuaded
to cooperate.

For regular expressions, here's an implementation, in C++,
of Python-like regular expressions.

http://linuxgazette.net/issue27/mueller.html

That might be a way to get a regular expression capability into
Shed Skin quickly.

> Finally, there may be some interesting Master's thesis subjects in
> improving Shed Skin, such as transforming heap allocation into stack-
> and static preallocation, where possible, to bring performance even
> closer to manual C++. Please let me know if you are interested in
> helping out, and/or join the Shed Skin mailing list.

Find out where the time is going before spending it on that.

A good test: BeautifulSoup.  Many people use it for parsing
web pages, and it's seriously compute-bound.

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


Re: Shed Skin Python-to-C++ Compiler 0.0.21, Help needed

2007-03-31 Thread Michael Torrie
On Sat, 2007-03-31 at 20:47 -0700, Paul Rubin wrote:
> Michael Torrie <[EMAIL PROTECTED]> writes:
> > The no-service contract version of the GPL is not the same as the
> > standard GPLv2.
> 
> I don't see how that can be--we're talking about a GCC-based compiler,
> right?

I found the real reason why the GPL'd GNAT compiler's produced
executables are required to be GPL'd, and it has nothing to do with the
license of the compiler:

"What is the license of the GNAT GPL Edition?
Everything (tools, runtime, libraries) in the GNAT GPL Edition is
licensed under the General Public License (GPL). This ensures that
executables generated by the GNAT GPL Edition are Free Software and that
source code is made available with the executables, giving the freedom
to recepients to run, study, modify, adapt, and redistribute sources and
execuatbles under the terms of the GPL."[1]

Note that it says the runtime *and* the libraries are GPL. Thus the
linking clause in the GPL requires that programs that link against them
(the executable in other words) must be GPL'd.  Note that GLibC, while
being GPL, has an exception clause in it, allowing linking to it by code
of any license.

Hence it's a red herring as far as the discussion and Shed Skin is
concerned, although the licensing of any Shed Skin runtime libraries
should be a concern to folks.

[1] https://libre.adacore.com/

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


Converting _node* to a Code object?

2007-03-31 Thread Brendon Costa
Hi All,

I have an application with an embedded python interpreter and i need to
get the embedded interpreter to "import" strangely named files as python
modules.

Anyhow the simple part of the question is:

How do i convert a _node* object returned from:
PyParser_SimpleParseStringFlagsFilename()

into a code object i can use as a module to import with:
PyImport_ExecCodeModule()


I cant seem to find any documentation about this. If you are wondering
why i want to do this, then you can read on and maybe there is a much
better way to achieve what i am after.



Thanks,
Brendon




- What i am trying to achieve -


Basically i want to "import" using the python C API a module from
various files which may have names that do not make valid python module
names.


In particular i have an embedded python interpreter that is used to
apply a number of operations on some data based on a user supplied
"suppressions file" (*.eds). This .eds file is just a python source file
designed only to be used from within this application.


Now the names of these suppression files usually matche that of a
library or application to which they will apply to. For example:

libstdc++.so.6.0.5 : has eds file: libstdc++.so.6.0.5.eds


Now i want to have my code import this eds file as a python module so
that i can then use it as any other standard python module. So i need to
separate the name of the module from the name of the file. I was
thinking for example for the above filename i would give it a module
name like:

libstdc___so_6_0_5

(The name is not important just that the above one is a valid module
name from what i understand and it is based on the original name)

So i have some random file:
/foo/bar/lib/libstdc++.so.6.0.5.eds

and i want to be able to import that as a module using the Python C API
so native python code can access the module like:

libstdc___so_6_0_5.PostCalculation()


If you have any better method of doing this, i would love to know what
it is.

Thanks in advance for any help,
Brendon.


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


Re: Shed Skin Python-to-C++ Compiler 0.0.21, Help needed

2007-03-31 Thread Michael Torrie
On Sat, 2007-03-31 at 20:47 -0700, Paul Rubin wrote:
> Michael Torrie <[EMAIL PROTECTED]> writes:
> > The no-service contract version of the GPL is not the same as the
> > standard GPLv2.
> 
> I don't see how that can be--we're talking about a GCC-based compiler,
> right?

Well, that's beside the point anyway.  The output of a program is beyond
the scope of the source code license for the program.  However the
default is for the output to be copyrighted the author.  Thus the author
of a program is free to say (give license, in other words) that the
output of a program can distributed.  The real point is the Shed Skin
author can both license the program under the GPLv2 and also say that
the output from his program is not bound by any license.  There's no
conflict unless the author of Shed Skin wants there to be.  Worst case,
if indeed the GPLv2 says it covers the output of the program (which I
don't believe it does), copyright law still trumps everything and the
author is free at add an exemption to the license if he chooses, which
is what I've seen done with Bison.  Bison is also a special case because
the output of bison contains code fragments that are part of the bison
source code itself, which is under the GPL.  Thus a special exception
had to be made in this case.  

Anyway, the only real point is that if there is a concern about the
copyright and licensing of the output of Shed Skin, then we merely need
to ask the author of it to clarify matters and move on with life.  With
the exception of GNAT, to date no GPL'd compiler has ever placed a GPL
restriction on its output.  Whether this is explicit or implicit doesn't
matter, so long as it's there.




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


Generic logic/conditional class or library for classification of data

2007-03-31 Thread Basilisk96
This topic is difficult to describe in one subject sentence...

Has anyone come across the application of the simple statement "if
(object1's attributes meet some conditions) then (set object2's
attributes to certain outcomes)", where "object1" and "object2" are
generic objects, and the "conditions" and "outcomes" are dynamic run-
time inputs? Typically, logic code for any application out there is
hard-coded. I have been working with Python for a year, and its
flexibility is nothing short of amazing. Wouldn't it be possible to
have a class or library that can do this sort of dynamic logic?

The main application of such code would be for classification
algorithms which, based on the attributes of a given object, can
classify the object into a scheme. In general, conditions for
classification can be complex, sometimes involving a collection of
"and", "or", "not" clauses. The simplest outcome would involve simply
setting a few attributes of the output object to given values if the
input condition is met. So each such "if-then" clause can be viewed as
a rule that is custom-defined at runtime.

As a very basic example, consider a set of uncategorized objects that
have text descriptions associated with them. The objects are some type
of tangible product, e.g., books. So the input object has a
Description attribute, and the output object (a categorized book)
would have some attributes like Discipline, Target audience, etc.
Let's say that one such rule is "if ( 'description' contains
'algebra') then ('discipline' = 'math', 'target' = 'student') ". Keep
in mind that all these attribute names and their values are not known
at design time.

Is there one obvious way to do this in Python?
Perhaps this is more along the lines of data mining methods?
Is there a library with this sort of functionality out there already?

Any help will be appreciated.

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


Re: Shed Skin Python-to-C++ Compiler 0.0.21, Help needed

2007-03-31 Thread Paul Rubin
Michael Torrie <[EMAIL PROTECTED]> writes:
> The no-service contract version of the GPL is not the same as the
> standard GPLv2.

I don't see how that can be--we're talking about a GCC-based compiler,
right?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Shed Skin Python-to-C++ Compiler 0.0.21, Help needed

2007-03-31 Thread Michael Torrie
On Sun, 2007-04-01 at 02:49 +, Dennis Lee Bieber wrote:
>   Take that up with ACT... GNAT 3.15p was explicitly unencumbered, but
> the current version of GNAT, in the GPL (no-service contract) form has
> gone the other direction, claiming that executables must be released
> GPL.

The no-service contract version of the GPL is not the same as the
standard GPLv2.  Ordinarily the GPLv2 does not apply to the output of
the program unless the license specifies that it does (a modification or
addendum).  Thus the output of a program is not part of the GPL usually,
unless specified  MySQL's take on the GPLv2 without an addendum is
mistaken, in my opinion.  However, copyright law probably still applies
to the programs output regardless of license, but in what way I don't
think the courts have ever specified, given that the output depends
largely on the input.  GCC, Bison, and Flex, all explicitly state that
the output of the program is not under any license, and is your own
property.  Perhaps the author of Shed Skin could make a note in the
license file to clarify the state of the output of his program.

There should be no problem with this Shed Skin program being under the
GPL and using it with python scripts that are not under the GPL.  But if
you have any concern with a copyright license at all, you should consult
your lawyer.  Too many companies see GPL'd programs as a free ride, not
willing to accept that they need a copyright license to use the code
just as they would with any code from any source.  It's sad to see
because free software gets an unfair bad rap because of the greed of
others.  On the other hand, others take an overly paranoid view of the
GPL and pretend it is viral and somehow magically infects your code with
the GPL license, which is false--if you use GPL'd code in your non GPL'd
application then you are in a copyright violation situation and your
only options are to either GPL your code or remove the offending GPL'd
source from your code and write your own dang code, thank you very much.



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


re.findall() hangs in python

2007-03-31 Thread [EMAIL PROTECTED]
Hi,

I have the following regular expression.
It works when 'data' contains the pattern and I see 'match2' get print
out.
But when 'data' does not contain pattern, it just hangs at
're.findall'

pattern = re.compile("(.*)http://mail.python.org/mailman/listinfo/python-list


Pygame Q (linux) beginner

2007-03-31 Thread enquiring mind
Running 2.4.1 Python (learning)
Running SUSE Linux 10

Am learning from a new books that mostly deals with windows python and
Pygames called "Game Programming" by Randy Harris (2007)  His books
references Python 2.4.2 and Pygame 1.7.1 with these comments:  

"If you are using a Linux machine, you probably won't have the simple
installer that came with the windows version.  Follow the instructions
at http://pygame.org/install.  You may have to run a couple of scripts
to make everything work, but just follow the directions and you will be
fine."  

Could anybody suggest or make a helpful comment in view of what
information I have supplied.  At Chapter 5 is where the Pygame module is
introduced so I have a little time before I have to figure out what I
have to download and install.  

Thanks very much in advance for any direction. 

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


CRC CCITT UPDATE in Python

2007-03-31 Thread pythoneiro
Please,

  Please, is there here some good soul that understand this
functions hi8 and lo8 (from GCC AVR) and can help me to port it to
Python?

uint16_t
crc_ccitt_update (uint16_t crc, uint8_t data)
{
   data ˆ= lo8 (crc);
   data ˆ= data << 4;
   return uint16_t)data << 8) | hi8 (crc)) ˆ (uint8_t)(data >> 4)
ˆ ((uint16_t)data << 3));
}

Source: 
http://tldp.tuxhilfe.de/linuxfocus/common/src2/article352/avr-libc-user-manual-1.0.4.pdf

 Reason, I would like to code in Python one simulator from one
code C++ AVR

Thanks.,

./Fã  -Py -Thorneiro

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

Re: I18n issue with optik

2007-03-31 Thread Steven Bethard
Thorsten Kampe wrote:
> I've written a script which uses Optik/Optparse to display the 
> options (which works fine). The text for the help message is localised 
> (with german umlauts) and when I execute the script with the localised 
> environment variable set, I get this traceback[1]. The interesting 
> thing is that the localised optparse messages from displays fine - 
> it's only my localisation that errors.
> 
> From my understanding, my script doesn't put out anything, it's 
> optik/optparse who does that. My po file is directly copied from the 
> optik po file (who displays fine) and modified so the po file should 
> be fine, too.
> 
> What can I do to troubleshoot whether the culprit is my script, optik 
> or gettext?
> 
> Would it make sense to post the script and the mo or po files?

Yes, probably.  Though if you can reduce it to the simplest test case 
that produces the error, it'll increase your chances of having someone 
look at it.

You could also try posting to the optik list:
 http://lists.sourceforge.net/lists/listinfo/optik-users

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


Re: Shed Skin Python-to-C++ Compiler 0.0.21, Help needed

2007-03-31 Thread Luis M. González
On Mar 31, 10:31 pm, Bjoern Schliessmann  wrote:
> Luis M. González wrote:
> > I think he should be taken very seriously.
>
> Agreed.
>
> Okay, it seems focusing a discussion on one single point is
> difficult for many people. Next time I'll be mind-bogglingly clear
> that even the last one understands after reading it one time ...
>
> Regards,
>
> Björn
>
> Fup2 p
>
> --
> BOFH excuse #46:
>
> waste water tank overflowed onto computer


Bjoern,

I understood what you said. It's just that it seemed that you were
mocking at the poster's message.
I apologize if that wasn't your intention.

Luis

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


Re: Shed Skin Python-to-C++ Compiler 0.0.21, Help needed

2007-03-31 Thread Bjoern Schliessmann
Luis M. González wrote:

> I think he should be taken very seriously.

Agreed.

Okay, it seems focusing a discussion on one single point is
difficult for many people. Next time I'll be mind-bogglingly clear
that even the last one understands after reading it one time ...
 
Regards,


Björn

Fup2 p

-- 
BOFH excuse #46:

waste water tank overflowed onto computer

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


Re: Shed Skin Python-to-C++ Compiler 0.0.21, Help needed

2007-03-31 Thread Paul Rubin
"Paul McGuire" <[EMAIL PROTECTED]> writes:
> Why would that be?  GPL'ed code libraries can be a turn-off for those
> who want to release commercial products using them, but a GPL'ed
> utility such as a compiler bears no relationship or encumbrance on the
> compiled object code it generates.

For some of us, doing volunteer work on non-GPL projects is a
turn-off.  I don't mind writing code that goes into proprietary
products, but I expect to get paid for it just like the vendors of the
products expect to get paid.  If I'm working for free I expect the
code to stay free.  This is why I don't contribute code to Python on
any scale.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Unicode list

2007-03-31 Thread Paul Boddie
Rehceb Rotkiv wrote:
> Hello,
>
> I have this little grep-like program:
>
> ++snip++
> #!/usr/bin/python
>
> import sys
> import re
>
> pattern = sys.argv[1]
> inputfile = file(sys.argv[2], 'r')
>
> for line in inputfile:
> matches = re.findall(pattern, line)
> if matches:
> print matches
> ++snip++
>
> Like this, the program prints some characters as strange escape
> sequences, which is due to the input file being encoded in utf-8:

So the UTF-8 data gets printed to your terminal which isn't configured
for UTF-8, right?

> When I convert "re.findall..." to a string and wrap an "unicode()" around it,
> the matches get printed correctly.

How do you meaningfully convert it to a string? The matches variable
refers to a list, but you surely don't want to be dealing with the
list's string representation.

> Is it possible to make "matches" unicode without saving it as a single string 
> first?

Why not convert your input into Unicode and then, for the benefit of
certain kinds of character classes, use re.findall in Unicode mode (by
specifying re.U as a flag)? Then, each match will be produced as a
Unicode object.

> The function "unicode()" seems only to work for strings. Or is there a 
> general way of telling
> Python to abandon the ancient and evil land of iso-8859 for good and use 
> utf-8 only?

The only refuge from ancient and evil lands is found by climbing the
mountain of Unicode: convert from encoded text as soon as you can,
work only with Unicode objects, produce encoded text only when
necessary.

Paul

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


Unicode list

2007-03-31 Thread Rehceb Rotkiv
Hello,

I have this little grep-like program:

++snip++
#!/usr/bin/python

import sys
import re

pattern = sys.argv[1]
inputfile = file(sys.argv[2], 'r')

for line in inputfile:
matches = re.findall(pattern, line)
if matches:
print matches
++snip++

Like this, the program prints some characters as strange escape 
sequences, which is due to the input file being encoded in utf-8: When I 
convert "re.findall..." to a string and wrap an "unicode()" around it, 
the matches get printed correctly. Is it possible to make "matches" 
unicode without saving it as a single string first? The function "unicode
()" seems only to work for strings. Or is there a general way of telling 
Python to abandon the ancient and evil land of iso-8859 for good and use 
utf-8 only?

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


Re: Shed Skin Python-to-C++ Compiler 0.0.21, Help needed

2007-03-31 Thread Paul McGuire
On Mar 31, 6:45 pm, Alexander Schmolck <[EMAIL PROTECTED]> wrote:
> Regardless of its merrits, it's GPL'ed which I assume is an immediate turn-off
> for many in the community.
>

Why would that be?  GPL'ed code libraries can be a turn-off for those
who want to release commercial products using them, but a GPL'ed
utility such as a compiler bears no relationship or encumbrance on the
compiled object code it generates.

-- Paul

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


Re: Shed Skin Python-to-C++ Compiler 0.0.21, Help needed

2007-03-31 Thread Paul Boddie
Alexander Schmolck wrote:
>
> Regardless of its merrits, it's GPL'ed which I assume is an immediate turn-off
> for many in the community.

In the way that tools such as gcc are GPL-licensed, or do you have
something else in mind?

Paul

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


Re: shelf membership

2007-03-31 Thread John Machin
On Apr 1, 8:02 am, Aaron Brady <[EMAIL PROTECTED]> wrote:
> can you shelve objects with membership?
>
> this gives you:
>
> TypeError: object does not support item assignment
> dict 0 True
> Exception exceptions.TypeError: 'object does not support item assignment'
> in  ignored
>
> > ignored is a bit mysterious.  tx in advance.
>
> from shelve import *
> class MyShelf(DbfilenameShelf):
> def __init__(self, filename, flag='c', protocol=None,
> writeback=False, binary=None):
> self.__dict__['ready']=False
> DbfilenameShelf.__init__(self, filename, flag, protocol,
> writeback, binary)
> self.ready=True
> def __setattr__(self,name,value):
> if not self.ready:
> self.__dict__[name]=value
> else:
> print name, value, self.ready
> self.__dict__[name]=value
> DbfilenameShelf.__setitem__(self,name,value)
>
> def open(filename, flag='c', protocol=None, writeback=False, binary=None):
>   return MyShelf(filename, flag, protocol, writeback, binary)

Please supply the *full* traceback, using copy/paste.

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


Re: help with dates

2007-03-31 Thread John Machin
On Apr 1, 7:51 am, "Pierre Quentel" <[EMAIL PROTECTED]> wrote:
> > Four groups of firefighters (group1, group2, group3, group4). Each
> > group works a 24 hr shift. So group1 works April 1, group2 works April
> > 2, group3 works April 3, group4 works April 4, group 1 works April 5,
> > etc. It just keeps rolling like this forever into next year, etc.
>
> > I need to come up with a methodology for the following:
>
> > If given a date, find out what group is working on that date.
>
> Hello,
>
> You can use method datetime.date.toordinal() :
>
> from datetime import date
> start = date(2007,4,1) # Arpil 1, 2007
>
> def group(_date):
> return (date.toordinal(_date)-date.toordinal(start)) % 4

... whose possible outcomes are (0, 1, 2, 3) whereas the groups are
numbered 1 to 4. However I'm sure the OP can make the necessary
adjustment :-)

>
> print group(date(2007,4,15))
>
> Regards,
> Pierre


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


Re: Shed Skin Python-to-C++ Compiler 0.0.21, Help needed

2007-03-31 Thread Alexander Schmolck
"Luis M. González" <[EMAIL PROTECTED]> writes:

> On Mar 31, 8:38 am, Bjoern Schliessmann  [EMAIL PROTECTED]> wrote:
> > Mark Dufour wrote:
> > > Shed Skin allows for translation of pure (unmodified), implicitly
> > > statically typed Python programs into optimized C++, and hence,
> >
> >^> highly 
> > optimized machine language.
> >
> >   
> >
> > Wow, I bet all C++ compiler manufacturers would want you to work for
> > them.
> >
> > Regards,
> >
> > Björn
> >
> > --
> > BOFH excuse #23:
> >
> > improperly oriented keyboard
> 
> 
> Mark has been doing an heroic job so far.
> Shedskin is an impressive piece of software and, if pypy hadn't been
> started some time ago, it should have gotten more attention from the
> community.

Regardless of its merrits, it's GPL'ed which I assume is an immediate turn-off
for many in the community.

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


Re: saving Python process state for later debugging

2007-03-31 Thread aspineux
On 31 mar, 16:48, [EMAIL PROTECTED] wrote:
> Hi!
>
> Is there a way to save the state of a Python process for later
> inspection with a debugger? One way to do this is to dump core, but is
> the result usable for debugging with pdb (it can be debugged by gdb,
> which can inspect PyObjects in a CPython core, for example, but it's
> not much fun)?
>
> If there is no way to do this today, are there essential difficulties
> in implementing this on top of an OS support for "raw" core dumps?

Pylon has something like that.
http://pylonshq.com/docs/0.9.4.1/interactive_debugger.html

Turbogears has the same with option tg.fancy_exception

You can navigate into the stack trace from the web interface :-)



>
> TIA,
> Yossi


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


Using Simple MAPI with MS Outlook 2007

2007-03-31 Thread tomer . ha
Hi there,

I'd like to send emails from a Python program using Simple MAPI. I've
tried this code: 
http://mail.python.org/pipermail/python-list/2004-December/298066.html
and it works well with Outlook Express 6 and Thunderbird 1.5, but it
doens't work at all with Microsoft Outlook 2007. I keep getting this
message: "WindowsError: MAPI error 2".

I don't want to use Extended MAPI because it doesn't support
thunderbird not OE. Therefore, Simple MAPI is the only option for me.

So, what did I miss here?

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


shelf membership

2007-03-31 Thread Aaron Brady
can you shelve objects with membership?

this gives you:

TypeError: object does not support item assignment
dict 0 True
Exception exceptions.TypeError: 'object does not support item assignment' 
in  ignored

> ignored is a bit mysterious.  tx in advance.

from shelve import *
class MyShelf(DbfilenameShelf):
def __init__(self, filename, flag='c', protocol=None, 
writeback=False, binary=None):
self.__dict__['ready']=False
DbfilenameShelf.__init__(self, filename, flag, protocol, 
writeback, binary)
self.ready=True
def __setattr__(self,name,value):
if not self.ready:
self.__dict__[name]=value
else:
print name, value, self.ready
self.__dict__[name]=value
DbfilenameShelf.__setitem__(self,name,value)

def open(filename, flag='c', protocol=None, writeback=False, binary=None):
  return MyShelf(filename, flag, protocol, writeback, binary)

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


I18n issue with optik

2007-03-31 Thread Thorsten Kampe
Hi,

I've written a script which uses Optik/Optparse to display the 
options (which works fine). The text for the help message is localised 
(with german umlauts) and when I execute the script with the localised 
environment variable set, I get this traceback[1]. The interesting 
thing is that the localised optparse messages from displays fine - 
it's only my localisation that errors.

>From my understanding, my script doesn't put out anything, it's 
optik/optparse who does that. My po file is directly copied from the 
optik po file (who displays fine) and modified so the po file should 
be fine, too.

What can I do to troubleshoot whether the culprit is my script, optik 
or gettext?

Would it make sense to post the script and the mo or po files?


Thorsten

[1]
Traceback (most recent call last):
  File "script.py", line 37, in 
options, args = cmdlineparser.parse_args()
  File "/usr/lib/python2.5/optparse.py", line 1378, in parse_args
stop = self._process_args(largs, rargs, values)
  File "/usr/lib/python2.5/optparse.py", line 1418, in _process_args
self._process_long_opt(rargs, values)
  File "/usr/lib/python2.5/optparse.py", line 1493, in 
_process_long_opt
option.process(opt, value, values, self)
  File "/usr/lib/python2.5/optparse.py", line 782, in process
self.action, self.dest, opt, value, values, parser)
  File "/usr/lib/python2.5/optparse.py", line 804, in take_action
parser.print_help()
  File "/usr/lib/python2.5/optparse.py", line 1648, in print_help
file.write(self.format_help().encode(encoding, "replace"))
UnicodeDecodeError: 'ascii' codec can't decode byte 0xc4 in position 
264: ordinal not in range(128)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: help with dates

2007-03-31 Thread Pierre Quentel
> Four groups of firefighters (group1, group2, group3, group4). Each
> group works a 24 hr shift. So group1 works April 1, group2 works April
> 2, group3 works April 3, group4 works April 4, group 1 works April 5,
> etc. It just keeps rolling like this forever into next year, etc.
>
> I need to come up with a methodology for the following:
>
> If given a date, find out what group is working on that date.
>
Hello,

You can use method datetime.date.toordinal() :

from datetime import date
start = date(2007,4,1) # Arpil 1, 2007

def group(_date):
return (date.toordinal(_date)-date.toordinal(start)) % 4

print group(date(2007,4,15))

Regards,
Pierre

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


Re: Shed Skin Python-to-C++ Compiler 0.0.21, Help needed

2007-03-31 Thread Luis M. González
On Mar 31, 8:38 am, Bjoern Schliessmann  wrote:
> Mark Dufour wrote:
> > Shed Skin allows for translation of pure (unmodified), implicitly
> > statically typed Python programs into optimized C++, and hence,
>
>^> highly 
> optimized machine language.
>
>   
>
> Wow, I bet all C++ compiler manufacturers would want you to work for
> them.
>
> Regards,
>
> Björn
>
> --
> BOFH excuse #23:
>
> improperly oriented keyboard


Mark has been doing an heroic job so far.
Shedskin is an impressive piece of software and, if pypy hadn't been
started some time ago, it should have gotten more attention from the
community.
I think he should be taken very seriously.

He is the first programmer I know who actually released working
code(and a lot of it) of a project that actually manages to speed up
python by a large margin, by means of advanced type inference
techniques.
Other people, in the past, have attended conferences and made
spectacular announcements of projects that could speed up python by
60x or more, but never ever released any code.

Mark has been working quietly for a long time, and his works deserves
a lot of credit (and hopefully, some help).




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


help with dates

2007-03-31 Thread rustybear
[sorry about the earlier post. accidently hit enter]

I'm working on a website for some firefighters that want to be able to
sign-up for overtime and I need some help figuring out a date related
problem.

Here's the scenario:

Four groups of firefighters (group1, group2, group3, group4). Each
group works a 24 hr shift. So group1 works April 1, group2 works April
2, group3 works April 3, group4 works April 4, group 1 works April 5,
etc. It just keeps rolling like this forever into next year, etc.

I need to come up with a methodology for the following:

If given a date, find out what group is working on that date.

Has anyone dealt with a problem like this before?  Obviously I'll need
to have a starting date where group1 is associated with a starting
date. Fortunately there are no surprises. Groups work in order
(1,2,3,4,1,2,3,4,1,2,...) and dates go in order and there are
absolutely no special exceptions for holidays and anything else.

Thanks in advance for any clues.

Kevin

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


help with dates

2007-03-31 Thread rustybear

I'm working on a website for some firefighters that want to be able to
sign-up for overtime and I need some help figuring out a date related
problem.

Here's the scenario:

Four groups of firefighters (group1, group2, group3, group4). Each
group works a 24 hr shift. So group1 works April 1, group2 works April
2, group3 works April 3, group4 works April 4, group 1 works April 5,
etc. It just keeps rolling like this forever into next year, etc.

I need to come up with a methodology for the following:

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


Re: Shed Skin Python-to-C++ Compiler 0.0.21, Help needed

2007-03-31 Thread Bjoern Schliessmann
[EMAIL PROTECTED] wrote:

> Why are you taking potshots at Mark? 

What suggests that I'm "taking potshots" at Mark?

> He's maybe onto something and he's asking for help.  If he can
> generate efficient C++ code from implicitly statically type Python
> it stands to reason that he can take advantage of the compiler's
> optimization facilities. 

Yes, compilers do output optimized machine code. But generally
calling that code "highly optimized" is, IMHO, exaggeration.

Regards,


Björn

-- 
BOFH excuse #426:

internet is needed to catch the etherbunny

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


Re: PyPy for dummies

2007-03-31 Thread Georg Brandl
Cameron Laird schrieb:
> In article <[EMAIL PROTECTED]>,
> Paddy <[EMAIL PROTECTED]> wrote:
>   .
>   .
>   .
>>It is also European funding for an open source project with sprints.
>>I'm sure some eurocrat will be dissecting the project to see if it is
>>aa good way to fund technical projects.
>>
>>- Paddy.
>>
> 
> PyPy-ers, what *are* the prospects in this direction?
> Are there write-ups planned that'll be of interest to
> computing people?

There is already a whole bunch of reports for the EU at

http://codespeak.net/pypy/extradoc/eu-report/

HTH,
Georg

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


Re: Sorting a multidimensional array by multiple keys

2007-03-31 Thread Duncan Booth
Peter Otten <[EMAIL PROTECTED]> wrote:

> Duncan Booth wrote:
> 
> from operator import itemgetter
> data.sort(key=itemgetter(0))
> data.sort(key=itemgetter(1))
> data.sort(key=itemgetter(4))
> data.sort(key=itemgetter(3))
> 
> Or, in Python 2.5:
> 
 data.sort(key=itemgetter(3, 4, 1, 0))
> 
Thanks, I'd forgotten itemgetter had that strangley assymmetric behaviour 
of returning either a single value or a tuple.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Game programming for kids: looking for open source 2D game development kit

2007-03-31 Thread pabloreda
I 'm doing the same

in forth...

www.reda4.org



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


Extending embedded python of multiple interpreters

2007-03-31 Thread vishnu
Hello All,

I have embedded python 2.5 in to my C application. As we need the
python scripts to run in multi threaded environment I have used
Py_NewInterpreter() and Py_EndInterpreter each time I execute a run
script function.
The code is as follows:
RunScript(char *pScriptName,char *pFuncName,...)
{
PyEval_AcquireLock()
threadState = Py_NewInterpreter();
PyThreadState_Swap(threadState);

/* Import the script module and run the fnc in that script module */
Pyobject *pModule = PyImport_Import(pScriptName);
PyObject *pFunc = PyObject_GetAttrString(pModule, pFuncName);

/* End running the script and calling the script fnc */
Py_EndInterpreter(threadState);
PyEval_ReleaseLock();
}.

And my python initialise looks as :
pythonInit() {
Py_initialise();
PyEval_initThreads();//which enables multi thread support
}

Now I am extending the embedded python to expose my application
library API's to python using SWIG. I written one extension module and
from python i am setting the C structure member values which i
wrapped. I execute this python code using call to RunScript (above
function), it works fine for the first time, but from second time
onwards I get an error - Type Error : in method
_set.
Hence my question is the same python code worked for first call, but
from 2nd call it is not working. Could any body help me where I am
making mistake.

Is extension modules does not work properly with multiple
interpreters? Does any body had this behaviour when worked with
extension modules and multiple interpreters creation for each thread.

Thanks in Advance for the help.

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


Re: What are OOP's Jargons and Complexities

2007-03-31 Thread Bart Willems
> 
> Even better: pick one entry of your choice from
> 
> http://images.google.com/images?q=%22don%27t+feed+the+troll%22
> 
> 
> Michele

OMG and here I am thinking that Ken Rockwell's site is full of crap. 
This one's worse... Does the guy have a job? Or a life?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Newbie Question (real-time communication between apps: audio, 3d, PD, Blender)

2007-03-31 Thread gregorywieber
Thank you, everyone!

On Mar 31, 6:43 am, Laurent Pointal <[EMAIL PROTECTED]>
wrote:
> [EMAIL PROTECTED] wrote:
> > Hi All,
>
> > I'm just beginning my exploration of Python and I have a rather
> > general question. If two particular programs have Python scripting
> > capabilities, does that mean those two programs can communicate in
> > real time through Python?
>
> > I'm running some audio experiments (for artistic purposes) in the
> > program Pure Data (PD). I would like to use data that I extract from
> > audio files to affect 3-d game simulations in Blender.  I don't know
> > specifically what it is I would be manipulating -- this is an artistic
> > project, so intend to do a lot of experimenting to see what I come up
> > with...
>
> > My question(s): Is this possible, reasonable, plausible?
>
> Plausible, with a recent PC.
>
> I use some Java code + a research TTS engine (C) + Python code + Pure Data +
> VirChor (3D renderer+interract, C++) in a TalkingHead project at LIMSI.
> All these communicate via UDP, we just tries to keep amount of transmitted
> data not too huge (ie. just transmit status, positions, commands...).
> For the realtime side capacity, it depend on the process you need in
> Python - if Python reveal to be too slow, you may write long computing code
> into a separate C module or library (may see ctypes and pyrex).
> Another point, if you build Python multithreading code in same process, the
> Global Lock may lead to unefficient use of your computing capacities.
>
> Note. You may take a look at OSC (Open Sound Control), there is a module for
> PD and one for Python.
>
> A+
>
> Laurent.


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


Re: Sorting a multidimensional array by multiple keys

2007-03-31 Thread Rehceb Rotkiv
Thank you all for your helpful solutions!

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


Re: When will 2.5.1 be released?

2007-03-31 Thread Martin v. Löwis
>> And while we're waiting for 2.5.1, can somebody post a clear (as
>> opposed to the one that comes with Tix ;)) explanation of how to
>> manually install Tix into python 2.5?  It should be possible...
> 
> LLoyd
> -Not possible - this is a known bug and won't be fixed until 2.5.1

This is not true. Copying the tix files into the Python installation
will work just fine.

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


Re: Long way around UnicodeDecodeError, or 'ascii' codec can't decode byte

2007-03-31 Thread Paul Boddie
Oleg  Parashchenko wrote:
> On Mar 29, 4:53 pm, "Paul Boddie" <[EMAIL PROTECTED]> wrote:
> > On 29 Mar, 06:26, "Oleg  Parashchenko" <[EMAIL PROTECTED]> wrote:
> > >
> > > I'm working on an unicode-aware application. I like to use "print" to
> > > debug programs, but in this case it was nightmare. The most popular
> > > result of "print" was:
> > >
> > > UnicodeDecodeError: 'ascii' codec can't decode byte 0xXX in position
> > > 0: ordinal not in range(128)

I think I've found the actual source of this, and it isn't the print
statement. UnicodeDecodeError relates to the construction of Unicode
objects, not the encoding of such objects as byte strings. The
terminology is explained using this simple diagram (which hopefully
won't be ruined in transmission):

  byte string in XYZ encoding
  |
  (decode from XYZ) --> possible UnicodeDecodeError
  |
  V
  Unicode object
  |
  (encode to ABC) --> possible UnicodeEncodeError
  |
  V
  byte string in ABC encoding

> > What does sys.stdout.encoding say?
>
> 'KOI8-R'

[...]

> > What do you get if you do this...?
> >
> > import locale
> > locale.setlocale(locale.LC_ALL, "")
> > print locale.getlocale()
>
> ('ru_RU', 'koi8-r')
>
> >
> > What is your terminal encoding?
>
> koi8-r

Here's a transcript on my system answering the same questions:

  Python 2.4.1 (#2, Oct  4 2006, 16:53:35)
  [GCC 3.3.5 (Debian 1:3.3.5-8ubuntu2.1)] on linux2
  Type "help", "copyright", "credits" or "license" for more
information.
  >>> import locale
  >>> locale.getlocale()
  (None, None)
  >>> locale.setlocale(locale.LC_ALL, "")
  'en_US.ISO-8859-15'
  >>> locale.getlocale()
  ('en_US', 'iso-8859-15')

So Python knows about the locale. Note that neither of us use UTF-8 as
a system encoding.

  >>> import sys
  >>> sys.stdout.encoding
  'ISO-8859-15'
  >>> sys.stdin.encoding
  'ISO-8859-15'

This tells us that Python could know things about writing Unicode
objects out in the appropriate encoding. I wasn't sure whether Python
was so smart about this, so let's see what happens...

  >>> print unicode("æøå")
  Traceback (most recent call last):
File "", line 1, in ?
  UnicodeDecodeError: 'ascii' codec can't decode byte 0xe6 in position
0: ordinal not in range(128)

Now this isn't anything to do with the print operation: what's
happening here is that I'm explicitly making a Unicode object but
haven't said what the encoding of my byte string is. The default
encoding is 'ascii' as stated in the error message. None of the
characters provided belong to the ASCII character set.

We can check this by not printing anything out:

  >>> s = unicode("æøå")
  Traceback (most recent call last):
File "", line 1, in ?
  UnicodeDecodeError: 'ascii' codec can't decode byte 0xe6 in position
0: ordinal not in range(128)

So, let's try again and provide an encoding...

  >>> print unicode("æøå", sys.stdin.encoding)
  æøå

Here, we've mentioned the encoding and even though the print statement
is acting on a Unicode object, it seems to be happy to work out the
resulting encoding.

  >>> print u"æøå"
  æøå

Here, we've skipped the explicit Unicode object construction by using
a Unicode literal, which works in this simple case.

Of course, if your system encoding (along with the terminal) isn't
capable of displaying every Unicode character, you'll experience
problems doing the above. Frequently, it's interesting to encode
things as UTF-8 and look at them in applications that are capable of
displaying the text. Thus, you'd do something like this:

  import unicodedata

(This gets an interesting function to help us look up characters in
the Unicode database.)

  somefile = open("somefile.txt", "wb")
  print >>somefile, unicodedata.lookup("MONGOLIAN VOWEL
SEPARATOR").encode("utf-8")

Or even this:

  import codecs
  somefile = codecs.open("somefile.txt", "wb", encoding="utf-8")
  print >>somefile, unicodedata.lookup("MONGOLIAN VOWEL SEPARATOR")

Here, we only specified the encoding once when opening the file. The
file object accepts Unicode objects thereafter.

> > Usually, if I'm wanting to print Unicode objects, I explicitly encode
> > them into something I know the terminal will support. The codecs
> > module can help with writing Unicode to streams in different
> > encodings, too.
>
> As long as input/output is the only place for such need, it's ok to
> encode expliciyely. But I also had problems, for example, with md5
> module, and I don't know the whole list of potential problematic
> places. Therefore, I'd better go with my brutal utf8ization.

It's best to decode (ie. construct Unicode objects) upon receiving
data as input, and to encode (ie. convert Unicode objects to byte
strings) upon producing output. What may be the problem with the md5
module, and you'd have to post example code for us to help you out, is
that it assumes byte strings and doesn't work properly with Unicode
objects, but I can't say for sure because I'm usually presenting byte
strings to 

Re: Sorting a multidimensional array by multiple keys

2007-03-31 Thread Peter Otten
Duncan Booth wrote:

 from operator import itemgetter
 data.sort(key=itemgetter(0))
 data.sort(key=itemgetter(1))
 data.sort(key=itemgetter(4))
 data.sort(key=itemgetter(3))

Or, in Python 2.5:

>>> data.sort(key=itemgetter(3, 4, 1, 0))

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


Re: os.system questions

2007-03-31 Thread Aahz
In article <[EMAIL PROTECTED]>,
Eric Price <[EMAIL PROTECTED]> wrote:
>
>I have a couple bugs to work out in the below script; namely, I don't
>know how to capture the result of an os.system command, nor am I
>convinced that the call to os.system actually results in the execution
>of the command. Here is the script:

Although you've already figured out the problem, I'll just make the
standard recommendation for the subprocess module, assuming you have
Python 2.4 or later.
-- 
Aahz ([EMAIL PROTECTED])   <*> http://www.pythoncraft.com/

Need a book?  Use your library!
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Sorting a multidimensional array by multiple keys

2007-03-31 Thread attn . steven . kuo
On Mar 31, 6:42 am, Rehceb Rotkiv <[EMAIL PROTECTED]> wrote:

(snipped)

> As each line consists of 5 words, I would break up the data into an array
> of five-field-arrays (Would you use lists or tuples or a combination in
> Python?). The word "BUT" would be in the middle, with two fields/words
> left and two fields/words right of it. I then want to sort this list by
>
> - field 3
> - field 4
> - field 1
> - field 0



import StringIO

buf = """
reaction is BUT by the
sodium , BUT it is
sea , BUT it is
this manner BUT the dissolved
pattern , BUT it is
rapid , BUT it is
""".lstrip()

mockfile = StringIO.StringIO(buf)

tokens = [ line.split() + [ line ] for line in mockfile ]
tokens.sort(key=lambda l: (l[3], l[4], l[1], l[0]))
for l in tokens:
print l[-1],


--
Hope this helps,
Steven

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


Re: What are OOP's Jargons and Complexities

2007-03-31 Thread Lew
Michele Dondi wrote:
> Even better: pick one entry of your choice from
> 
> http://images.google.com/images?q=%22don%27t+feed+the+troll%22

I pick 

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


Re: What are OOP's Jargons and Complexities

2007-03-31 Thread Lew
Arved Sandstrom wrote:
> "Timofei Shatrov" <[EMAIL PROTECTED]> wrote in message 
> news:[EMAIL PROTECTED]
>> On Fri, 30 Mar 2007 06:48:05 GMT, "Mike Schilling" 
>> <[EMAIL PROTECTED]>
>> tried to confuse everyone with this message:
>>
>>> Xah Lee wrote:
>>>
 So, a simple code like this in normal languages:
 becomes in Java:
>>> Only when written by someone almost entirely ignorant of Java.
>>>
>> Which is the state most people want to be in...
> 
> Which based on what I've seen, is the state that most Java programmers are 
> in. They'd have no idea why Mike said what he did.

what EVerrr!

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


Re: Sorting a multidimensional array by multiple keys

2007-03-31 Thread Duncan Booth
Rehceb Rotkiv <[EMAIL PROTECTED]> wrote:

> Wait, I made a mistake. The correct result would be
> 
> reaction is BUT by the
> pattern , BUT it is
> rapid , BUT it is
> sea , BUT it is
> sodium , BUT it is
> this manner BUT the dissolved
> 
> because "by the" comes before and "the dissolved" after "it is". Sorry 
> for the confusion.

>>> data = [
"reaction is BUT by the",
"sodium , BUT it is",
"sea , BUT it is",
"this manner BUT the dissolved",
"pattern , BUT it is",
"rapid , BUT it is",
]
>>> data = [ s.split() for s in data]
>>> from pprint import pprint
>>> pprint(data)
[['reaction', 'is', 'BUT', 'by', 'the'],
 ['sodium', ',', 'BUT', 'it', 'is'],
 ['sea', ',', 'BUT', 'it', 'is'],
 ['this', 'manner', 'BUT', 'the', 'dissolved'],
 ['pattern', ',', 'BUT', 'it', 'is'],
 ['rapid', ',', 'BUT', 'it', 'is']]
>>> from operator import itemgetter
>>> data.sort(key=itemgetter(0))
>>> data.sort(key=itemgetter(1))
>>> data.sort(key=itemgetter(4))
>>> data.sort(key=itemgetter(3))
>>> pprint(data)
[['reaction', 'is', 'BUT', 'by', 'the'],
 ['pattern', ',', 'BUT', 'it', 'is'],
 ['rapid', ',', 'BUT', 'it', 'is'],
 ['sea', ',', 'BUT', 'it', 'is'],
 ['sodium', ',', 'BUT', 'it', 'is'],
 ['this', 'manner', 'BUT', 'the', 'dissolved']]
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Sorting a multidimensional array by multiple keys

2007-03-31 Thread Steven Bethard
Rehceb Rotkiv wrote:
>> If you want a good answer you have to give me/us more details, and an
>> example too.
> 
> OK, here is some example data:
> 
> reaction is BUT by the
> sodium , BUT it is
> sea , BUT it is
> this manner BUT the dissolved
> pattern , BUT it is
> rapid , BUT it is
> 
> As each line consists of 5 words, I would break up the data into an array 
> of five-field-arrays (Would you use lists or tuples or a combination in 
> Python?). The word "BUT" would be in the middle, with two fields/words 
> left and two fields/words right of it. I then want to sort this list by
> 
> - field 3
> - field 4
> - field 1
> - field 0

You're probably looking for the key= argument to list.sort().  If your 
function simply returns the fields in the order above, I believe you get 
the right thing::

 >>> s = '''\
... reaction is BUT by the
... sodium , BUT it is
... sea , BUT it is
... this manner BUT the dissolved
... pattern , BUT it is
... rapid , BUT it is
... '''
 >>> word_lists = [line.split() for line in s.splitlines()]
 >>> def key(word_list):
... return word_list[3], word_list[4], word_list[1], word_list[0]
...
 >>> word_lists.sort(key=key)
 >>> word_lists
[['reaction', 'is', 'BUT', 'by', 'the'],
  ['pattern', ',', 'BUT', 'it', 'is'],
  ['rapid', ',', 'BUT', 'it', 'is'],
  ['sea', ',', 'BUT', 'it', 'is'],
  ['sodium', ',', 'BUT', 'it', 'is'],
  ['this', 'manner', 'BUT', 'the', 'dissolved']]

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


Re: Is any way to split zip archive to sections?

2007-03-31 Thread Tim Williams
On 30/03/07, Durumdara <[EMAIL PROTECTED]> wrote:
> Hi!
>
> I want to create some backup archives with python (I want to write a backup
> application in Python).
> Some package managers (7z, arj, winzip) can create splitted archives (1
> mega, 650, 700 mega, etc).
>
> Because I want to ftp these results to a ftp server, I want to split large
> volumes to 15 mb sections.
>
> Can I do it with any python wrapper automatically (like in Cobian), or I
> need to create the large volume, and next split it with another tool?
>
> Or anybody knows about a command line tool (like 7z, or arj) that can expand
> the splitted archive (and I can add files with them from Python one by one)?
>

If you are iterating through a list of files to be backed up, and
adding them to a ZIP one-by-one then you could use something like this
 which adds each file until the zip is over 15mb - then it closes the
ZIP and creates the next one.

Not tested or optimised :)
---
import zipfile

archive_num = 1
outfile = zipfile.ZipFile('/zips/archive%s.zip' % archive_num, "w")
zsize = 0

for full_name in filelist:
full_name_path = os.path.join(full_name, full_path)

if zsize > 15728640 : # 15mb
outfile.close()
archive_num += 1
outfile = zipfile.ZipFile('/zips/archive%s.zip' % archive_num, "w")
zsize= 0

outfile.write( full_name_path , full_name_path ,
zipfile.ZIP_DEFLATED) # add the file
zsize += outfile.getinfo(full_name_path).compress_size #  get
compressed size of file

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


Re: os.system questions

2007-03-31 Thread David Brochu








From: "Eric Price" <[EMAIL PROTECTED]>
Date: March 31, 2007 9:38:53 AM EDT
To: [EMAIL PROTECTED], [EMAIL PROTECTED]
Cc: python-list@python.org
Subject: Re: os.system questions


Oops! The problem isn't in the os.system call. It's in the fact  
that I don't call the function. That is, I write a script called  
"test.py" with a function in it called "freshReboot". Now, how do I  
call that function from test.py? That is, how do I write a cron  
event such that "freshReboot" actually gets called when I run test.py?

TIA,
Eric



>>> Eric - to call a function that is located inside another module  
you first need to import that module into the program you are running:



from test.py import * # this would import all functions from test.py
from test.py import freshReboot # this will import freshReboot from  
test.py



to call freshReboot in your program you would simply call it by it's  
name freshReboot


ex: x = freshReboot()-- 
http://mail.python.org/mailman/listinfo/python-list

Re: wxPython help

2007-03-31 Thread hg
Blh ([EMAIL PROTECTED]) wrote:

> i have installed wxpython v2.6 for python 2.4
> my python installation is at d:\python24
> 
> the statement "import wx" works perfectly
> but when i use "import images", it says that there is no module, but
> i know for a fact that there is.
> 
> can anyone help?
> 
> 
> --
> - --- -- -
> Posted with NewsLeecher v3.8 Beta 8
> Web @ http://www.newsleecher.com/?usenet
> --- -  -- -

Maybe this:

http://mail.python.org/pipermail/python-list/2002-February/128104.html

hg

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


Re: os.system questions

2007-03-31 Thread Eric Price
Thank you :)
Eric


>From: "Parthan SR" <[EMAIL PROTECTED]>
>To: "Eric Price" <[EMAIL PROTECTED]>
>Subject: Re: os.system questions
>Date: Sat, 31 Mar 2007 19:52:01 +0530
>
>On 3/31/07, Eric Price <[EMAIL PROTECTED]> wrote:
>>
>>Oops! The problem isn't in the os.system call. It's in the fact that I
>>don't
>>call the function. That is, I write a script called "test.py" with a
>>function in it called "freshReboot". Now, how do I call that function from
>>test.py? That is, how do I write a cron event such that "freshReboot"
>>actually gets called when I run test.py?
>
>
>Just call the function name within the test.py itself
>
>def freshReboot():
>...
>...
>...
>...
>
>if __name__ == '__main__':
>freshReboot()
>
>(or)
>
>freshReboot()
>
>Now, run test.py. If you are printing anything or having a return value,
>then it will be displayed in the terminal from where you call the program.
>If you are executing it from another script, then the return value will be
>returned where it is being called.
>--
>With Regards
>
>---
>Parthan.S.R.
>Research Assistant
>National Resource Center for Free/Open Source Software
>Python Developer n00b

_
Interest Rates near 39yr lows! $430,000 Mortgage for $1,399/mo - Calculate 
new payment 
http://www.lowermybills.com/lre/index.jsp?sourceid=lmb-9632-18466&moid=7581

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


Re: Mouse click in python

2007-03-31 Thread hlubenow
Synt4x wrote:

> I'm creating a webcam user interface (to control google earth through
> my webcam) and I still can't find a good example to how to control the
> mouse to "click and drag" (not just click and release).

Pygame:

http://www.pygame.org/
http://www.pygame.org/docs/ref/mouse.html

provides event-control including mouse-event-control.
Mainly it's intended for games, but it should work for other projects like
yours too. HTH

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


wxPython help

2007-03-31 Thread [EMAIL PROTECTED]
i have installed wxpython v2.6 for python 2.4 
my python installation is at d:\python24

the statement "import wx" works perfectly
but when i use "import images", it says that there is no module, but 
i know for a fact that there is.

can anyone help?


--
- --- -- -
Posted with NewsLeecher v3.8 Beta 8
Web @ http://www.newsleecher.com/?usenet
--- -  -- -

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


saving Python process state for later debugging

2007-03-31 Thread yossi . kreinin
Hi!

Is there a way to save the state of a Python process for later
inspection with a debugger? One way to do this is to dump core, but is
the result usable for debugging with pdb (it can be debugged by gdb,
which can inspect PyObjects in a CPython core, for example, but it's
not much fun)?

If there is no way to do this today, are there essential difficulties
in implementing this on top of an OS support for "raw" core dumps?

TIA,
Yossi

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


Re: Remote XML Parsing

2007-03-31 Thread Laurent Pointal
[EMAIL PROTECTED] wrote:

> On Mar 30, 5:56 pm, Laurent Pointal <[EMAIL PROTECTED]> wrote:
>> [EMAIL PROTECTED] a écrit :
>>
>> > How can I parse a remote XML file with Python?
>> > And what will I be able to do with this XML file in Python?
>>
>> > Sorry if this is a noob-ish question.
>>
>> You can process XML data with Python as long as you can get it - you
>> will be able to do what you want with it.
>>
>> How do you access your remote file ?
>>
>> ...more details would be welcome...
> 
> Well I'll be happy to access in the way your comfortable with.

Net protocols -> urllib2 module
Local files (or network mounted files) -> open function
Remote call -> xmlrpc, omniORBpy, pyrpc...


Once you get the XML data... sax/dom/elementtree & Co (see Python docs, Dive
Into Python...).


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

Re: Newbie Question (real-time communication between apps: audio, 3d, PD, Blender)

2007-03-31 Thread Laurent Pointal
[EMAIL PROTECTED] wrote:

> Hi All,
> 
> I'm just beginning my exploration of Python and I have a rather
> general question. If two particular programs have Python scripting
> capabilities, does that mean those two programs can communicate in
> real time through Python?
> 
> I'm running some audio experiments (for artistic purposes) in the
> program Pure Data (PD). I would like to use data that I extract from
> audio files to affect 3-d game simulations in Blender.  I don't know
> specifically what it is I would be manipulating -- this is an artistic
> project, so intend to do a lot of experimenting to see what I come up
> with...
> 
> My question(s): Is this possible, reasonable, plausible?

Plausible, with a recent PC.

I use some Java code + a research TTS engine (C) + Python code + Pure Data +
VirChor (3D renderer+interract, C++) in a TalkingHead project at LIMSI.
All these communicate via UDP, we just tries to keep amount of transmitted
data not too huge (ie. just transmit status, positions, commands...).
For the realtime side capacity, it depend on the process you need in
Python - if Python reveal to be too slow, you may write long computing code
into a separate C module or library (may see ctypes and pyrex). 
Another point, if you build Python multithreading code in same process, the
Global Lock may lead to unefficient use of your computing capacities.

Note. You may take a look at OSC (Open Sound Control), there is a module for
PD and one for Python.

A+

Laurent.

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


Re: Shed Skin Python-to-C++ Compiler 0.0.21, Help needed

2007-03-31 Thread skip

Björn> Mark Dufour wrote:
>> Shed Skin allows for translation of pure (unmodified), implicitly
>> statically typed Python programs into optimized C++, and hence,
>> highly optimized machine language.
Bjoern>   

Bjoern> Wow, I bet all C++ compiler manufacturers would want you to work
Bjoern> for them.

Why are you taking potshots at Mark?  He's maybe onto something and he's
asking for help.  If he can generate efficient C++ code from implicitly
statically type Python it stands to reason that he can take advantage of the
compiler's optimization facilities.

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


Opening Photoshop EPS with PIL?

2007-03-31 Thread [EMAIL PROTECTED]
Hey Everyone,

I am trying to get PIL to open some EPS files I have (Photoshop EPS,
whatever the difference is). I'm trying to use PIL to do this, but
when I run it, the following happens:

>>> from PIL import Image, ImageOps
>>> Image.open('/flora.eps')
Traceback (most recent call last):
  File "", line 1, in ?
  File "/opt/local/lib/python2.4/site-packages/PIL/Image.py", line
1741, in open
return factory(fp, filename)
  File "/opt/local/lib/python2.4/site-packages/PIL/ImageFile.py", line
82, in __init__
self._open()
  File "/opt/local/lib/python2.4/site-packages/PIL/EpsImagePlugin.py",
line 206, in _open
raise IOError, "bad EPS header"

I've never had any real trouble with PIL before (never used it for EPS
though). Can anyone offer any advice on this one? I'd be most
grateful.

Many Thanks Everyone,
Oliver Beattie

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


Re: Indentation for code readability

2007-03-31 Thread jkn
If I wanted to mark out stack depth stuff like this in python, I'd do
it
with some form of stylised comment, like this:

# LEVEL 0

pushMatrix():
# LEVEL 1

drawstuff()
pushMatrix()
# LEVEL 2

drawSomeOtherStuff()
popMatrix()
# LEVEL 1

popMatrix()
# LEVEL 0

(there's probably a better comment form for your specific
requirement).

Any decent modern editor should be capable of being set up to
highlight such lines in a colour/style of your choice, and you then
set your eyeball filter to look for those lines when you want to be
sure of where you are.

jon N

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


Re: Sorting a multidimensional array by multiple keys

2007-03-31 Thread Rehceb Rotkiv
Wait, I made a mistake. The correct result would be

reaction is BUT by the
pattern , BUT it is
rapid , BUT it is
sea , BUT it is
sodium , BUT it is
this manner BUT the dissolved

because "by the" comes before and "the dissolved" after "it is". Sorry 
for the confusion.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Sorting a multidimensional array by multiple keys

2007-03-31 Thread Rehceb Rotkiv
> If you want a good answer you have to give me/us more details, and an
> example too.

OK, here is some example data:

reaction is BUT by the
sodium , BUT it is
sea , BUT it is
this manner BUT the dissolved
pattern , BUT it is
rapid , BUT it is

As each line consists of 5 words, I would break up the data into an array 
of five-field-arrays (Would you use lists or tuples or a combination in 
Python?). The word "BUT" would be in the middle, with two fields/words 
left and two fields/words right of it. I then want to sort this list by

- field 3
- field 4
- field 1
- field 0

in this hierarchy. This is the desired result:  

pattern , BUT it is
rapid , BUT it is
sea , BUT it is
sodium , BUT it is
reaction is BUT by the
this manner BUT the dissolved

The first 4 lines all could not be sorted by fields 3 & 4, as they are 
identical ("it", "is"), so they have been sorted first by field 1 (which 
is also identical: ",") and then by field 0:

pattern
rapid
sea
sodium

I hope I have explained this in an understandable way. It would be cool 
if you could show me how this can be done in Python!

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


Re: os.system questions

2007-03-31 Thread Eric Price
Oops! The problem isn't in the os.system call. It's in the fact that I don't 
call the function. That is, I write a script called "test.py" with a 
function in it called "freshReboot". Now, how do I call that function from 
test.py? That is, how do I write a cron event such that "freshReboot" 
actually gets called when I run test.py?
TIA,
Eric


>From: "Eric Price" <[EMAIL PROTECTED]>
>To: [EMAIL PROTECTED]
>CC: python-list@python.org
>Subject: Re: os.system questions
>Date: Sat, 31 Mar 2007 09:33:03 -0400
>
>Great! That seems to work fine:
>
>#!/usr/local/bin/python
>import re, os
>
>def freshReboot():
>   up = os.popen('uptime').readlines()
>   up = up[0]
>   if re.search('day|hour', up):
>   pass
>   else:
>   tup = re.split('min', up)
>   first = tup[0]
>   n = len(first)
>   char = first[n-3:n-2]
>   if re.match(' ', char):
>   
> os.system("/usr/local/etc/rc.d/zz_mysql_starter_script.sh")
>
>However, I don't see evidence that the os.system call at the end actually
>executes said script. The reason for this screwy script is because MySQL
>doesn't set the proper environment on boot and that screws up my Zope
>instances. So, I'll cron this script to run every 6 mins. If the server has
>been up less than 10 mins, this script will run. So, I rebooted the server
>and ran the script. But it didn't execute the os.system script at the end!
>If I run this from the python prompt instead:
>
>import re, os
>
>def a():
>   up = os.popen('uptime').readlines()
>   up = up[0]
>   up = " 7:25AM  up 2 mins, 1 user, load averages: 2.42, 1.01, 0.41"
>   if re.search('day|hour', up):
>   pass
>   else:
>   tup = re.split('min', up)
>   first = tup[0]
>   n = len(first)
>   char = first[n-3:n-2]
>   if re.match(' ', char):
>   print "gotcha!"
>
>it prints "gocha!" Now, that substitution for the "up" var is what I got as
>output from the "uptime" command at the shell prompt. So, obviously, it
>should be running the script! What am I doing wrong?
>TIA,
>Eric
>
>_
>Watch free concerts with Pink, Rod Stewart, Oasis and more. Visit MSN
>Presents today.
>http://music.msn.com/presents?icid=ncmsnpresentstagline&ocid=T002MSN03A07001
>
>--
>http://mail.python.org/mailman/listinfo/python-list

_
5.5%* 30 year fixed mortgage rate. Good credit refinance. Up to 5 free 
quotes - *Terms 
https://www2.nextag.com/goto.jsp?product=10035&url=%2fst.jsp&tm=y&search=mortgage_text_links_88_h2a5d&s=4056&p=5117&disc=y&vers=910

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


Re: os.system questions

2007-03-31 Thread Eric Price
Great! That seems to work fine:

#!/usr/local/bin/python
import re, os

def freshReboot():
up = os.popen('uptime').readlines()
up = up[0]
if re.search('day|hour', up):
pass
else:
tup = re.split('min', up)
first = tup[0]
n = len(first)
char = first[n-3:n-2]
if re.match(' ', char):

os.system("/usr/local/etc/rc.d/zz_mysql_starter_script.sh")

However, I don't see evidence that the os.system call at the end actually 
executes said script. The reason for this screwy script is because MySQL 
doesn't set the proper environment on boot and that screws up my Zope 
instances. So, I'll cron this script to run every 6 mins. If the server has 
been up less than 10 mins, this script will run. So, I rebooted the server 
and ran the script. But it didn't execute the os.system script at the end! 
If I run this from the python prompt instead:

import re, os

def a():
up = os.popen('uptime').readlines()
up = up[0]
up = " 7:25AM  up 2 mins, 1 user, load averages: 2.42, 1.01, 0.41"
if re.search('day|hour', up):
pass
else:
tup = re.split('min', up)
first = tup[0]
n = len(first)
char = first[n-3:n-2]
if re.match(' ', char):
print "gotcha!"

it prints "gocha!" Now, that substitution for the "up" var is what I got as 
output from the "uptime" command at the shell prompt. So, obviously, it 
should be running the script! What am I doing wrong?
TIA,
Eric

_
Watch free concerts with Pink, Rod Stewart, Oasis and more. Visit MSN 
Presents today. 
http://music.msn.com/presents?icid=ncmsnpresentstagline&ocid=T002MSN03A07001

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


Re: Sorting a multidimensional array by multiple keys

2007-03-31 Thread bearophileHUGS
Rehceb Rotkiv:
> can I sort a multidimensional array in Python by multiple sort keys? A
> litte code sample would be nice!

If you want a good answer you have to give me/us more details, and an
example too.

Bye,
bearophile

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


Need help with python and pyxml on AIX

2007-03-31 Thread loial
I have been asked to install a python application on AIX 5.3 that runs
OK on Windows
I have installed Python 4.2.2 from python.org and pyXML form
sourceforge.

However when I run the application I get the following error :

class xml.sax._exceptions.SAXReaderNotAvailable

Do I need to set some Python environment variables?

Can I test the availibility of this from the python command line. e.g
import something?

I am new to Python

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


Re: Sorting a multidimensional array by multiple keys

2007-03-31 Thread Thomas Krüger
Rehceb Rotkiv schrieb:
> can I sort a multidimensional array in Python by multiple sort keys? A 
> litte code sample would be nice!

You can pass a function as argument to the sort method of a list.
The function should take two arguments and return -1, 0 or 1 as
comparison result. Just like the cmp function.

This will objects in list obj_lst by their id attributes:

def sorter(a, b):
return cmp(a.id, b.id)

obj_lst.sort(sorter)

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


Re: os.system questions

2007-03-31 Thread Amit Khemka
On 3/31/07, Eric Price <[EMAIL PROTECTED]> wrote:
> Hi;
> I have a couple bugs to work out in the below script; namely, I don't know
> how to capture the result of an os.system command, nor am I convinced that
> the call to os.system actually results in the execution of the command. Here
> is the script:
>
> #!/usr/local/bin/python
> import re, os
>
> def freshReboot():
> up = os.system("uptime")
> if re.search('day|hour', up):
> pass
> else:
> first = up
> tup = re.split('min', up)
> first = tup[0]
> n = len(first)
> char = first[n-3:n-2]
> if re.match(' ', char):
> 
> os.system("/usr/local/etc/rc.d/zz_mysql_starter_script.sh")
>
>
> Here are my problems:
>
> up = os.system("uptime")
> How do I assign the output of "uptime" to the variable "up"?
>
> os.system("/usr/local/etc/rc.d/zz_mysql_starter_script.sh")
> When I substitute a test variable for "up", I don't get this script to
> actually run. Everything else is tested and works. Why won't this script
> run?

os.system doesn't allow you to get the output of the program, use
os.popen instead.
example:
import os
up = os.popen('uptime').readlines()

Cheers,

-- 

Amit Khemka -- onyomo.com
Home Page: www.cse.iitd.ernet.in/~csd00377
Endless the world's turn, endless the sun's Spinning, Endless the quest;
I turn again, back to my own beginning, And here, find rest.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: os.system questions

2007-03-31 Thread Thomas Krüger
Eric Price schrieb:
> up = os.system("uptime")
> How do I assign the output of "uptime" to the variable "up"?

| >>> print os.system.__doc__
| system(command) -> exit_status
|
| Execute the command (a string) in a subshell.

os.system returns the exitcode of the given command. To get the output
try os.popen to os.popen4 or the commands lib.

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


Sorting a multidimensional array by multiple keys

2007-03-31 Thread Rehceb Rotkiv
Hello everyone,

can I sort a multidimensional array in Python by multiple sort keys? A 
litte code sample would be nice!

Thx,
Rehceb

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


Re: What are OOP's Jargons and Complexities

2007-03-31 Thread Michele Dondi
On Fri, 30 Mar 2007 09:28:36 +0100, bugbear
<[EMAIL PROTECTED]> wrote:

>Er. How about
>
>public class test {
>   public static void main(String[] args) {
> String a = "a string";
> String b = "another one";
> StringBuffer c = a + b;
> System.out.println(c);
> }
>}

Even better: pick one entry of your choice from

http://images.google.com/images?q=%22don%27t+feed+the+troll%22


Michele
-- 
{$_=pack'B8'x25,unpack'A8'x32,$a^=sub{pop^pop}->(map substr
(($a||=join'',map--$|x$_,(unpack'w',unpack'u','G^http://mail.python.org/mailman/listinfo/python-list


Re: Shed Skin Python-to-C++ Compiler 0.0.21, Help needed

2007-03-31 Thread Bjoern Schliessmann
Mark Dufour wrote:

> Shed Skin allows for translation of pure (unmodified), implicitly
> statically typed Python programs into optimized C++, and hence,
   ^
> highly optimized machine language. 
  

Wow, I bet all C++ compiler manufacturers would want you to work for
them.

Regards,


Björn

-- 
BOFH excuse #23:

improperly oriented keyboard

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


os.system questions

2007-03-31 Thread Eric Price

Hi;
I have a couple bugs to work out in the below script; namely, I don't know 
how to capture the result of an os.system command, nor am I convinced that 
the call to os.system actually results in the execution of the command. Here 
is the script:


#!/usr/local/bin/python
import re, os

def freshReboot():
up = os.system("uptime")
if re.search('day|hour', up):
pass
else:
first = up
tup = re.split('min', up)
first = tup[0]
n = len(first)
char = first[n-3:n-2]
if re.match(' ', char):

os.system("/usr/local/etc/rc.d/zz_mysql_starter_script.sh")


Here are my problems:

up = os.system("uptime")
How do I assign the output of "uptime" to the variable "up"?

os.system("/usr/local/etc/rc.d/zz_mysql_starter_script.sh")
When I substitute a test variable for "up", I don't get this script to 
actually run. Everything else is tested and works. Why won't this script 
run?


TIA,
Eric

_
It’s tax season, make sure to follow these few simple tips 
http://articles.moneycentral.msn.com/Taxes/PreparationTips/PreparationTips.aspx?icid=HMMartagline


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

Re: Long way around UnicodeDecodeError, or 'ascii' codec can't decode byte

2007-03-31 Thread Jarek Zgoda
Oleg Parashchenko napisał(a):

>>> I spent two hours fixing it, and I hope it's done. The solution is one
>>> of the ugliest hack I ever written, but it solves the pain. The full
>>> story and the code is in my blog:
>>> http://uucode.com/blog/2007/03/23/shut-up-you-dummy-7-bit-python/
>> Calling sys.setdefaultencoding might not even help in this case, and
>> the consensus is that it may be harmful to your code's portability
>> [1].
> 
> Yes, but I think UTF-8 is now everywhere.

No, it is not. Your own system is "not ready for UTF-8", as you stated
somewhere in this blog entry. How can you expect everybody else's system
being utf-8, while "you are not ready for transition"?

It would be better if you write your programs in encoding-agnostic way,
using byte streams only for input and output (yes, printing a debug
statement on terminal *is* a kind of producing the output). An, oh, you
cann't encode/decode text not knowing the encoding...

-- 
Jarek Zgoda
http://jpa.berlios.de/
-- 
http://mail.python.org/mailman/listinfo/python-list


Shed Skin Python-to-C++ Compiler 0.0.21, Help needed

2007-03-31 Thread Mark Dufour
Hi all,

I have recently released version 0.0.20 and 0.0.21 of Shed Skin, an
optimizing Python-to-C++ compiler. Shed Skin allows for translation of
pure (unmodified), implicitly statically typed Python programs into
optimized C++, and hence, highly optimized machine language. Besides
many bug fixes and optimizations, these releases add the following
changes:

-support for 'bisect', 'collections.deque' and 'string.maketrans'
-improved 'copy' support
-support for 'try, else' construction
-improved error checking for dynamic types
-printing of floats is now much closer to CPython

For more details about Shed Skin and a collection of 27 programs, at a
total of about 7,000 lines, that it can compile (resulting in an
average speedup of about 39 times over CPython and 11 times over Psyco
on my computer), please visit the homepage at:

http://mark.dufour.googlepages.com

I could really use more help it pushing Shed Skin further. Simple ways
to help out, but that can save me lots of time, are to find smallish
code fragments that Shed Skin currently breaks on, and to help
improve/optimize the (C++) builtins and core libraries. I'm also
hoping someone else would like to deal with integration with CPython
(so Shed Skin can generate extension modules, and it becomes easier to
use 'arbitrary' external CPython modules such as 're' and 'pygame'.)
Finally, there may be some interesting Master's thesis subjects in
improving Shed Skin, such as transforming heap allocation into stack-
and static preallocation, where possible, to bring performance even
closer to manual C++. Please let me know if you are interested in
helping out, and/or join the Shed Skin mailing list.


Thanks!
Mark Dufour.
-- 
"One of my most productive days was throwing away 1000 lines of code"
- Ken Thompson
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: with timeout(...):

2007-03-31 Thread Nick Craig-Wood
John Nagle <[EMAIL PROTECTED]> wrote:
>  Diez B. Roggisch wrote:
> > Nick Craig-Wood wrote:
> > 
> > 
> >>Did anyone write a contextmanager implementing a timeout for
> >>python2.5?
> >>
> >>And have it work reliably and in a cross platform way!
> > 
> > Cross platform isn't the issue here - reliability though is. To put it
> > simple: can't be done that way. You could of course add a timer to the
> > python bytecode core, that would "jump back" to a stored savepoint or
> > something like that.
> 
>   Early versions of Scheme had a neat solution to this problem.
>  You could run a function with a limited amount of "fuel".  When the
>  "fuel" ran out, the call returned with a closure.  You could
>  run the closure again and pick up from where the function had been
>  interrupted, or just discard the closure.

That sounds like a really nice concept.  That would enable you to make
long running stuff yield without threads too.

I wonder if it is possible in python...

-- 
Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-wood.com/nick
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: with timeout(...):

2007-03-31 Thread Nick Craig-Wood
Hendrik van Rooyen <[EMAIL PROTECTED]> wrote:
>   "Nick Craig-Wood" <[EMAIL PROTECTED]> wrote:
> 
> > I'd like there to be something which works well enough for day to day
> > use.  Ie doesn't ever wreck the internals of python.  It could have
> > some caveats like "may not timeout during C functions which haven't
> > released the GIL" and that would still make it very useable.
> 
>  I second this (or third or whatever if my post is slow).
>  It is tremendously useful to start something and to be told it has timed
>  out by a call, rather than to have to unblock the i/o yourself and
>  to "busy-loop" to see if its successful.

Yes, exactly!

>  And from what I can see the select functionality is not much
>  different from busy looping...

Conceptually it is no different.  In practice your process goes to
sleep until the OS wakes it up again with more data so it is much more
CPU efficient (and possibly lower latency) than busy waiting.

-- 
Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-wood.com/nick
-- 
http://mail.python.org/mailman/listinfo/python-list


Send Anti-Flickering off to logitech cam

2007-03-31 Thread eriq
Hi,

I am currently working with a Logitech Quickcam STX via USB. Using the
VideoCapture module to make pictures. Because the camera is outside I
will have to turn off a special Option on the camera called "Anti-
Flickering". Is there anyway that I can send a hardware seq to the cam
to do this. Or manipulate the driver (Accessed via DirectX). Any
ideals what path I should follow to achieve this?

Thx

bytesman

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


wx textctrl font style

2007-03-31 Thread Pom
Hello

I have a tuple of strings which I must show in a textctrl, each item in 
the tuple representing one line of text.

The first three lines of text should each have another style (fontsize 
and color)

i'm using this code to achieve this:
   tmppos = self.txtInfo.GetInsertionPoint() # get the cursor pos
   self.txtInfo.write(str(csr[0])+'\n')
   tmppos2 = self.txtInfo.GetInsertionPoint() # get the new cursor pos
   self.txtInfo.SetStyle(tmppos, tmppos2, wx.TextAttr("BLUE", 
wx.NullColour, tmpnewfont))
   self.txtInfo.write(str(csr[1])+'\n')
   tmppos3 = self.txtInfo.GetInsertionPoint() # get the new cursor pos
   self.txtInfo.SetStyle(tmppos2, tmppos3, wx.TextAttr("BLUE", 
wx.NullColour, tmpnewfont2))
   self.txtInfo.write(str(csr[2])+'\n')
   tmppos4 = self.txtInfo.GetInsertionPoint() # get the new cursor pos
   self.txtInfo.SetStyle(tmppos3, tmppos4, wx.TextAttr(wx.Nullcolour, 
wx.NullColour, tmpnewfont3))


Now, I was wondering if this is the right way of doing this, because I 
have the feeling this code sucks.

Anybody has a better way of doing this?

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


Re: Hpw make lists that are easy to sort.

2007-03-31 Thread Anton Vredegoor
Paul Rubin wrote:

> Oh, I see what you mean.  I don't see an obvious faster way to do it
> and I don't have the feeling that one necessarily exists.  As someone
> mentioned, you could do an n-way merge, which at least avoids using
> quadratic memory.  Here's a version using Frederik Lundh's trick of
> representing a lazy list as its head plus the generator for the tail:

That's a beautiful trick! I was just exploring some idea about 
traversing the matrix starting from the upper left and ending at the 
lower right by forming some kind of wave like front line. It's currently 
very slow but I hope it can be polished a bit.

Also I was trying to figure out if it could have any advantage over the 
straight row by row merge, but now that these lazy rows have appeared 
the field has changed a lot :-)

def typewriter(L,R):
 Z = [0] * len(R)
 M = [(L[0]+R[0],0)]
 while M:
 val,k = min(M)
 yield val
 Z[k] += 1
 M = []
 for k,x in enumerate(Z):
 if x < len(R):
 M.append((L[k]+R[x],k))
 if not x:
 break

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