Re: Some posts do not show up in Google Groups

2012-04-30 Thread Terry Reedy

On 4/30/2012 2:20 AM, Frank Millman wrote:

Hi all

For a while now I have been using Google Groups to read this group, but on the 
odd occasion when I want to post a message, I use Outlook Express, as I know 
that some people reject all messages from Google Groups due to the high spam 
ratio (which seems to have improved recently, BTW).


From time to time I see a thread where the original post is missing, but the 
follow-ups do appear. My own posts have shown up with no problem.


Now, in the last month, I have posted two messages using Outlook Express, and 
neither of them have shown up in Google Groups. I can see replies in OE, so 
they are being accepted. I send to the group gmane.comp.python.general.

Does anyone know a reason for this, or have a solution?


Read and post through news.gmane.org

--
Terry Jan Reedy

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


Europython 2012 - Early Bird will end in 3 days!

2012-04-30 Thread Palla
Hi all,
the end of Early bird is on May 2nd, 23:59:59 CEST. We'd like to ask
to you to forward this post to anyone that you feel may be interested.

We have an amazing lineup of tutorials and talks. We have some
excellent keynote speakers and Guido will be with us!
[https://ep2012.europython.eu/p3/whos-coming?speaker=on#guido-van-
rossum]

If you plan to attend, you could save quite a bit on registration
fees ... but remember that early bird registration ends in 3 days!

Things to Remember:
- House your server: We will be running an Intranet at EuroPython, to
let sponsors, startups, open-source projects and speakers showcase
their products directly within our network.
- Training: You can book the trainings you want to attend, directly
from the schedule (click on the training, and then click on the "Book"
button).
- Sprints: Wonderful hacking sessions during the weekend, learn from
expert Python developers, and contribute to the Python ecosystem!
- Probably we've already discussed about the fact that Guido Van
Rossum will be at Europython in Florence :)

---> Register Now! - https://ep2012.europython.eu/p3/cart/

All the Best,
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: numpy (matrix solver) - python vs. matlab

2012-04-30 Thread Kiuhnm

On 4/30/2012 2:17, someone wrote:

On 04/30/2012 12:39 AM, Kiuhnm wrote:


So Matlab at least warns about "Matrix is close to singular or badly
scaled", which python (and I guess most other languages) does not...


A is not just close to singular: it's singular!


Ok. When do you define it to be singular, btw?


Which is the most accurate/best, even for such a bad matrix? Is it
possible to say something about that? Looks like python has a lot more
digits but maybe that's just a random result... I mean Element 1,1 =
2.81e14 in Python, but something like 3e14 in Matlab and so forth -
there's a small difference in the results...


Both results are *wrong*: no inverse exists.


What's the best solution of the two wrong ones? Best least-squares
solution or whatever?


Trust me. They're both so wrong that it doesn't matter.
Have a look at A*inv(A) and inv(A)*A and you'll see by yourself.


With python, I would also kindly ask about how to avoid this problem in
the future, I mean, this maybe means that I have to check the condition
number at all times before doing anything at all ? How to do that?


If cond(A) is high, you're trying to solve your problem the wrong way.


So you're saying that in another language (python) I should check the
condition number, before solving anything?


Yes, unless you already know that it will always be low by design.


You should try to avoid matrix inversion altogether if that's the case.
For instance you shouldn't invert a matrix just to solve a linear system.


What then?


Look at the documentation of the library you're using.


Cramer's rule?


Surprisingly, yes. That's an option. See
"A condensation-based application of Cramerʼs rule for solving 
large-scale linear systems"
Popular linear codes are based on Gaussian elimination or some iterative 
method, though.


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


For loop

2012-04-30 Thread viral shah
Hi

I want to make a pattern like this

*1
22
333

5
*
and I did the following code,

*for i in range (5):
  for j in range (i):
print i
  print " "*

got the output :
*
*

*1

2
2

3
3
3

4
4
4
4*


What's I'm not doing right, please let me know about this
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: For loop

2012-04-30 Thread Chris Angelico
On Mon, Apr 30, 2012 at 8:41 PM, viral shah  wrote:
> for i in range (5):
>   for j in range (i):
>     print i
>   print " "

The print command (you're clearly using Python 2 here - it's slightly
different in Python 3) by default prints a whole line - that is, it
finishes with a newline or '\n'. You'll find information on how to
suppress that here:

http://docs.python.org/reference/simple_stmts.html#the-print-statement

Hope that helps!

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


Re: numpy (matrix solver) - python vs. matlab

2012-04-30 Thread Kiuhnm

On 4/30/2012 3:35, Nasser M. Abbasi wrote:

But you still need to check the cond(). If it is too large, not good.
How large and all that, depends on the problem itself. But the rule of
thumb, the lower the better. Less than 100 can be good in general, but I
really can't give you a fixed number to use, as I am not an expert in
this subjects, others who know more about it might have better
recommendations.


Alas, there's no fixed number and as if that wasn't enough, there are 
many condition numbers, each one with different properties. For 
instance, the Skeel condition number is scale-invariant and it's useful 
when a matrix is ill-conditioned just because its rows are out of scale.


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


Re: syntax for code blocks

2012-04-30 Thread mwilson
Ben Finney wrote:

> [ ... ] Even worse is the
> penchant for ‘foo .bar()’, the space obscures the fact that this is
> attribute access.

I like the style sometimes when it helps to break the significantly different 
parts out of 
boilerplate:

libbnem. BN_add .argtypes = [ctypes.POINTER (BignumType), ctypes.POINTER 
(BignumType), 
ctypes.POINTER (BignumType)]
libbnem. BN_add .restype = ctypes.c_int
libbnem. BN_add_word .argtypes = [ctypes.POINTER (BignumType), 
ctypes.c_ulong]
libbnem. BN_add_word .restype = ctypes.c_int

libbnem. BN_sub .argtypes = [ctypes.POINTER (BignumType), ctypes.POINTER 
(BignumType), 
ctypes.POINTER (BignumType)]
libbnem. BN_sub .restype = ctypes.c_int
libbnem. BN_sub_word .argtypes = [ctypes.POINTER (BignumType), 
ctypes.c_ulong]
libbnem. BN_sub_word .restype = ctypes.c_int

(there were a lot more in the original program where those came from.)  Another 
take-away 
might be don't use boilerplate, but in the situation I didn't see a simple way 
to avoid it.

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


Re: syntax for code blocks

2012-04-30 Thread Kiuhnm

On 4/30/2012 16:17, mwil...@the-wire.com wrote:

Ben Finney wrote:


[ ... ] Even worse is the
penchant for ‘foo .bar()’, the space obscures the fact that this is
attribute access.


I like the style sometimes when it helps to break the significantly different 
parts out of
boilerplate:

 libbnem. BN_add .argtypes = [ctypes.POINTER (BignumType), ctypes.POINTER 
(BignumType),
ctypes.POINTER (BignumType)]
 libbnem. BN_add .restype = ctypes.c_int
 libbnem. BN_add_word .argtypes = [ctypes.POINTER (BignumType), 
ctypes.c_ulong]
 libbnem. BN_add_word .restype = ctypes.c_int

 libbnem. BN_sub .argtypes = [ctypes.POINTER (BignumType), ctypes.POINTER 
(BignumType),
ctypes.POINTER (BignumType)]
 libbnem. BN_sub .restype = ctypes.c_int
 libbnem. BN_sub_word .argtypes = [ctypes.POINTER (BignumType), 
ctypes.c_ulong]
 libbnem. BN_sub_word .restype = ctypes.c_int

(there were a lot more in the original program where those came from.)  Another 
take-away
might be don't use boilerplate, but in the situation I didn't see a simple way 
to avoid it.

Mel.


BignumTypePtr = ctypes.POINTER(BignumType)

for op, op_word in ((libbnem.BN_add, libbnem.BN_add_word),
(libbnem.BN_sub, libbnem.BN_sub_word)):
op.argtypes = [BignumTypePtr] * 3
op_word.argtypes = [BignumTypePtr, ctypes.c_ulong]
op.restype = op_word.restype = ctypes.c_int

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


Creating a directory structure and modifying files automatically in Python

2012-04-30 Thread deltaquattro
Hi,

I would like to automate the following task under Linux. I need to create a set 
of directories such as

075
095
100
125

The directory names may be read from a text file foobar, which also contains a 
number corresponding to each dir, like this:

075 1.818
095 2.181
100 2.579
125 3.019


In each directory I must copy a text file input.in. This file contains  two 
lines which need to be edited:

.
.
.
foo = 1.5 !edit me..
.
.
.
bar = 1.5 !..and me, too
.
.

The number after the "=" must be set to the value given in foobar for the 
corresponding directory
I thought to write a bash/awk shell script for this. However, if and when the 
script works, I'll probably start to add more features in order to automate 
even more tasks. It seems to me that Python or perl would be better suited to 
write a larger, mantainable script. Unfortunately, I know neither of them. 
Could you show me how to write the script in Python? Thanks,

Best Regards

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


Re: syntax for code blocks

2012-04-30 Thread Kiuhnm

On 4/30/2012 17:02, Kiuhnm wrote:

On 4/30/2012 16:17, mwil...@the-wire.com wrote:

Ben Finney wrote:


[ ... ] Even worse is the
penchant for ‘foo .bar()’, the space obscures the fact that this is
attribute access.


I like the style sometimes when it helps to break the significantly
different parts out of
boilerplate:

libbnem. BN_add .argtypes = [ctypes.POINTER (BignumType),
ctypes.POINTER (BignumType),
ctypes.POINTER (BignumType)]
libbnem. BN_add .restype = ctypes.c_int
libbnem. BN_add_word .argtypes = [ctypes.POINTER (BignumType),
ctypes.c_ulong]
libbnem. BN_add_word .restype = ctypes.c_int

libbnem. BN_sub .argtypes = [ctypes.POINTER (BignumType),
ctypes.POINTER (BignumType),
ctypes.POINTER (BignumType)]
libbnem. BN_sub .restype = ctypes.c_int
libbnem. BN_sub_word .argtypes = [ctypes.POINTER (BignumType),
ctypes.c_ulong]
libbnem. BN_sub_word .restype = ctypes.c_int

(there were a lot more in the original program where those came from.)
Another take-away
might be don't use boilerplate, but in the situation I didn't see a
simple way to avoid it.

Mel.


BignumTypePtr = ctypes.POINTER(BignumType)

for op, op_word in ((libbnem.BN_add, libbnem.BN_add_word),
(libbnem.BN_sub, libbnem.BN_sub_word)):
op.argtypes = [BignumTypePtr] * 3
op_word.argtypes = [BignumTypePtr, ctypes.c_ulong]
op.restype = op_word.restype = ctypes.c_int


On second thought, BignumPtrType is probably the right name.

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


ctypes details was: Re: syntax for code blocks

2012-04-30 Thread mwilson
> On 4/30/2012 17:02, Kiuhnm wrote:
>> BignumTypePtr = ctypes.POINTER(BignumType)
>>
>> for op, op_word in ((libbnem.BN_add, libbnem.BN_add_word),
>> (libbnem.BN_sub, libbnem.BN_sub_word)):
>> op.argtypes = [BignumTypePtr] * 3
>> op_word.argtypes = [BignumTypePtr, ctypes.c_ulong]
>> op.restype = op_word.restype = ctypes.c_int
> 
> On second thought, BignumPtrType is probably the right name.

(Way off the original topic, aren't we?)  I haven't looked inside ctypes, 
and don't know what kind of thing ctypes.POINTER actually constructs.  I was 
worried about falling into a [[a]]*3 kind of error -- unwittingly sharing a 
mutable object.  I guess I really should look.

Mel.

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


Re: ctypes details was: Re: syntax for code blocks

2012-04-30 Thread Kiuhnm

On 4/30/2012 17:42, mwil...@the-wire.com wrote:

On 4/30/2012 17:02, Kiuhnm wrote:

BignumTypePtr = ctypes.POINTER(BignumType)

for op, op_word in ((libbnem.BN_add, libbnem.BN_add_word),
(libbnem.BN_sub, libbnem.BN_sub_word)):
op.argtypes = [BignumTypePtr] * 3
op_word.argtypes = [BignumTypePtr, ctypes.c_ulong]
op.restype = op_word.restype = ctypes.c_int


On second thought, BignumPtrType is probably the right name.


(Way off the original topic, aren't we?)  I haven't looked inside ctypes,
and don't know what kind of thing ctypes.POINTER actually constructs.  I was
worried about falling into a [[a]]*3 kind of error -- unwittingly sharing a
mutable object.  I guess I really should look.


Better off topic than uninterestingly in topic, IMHO.

Regarding ctypes, try this to convince yourself that there's no problem 
in reusing BignumPtrType:

from ctypes import POINTER, c_int
assert POINTER(c_int) is POINTER(c_int)

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


Re: Creating a directory structure and modifying files automatically in Python

2012-04-30 Thread MRAB

On 30/04/2012 16:19, deltaquat...@gmail.com wrote:

Hi,

I would like to automate the following task under Linux. I need to create a set 
of directories such as

075
095
100
125

The directory names may be read from a text file foobar, which also contains a 
number corresponding to each dir, like this:

075 1.818
095 2.181
100 2.579
125 3.019


In each directory I must copy a text file input.in. This file contains  two 
lines which need to be edited:

.
.
.
foo = 1.5 !edit me..
.
.
.
bar = 1.5 !..and me, too
.
.

The number after the "=" must be set to the value given in foobar for the 
corresponding directory
I thought to write a bash/awk shell script for this. However, if and when the 
script works, I'll probably start to add more features in order to automate 
even more tasks. It seems to me that Python or perl would be better suited to 
write a larger, mantainable script. Unfortunately, I know neither of them. 
Could you show me how to write the script in Python? Thanks,

If you don't know Python, could I suggest that you start by reading a 
tutorial such as "Dive Into Python", which is at 
http://www.diveintopython.net/

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


Re: ctypes details was: Re: syntax for code blocks

2012-04-30 Thread mwilson
Kiuhnm wrote:
> Regarding ctypes, try this to convince yourself that there's no problem
> in reusing BignumPtrType:
>  from ctypes import POINTER, c_int
>  assert POINTER(c_int) is POINTER(c_int)

print ('POINTERs are shareable:', ctypes.POINTER (BignumType) is ctypes.POINTER 
(BignumType))
[ ... ]
('POINTERs are shareable:', True)

Thanks.
Mel.

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


Re: Creating a directory structure and modifying files automatically in Python

2012-04-30 Thread Chris Rebert
On Mon, Apr 30, 2012 at 8:19 AM,   wrote:
> Hi,
>
> I would like to automate the following task under Linux. I need to create a 
> set of directories such as
>
> 075
> 095
> 100
> 125
>
> The directory names may be read from a text file foobar, which also contains 
> a number corresponding to each dir, like this:
>
> 075 1.818
> 095 2.181
> 100 2.579
> 125 3.019
>
>
> In each directory I must copy a text file input.in. This file contains  two 
> lines which need to be edited:
>
> .
> .
> .
> foo = 1.5 !edit me..
> .
> .
> .
> bar = 1.5 !..and me, too
> .
> .
>
> The number after the "=" must be set to the value given in foobar for the 
> corresponding directory
> I thought to write a bash/awk shell script for this. However, if and when the 
> script works, I'll probably start to add more features in order to automate 
> even more tasks. It seems to me that Python or perl would be better suited to 
> write a larger, mantainable script. Unfortunately, I know neither of them. 
> Could you show me how to write the script in Python? Thanks,

Your script would use the following modules:
http://docs.python.org/library/shutil.html
http://docs.python.org/library/os.path.html

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


Re: Some posts do not show up in Google Groups

2012-04-30 Thread Colin J. Williams

On 30/04/2012 2:20 AM, Frank Millman wrote:

Hi all

For a while now I have been using Google Groups to read this group, but on the 
odd occasion when I want to post a message, I use Outlook Express, as I know 
that some people reject all messages from Google Groups due to the high spam 
ratio (which seems to have improved recently, BTW).

 From time to time I see a thread where the original post is missing, but the 
follow-ups do appear. My own posts have shown up with no problem.

Now, in the last month, I have posted two messages using Outlook Express, and 
neither of them have shown up in Google Groups. I can see replies in OE, so 
they are being accepted. I send to the group gmane.comp.python.general.

Does anyone know a reason for this, or have a solution?

Frank Millman


I lose about two messages a day from the Usenet Group.  At the end of 
the day, the Group reports one or two messges as being available, but 
they are not.


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


Re: For loop

2012-04-30 Thread Terry Reedy

On 4/30/2012 6:41 AM, viral shah wrote:

Hi

I want to make a pattern like this

*1
22
333

5


Python 3:
>>> for i in range(1,6): print(i*str(i))

1
22
333

5

--
Terry Jan Reedy

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


Re: Communication between C++ server and Python app

2012-04-30 Thread kenk
Failr point  - I should do that in original question.

The C++ server runs on Unix (Mac OS X as a matter of fact) and, as I'm
the one who develops it, can use whthever technology is suitable.
Currently it uses STL, Boost and Qt libraries.

The server is responsible for providing connectivity to stock exchange
and will be used mainly to monitor price of certain financial
instruments and placing/cancelling orders.
My idea is to keep this as simple tool that will execute whathever
it's asked for.

On top of this server I plan to write some trading logic in Python -
scripts that will trigger certain actions depending on situation on
market.

I planned to exchange text commands between the C++ server and Python
scripts as Python is really good in parsing text and on server side
Boost/STL also do the trick.
Communication between 'logic' and the server won't be high frequency -
I plan to talk to teh server ~10 times a minute.

Will appreciate suggestions.

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


Re: Communication between C++ server and Python app

2012-04-30 Thread Miki Tebeka
> > I've got a server process written in C++ running on Unix machine.
> > On the same box I'd like to run multiple Python scripts that will
> > communicate with this server.
> > 
> > Can you please suggest what would be best was to achieve this ?
As said before, there are many options. Here are some:
* protobuf, thrift, avro ...
* json/xml over http
   - Python has XMLRPC module
* zeromq
* ...

IMO investigate some time learning the options, code a simple api using one or 
two that you like and pick a winner.

For 10 calls/min you can go that wrong either way :)
-- 
http://mail.python.org/mailman/listinfo/python-list


Create directories and modify files with Python

2012-04-30 Thread deltaquattro
Hi,

I would like to automate some simple tasks I'm doing by hand. Given a text file 
foobar.fo:

073 1.819
085 2.132
100 2.456
115 2.789

I need to create the directories 073, 085, 100, 115, and copy in each directory 
a modified version of the text file input.in:

.
.
.
foo = 1.5 ! edit this value 
.
.
.
bar = 1.5 ! this one, too
.
.
.

Tthe modification consists in substituting the number in the above lines with 
the value associated to the directory in the file foobar.fo. Thus, the input.in 
file in the directory 100 will be:

.
.
.
foo = 2.456 ! edit this value 
.
.
.
bar = 2.456 ! this one, too
.
.
.

At first, I tried to write a bash script to do this. However, when and if the 
script will work, I'll probably want to add more features to automate some 
other tasks. So I thought about using some other language, to have a more 
flexible and mantainable code. I've been told that both Python and perl are 
well suited for such tasks, but unfortunately I know neither of them. Can you 
show me how to write the script in Python? Thanks,

Best Regards

Sergio Rossi





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


Re: Create directories and modify files with Python

2012-04-30 Thread Mark Lawrence

On 01/05/2012 00:24, deltaquat...@gmail.com wrote:

Hi,

I would like to automate some simple tasks I'm doing by hand. Given a text file
foobar.fo:

073 1.819
085 2.132
100 2.456
115 2.789

I need to create the directories 073, 085, 100, 115, and copy in each directory 
a modified version of the text file input.in:

.
.
.
foo = 1.5 ! edit this value
.
.
.
bar = 1.5 ! this one, too
.
.
.

Tthe modification consists in substituting the number in the above lines with 
the value associated to the directory in the file foobar.fo. Thus, the input.in 
file in the directory 100 will be:

.
.
.
foo = 2.456 ! edit this value
.
.
.
bar = 2.456 ! this one, too
.
.
.

At first, I tried to write a bash script to do this. However, when and if the 
script will work, I'll probably want to add more features to automate some 
other tasks. So I thought about using some other language, to have a more 
flexible and mantainable code. I've been told that both Python and perl are 
well suited for such tasks, but unfortunately I know neither of them. Can you 
show me how to write the script in Python? Thanks,

Best Regards

Sergio Rossi







Please show us the code you've written so far, including full traceback 
for any errors.  Let's face it, this is similar to the question you 
posted some eight hours ago give or take.  For more data on the problems 
with time please see this amongst others 
http://thread.gmane.org/gmane.comp.python.devel/132284


--
Cheers.

Mark Lawrence.

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


Re: Create directories and modify files with Python

2012-04-30 Thread Irmen de Jong
On 1-5-2012 1:24, deltaquat...@gmail.com wrote:
> Hi, 0 I would like to automate some simple tasks I'm doing by hand. Given a 
> text file
>  foobar.fo:

[...]

> At first, I tried to write a bash script to do this. However, when and if the 
> script
> will work, I'll probably want to add more features to automate some other 
> tasks. So I
> thought about using some other language, to have a more flexible and 
> mantainable
> code. I've been told that both Python and perl are well suited for such 
> tasks, but
> unfortunately I know neither of them. Can you show me how to write the script 
> in
> Python? Thanks,

Err.. if you don't know Python, why do you think a Python script will be more 
flexible
and maintainable for you?

But if you really want to go this way (and hey, why not) then first you'll have 
to learn
some basic Python. A good resource for this might be: 
http://learnpythonthehardway.org/

Focus on file input and output, string manipulation, and look in the os module 
for stuff
to help scanning directories (such as os.walk).

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


Re: Some posts do not show up in Google Groups

2012-04-30 Thread Ben Finney
Frank Millman  writes:

> Does anyone know a reason for this, or have a solution?

To my knowledge no-one responsible at Google Groups has bothered to
comment about the issue. It's not clear to we outsiders that they are
even aware of it.

In the absence of their participation in resolving the problems Google
Groups has with Usenet, I think the best course of action is to avoid
Google Groups.

-- 
 \   “Faith, n. Belief without evidence in what is told by one who |
  `\   speaks without knowledge, of things without parallel.” —Ambrose |
_o__)   Bierce, _The Devil's Dictionary_, 1906 |
Ben Finney
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: syntax for code blocks

2012-04-30 Thread Ben Finney
mwil...@the-wire.com writes:

> Another take-away might be don't use boilerplate, but in the situation
> I didn't see a simple way to avoid it.

It seems we agree, then, that avoiding boilerplate code is preferable to
writing bad boilerplate code.

-- 
 \  “Computer perspective on Moore's Law: Human effort becomes |
  `\   twice as expensive roughly every two years.” —anonymous |
_o__)  |
Ben Finney
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Some posts do not show up in Google Groups

2012-04-30 Thread alex23
On May 1, 12:38 pm, Ben Finney  wrote:
> In the absence of their participation in resolving the problems Google
> Groups has with Usenet, I think the best course of action is to avoid
> Google Groups.

The new interface effectively kills Groups dead as a useful Usenet
reader anyway :(
-- 
http://mail.python.org/mailman/listinfo/python-list


Trouble splitting strings with consecutive delimiters

2012-04-30 Thread deuteros
I'm using regular expressions to split a string using multiple delimiters.
But if two or more of my delimiters occur next to each other in the
string, it puts an empty string in the resulting list. For example: 

re.split(':|;|px', "width:150px;height:50px;float:right")

Results in

['width', '150', '', 'height', '50', '', 'float', 'right']

Is there any way to avoid getting '' in my list without adding px; as a
delimiter? 
-- 
http://mail.python.org/mailman/listinfo/python-list


Sort comparison

2012-04-30 Thread Dan Stromberg
A while back I did a sort algorithm runtime comparison for a variety of
sorting algorithms, and then mostly sat on it.

Recently, I got into a discussion with someone on stackoverflow about the
running time of radix sort.

I realize it's commonly said that radixsort is n*k rather than n*log(n).
I've been making that case that in real life, frequently k==log(n).

Anyway, here's the comparison, with code and graph:
http://stromberg.dnsalias.org/~strombrg/sort-comparison/

(It's done in Pure python and Cython, with a little m4).

Interesting, BTW, that an unstable quicksort in Cython was approaching
timsort as a C extension module in performance, even though timsort in
Cython wasn't that performant.  It makes one wonder if a highly optimized
quicksort as a C extension module wouldn't outperform timsort in the
standard library.

Yes, I know, we've committed to keeping list_.sort() stable now, and
quicksort normally isn't stable.

Also, before timsort, did CPython use quicksort?  I'd be a little surprised
if it hadn't, since people used to say quicksort was the best thing around
in practice.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Creating a directory structure and modifying files automatically in Python

2012-04-30 Thread John Nagle

On 4/30/2012 8:19 AM, deltaquat...@gmail.com wrote:

Hi,

I would like to automate the following task under Linux. I need to create a set 
of directories such as

075
095
100
125

The directory names may be read from a text file foobar, which also contains a 
number corresponding to each dir, like this:

075 1.818
095 2.181
100 2.579
125 3.019


In each directory I must copy a text file input.in. This file contains  two 
lines which need to be edited:


   Learn how to use a database.  Creating and managing a
big collection of directories to handle small data items is the
wrong approach to data storage.

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


Re: Trouble splitting strings with consecutive delimiters

2012-04-30 Thread Jussi Piitulainen
deuteros writes:

> I'm using regular expressions to split a string using multiple
> delimiters.  But if two or more of my delimiters occur next to each
> other in the string, it puts an empty string in the resulting
> list. For example:
> 
>   re.split(':|;|px', "width:150px;height:50px;float:right")
> 
> Results in
> 
>   ['width', '150', '', 'height', '50', '', 'float', 'right']
> 
> Is there any way to avoid getting '' in my list without adding px;
> as a delimiter?

You could use a sequence of such delimiters.

>>> re.split('(?::|;|px)+', "width:150px;height:50px;float:right")
['width', '150', 'height', '50', 'float', 'right']

Consider splitting twice instead: first into key-value substrings at
semicolons, and those into key-value pairs at colons. Here as a dict.
Better handle the units after that.

>>> dict(kv.split(':') for kv in 
>>> "width:150px;height:50px;float:right".split(';'))
{'width': '150px', 'float': 'right', 'height': '50px'}

You might also want to accept whitespace as part of the delimiters.

(There might be a parser for such data formats somewhere in the
library already. CSV?)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Some posts do not show up in Google Groups

2012-04-30 Thread Frank Millman
On Apr 30, 8:20 am, Frank Millman  wrote:
> Hi all
>
> For a while now I have been using Google Groups to read this group, but on 
> the odd occasion when I want to post a message, I use Outlook Express, as I 
> know that some people reject all messages from Google Groups due to the high 
> spam ratio (which seems to have improved recently, BTW).
>
> From time to time I see a thread where the original post is missing, but the 
> follow-ups do appear. My own posts have shown up with no problem.
>
> Now, in the last month, I have posted two messages using Outlook Express, and 
> neither of them have shown up in Google Groups. I can see replies in OE, so 
> they are being accepted. I send to the group gmane.comp.python.general.
>
> Does anyone know a reason for this, or have a solution?
>
> Frank Millman

Thanks for the replies. I am also coming to the conclusion that Google
Groups is no longer fit-for-purpose.

Ironically, here are two replies that I can see in Outlook Express,
but do not appear in Google Groups.

Reply from Benjamin Kaplan -
> I believe the mail-to-news gateway has trouble with HTML messages. Try 
> sending everything as plain text and see if that works.

I checked, and all my posts were sent in plain text.

Reply from Terry Reedy -
> Read and post through news.gmane.org

I have had a look at this before, but there is one thing that Google
Groups does that no other reader seems to do, and that is that
messages are sorted according to thread-activity, not original posting
date. This makes it easy to see what has changed since the last time I
checked.

All the other ones I have looked at - Outlook Express, Thunderbird,
and gmane.org, sort by original posting date, so I have to go
backwards to see if any threads have had any new postings.

Maybe there is a setting that I am not aware of. Can anyone enlighten
me?

Thanks

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