Re: problem with array and for loop

2006-05-10 Thread Robert Kern
Fabian Braennstroem wrote:
> Hi Robert,
> 
> * Robert Kern <[EMAIL PROTECTED]> wrote:

>>Are you aware that numpy array indices start with 0, not 1?
>>
>>You will probably want to ask numpy questions on the numpy-discussion mailing 
>>list:
>>
>>  http://www.scipy.org/Mailing_Lists
> 
> I thought a simple for loop-array-declaration question would
> fit in this group ... it actually help for this simple
> problem. Thanks!

When you have an issue with a certain package, and that package has a dedicated
mailing list, you will usually a get a much better response on that list instead
of a general one. While I usually read comp.lang.python every day and try to
answer all numpy and scipy questions that come by, I really prefer to see these
questions on the appropriate lists.

-- 
Robert Kern

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

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


Re: problem with array and for loop

2006-05-10 Thread Fabian Braennstroem
Hi Robert,

* Robert Kern <[EMAIL PROTECTED]> wrote:
> Fabian Braennstroem wrote:
>> Hi,
>> 
>> I have a 'simple' problem with a multidimension array in a
>> for loop. It looks like this:
>> 
>> wert= zeros([127,2])
>> wert1= zeros(127)
>> m=1
>> l=1
>> 
>> for pos in [pos1,pos2,pos3]: 
>> for i in range(1,125):
>> wert[l,m]= 
>> probe1.GetOutput().GetPointData().GetScalars().GetTuple1(i);
>> #wert1[i]= 
>> probe1.GetOutput().GetPointData().GetScalars().GetTuple1(i);
>> m=m+1;
>> l=l+1;
>> 
>> It works for the 1D 'wert1'. Does anyone have an idea? 
>
> Oy vey.
>
> So the first time through, you are setting the second column of wert. Then l
> (btw, never, ever use lower-case "l" as a single-letter variable name; it 
> looks
> like "1") gets incremented to 2, which would try to put data into the third
> column of wert. However, wert only has two columns.

Thanks! I misunderstood the declaration of a multid-dim
array; it works now.
>
> Are you aware that numpy array indices start with 0, not 1?
>
> You will probably want to ask numpy questions on the numpy-discussion mailing 
> list:
>
>   http://www.scipy.org/Mailing_Lists

I thought a simple for loop-array-declaration question would
fit in this group ... it actually help for this simple
problem. Thanks!

Greetings!
 Fabian

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


Re: python sqlite3 api question

2006-05-10 Thread [EMAIL PROTECTED]
Ah, je comprend. Thanks for pointing that out to me - I'll just have to
spend more time at the code face to get the job done.
Many thanks,
Lol

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


2 books for me

2006-05-10 Thread Gary Wessle
Hi

I am about to order 2 books, and thought I should talk to you first.
I am getting Python Cookbook by Alex Martelli, David Ascher, Anna
Martelli Ravenscroft, Anna Martelli Ravenscroft, since Bruce Eckel's
Thinking in Python is not finished and didn't have any new revisions
since some time in 2001, having owned his Thinking in C++ v1 and v2 I
am used to learning from him. any way, the second book is gui one, I
notices there are 3 flavors according to
http://wiki.python.org/moin/GuiBooks, wxPython, Qt, and Tkinter.I am
not sure what package is best for and would like to know before I
order one of those three. 

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


Re: python rounding problem.

2006-05-10 Thread Tim Roberts
"chun ping wang" <[EMAIL PROTECTED]> wrote:
>
>Hey i have a stupid question.
>
>How do i get python to print the result in only three decimal place...
>
>Example>>> round (2.9954254, 3)
>2.9951
>
>but i want to get rid of all trailing 0's..how would i do that?

Your "problem" is not a problem in real programs -- it's only a problem
because of the way the interactive interpreter works:

C:\WINDOWS>python
Python 2.4.1 (#65, Mar 30 2005, 09:13:57) [MSC v.1310 32 bit (Intel)] on
win32
Type "help", "copyright", "credits" or "license" for more information.
>>> round(2.99543322,3)
2.9951
>>> print round(2.99543322,3)
2.995
>>>

-- 
- Tim Roberts, [EMAIL PROTECTED]
  Providenza & Boekelheide, Inc.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: A critic of Guido's blog on Python's lambda

2006-05-10 Thread M Jared Finder
Chris Uppal wrote:

> E.g. can you add three-way comparisons (less-than, same-as, greater-than to,
> say, Python with corresponding three-way conditional control structures to
> supplement "if" etc ?  Are they on a semantic and syntactic par with the
> existing ones ?  In Smalltalk that is trivial (too trivial to be particularly
> interesting, even), and I presume the same must be true of Lisp (though I
> suspect you might be forced to use macros).

As an illustration, here's the definition and usage of such a numeric-if 
in Lisp.

Using raw lambdas, it's ugly, but doable:

(defun fnumeric-if (value lt-body eq-body gt-body)
   (cond ((< value 0) (funcall lt-body))
 ((= value 0) (funcall eq-body))
 ((> value 0) (funcall gt-body

(fnumeric-if (- a b)
   (lambda () (print "a < b"))
   (lambda () (print "a = b"))
   (lambda () (print "a > b")))

A macro helps clean that up and make it look prettier:

(defmacro numeric-if (value lt-body eq-body gt-body)
   `(fnumeric-if ,value
 (lambda () ,lt-body)
 (lambda () ,eq-body)
 (lambda () ,gt-body)))

(numeric-if (- a b)
   (print "a < b")
   (print "a = b")
   (print "a > b"))

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


Re: problem with array and for loop

2006-05-10 Thread Robert Kern
Fabian Braennstroem wrote:
> Hi,
> 
> I have a 'simple' problem with a multidimension array in a
> for loop. It looks like this:
> 
> wert= zeros([127,2])
> wert1= zeros(127)
> m=1
> l=1
> 
> for pos in [pos1,pos2,pos3]: 
> for i in range(1,125):
> wert[l,m]= 
> probe1.GetOutput().GetPointData().GetScalars().GetTuple1(i);
> #wert1[i]= 
> probe1.GetOutput().GetPointData().GetScalars().GetTuple1(i);
> m=m+1;
> l=l+1;
> 
> It works for the 1D 'wert1'. Does anyone have an idea? 

Oy vey.

So the first time through, you are setting the second column of wert. Then l
(btw, never, ever use lower-case "l" as a single-letter variable name; it looks
like "1") gets incremented to 2, which would try to put data into the third
column of wert. However, wert only has two columns.

Are you aware that numpy array indices start with 0, not 1?

You will probably want to ask numpy questions on the numpy-discussion mailing 
list:

  http://www.scipy.org/Mailing_Lists

-- 
Robert Kern

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

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


Re: A critic of Guido's blog on Python's lambda

2006-05-10 Thread M Jared Finder
Alex Martelli wrote:
> M Jared Finder <[EMAIL PROTECTED]> wrote:
>...
>> Your reasoning, taken to the extreme, implies that an assembly language,
>> by virtue of having the fewest constructs, is the best designed language
> 
> Except that the major premise is faulty!  Try e.g.
>  and count the
> number of distinct instructions -- general purpose, floating point,
> SIMD, MMX, SSE, SSE2, OS support... there's *hundreds*, each with its
> own rules as to what operand(s) are allowed plus variants such as (e.g.)
> cmovbe{w,l,q} for "conditional move if below or equal" for word, long,
> quadword (no byte variant) -- but e.g cmpxchg{b,w,l,q} DOES have a byte
> variant too, while setbe for "set if below or equal" ONLY has a byte
> variant, etc, etc -- endless memorization;-).
> 
> When you set up your strawman arguments, try to have at least ONE of the
> premises appear sensible, will you?-)
> 
> I never argued against keeping languages at a high level, of course
> (that's why your so utterly unfounded argument would be a "strawman"
> even if it WAS better founded;-).
> 
>> prone, code.  I think the advantages of anonymous functions:
>...
>> e) making the language simpler to implement
> 
> Adding one construct (e.g., in Python, having both def and lambda with
> vast semantic overlap, rather than just one) cannot "make the language
> simpler to implement" -- no doubt this kind of "reasoning" (?) is what
> ended up making the instruction-set architecture of the dominant
> families of CPUs so bizarre, intricate, and abstruse!-)

It sure can.  First, let's cover the cost.  I'll be measuring everything 
in terms of lines of code, with the assumption that the code has been 
kept readable.

Here's an implementation of lambda (anonymous functions) in Lisp based 
on flet (lexically scoped functions):

(defmacro lambda (args &rest body)
   (let ((name (gensym)))
 `(flet ((,name ,args ,@body)) (function ,name

That's three lines of code to implement.  An almost trivial amount.

Now by using anonymous functions, you can implement many other language 
level features simpler.  Looping can be made into a regular function 
call.  Branching can be made into a regular function call.  Defining 
virtual functions can be made into a regular function call.  Anything 
that deals with code blocks can be made into a regular function call.

By removing the special syntax and semantics from these language level 
features and making them just pain old function calls, you can reuse the 
same evaluator, optimizer, code parser, introspector, and other code 
analyzing parts of your language for these (no longer) special 
constructs.   That's a HUGE savings, well over 100 lines of code.

Net simplification, at least 97 lines of code.  For a concrete example 
of this in action, see Smalltalk.

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


Python and windows bandwidth statistics?

2006-05-10 Thread Dave Reid
I've been searching for a something in Python for me to be able to get
the total outbound or inbound bandwidth (in Windows (or cross-OS
compatible). Can anyone help me out? Thanks!

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


problem with array and for loop

2006-05-10 Thread Fabian Braennstroem
Hi,

I have a 'simple' problem with a multidimension array in a
for loop. It looks like this:

wert= zeros([127,2])
wert1= zeros(127)
m=1
l=1

for pos in [pos1,pos2,pos3]: 
for i in range(1,125):
wert[l,m]= probe1.GetOutput().GetPointData().GetScalars().GetTuple1(i);
#wert1[i]= probe1.GetOutput().GetPointData().GetScalars().GetTuple1(i);
m=m+1;
l=l+1;

It works for the 1D 'wert1'. Does anyone have an idea? 


Greetings!
 Fabian

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


Re: glob() that traverses a folder tree

2006-05-10 Thread seannakasone
# i'm guessing os.walk() is the best way to traverse folder trees.

import os, glob

for dir, subdir, files in os.walk('.\InteropSolution'):
   for file in files:
  if glob.fnmatch.fnmatch(file,"*.dll") or
glob.fnmatch.fnmatch(file,"*.exe"):
 print dir+file

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


Re: 345 free programming books

2006-05-10 Thread Tim
Anyone has any free books to submit?

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


Re: data entry tool

2006-05-10 Thread Serge Orlov
[EMAIL PROTECTED] wrote:
> If the data to be entered is simple and textual you can even think
> about using a text only interface. The resulting program will be really
> simple, and probably good enough.

FWIW here is size of "Hello, world!" program distribution using
different interfaces:

text console: 1.2Mb
web.py w/o ssl: 1.5Mb
tkinter: 2.1Mb
wxpython: 3.0Mb

Getting more slim distributions requires some manual work

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


Re: Nested loops confusion

2006-05-10 Thread Matthew Graham
Oops, I forget to reset the j after the inner loop.  Always manage to 
work these things out just after asking for help! ;-)

Matthew Graham wrote:
> Hi,
> 
> I expect this is very obvious for anyone who knows what they're doing - 
> but I don't understand what's the problem with the following code.  I 
> was intending that the program cycle through all i and j (ie. all 
> possible (i,j) coordinates, but the output when I run the program shows 
> me up to
> 
> "1
> 99
> plot 3
> 1
> 100
> plot 2
> done j"
> 
> and doesn't perform the print functions for any i > 1.
> 
> Help much appreciated! :)
> 
> Matt
> 
> 
> corna = int(raw_input("CornA? "))
> cornb = int(raw_input("CornB? "))
> side = int(raw_input("Side? "))
> i = 0
> j = 0
> for i in range(100):
> for j in range(100):
> x = corna + i * side / 100
> y = cornb + j * side / 100
> c = int(x^2 + y^2)
> if  c%3 == 1:
> print i
> print j
> print "plot 1"
> elif  c%3 == 2:
> print i
> print j
> print "plot 2"
> elif  c%3 == 0:
> print i
> print j
> print "plot 3"
> print "done j"
> print "Done i"
> 
> 
-- 
http://mail.python.org/mailman/listinfo/python-list


Nested loops confusion

2006-05-10 Thread Matthew Graham
Hi,

I expect this is very obvious for anyone who knows what they're doing - 
but I don't understand what's the problem with the following code.  I 
was intending that the program cycle through all i and j (ie. all 
possible (i,j) coordinates, but the output when I run the program shows 
me up to

"1
99
plot 3
1
100
plot 2
done j"

and doesn't perform the print functions for any i > 1.

Help much appreciated! :)

Matt


corna = int(raw_input("CornA? "))
cornb = int(raw_input("CornB? "))
side = int(raw_input("Side? "))
i = 0
j = 0
for i in range(100):
 for j in range(100):
 x = corna + i * side / 100
 y = cornb + j * side / 100
 c = int(x^2 + y^2)
 if  c%3 == 1:
 print i
 print j
 print "plot 1"
 elif  c%3 == 2:
 print i
 print j
 print "plot 2"
 elif  c%3 == 0:
 print i
 print j
 print "plot 3"
 print "done j"
print "Done i"


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


Re: A critic of Guido's blog on Python's lambda

2006-05-10 Thread Ken Tilton


Alex Martelli wrote:
> Stefan Nobis <[EMAIL PROTECTED]> wrote:
> 
> 
>>[EMAIL PROTECTED] (Alex Martelli) writes:
>>
>>
>>>if anonymous functions are available, they're used in even more
>>>cases where naming would help
>>
>>Yes, you're right. But don't stop here. What about expressions? Many
>>people write very complex expression, that are hard to understand. A
>>good language should forbid these abuse and don't allow expressions
>>with more than 2 or maybe 3 operators!
> 
> 
> That would _complicate_ the language (by adding a rule).  I repeat what
> I've already stated repeatedly: a good criterion for deciding which good
> practices a language should enforce and which ones it should just
> facilitate is _language simplicity_.  If the enforcement is done by
> adding rules or constructs it's probably not worth it; if the
> "enforcements" is done by NOT adding extra constructs it's a double win
> (keep the language simpler AND push good practices).

Gosh, that looks like fancy footwork. But maybe I misunderstand, so I 
will just ask you to clarify.

In the case of (all syntax imaginary and not meant ot be Python):

  if whatever = 42
 dothis
 do that
 do something else
  else
 go ahead
 make my day

You do not have a problem with unnamed series of statements. But in the 
case of:

 treeTravers( myTree, lambda (node):
  if xxx(node)
 print "wow"
 return 1
  else
 print "yawn"
 return 0)

...no, no good, you want a named yawnOrWow function? And though they 
look similar, the justification above was that IF-ELSE was lucky enough 
to get multiline branches In the Beginning, so banning it now would be 
"adding a rule", whereas lambda did not get multiline In the Beginning, 
so allowing it would mean "adding a construct". So by positing "adding a 
rule or construct" as always bad (even if they enforce a good practice 
such as naming an IF branch they are bad since one is /adding/ to the 
language), the inconsistency becomes a consistency in that keeping IF 
powerful and denying lambda the same power each avoids a change?

In other words, we are no longer discussing whether unnamed multi-line 
statements are a problem. The question is, would adding them to lambda 
mean a change?

Oh, yeah, it would. :)

hth, kenny


-- 
Cells: http://common-lisp.net/project/cells/

"Have you ever been in a relationship?"
Attorney for Mary Winkler, confessed killer of her
minister husband, when asked if the couple had
marital problems.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: segmentation fault in scipy?

2006-05-10 Thread Robert Kern
[EMAIL PROTECTED] wrote:
> Im using rprop (not dependent on error function in this case ie.
> standard rprop vs. irprop or arprop) for an MLP tanh, sigmod nnet as
> part of a hybrid model. I guess I was using a little Matlab thought
> when I wrote the SSE funtion.  My batches are about 25,000 x 80 so my
> absolute error (diff between net outputs and desired outputs) when
> using *one* output unit is shape(~25000,), am I wrong to assume
> trace(error*transpose(error)) is the sum of the squared errors which
> should be an shape(1,)?

I'm afraid you're using terminology (and abbreviations!) that I can't follow.
Let me try to restate what's going on and you can correct me as I screw up. You
have a neural net that has 80 output units. You have 25000 observations that you
are using to train the neural net. Each observation vector (and consequently,
each error vector) has 80 elements.

Judging by your notation, you are using the matrix subclass of array to change *
to matrix multiplication. In my message you are responding to (btw, please quote
the emails you respond to so we can maintain some context), I gave an answer for
you using regular arrays which have * as elementwise multiplication. The matrix
object's behavior gets in the way of the most natural way to do these
calculations, so I do recommend avoiding the matrix object and learning to use
the dot() function to do matrix multiplication instead. But if you want to
continue using matrix objects, then you can use the multiply() function to do
element-wise multiplication.

The answer I gave also used the wrong name for the result. It seems that you
want the sum of the squared errors across all of the observations. In this case,
you can use axis=None to specify that every element should be summed:

  SSE = sum(multiply(error, error), axis=None)

trace(dot(error, transpose(error))) wastes a *huge* amount of time and memory
since you are calculating (if your machine was capable of it) a gigantic matrix,
then throwing away all of the off-diagonal elements. The method I give above
wastes a little memory; there is one temporary matrix the size of error.

-- 
Robert Kern

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

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


Re: New tail recursion decorator

2006-05-10 Thread Carl Banks

Michele Simionato wrote:
> CONTINUE = object() # sentinel value returned by iterfunc
>
> def tail_recursive(func):
> """
> tail_recursive decorator based on Kay Schluehr's recipe
> http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/496691
> """
> var = dict(in_loop=False, cont=True, argkw='will be set later')
> # the dictionary is needed since Python closures are read-only
>
> def iterfunc(*args, **kwd):
> var["cont"] = not var["cont"]
> if not var["in_loop"]: # start looping
> var["in_loop"] = True
> while True:
> res = func(*args,**kwd)
> if res is CONTINUE:
> args, kwd = var["argkw"]
> else:
> var["in_loop"] = False
> return res
> else:
> if var["cont"]:
> var["argkw"] = args, kwd
> return CONTINUE
> else:
> return func(*args,**kwd)
> return iterfunc

CONTINUE could be put inside tail_recursive, couldn't it?  And to
squeeze a little more speed out of it, var could be a list (saves a
hash lookup).

Cool decorator.


Carl Banks

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


Re: segmentation fault in scipy?

2006-05-10 Thread conor . robinson
Im using rprop (not dependent on error function in this case ie.
standard rprop vs. irprop or arprop) for an MLP tanh, sigmod nnet as
part of a hybrid model. I guess I was using a little Matlab thought
when I wrote the SSE funtion.  My batches are about 25,000 x 80 so my
absolute error (diff between net outputs and desired outputs) when
using *one* output unit is shape(~25000,), am I wrong to assume
trace(error*transpose(error)) is the sum of the squared errors which
should be an shape(1,)?  I'm just now starting to dig a little deeper
into scipy, and I need to get the full doc. 

Thanks for all your input.

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


Formmating excel cells with PyExcelerator or COM

2006-05-10 Thread Mauricio Tellez
Hi, I just want that a number like 1234.123 appear in excel as 1,234.12In excel I just select some cells, then right click on them and select "Cell Formatting" then select Number, and check "Use thounsands separator" and 2 decimal places. I can't find how to do this with PyExcelerator neither with COM. Any clue?
-- Mauricio Tellez
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: reusing parts of a string in RE matches?

2006-05-10 Thread BartlebyScrivener
Thanks, Ben. Quite an education!

rick

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


Re: data entry tool

2006-05-10 Thread Cameron Laird
In article <[EMAIL PROTECTED]>,
 <[EMAIL PROTECTED]> wrote:
>Peter wrote>Wow - why so big for such a simple tool? 2MB sounds like a
>LOT of coding.<
>
>Yes, it's a lot of code, but it's code written by other people (Python,
>Tkinter). Using Tkinter your program will probably be quite short, even
>if you use some dbase.
>If the data to be entered is simple and textual you can even think
>about using a text only interface. The resulting program will be really
>simple, and probably good enough.
>2+ MB is the size of the executable package you need to give people to
>install Python + some libs + your program.
.
.
.
... and if it's really an issue, it's generally feasible to
squish a Python installable down enough so it fits on a 1.4
Mb floppy.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: reusing parts of a string in RE matches?

2006-05-10 Thread Ben Cartwright
Murali wrote:
> > Yes, and no extra for loops are needed!  You can define groups inside
> > the lookahead assertion:
> >
> >   >>> import re
> >   >>> re.findall(r'(?=(aba))', 'abababababababab')
> >   ['aba', 'aba', 'aba', 'aba', 'aba', 'aba', 'aba']
>
> Wonderful and this works with any regexp, so
>
> import re
>
> def all_occurences(pat,str):
>   return re.findall(r'(?=(%s))'%pat,str)
>
> all_occurences("a.a","abacadabcda") returns ["aba","aca","ada"] as
> required.


Careful.  That won't work as expected for *all* regexps.  Example:

  >>> import re
  >>> re.findall(r'(?=(a.*a))', 'abaca')
  ['abaca', 'aca']

Note that this does *not* find 'aba'.  You might think that making it
non-greedy might help, but:

  >>> re.findall(r'(?=(a.*?a))', 'abaca')
  ['aba', 'aca']

Nope, now it's not finding 'abaca'.

This is by design, though.   From
http://www.regular-expressions.info/lookaround.html (a good read, by
the way):

"""As soon as the lookaround condition is satisfied, the regex engine
forgets about everything inside the lookaround. It will not backtrack
inside the lookaround to try different permutations."""

Moral of the story:  keep lookahead assertions simple whenever
possible.  :-)

--Ben

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


Re: Econometrics in Panel data?

2006-05-10 Thread N/A
Oh! I think I should stop wasting time to learn Python to do my 
econometric algorithms. >_<


[EMAIL PROTECTED] wrote:
> Cameron Laird wrote:
>> In article <[EMAIL PROTECTED]>, I counseled:
>>> In article <[EMAIL PROTECTED]>,
>>> DeepBlue  <[EMAIL PROTECTED]> wrote:
 so are you saying that Python is not an appropriate language for doing
 econometrics stuff?


 Dennis Lee Bieber wrote:
> On Tue, 09 May 2006 05:58:10 +0800, DeepBlue <[EMAIL PROTECTED]> 
> declaimed the
> following in comp.lang.python:
>
>> Hi all,
>>
>> I am new to Python. Just wondering can Python able to do econometric
>> regression in either Time-series or pooled (panel) data? As well as test
>> for hetero, autocorrelation, or endogeneity?
>>  .
>>  .
>>  .
>>> There is not, however, a readily-accessible library targeted
>>> for this sort of work.  If I had the opportunity to work in
>>> econometrics now, I'd think seriously about R, Lisp, and
>>> Mathematica, and see what's available among the functional
>>> languages, along with Python.
>> Smalltalk, too; I'd throw it in the mix.  Much serious econometrics
>> has been done with Fortran, but I have no enthusiasm for pursuing
>> that direction, mostly because I think too much of the computing
>> world is going in a different one.
> 
> There are many statistics packages and programming languages used in
> econometrics and in general, so most of the computing world is going in
> a different
> "direction", no matter which package or language you choose.
> 
> Enough programmers still use Fortran that major hardware vendors such
> as Intel, IBM, and Sun are actively maintaining their Fortran 95
> compilers and adding features from Fortran 2003. G95 is free, available
> almost everywhere that gcc is, and good enough for production use IMO.
> 
> The recent book
> http://methcenter.psu.edu/newbooks/fortranbook/thebook.html
> Developing Statistical Software in Fortran 95
> by David R. Lemmon and Joseph L. Schafer
> Spriger (2005)
> 
> discusses how to build statistical software components in Fortran that
> can be used in statistical packages.
> 
> The IMSL and NAG software libraries have extensive statistical
> functionality and are available in Fortran, among other languages.
> 
> It is important for a programming language used for econometrics to
> conveniently handle multidimensional arrays, and here Fortran outshines
> C, C++, and Java (NumPy is good, though).
> 
> I am a quantitative financial analyst who implements econometrics
> algorithms. Data sets are getting bigger -- use of intraday data is now
> common -- and the CPU time for many algorithms scales as the N^2 or
> N^3, where N is the number of observations. Speed still matters.
> 
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: hyperthreading locks up sleeping threads

2006-05-10 Thread Grant Edwards
On 2006-05-10, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote:
> Grant
>
>> You might want to run some memory tests.
>
> We have multiple identical boxes and they all have the same problem.

Maybe whoever built them got a bad batch of RAM.  Or maybe the
just used RAM with the wrong specs.  It doesn't really cost
anything to run a memory test for a few hours, and if it
passes, then you can cross that off the list.

-- 
Grant Edwards   grante Yow!  KARL MALDEN'S NOSE
  at   just won an ACADEMY AWARD!!
   visi.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: reusing parts of a string in RE matches?

2006-05-10 Thread Murali
> Yes, and no extra for loops are needed!  You can define groups inside
> the lookahead assertion:
>
>   >>> import re
>   >>> re.findall(r'(?=(aba))', 'abababababababab')
>   ['aba', 'aba', 'aba', 'aba', 'aba', 'aba', 'aba']

Wonderful and this works with any regexp, so

import re

def all_occurences(pat,str):
  return re.findall(r'(?=(%s))'%pat,str)

all_occurences("a.a","abacadabcda") returns ["aba","aca","ada"] as
required.

- Murali

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


Slow network reading?

2006-05-10 Thread Ivan Voras
I have a simple network protocol client (it's a part of this: 
http://sqlcached.sourceforge.net) implemented in Python, PHP and C. 
Everything's fine, except that the Python implementation is the slowest 
- up to 30% slower than the PHP version (which implements exactly the 
same logic, in a class).

In typical usage (also in the benchmark), an object is created and 
.query is called repeatedly. Typical numbers for the benchmark are:

For Python version:

Timing 10 INSERTs...
5964.4 qps
Timing 10 SELECTs...
7491.0 qps

For PHP version:

Timing 10 inserts...
7820.2 qps
Timing 10 selects...
9926.2 qps


The main part of the client class is:



import os, socket, re

class SQLCacheD_Exception(Exception):
 pass

class SQLCacheD:

 DEFAULT_UNIX_SOCKET = '/tmp/sqlcached.sock'
 SC_VER_SIG = 'sqlcached-1'
 SOCK_UNIX = 'unix'
 SOCK_TCP = 'tcp'

 re_rec = re.compile(r"\+REC (\d+), (\d+)")
 re_ok = re.compile(r"\+OK (.+)")
 re_ver = re.compile(r"\+VER (.+)")

 def __init__(self, host = '/tmp/sqlcached.sock', type = 'unix'):
 if type != SQLCacheD.SOCK_UNIX:
 raise

 self.sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
 self.sock.connect(host)
 self.sf = self.sock.makefile('U', 4000)

 self.sf.write("VER %s\r\n" % SQLCacheD.SC_VER_SIG)
 self.sf.flush()
 if self.sf.readline().rstrip() != '+VER %s' % SQLCacheD.SC_VER_SIG:
 raise SQLCacheD_Exception("Handshake failure (invalid 
version signature?)")


 def query(self, sql):
 self.sf.write("SQL %s\r\n" % sql)
 self.sf.flush()
 resp = self.sf.readline().rstrip()
 m = SQLCacheD.re_rec.match(resp)
 if m != None: # only if some rows are returned (SELECT)
 n_rows = int(m.group(1))
 n_cols = int(m.group(2))
 cols = []
 for c in xrange(n_cols):
 cols.append(self.sf.readline().rstrip())
 rs = []
 for r in xrange(n_rows):
 row = {}
 for c in cols:
 row[c] = self.sf.readline().rstrip()
 rs.append(row)
 return rs
 m = SQLCacheD.re_ok.match(resp)
 if m != None: # no rows returned (e.g. INSERT/UPDATE/DELETE)
 return True
 raise SQLCacheD_Exception(resp)



My question is: Am I missing something obvious? The C implementation is 
(as expected) the fastest with result of 1:15000, but somehow I 
expected the Python one to be closer to, or even faster than PHP.

I tried using 'r' mode for .makefile() but it had no significant effect.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: New tail recursion decorator

2006-05-10 Thread Felipe Almeida Lessa
Em Ter, 2006-05-09 às 23:30 -0700, Kay Schluehr escreveu:
> http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/496691

Is it thread safe?

-- 
Felipe.

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

Re: A critic of Guido's blog on Python's lambda

2006-05-10 Thread Alex Martelli
Joe Marshall <[EMAIL PROTECTED]> wrote:

> Alex Martelli wrote:
> > Joe Marshall <[EMAIL PROTECTED]> wrote:
> >...
> > > The problem is that a `name' is a mapping from a symbolic identifier to
> > > an object and that this mapping must either be global (with the
> > > attendant name collision issues) or within a context (with the
> > > attendant question of `in which context').
> >
> > Why is that a problem?  Even for so-called "global" names, Python
> > supports a structured, hierarchical namespace, so there can never be any
> > collision betwen the "globals" of distinct modules (including modules
> > which happen to have the same name but live in distinct packages or
> > subpackages) -- I did mention that names could usefully be displayed in
> > some strcutured form such as apackage.somemodule.thefunction but perhaps
> > I was too tangential about it;-).
> 
> Can you refer to inner functions from the global context?  Suppose I
> have this Python code:
> 
> def make_adder(x):
> def adder_func(y):
> sum = x + y
> return sum
> return adder_func
> 
> Can I refer to the inner adder_func in any meaningful way?

You can refer to one instance/closure (which make_adder returns), of
course -- you can't refer to the def statement itself (but that's a
statement, ready to create a function/closure each time it executes, not
a function, thus, not an object) except through introspection. Maybe I
don't understand what you mean by this question...


> > If I used continuations (I assume you mean in the call/cc sense rather
> > than some in which I'm not familiar?) I might feel the same way, or not,
> > but I don't (alas), so I can't really argue the point either way for
> > lack of real-world experience.
> 
> I meant continuations as in the receiver function in
> continuation-passing-style.  If you have a function that has to act
> differently in response to certain conditions, and you want to
> parameterize the behavior, then one possibility is to pass one or more
> thunks to the function in addition to the normal arguments.  The

Ah, OK, I would refer to this as "callbacks", since no
call-with-continuation is involved, just ordinary function calls; your
use case, while pretty alien to Python's typical style, isn't all that
different from other uses of callbacks which _are_ very popular in
Python (cfr the key= argument to the sort methods of list for a typical
example).  I would guess that callbacks of all kinds (with absolutely
trivial functions) is the one use case which swayed Guido to keep lambda
(strictly limited to just one expression -- anything more is presumably
worth naming), as well as to add an if/else ternary-operator.  I still
disagree deeply, as you guessed I would -- if I had to work with a
framework using callbacks in your style, I'd name my callbacks, and I
wish Python's functools module provided for the elementary cases, such
as:

def constant(k):
def ignore_args(*a): return k
return ignore_args

def identity(v): return v

and so on -- I find, for example, that to translate your

> (define (option3 key table default-value)
>   (lookup key table
> (lambda (value) value)
> (lambda () default-value)))

I prefer to use:

def option3(key, table, default_value):
return lookup(key, table, identity, constant(default_value))

as being more readable than:

def option3(key, table, default_value):
return lookup(key, table, lambda v: v, lambda: default_value)

After all, if I have in >1 place in my code the construct "lambda v: v"
(and if I'm using a framework that requires a lot of function passing
I'm likely to be!), the "Don't Repeat Yourself" (DRY) principle suggests
expressing the construct *ONCE*, naming it, and using the name.

By providing unnamed functions, the language aids and abets violations
of DRY, while having the library provide named elementary functions (in
the already-existing appropriate module) DRY is reinforced and strongly
supported, which, IMHO, is a very good thing.


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


glob() that traverses a folder tree

2006-05-10 Thread seannakasone
i'm looking for something like glob.glob() that traverses
sub-directories.  is there anything like that?  i guess i'm looking for
something to replace the unix find command.

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


Re: Econometrics in Panel data?

2006-05-10 Thread beliavsky
Cameron Laird wrote:
> In article <[EMAIL PROTECTED]>, I counseled:
> >In article <[EMAIL PROTECTED]>,
> >DeepBlue  <[EMAIL PROTECTED]> wrote:
> >>so are you saying that Python is not an appropriate language for doing
> >>econometrics stuff?
> >>
> >>
> >>Dennis Lee Bieber wrote:
> >>> On Tue, 09 May 2006 05:58:10 +0800, DeepBlue <[EMAIL PROTECTED]> 
> >>> declaimed the
> >>> following in comp.lang.python:
> >>>
>  Hi all,
> 
>  I am new to Python. Just wondering can Python able to do econometric
>  regression in either Time-series or pooled (panel) data? As well as test
>  for hetero, autocorrelation, or endogeneity?
>   .
>   .
>   .
> >There is not, however, a readily-accessible library targeted
> >for this sort of work.  If I had the opportunity to work in
> >econometrics now, I'd think seriously about R, Lisp, and
> >Mathematica, and see what's available among the functional
> >languages, along with Python.
>
> Smalltalk, too; I'd throw it in the mix.  Much serious econometrics
> has been done with Fortran, but I have no enthusiasm for pursuing
> that direction, mostly because I think too much of the computing
> world is going in a different one.

There are many statistics packages and programming languages used in
econometrics and in general, so most of the computing world is going in
a different
"direction", no matter which package or language you choose.

Enough programmers still use Fortran that major hardware vendors such
as Intel, IBM, and Sun are actively maintaining their Fortran 95
compilers and adding features from Fortran 2003. G95 is free, available
almost everywhere that gcc is, and good enough for production use IMO.

The recent book
http://methcenter.psu.edu/newbooks/fortranbook/thebook.html
Developing Statistical Software in Fortran 95
by David R. Lemmon and Joseph L. Schafer
Spriger (2005)

discusses how to build statistical software components in Fortran that
can be used in statistical packages.

The IMSL and NAG software libraries have extensive statistical
functionality and are available in Fortran, among other languages.

It is important for a programming language used for econometrics to
conveniently handle multidimensional arrays, and here Fortran outshines
C, C++, and Java (NumPy is good, though).

I am a quantitative financial analyst who implements econometrics
algorithms. Data sets are getting bigger -- use of intraday data is now
common -- and the CPU time for many algorithms scales as the N^2 or
N^3, where N is the number of observations. Speed still matters.

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


Re: reusing parts of a string in RE matches?

2006-05-10 Thread Ben Cartwright
John Salerno wrote:
> So my question is, how can find all occurrences of a pattern in a
> string, including overlapping matches? I figure it has something to do
> with look-ahead and look-behind, but I've only gotten this far:
>
> import re
> string = 'abababababababab'
> pattern = re.compile(r'ab(?=a)')
> m = pattern.findall(string)
>
> This matches all the 'ab' followed by an 'a', but it doesn't include the
> 'a'. What I'd like to do is find all the 'aba' matches. A regular
> findall() gives four results, but really there are seven.
>
> Is there a way to do this with just an RE pattern, or would I have to
> manually add the 'a' to the end of the matches?

Yes, and no extra for loops are needed!  You can define groups inside
the lookahead assertion:

  >>> import re
  >>> re.findall(r'(?=(aba))', 'abababababababab')
  ['aba', 'aba', 'aba', 'aba', 'aba', 'aba', 'aba']

--Ben

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


Re: create a c++ wrapper for python class?

2006-05-10 Thread Diez B. Roggisch
Mark Harrison schrieb:
> Right now I'm using Boost Python to wrap some C++ code so
> that applications from both languages can use it.
> 
> This is great, but I'm rapidly coming to the conclusion that
> a lot of this work is better coded in Python.  There's nothing
> particularly CPU-bound, and the comprehensive Python library is a 
> big help.
> 
> So, I'm looking for a C++ wrapper generator, so that I can
> write a class in Python, and then have a .h and .cpp generated
> that will give me a corresponding C++ class.
> 
> Of course, the usual restrictions apply:  no dynamically
> added methods, accessing all instance data via getters
> and setters, etc.
> 
> It seems a first cut of  this is pretty straightforward,
> using introspection to get the required methods.  Something
> needs to be done to specify the C++ types of the parameters.
> 
> Is there any work being done in this area?

No - and I doubt there is much to do about that. C++ needs so many 
static information to form a proper class, you'd end up duplicating the 
whole declarational efforts in some awkward addition or complementary 
annotation to python's syntax that it just isn't feasible. There is 
shedskin, avery interesting project, but then this sufers from being a 
subset of python and AFAIK no  seamless interoperability between python 
and C++.

I don't know  about boost - but I know my way around SIP a little bit. 
So what I would do is to declare whatever you need in C++ in a class 
with all virtual methods. SIP then should be able to let you subclass 
that class in python, and pass back instances of your python classes to 
your C++-core/library/whatever.

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


Re: Best form when using matrices and arrays in scipy...

2006-05-10 Thread Robert Kern
[EMAIL PROTECTED] wrote:
> Using large arrays of data I found it is MUCH faster to cast arrays to
> matricies and then multiply the two matricies togther
> (scipy.matrix(ARRAY1)*scipy.matrix(ARRAY2)) in order to do a matrix
> multipy of two arrays vs. scipy.matrixmultipy(ARRAY1, ARRAY2).
> 
> Are there any logical/efficiency errors with this train of thought and
> is there a valid reason for the speed increase?

matrixmultiply is a backwards-compatibility alias. You should be using dot()
instead. When an optimized BLAS is available dot() is replaced with an optimized
version. numpy.matrix uses dot() to implement its multiplication operation.
Unfortunately, the code that does the replacement does not seem to handle
matrixmultiply correctly.

Also, there are better fora for asking questions about numpy and scipy:

  http://www.scipy.org/Mailing_Lists

-- 
Robert Kern

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

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


Re: segmentation fault in scipy?

2006-05-10 Thread Robert Kern
[EMAIL PROTECTED] wrote:
> Good point.  Finding the SSE using an absolute error matrix of (25000 x
> 1) is insane.  I pulled out the error function (for now) and I'm back
> in business.  Thanks for all the great advise.

Could you go back for a second and describe your problem a little bit more. It
sounds like you were doing the wrong operation. By SSE, you mean "Sum of Squared
Errors" of the 25000 length-80 vectors, right? In that case, using matrix
multiplication won't give you that. That will, in essence calculate the
dot-product of each of the 25000 length-80 vectors with *each* of the other
25000 length-80 vectors in addition to themselves. It seems to me like you want
something like this:

  SSE = sum(error * error, axis=-1)

Then SSE.shape == (25000,).

-- 
Robert Kern

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

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


Best form when using matrices and arrays in scipy...

2006-05-10 Thread conor . robinson

Using large arrays of data I found it is MUCH faster to cast arrays to
matricies and then multiply the two matricies togther
(scipy.matrix(ARRAY1)*scipy.matrix(ARRAY2)) in order to do a matrix
multipy of two arrays vs. scipy.matrixmultipy(ARRAY1, ARRAY2).

Are there any logical/efficiency errors with this train of thought and
is there a valid reason for the speed increase?

Thanks,
Conor

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


create a c++ wrapper for python class?

2006-05-10 Thread Mark Harrison
Right now I'm using Boost Python to wrap some C++ code so
that applications from both languages can use it.

This is great, but I'm rapidly coming to the conclusion that
a lot of this work is better coded in Python.  There's nothing
particularly CPU-bound, and the comprehensive Python library is a 
big help.

So, I'm looking for a C++ wrapper generator, so that I can
write a class in Python, and then have a .h and .cpp generated
that will give me a corresponding C++ class.

Of course, the usual restrictions apply:  no dynamically
added methods, accessing all instance data via getters
and setters, etc.

It seems a first cut of  this is pretty straightforward,
using introspection to get the required methods.  Something
needs to be done to specify the C++ types of the parameters.

Is there any work being done in this area?

Many TIA,
Mark

-- 
Mark Harrison
Pixar Animation Studios
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Memory leak in Python

2006-05-10 Thread diffuser78
I ran simulation for 128 nodes and used the following

oo = gc.get_objects()
print len(oo)

on every time step the number of objects are increasing. For 128 nodes
I had 1058177 objects.

I think I need to revisit the code and remove the referencesbut how
to do that. I am still a newbie coder and every help will be greatly
appreciated.

thanks

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


Re: segmentation fault in scipy?

2006-05-10 Thread conor . robinson
Good point.  Finding the SSE using an absolute error matrix of (25000 x
1) is insane.  I pulled out the error function (for now) and I'm back
in business.  Thanks for all the great advise.

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


Re: Memory leak in Python

2006-05-10 Thread diffuser78
With 1024 nodes it runs fine...but takes around4 hours to run on AMD
3100.

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


Re: Memory leak in Python

2006-05-10 Thread diffuser78
Sure, are there any available simulators...since i am modifying some
stuff i thought of creating one of my own. But if you know some
exisiting simlators , those can be of great help to me.

Thanks

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


Re: segmentation fault in scipy?

2006-05-10 Thread Robert Kern
[EMAIL PROTECTED] wrote:
> I'm running operations large arrays of floats, approx 25,000 x 80.
> Python (scipy) does not seem to come close to using 4GB of wired mem,
> but segments at around a gig. Everything works fine on smaller batches
> of data around 10,000 x 80 and uses a max of ~600mb of mem.  Any Ideas?
>  Is this just too much data for scipy?
>
> Thanks Conor
> 
> Traceback (most recent call last):
>  File "C:\Temp\CR_2\run.py", line 68, in ?
>net.rProp(1.2, .5, .01, 50.0, input, output, 1)
>  File "/Users/conorrob/Desktop/CR_2/Network.py", line 230, in rProp
>print scipy.trace(error*scipy.transpose(error))
>  File "D:\Python24\Lib\site-packages\numpy\core\defmatrix.py", line
> 149, in
> __mul__
>return N.dot(self, other)
> MemoryError

This is not a segfault. Is this the only error you see? Or are you actually
seeing a segfault somewhere?

If error.shape == (25000, 80), then dot(error, transpose(error)) will be
returning an array of shape (25000, 25000). Assuming double precision floats,
that array will take up about 4768 megabytes of memory, more than you have. The
memory usage doesn't go up near 4 gigabytes because the allocation of the very
large returned array fails, so the large chunk of memory never gets allocated.

There are two possibilities:

1. As Travis mentioned, numpy won't create the array because it is still
32-bit-limited due to the Python 2.4 C API. This has been resolved with Python 
2.5.

2. The default build of numpy uses plain-old malloc(3) to allocate memory, and
it may be failing to create such large chunks of memory.

-- 
Robert Kern

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

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


Re: hyperthreading locks up sleeping threads

2006-05-10 Thread David Reed

On May 10, 2006, at 5:39 PM, [EMAIL PROTECTED] wrote:

> Grant
>
>> You might want to run some memory tests.
>
> We have multiple identical boxes and they all have the same problem.
>
> Olaf


They might all have flaky memory - I would follow the other poster's  
advice and run memtest86 on them.

Dave

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


Re: segmentation fault in scipy?

2006-05-10 Thread conor . robinson
If I run it from the shell (unix) I get: Segmentation fault and see a
core dump in my processes.  If I run it in the python shell I get as
above:
File "D:\Python24\Lib\site-packages\numpy\core\defmatrix.py", line
149, in
__mul__
   return N.dot(self, other)
MemoryError

I your experience as one of the dev of scipy, is this too much data?

thank you

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


Re: syntax for -c cmd

2006-05-10 Thread Paul McGuire
"James" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
> Wrong syntax is shown below. What should be the delimiter before else?
>
> python -c 'if 1==1: print "yes"; else print "no"'
>
> James
>

So you can approximate this same logic with a boolean expression:

print (1==1 and "yes" or "no")

This is because Python short-circuits boolean and's and or's, and returns
the last evaluated value.  So the expanded logic here is:
evaluate 1==1 -> True
evaluate "yes" -> True - we are done, return "yes"

if the expression were (math.pi==3 and "yes" or "no"), we would get:
evaluate math.pi==3 -> False
(skip evaluation of "yes", first part failed so go straight to or term)
evaluate "no" -> well, doesn't matter if this is True or False, it's the
last thing we have to evaluate, return it

Generally this gets idiomatically expressed as:

(condition and trueConditionValue or falseConditionValue)


This is currently (Python 2.4) the closest Python gets to C's ternary
operator.  Note that there are some risks, for example, this rendition
*wont* work.

numberOfApples = 1
print "I have %d apple%s" % ( numberOfApples, (numberOfApples ==1 and "" or
"s"))

This is because "" evaluates boolean-ly to False, so the conditional
conjunction of (numberOfApples==1) and "" is False, so we continue to
evaluate the expression, and wind up printing  "I have 1 apples".

The resolution is to invert the test:
numberOfApples = 1
print "I have %d apple%s" % ( numberOfApples, (numberOfApples !=1 and "s" or
""))

(If I have zero of something, I prefer to say "I have 0 somethings" - if you
like to say "I have 0 something" then make the test read (numberOfApples > 1
and "s" or "") )

In the coming 2.5 version of Python, there is a ternary-like expression:

numberOfApples = 1
print "I have %d apple%s" % ( numberOfApples, ("" if numberOfApples ==1 else
"s"))

Python 2.5 is still in preliminary releases though, and will not be
generally available until this coming fall.  This will allow you to spell
out if-then-else conditions on the command line.  In general scripting,
though, compaction of code into one-liners is not always considered a
virtue.  This code:

print "I have %s apple%s" % (numberOfApples==0 and "no" or numberOfApples,
numberOfApples !=1 and "s" or "")

will not win you points with your software maintenance team.

-- Paul


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


Re: Calling C/C++ functions in a python script

2006-05-10 Thread Ravi Teja
If all you have are functions, the easiest is to create a simple dll/so
and load it into Python with ctypes.
http://starship.python.net/crew/theller/ctypes/tutorial.html

For more advanced needs, take a look at some of the extending options
available.
http://www.suttoncourtenay.org.uk/duncan/accu/integratingpython.html

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


Re: segmentation fault in scipy?

2006-05-10 Thread Travis E. Oliphant
[EMAIL PROTECTED] wrote:
> I'm running operations large arrays of floats, approx 25,000 x 80.
> Python (scipy) does not seem to come close to using 4GB of wired mem,
> but segments at around a gig. Everything works fine on smaller batches
> of data around 10,000 x 80 and uses a max of ~600mb of mem.  Any Ideas?
>  Is this just too much data for scipy?
> 
> Thanks Conor
> 
> Traceback (most recent call last):
>  File "C:\Temp\CR_2\run.py", line 68, in ?
>net.rProp(1.2, .5, .01, 50.0, input, output, 1)
>  File "/Users/conorrob/Desktop/CR_2/Network.py", line 230, in rProp
>print scipy.trace(error*scipy.transpose(error))
>  File "D:\Python24\Lib\site-packages\numpy\core\defmatrix.py", line
> 149, in
> __mul__
>return N.dot(self, other)
> MemoryError

You should ask this question on the numpy-discussion list for better 
feedback.


Does it actually segfault or give you this Memory Error?


Temporary arrays that need to be created could be the source of the 
extra memory.


Generally, you should be able to use all the memory on your system 
(unless you are on a 64-bit system and are not using Python 2.5).



-Travis

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


Re: interactive shell -- reload definitions?

2006-05-10 Thread Metalone
Thanks everybody.

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


Calling C/C++ functions in a python script

2006-05-10 Thread chaosquant
I'm kind of beginner in Python, so I must ask what are probably silly
questions.

Here is my problem:

I have a static library say, a file library.lib, which can be linked to
C or C++ programs.

Now I would like to use the functions of the library in Python script,
under Win XP.

Can someone give me a simple example of how to do so?

Thanks a lot,

 Jean-Claude

Please reply also to [EMAIL PROTECTED]

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


segmentation fault in scipy?

2006-05-10 Thread conor . robinson
I'm running operations large arrays of floats, approx 25,000 x 80.
Python (scipy) does not seem to come close to using 4GB of wired mem,
but segments at around a gig. Everything works fine on smaller batches
of data around 10,000 x 80 and uses a max of ~600mb of mem.  Any Ideas?
 Is this just too much data for scipy?

Thanks Conor

Traceback (most recent call last):
 File "C:\Temp\CR_2\run.py", line 68, in ?
   net.rProp(1.2, .5, .01, 50.0, input, output, 1)
 File "/Users/conorrob/Desktop/CR_2/Network.py", line 230, in rProp
   print scipy.trace(error*scipy.transpose(error))
 File "D:\Python24\Lib\site-packages\numpy\core\defmatrix.py", line
149, in
__mul__
   return N.dot(self, other)
MemoryError
>>>

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


Re: installing numpy

2006-05-10 Thread Robert Kern
Gary Wessle wrote:
> thanks
> I followed your suggestions, it built the package ok, while it was
> building, I noticed lots of lines going by the screen in groups of
> different colors, white, yellow, red.
> the red got my attention: 
> 
> 
> Could not locate executable gfortran
> Could not locate executable f95
> 

Don't worry about those. numpy does not require a Fortran compiler to build.
Some projects using numpy.distutils, like scipy, will. The information flow in
distutils is not ideal, so the checks are done regardless of whether you need
Fortran or not.

> is there a way to find out if the built is fine and it is using the
> high performance libraries?

You can use the ldd(1) program on the extension modules (they're the ones with
the .so extension) to see what libraries they link against.

To run all of the unit tests:

[~]$ python
Python 2.4.1 (#2, Mar 31 2005, 00:05:10)
[GCC 3.3 20030304 (Apple Computer, Inc. build 1666)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import numpy
>>> numpy.test()
  Found 5 tests for numpy.distutils.misc_util
  Found 3 tests for numpy.lib.getlimits
  Found 30 tests for numpy.core.numerictypes
  Found 13 tests for numpy.core.umath
  Found 8 tests for numpy.lib.arraysetops
  Found 42 tests for numpy.lib.type_check
  Found 93 tests for numpy.core.multiarray
  Found 3 tests for numpy.dft.helper
  Found 36 tests for numpy.core.ma
  Found 9 tests for numpy.lib.twodim_base
  Found 2 tests for numpy.core.oldnumeric
  Found 8 tests for numpy.core.defmatrix
  Found 1 tests for numpy.lib.ufunclike
  Found 34 tests for numpy.lib.function_base
  Found 1 tests for numpy.lib.polynomial
  Found 6 tests for numpy.core.records
  Found 19 tests for numpy.core.numeric
  Found 4 tests for numpy.lib.index_tricks
  Found 46 tests for numpy.lib.shape_base
  Found 0 tests for __main__
...
--
Ran 363 tests in 2.812s

OK

>>>

-- 
Robert Kern

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

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


Re: design a Condition class

2006-05-10 Thread Paul McGuire
<[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
> Hello,
>
> i posted for suggestions a little idea even if it still needs further
> thoughts but as i'm sure you could help :)
>
> if would like to implement some kind of Condition class which i coud
> use to build bricks of more complex condition, conditions are based on
> fields by using regexp
>
> class Condition:
> def __init__(self, field0, field1, field2):
> self.field0 = field0
> self.field1 = field1
> self.field2 = field2
> def match(self, against):
> w, t, l = against
> f0 = False
> if self.field0 is None:
> f0 = True
> else:
> f0 = self.field0.search(w)
> if self.field1 is None:
> f1 = True
> else:
> f1 = self.field1.search(t)
> if self.field2 is None:
> f2 = True
> else:
> f2 = self.field2.search(l)
> return f0 and f1 and f2
>
> c0 = Condition(re.compile("something"), None,
> re.compile("somethingelse"))
> c1 = Condition(re.compile("another"), None, None)
>
> i can use
>
> if c0.search(myitem)
>
> but i would like to be able to have composition such as :
>
> c2 = c0 | c1
>
> which should be understood as defining a new c2 which is able to match
> (c0 or c1) from c0 and c1 already defined.
>
> actually i can imagine a
>
> def OR(c0, c1):
>  # here => missing None support 'a or None' is 'a'
>  return Condition(re.compile("|".join((c0.field0.pattern,
> c1.field0.pattern)),
>   re.compile("|".join((c0.field1.pattern,
> c1.field1.pattern)),
>   re.compile("|".join((c0.field2.pattern,
> c1.field2.pattern))
>
> the idea is to build c2 = Condition(re.compile("something|another"),
> None, re.compile("somethingelse"))
> c2 = OR(c0, c1)
>
> but maybe have you clever suggestions ?
>
> best regards.
>

Your composition of expressions to match is very similar to the definition
of grammars in pyparsing.  Here's a small example, to parse "Hello,
World!"-type strings.


from pyparsing import Word, alphas

# define grammar
greet = Word( alphas ) + "," + Word( alphas ) + "!"

# input string
hello = "Hello, World!"

# parse input string
print hello, "->", greet.parseString( hello )


The Word class matches any group of characters composed of the letters in
the string passed to the constructor.  alphas is a string constant of the
upper and lower case letters A thru Z.  This sample program prints out:

Hello, World! -> ['Hello', ',', 'World', '!']

pyparsing has many more expression types, including Literal,
CaselessLiteral, Optional, ZeroOrMore, and OneOrMore.  There are also
combining forms, And, Or, MatchFirst, and Each.  The handy part of these
combining forms is that there are operator short-cuts:
a + b  is the same as And([a,b]) (that is, a followed by b)
a | b is the same as MatchFirst([a,b]) (if not match a, then try to match b)
a ^ b is the same as Or([a,b]) (try matching a and b, choose longest match)
a @ b is the same as Each([a,b]) (match a and b in any order - good for
matching options that can be specified in any order)

The resulting grammar expressions are fairly readable.  The greet expression
above translates to

greet is a word group of alphabetic characters, followed by a ",", followed
by another word group of alphabetic characters, followed by a "!".  Note
that there is no explicit specification of whitespace - whitespace will
terminate a word group, but is not necessary if the grammar is unambiguous
without it.  For instance, this expression will match any of:

Hello,World!
Hello , World !
Hello ,World !
... and so on.

Of course it will also match:
Howdy, pardner!
Greetings, Earthling!
Aloha, wahini!

The matched results are returned as an object of type ParseResults, which
can be accessed like a list, a dictionary, or an object with attributes (if
you associated names with individual elements of the parse expression).

You can get more info and download info at pyparsing.wikispaces.com.  Even
if you choose not to use pyparsing, you might get some ideas on your own
implementation.

-- Paul


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


Re: installing numpy

2006-05-10 Thread Gary Wessle

thanks
I followed your suggestions, it built the package ok, while it was
building, I noticed lots of lines going by the screen in groups of
different colors, white, yellow, red.
the red got my attention: 


Could not locate executable gfortran
Could not locate executable f95


is there a way to find out if the built is fine and it is using the
high performance libraries?

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


Re: combined files together

2006-05-10 Thread Gary Wessle
Eric Deveaud <[EMAIL PROTECTED]> writes:

> Gary Wessle wrote:
> > 
> >  I need to traverse those files in the order they were created
> >  chronologically. listdir() does not do it, is there a way besides
> >  build a list then list.sort(), then for element in list_of_files open
> >  element?
> 
> are the name of the files describing the cration date, 

yes 

> or have to rely on the creation date ?

no


> 
> if the name allows to discriminate the chronology, check glob module.

I just tried glob, it does not put out a list with file names sorted. 
> 
>   Eric
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: A critic of Guido's blog on Python's lambda

2006-05-10 Thread Frank Goenninger DG1SBG
Ken Tilton <[EMAIL PROTECTED]> writes:

> sross wrote:
>>>I do wonder what would happen to Cells if I ever want to support
>>>multiple threads. Or in a parallel processing environment.
>> AFAIK It should be fine.
>> In LW, SBCL and ACL all bindings of dynamic variables are thread-local.
>> 
>
> Ah, I was guilty of making an unspoken segue: the problem is not with
> the *dependent* special variable, but with the sequentially growing
> numeric *datapulse-id* ("the ID") that tells a cell if it needs to
> recompute its value. The ID is not dynamically bound. If threads T1
> and T2 each execute a toplevel, imperative assignment, two threads
> will start propagating change up the same dependency
> graph... 
>
> Might need to specify a "main" thread that gets to play with Cells and
> restrict other threads to intense computations but no Cells?

Hmmm. I am wondering if a Cells Manager class could be the home for
all Cells. Each thread could the have its own Cells Manager...

>
> Actually, I got along quite a while without an ID, I just propagated
> to dependents and ran rules. This led sometimes to a rule running
> twice for one change and transiently taking on a garbage value, when
> the dependency graph of a Cell had two paths back to some changed
> Cell.
>
> Well, Cells have always been reengineered in the face of actual use
> cases, because I am not really smart enough to work these things out
> in the abstract. Or too lazy or something. Probably all three.

Nah. It's me asking again and again those silly questions about 
real Cells usage in some real life apps ;-)

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


Re: design a Condition class

2006-05-10 Thread Carl J. Van Arsdall


[EMAIL PROTECTED] wrote:
> Hello,
>
> i posted for suggestions a little idea even if it still needs further
> thoughts but as i'm sure you could help :)
>
> if would like to implement some kind of Condition class which i coud
> use to build bricks of more complex condition, conditions are based on
> fields by using regexp
>
>   
I just wanted to make the comment that there already exists a 
Condition() class in the threading module.  If you plan on using your 
class with the threading module you might wish to use another name.

-carl


-- 

Carl J. Van Arsdall
[EMAIL PROTECTED]
Build and Release
MontaVista Software

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


design a Condition class

2006-05-10 Thread joh12005
Hello,

i posted for suggestions a little idea even if it still needs further
thoughts but as i'm sure you could help :)

if would like to implement some kind of Condition class which i coud
use to build bricks of more complex condition, conditions are based on
fields by using regexp

class Condition:
def __init__(self, field0, field1, field2):
self.field0 = field0
self.field1 = field1
self.field2 = field2
def match(self, against):
w, t, l = against
f0 = False
if self.field0 is None:
f0 = True
else:
f0 = self.field0.search(w)
if self.field1 is None:
f1 = True
else:
f1 = self.field1.search(t)
if self.field2 is None:
f2 = True
else:
f2 = self.field2.search(l)
return f0 and f1 and f2

c0 = Condition(re.compile("something"), None,
re.compile("somethingelse"))
c1 = Condition(re.compile("another"), None, None)

i can use

if c0.search(myitem)

but i would like to be able to have composition such as :

c2 = c0 | c1

which should be understood as defining a new c2 which is able to match
(c0 or c1) from c0 and c1 already defined.

actually i can imagine a

def OR(c0, c1):
 # here => missing None support 'a or None' is 'a'
 return Condition(re.compile("|".join((c0.field0.pattern,
c1.field0.pattern)),
  re.compile("|".join((c0.field1.pattern,
c1.field1.pattern)),
  re.compile("|".join((c0.field2.pattern,
c1.field2.pattern))

the idea is to build c2 = Condition(re.compile("something|another"),
None, re.compile("somethingelse"))
c2 = OR(c0, c1)

but maybe have you clever suggestions ?

best regards.

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


Re: hyperthreading locks up sleeping threads

2006-05-10 Thread OlafMeding
Grant

> You might want to run some memory tests.

We have multiple identical boxes and they all have the same problem.

Olaf

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


Re: ConfigParser and multiple option names

2006-05-10 Thread Florian Lindner
[EMAIL PROTECTED] wrote:

> that will break horribly in windows, remenber it install all it's crap
> in c:\Program Files

Why should this break? If you split at the \n character?

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


Re: Can Python installation be as clean as PHP?

2006-05-10 Thread Peter Maas
Jack wrote:
> With Python, things are really messy. I have to run the installer
> to install dozens of directories and hundreds of files, and I don't
> really know if  all of them are necessary.

PHP has LOTS of functions in a single namespace. I don't know wether
they are in separate files or packed in the exexutable but I'm sure
that you don't need them all ;)

> Plus, lots of libraries
> are in .py, which is of course not as efficient/clean as having all
> of the core functions built-in in the C/C++ core, like in PHP.

Python is faster than PHP in most situations (2-3x). Look at
http://dada.perl.it/shooutout for win32 and
http://shooutout.alioth.debian.org for linux.

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


Re: hyperthreading locks up sleeping threads

2006-05-10 Thread Grant Edwards
On 2006-05-10, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote:

> So to make sure that no other software is involved we took the
> PC with the problem, reset the BIOS to its defaults (which
> also enables hyper-threading) and installed Windows XP
> Professional (SP2) on it (but no further driver software,
> etc).  We accepted all defaults during the installation.
>
> Once Windows XP was running we installed Python downloaded
> from (and accepted all defaults during the installation):
> http://www.python.org/ftp/python/2.4.3/python-2.4.3.msi
>
> And we then ran our Python test program and it hung after less
> than 15 minutes!
>
> We are now contacting the company that puts that PC together
> for further advice.

You might want to run some memory tests. I don't see why
hyperthreading would make a difference, but running the test is
dead simple: download the ISO image, burn a CD, boot from the
CD, come back in a day or two:

  http://www.memtest86.com/

-- 
Grant Edwards   grante Yow!  Does that mean
  at   I'm not a well-adjusted
   visi.comperson??
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: hyperthreading locks up sleeping threads

2006-05-10 Thread OlafMeding
This is an update on what we found so far:

We located one other PC that was not identical to the PC with the
problem.  So we installed Windows XP on it and ran the Python test
program.  It ran fine all night w/o locking up.

Here is what winmsd reports for this PC:
winmsd:
OS Name: Microsoft Windows XP Professional
Version: 5.1.2600 Service Pack 2 Build 2600
Processor: x86 Family 15 Model 4 Stepping 3 GenuineIntel ~3600Mhz
Processor: x86 Family 15 Model 4 Stepping 3 GenuineIntel ~3600Mhz

Okay so this together with what others reported on in this newsgroup
leads to the conclusion that the problem is with the specific software
or hardware configuration of our PC.

So to make sure that no other software is involved we took the PC with
the problem, reset the BIOS to its defaults (which also enables
hyper-threading) and installed Windows XP Professional (SP2) on it (but
no further driver software, etc).  We accepted all defaults during the
installation.

Once Windows XP was running we installed Python downloaded from (and
accepted all defaults during the installation):
http://www.python.org/ftp/python/2.4.3/python-2.4.3.msi

And we then ran our Python test program and it hung after less than 15
minutes!

We are now contacting the company that puts that PC together for
further advice.

Olaf

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


Re: data entry tool

2006-05-10 Thread bearophileHUGS
Peter wrote>Wow - why so big for such a simple tool? 2MB sounds like a
LOT of coding.<

Yes, it's a lot of code, but it's code written by other people (Python,
Tkinter). Using Tkinter your program will probably be quite short, even
if you use some dbase.
If the data to be entered is simple and textual you can even think
about using a text only interface. The resulting program will be really
simple, and probably good enough.
2+ MB is the size of the executable package you need to give people to
install Python + some libs + your program.

Bye,
bearophile

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


Re: reusing parts of a string in RE matches?

2006-05-10 Thread mpeters42
Exactly,

Now this will work as long as there are no wildcards in the pattern.
Thus, only with fixed strings.  But if you have a fixed string, there
is really no need to use regex, as it will complicate you life for no
real reason (as opposed to simple string methods).

With a more complex pattern (like 'a.a': match any character between
two 'a' characters) this will get the length, but not what character is
between the a's.

To actually do that you will need to iterate through the string and
apply the pattern match (which matches only the beginning of a string)
to a indexed subset of the original (see example in the last post)

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


Re: data entry tool

2006-05-10 Thread Dan Sommers
On Thu, 11 May 2006 06:54:14 +1200,
Peter <[EMAIL PROTECTED]> wrote:

> Serge Orlov wrote:

[ ... ]

>> Keep in mind that standalone application for windows will be about
>> 2Mb.

> Wow - why so big for such a simple tool?
> 2MB sounds like a LOT of coding.

Actually, just the opposite:  that's 2MB of things someone else wrote in
order that your application code remain small.

Regards,
Dan

-- 
Dan Sommers

"I wish people would die in alphabetical order." -- My wife, the genealogist
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: A critic of Guido's blog on Python's lambda

2006-05-10 Thread Chris F Clark
Kenny replied to me saying:
> Yep. But with Cells the dependency graph is just a shifting record of
> who asked who, shifting because all of a sudden some outlier data will
> enter the system and a rule will branch to code for the first time,
> and suddenly "depend on" on some new other cell (new as in never
> before used by this cell). This is not subject to static analysis
> because, in fact, lexically everyone can get to everything else, what
> with closures, first-class functions, runtime branching we cannot
> predict... fuggedaboutit.
> 
> So we cannot say, OK, here is "the graph" of our application
> model. All we can do is let her rip and cross our fingers. :)

Yes, if you have Turing completeness in your dependency graph, the
problem is unsolvable.  However, it's like the static v. dynamic
typing debate, you can pick how much you want to allow your graph to
be dynamic versus how much "safety" you want.  In particular, I
suspect that in many applications, one can compute the set of
potentially problematic dependencies (and that set will be empty).
It's just a matter of structuring and annotating them correctly.  Just
like one can create type systems that work for ML and Haskell.  Of
course, if you treat your cell references like C pointers, then you
get what you deserve.

Note that you can even run the analysis dynamically, recomputing
whether the graph is cycle free as each dependency changes.  Most
updates have local effect.  Moreover, if you have used topological
sort to compute an ordering as well as proving cycle-free-ness, the
edge is only pontentially problemantic when it goes from a later
vertex in the order to an earlier one.  I wouldn't be surprised to
find efficient algorithms for calculating and updating a topological
sort already in the literature.

It is worth noting that in typical chip circuitry there are
constructions, generally called "busses" where the flow of information
is sometimes "in" via an edge and sometimes "out" via the same edge
and we can model them in a cycle-free manner.

If you want to throw up your hands and say the problem is intractable
in general, you can.  However, in my opinion one doesn't have to give
up quite that easily.

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


Re: MySQLdb trouble

2006-05-10 Thread Nicolay A. Vasiliev




Hi!

I use the DB connection from many application modules. In fact, I test
some technic hardly on the local machine. When I get coming result I
upload the script to the web server. I have 2 functions: connect_db and
loc_connect_db. First contains the remote server login data, second -
local server. Before I upload the script to the server I just switch
loc_connect_db to connect_db. That's it :)

John Salerno wrote:

  Nicolay A. Vasiliev wrote:

  
  
def loc_connect_db():
   """
   The DB connection subroutine
   """
   db = MySQLdb.connect(host = "localhost",
   user = "root",
   passwd="mysql",
   db="some_db")
   return db

  
  
Hi. Sorry I can't help, but I'm interested in learning about mysqldb and 
I was wondering why you chose to wrap the 'connect' function inside your 
own function. Does this accomplish something that I'm not seeing? 
Couldn't you just use the body of the loc_connect_db() function as your 
actual code in order to get 'db'?

Thanks.
  




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

Re: reusing parts of a string in RE matches?

2006-05-10 Thread Kent Johnson
John Salerno wrote:
> I probably should find an RE group to post to, but my news server at 
> work doesn't seem to have one, so I apologize. But this is in Python 
> anyway :)
> 
> So my question is, how can find all occurrences of a pattern in a 
> string, including overlapping matches? 

You can specify a start location to re.search(), and get the location of 
a match from a match object. This allows you to loop, searching the 
string following the last match:

import re
string = 'abababababababab'
pattern = re.compile(r'ab(?=a)')

ans = []
start = 0
while True:
 m = pattern.search(string, start)
 if not m: break
 ans.append( (m.start(), m.end()) )
 start = m.start() + 1

print ans # => [(0, 2), (2, 4), (4, 6), (6, 8), (8, 10), (10, 12), (12, 14)]

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


can distutils windows installer invoke another distutils windows installer

2006-05-10 Thread timw.google
Hi all.

I have a package that uses other packages. I created a setup.py to use
'try:' and import to check if some required packages are installed. I
have the tarballs and corresponding windows installers in my sdist
distribution, so if I untar my source distribution and do 'python
setup.py install', the script either untars the subpackages to a tmp
directory and does an os.system('python setup.py install') (Linux), or
os.system() (win32) for the missing
subpackage.

This seems to work fine, except that on Windows, I can't uninstall the
main package with Windows 'Add or Remove Programs' from the control
panel.  If I install my main package with a bdist_winst installer, I
can.

Is there a way to set up a bdist_wininst installer to do what I can do
with the source dist?

Thanks in advance,


Tim Williams

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


Re: reusing parts of a string in RE matches?

2006-05-10 Thread John Salerno
John Salerno wrote:
> [EMAIL PROTECTED] wrote:
> 
> string = 'abababababababab'
> pat = 'aba'
> [pat for s in re.compile('(?='+pat+')').findall(string)]
>> ['aba', 'aba', 'aba', 'aba', 'aba', 'aba', 'aba']
> 
> Wow, I have no idea how to read that RE. First off, what does it match? 
> Should something come before the parentheses, and that will be what 
> matches? Also, what are the '+'s doing? Are they literal +s or still 
> being used as RE syntax?

Nevermind, I get it! The point is that you *aren'* matching anything 
(except the empty string), and this only to see how many times it 
occurs, then you are replacing those occurrences with the pattern 
string. So this is basically like a counter?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: reusing parts of a string in RE matches?

2006-05-10 Thread John Salerno
[EMAIL PROTECTED] wrote:

 string = 'abababababababab'
 pat = 'aba'
 [pat for s in re.compile('(?='+pat+')').findall(string)]
> ['aba', 'aba', 'aba', 'aba', 'aba', 'aba', 'aba']

Wow, I have no idea how to read that RE. First off, what does it match? 
Should something come before the parentheses, and that will be what 
matches? Also, what are the '+'s doing? Are they literal +s or still 
being used as RE syntax?
-- 
http://mail.python.org/mailman/listinfo/python-list


[ANN] tdir 1.69 Released And Available

2006-05-10 Thread Tim Daneliuk
'tdir' Version 1.69 is released and available at:

   http://www.tundraware.com/Software/tdir/

A FreeBSD port update has also been submitted.


What's New
--

This version introduces the -D option which supresses "dotfile/dir" display.


What Is 'tdir'?
---

'tdir' is a reimplementation and enhancement of the old 'xdir' CP/M
utility from Ancient Times.

'tdir' is an advanced directory display utility written in Pure Python,
and runs on both *nix and Win32 systems.\

With 'tdir' you can display directories sorted by file "extension",
display directory trees, and separate directories from files in the
output listing.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: reusing parts of a string in RE matches?

2006-05-10 Thread BartlebyScrivener
>> otherwise i might as well just use string
>> methods

I think you're supposed to use string methods if you can, to avoid the
old adage about having two problems instead of one when using regex.

rd

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


Re: data entry tool

2006-05-10 Thread Peter
Serge Orlov wrote:
> Peter wrote:
>> A webapp isn't feasible as most of the users are on dial up (this is in
>> New Zealand and broadband isn't available for lots of people).
> 
> I don't see connection here, why it's not feasible?

Our volunteers won't sit on their dial up connection for hours at a time. 
Many dial up plans charge an hourly rate after the first so many hours per
month, plus it means you can't use your phone line to receive or make phone
calls.
 
> You can do it using for example Tkinter
>  that comes with python
> distribution for windows.

thanks - I'll take a look.

> Keep in mind that standalone application for windows will be about 2Mb.

Wow - why so big for such a simple tool?
2MB sounds like a LOT of coding.


Peter



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


Re: reusing parts of a string in RE matches?

2006-05-10 Thread mpeters42
>From the Python 2.4 docs:

  findall( pattern, string[, flags])
  Return a list of all ***non-overlapping*** matches of pattern in
string

By design, the regex functions return non-overlapping patterns.

Without doing some kind of looping, I think you are out of luck.

If you pattern is fixed, then a solution might be:
>>>string = 'abababababababab'
>>>pat = 'aba'
>>>[pat for s in re.compile('(?='+pat+')').findall(string)]
['aba', 'aba', 'aba', 'aba', 'aba', 'aba', 'aba']

If the pattern is not fixed (i.e. 'a.a') then this method can still get
a count of overlapping matches, but cannot get the individual match
strings themselves.

A simple loop should do in this case, though:

>>> for i in range(len(string)):
... r= re.match(pat,string[i:])
... if r: print r.group()
...
aba
aba
aba
aba
aba
aba
aba

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


Re: syntax for -c cmd

2006-05-10 Thread Simon Brunning
On 5/10/06, Fredrik Lundh <[EMAIL PROTECTED]> wrote:
> James wrote:
>
> > Wrong syntax is shown below. What should be the delimiter before else?
> >
> > python -c 'if 1==1: print "yes"; else print "no"'
>
> there is no such delimiter.  Python's syntax doesn't allow you to put multiple
> clauses on a single line.  if your shell supports it, use a "here document", 
> or
> embedded newlines.  if not, use a script.

Or there's always this; cool in a "The Dark Side is strong" kind of a way:



--
Cheers,
Simon B,
[EMAIL PROTECTED],
http://www.brunningonline.net/simon/blog/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Masked arrays

2006-05-10 Thread Robert Kern
Tommy Grav wrote:
> I am trying to get the flux of a star in an image. I have been using numpy 
> and pyfits and have the code.

You will probably want to ask on numpy-discussion, instead.

  http://www.scipy.org/Mailing_Lists

> def distance(im,xc,yc):
> (rows,cols) = im.shape
> dist = zeros([rows,cols]).astype(Float64)
> for row in range(rows):
> for col in range(cols):
> dist[row,col] = sqrt(((row + 0.5) - yc)**2 + ((col + 0.5) -
> xc)**2)
> return dist

You will probably want to use numpy.fromfunction() instead.

> def apphot(im,x,y,r):
> dist = distance(im,x,y)
> appmask = where(dist <= r,1,0)

You don't have to use where() here. (dist <= r) returns an array of bools, which
are already 1 and 0 (for most purposes).

> fluxim = where(appmask,im,0)
> appflux = sum(sum(fluxim))
> skymask = where(dist > r, 1,0)
> skyim = where(skymask,im,0)
> sky = mean(skyim)
> print skyim
> print sky
>
> return 1
> 
> Output:
>> array (20,20) , type = f, has 400 elements
>> [ 45.89742126, 45.92555847, 45.8874054 , 45.88538208, 45.88244934,
> 45.9353241 ,
>36.75245361, 29.85816345, 27.53547668, 22.93712311, 22.93178101,
>22.93699799, 22.91038208, 27.4988739 , 29.84021606, 36.71789551,
>45.86646729, 45.86741638, 45.85328979, 45.823349  ,]
> 
> where im is a ndarray, x and y are the position of the star and r is 
> the radius of the aperture. I calculate the flux inside the aperture,
> but when I want to calculate the mean of the pixels outside the 
> aperture I run into problems as the pixels values inside the aperture
> is 0 and is still considered in the mean calculation. Is there a way to 
> do this without using masked arrays?

Sure! But ...

> How would I use a masked array
> to do it?

... masked arrays already do the appropriate tasks for you.

In [1]: from numpy import ma

In [2]: ma.average?
Type:   function
Base Class: 
String Form:
Namespace:  Interactive
File:
/Library/Frameworks/Python.framework/Versions/2.4/lib/python2.4/site-packages/numpy-0.9.7.2476-py2.4-macosx-10.4-ppc.egg/numpy/core/ma.py
Definition: ma.average(a, axis=0, weights=None, returned=0)
Docstring:
average(a, axis=0, weights=None)
Computes average along indicated axis.
If axis is None, average over the entire array
Inputs can be integer or floating types; result is of type float.

If weights are given, result is sum(a*weights)/(sum(weights)*1.0)
weights must have a's shape or be the 1-d with length the size
of a in the given axis.

If returned, return a tuple: the result and the sum of the weights
or count of values. Results will have the same shape.

masked values in the weights will be set to 0.0

-- 
Robert Kern

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

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


Re: reusing parts of a string in RE matches?

2006-05-10 Thread John Salerno
BartlebyScrivener wrote:
> I have to at least try :)
> 
> s = "abababababababab"
> 
> for x in range(len(s)):
> ...   try:
> ...   s.index("aba", x, x + 3)
> ...   except ValueError:
> ...   pass
> 
> rd
> 

yeah, looks like index() or find() can be used to do it instead of RE, 
but still, i'd like to know if there's a way you can write an RE 
expression to do it (and just an RE expression, without all the other 
for loops and extra nonsense...otherwise i might as well just use string 
methods)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: multiline strings and proper indentation/alignment

2006-05-10 Thread Dave Hansen
On Wed, 10 May 2006 15:50:38 GMT in comp.lang.python, John Salerno
<[EMAIL PROTECTED]> wrote:

>Dave Hansen wrote:
>
> print textwrap.dedent(s).strip().replace('\n',' ')
>> this is a multiline triple-quted string with indentation for nicer
>> code formatting
>
>But I have some newlines that are already embedded in the string, and I 
>wouldn't want those replaced.

>>> s = """
I want the following line-
concatenated, but leave this
line break alone.
"""
>>> print textwrap.dedent(s).strip().replace('-\n',' ')
I want the following line concatenated, but leave this
line break alone.
>>> 

But I'd still recommend using parens and string concatentation.

>>> s2 = (
"I want the following line "
"concatentated, but leave this\n"
"line break alone."
)
>>> print s2
I want the following line concatentated, but leave this
line break alone.

Regards,
-=Dave

-- 
Change is inevitable, progress is not.
-- 
http://mail.python.org/mailman/listinfo/python-list


PyThreadState_SetAsyncExc, PyErr_Clear and boost::python

2006-05-10 Thread gabriel . becedillas
I use PyThreadState_SetAsyncExc to stop a python thread but there are
situations when the thread doesn't stop and continues executing
normally. After some debugging, I realized that the problem is that
PyThreadState_SetAsyncExc was called when the thread was inside a
native extension, that for some reason calls PyErr_Clear. That code
happens to be inside boost::python.
I do need to stop the thread from executing Python code as soon as
possible (as soon as it returns from a native function is also
acceptable).
Because we have embedded Python's VM in our product, I'm thinking of
modifying PyErr_Clear() to return immediately if the thread was stopped
(we determine if the thread should stop using our own functions).
Example:

void PyErr_Clear(void)
{
if (!stop_executing_this_thread())
PyErr_Restore(NULL, NULL, NULL);
}

Does anybody see any problem with this approach ?, Does anybody have a
cleaner/better solution ?
Thanks.

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


Re: syntax for -c cmd

2006-05-10 Thread Fredrik Lundh
James wrote:

> Wrong syntax is shown below. What should be the delimiter before else?
>
> python -c 'if 1==1: print "yes"; else print "no"'

there is no such delimiter.  Python's syntax doesn't allow you to put multiple
clauses on a single line.  if your shell supports it, use a "here document", or
embedded newlines.  if not, use a script.





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


Re: Python's DSLs (was: A critic of Guido's blog on Python's lambda)

2006-05-10 Thread aaronwmail-usenet
Cameron Laird wrote:
> In article <[EMAIL PROTECTED]>,
> Alex Martelli <[EMAIL PROTECTED]> wrote:
... .
> >Of course, the choice of Python does mean that, when we really truly
> >need a "domain specific little language", we have to implement it as a
> >language in its own right, rather than piggybacking it on top of a
> >general-purpose language as Lisp would no doubt afford; see
> > for such a DSLL developed
> >at Google. However, I think this tradeoff is worthwhile, and, in
> >particular, does not impede scaling
>
> I'm confused, Alex:  I sure
> think *I* have been writing DSLs as specializations of Python,
> and NOT as "a language in its own right"

I think Alex is suggesting that if they used, for example, a version of
scheme
with a good optimizing compiler they could implement sawzall like
convenience
with almost the same performance, including startup, etc. whereas even
a
highly optimized python based approach would at least have a
comparatively
large startup penalty.  For an environment like Google where they
scrape
thru their logs of various sorts doing lots of trivial scans you can
probably save
a lot of money and time on lots of machines by optimizing such scrapes
(but keep your bactine handy).  And as the sawzall paper pointed out,
even static
type checks can prevent a lot of wasted machine bandwidth by avoiding
dumb
errors.

But the real question for someone like Rob Pike is why use scheme when
you
can invent another little language instead, I suspect :).

  -- Aaron Watters

===

Stop procrastinating soon.

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


Re: python sqlite3 api question

2006-05-10 Thread Fredrik Lundh
[EMAIL PROTECTED] wrote:

> is it possible to pass args through the api which are the same as the
> args you can use on the sqlite3 command line?
> What I'm talking about is the .mode or .output commands which you can
> enter via the sqlite3 cli so I can dynamically change were the output
> goes.

sqlite/sqlite3 is an application built on top of the sqlite database engine,
while Python's pysqlite/sqlite3 library is a binding to the same database
engine.

the database never prints anything to anywhere, and neither does Python's
binding.  if you want to print things, you have to print them yourself.





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


syntax for -c cmd

2006-05-10 Thread James
Wrong syntax is shown below. What should be the delimiter before else?

python -c 'if 1==1: print "yes"; else print "no"'

James

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


Masked arrays

2006-05-10 Thread Tommy Grav
I am trying to get the flux of a star in an image. I have been using numpy and pyfits and have the code.def distance(im,xc,yc):    (rows,cols) = im.shape    dist = zeros([rows,cols]).astype(Float64)    for row in range(rows):        for col in range(cols):            dist[row,col] = sqrt(((row + 0.5) - yc)**2 + ((col + 0.5) - xc)**2)    return distdef apphot(im,x,y,r):    dist = distance(im,x,y)    appmask = where(dist <= r,1,0)    fluxim = where(appmask,im,0)    appflux = sum(sum(fluxim))     skymask = where(dist > r, 1,0)    skyim = where(skymask,im,0)     sky = mean(skyim)    print skyim    print sky        return 1Output:> array (20,20) , type = f, has 400 elements> [ 45.89742126, 45.92555847, 45.8874054 , 45.88538208, 45.88244934, 45.9353241 ,       36.75245361, 29.85816345, 27.53547668, 22.93712311, 22.93178101,       22.93699799, 22.91038208, 27.4988739 , 29.84021606, 36.71789551,       45.86646729, 45.86741638, 45.85328979, 45.823349  ,]where im is a ndarray, x and y are the position of the star and r is the radius of the aperture. I calculate the flux inside the aperture,but when I want to calculate the mean of the pixels outside the aperture I run into problems as the pixels values inside the apertureis 0 and is still considered in the mean calculation. Is there a way to do this without using masked arrays? How would I use a masked arrayto do it? CheersTommy[EMAIL PROTECTED]http://homepage.mac.com/tgrav/"Any intelligent fool can make things bigger, more complex, and more violent. It takes a touch of genius -- and a lot of courage -- to move in the opposite direction"                         -- Albert Einstein -- 
http://mail.python.org/mailman/listinfo/python-list

Re: unittest: How to fail if environment does not allow execution?

2006-05-10 Thread Roy Smith
Kai Grossjohann  <[EMAIL PROTECTED]> wrote:
> I wrote a test case that depends on a certain file existing in the
> environment.

In theory, unit tests should not depend on any external factors, but
we all know the difference between theory and practice, right?

> So, I guess I should test that the file exists in the
> setUp method.  But what if it doesn't exist?  How do I fail in that case?

def setUp (self):
try:
open ("myEssentialTestFile")
except IOError:
self.fail ("Hey, dummy, myEssentialTestFile is missing!")
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: A critic of Guido's blog on Python's lambda

2006-05-10 Thread Robert Uhl
Ken Tilton <[EMAIL PROTECTED]> writes:
>
> Set Kelvin, and make Celsius and Fahrneheit functions of that.

Or Rankine:-)

-- 
Robert Uhl 
Brought to you by 'Ouchies', the sharp, prickly toy you bathe with...
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: help with Linker dependencies missing went compiling mysql-python on Windows without VisualStudio

2006-05-10 Thread Jorge Vargas
noone here has try this??On 5/8/06, Jorge Vargas <[EMAIL PROTECTED]> wrote:
Hi everyone I'm stuck at doing this and can't find the problem, maybe someone with more experience then I compiling python can help me out. I google around and found some old articles, from them the one that seems more accurate is 
http://www.vrplumber.com/programming/mstoolkit/of couse I had to difer from that a little so this is what I have install
Microsoft Windows Platform SDK Collection for Windows Server 2003 SP1
Microsoft Visual Studio 2005 Version 8.0.50727.42  (RTM.050727-4200) thats Microsoft Visual C++ 2005I have try with either one installMicrosoft .NET framework SDK 1.1Microsoft .NET Framework Version 
2.0.50727

On the other part I havePython 2.4.2mysql-4.1.18-win32.zipmysqlpython 1.2.0, 1.2.1 and 1.2.1_p2-Changes to the sources

I apply the patch posted on the website, for disutils http://www.vrplumber.com/programming/mstoolkit/msvccompiler.patch
I commented out the code related to version in _mysql.c ( wont give the line numbers cause they differ from file to file.
/*if (PyDict_SetItemString(dict, "version_info",

               PyRun_String(version_info, Py_eval_input,
                   dict, dict)))
        goto error;
    if (PyDict_SetItemString(dict, "__version__",
               PyString_FromString(__version_
_)))
        goto error;*/
  

I copy over the file my_config.h from the mysql sources (because it's NOT distributed with the installer)and finally I edit site.cfg to this, the rest of the file is not changed.[compiler]

mysqlroot: C:\mysqllibrary_dirs: %(mysqlroot)s\lib\optinclude_dirs: %(mysqlroot)s\includelibraries: mysqlclient zlib libcmt wsock32 advapi32# libcmt msvcrt #extra_compile_args:#extra_objects:

I started the "Visual Studio 2005 Command Prompt" and setup.py build So far I belive I have compile a working copy of the code but i'm stuck at the linkerRight now my problem is with the linker the values in 
site.cfg seems to be wrong.libraries: mysqlclient zlib msvcrt libcmt wsock32 advapi32libs msvcrt libcmt seems to conflict with eachother and with MSVCR80.dll


I have try using msvcrt and have /NODEFAULTLIB:libcrtC:\MySQL-python-1.2.1_p2.tar\MySQL-python-1.2.1_p2>"C:\Program Files\Microsoft Visual Studio 8\VC\BIN\link.exe" /DLL /nologo /INCREMENTAL:NO /LIBPATH:C:\mysql\lib\opt /LIBPATH:c:\python24\libs /LIBPATH:c:\python24\PCBuild 
mysqlclient.lib zlib.lib msvcrt.lib wsock32.lib advapi32.lib /EXPORT:init_mysql build\temp.win32-2.4\Release\_mysql.obj /OUT:build\lib.win32-2.4\_mysql.pyd /IMPLIB:build\temp.win32-2.4\Release\_mysql.lib /NODEFAULTLIB:libcrt
LIBCMT.lib(crtheap.obj) : error LNK2005: __malloc_crt already defined in msvcrt.lib(MSVCR80.dll)


LIBCMT.lib(crt0dat.obj) : error LNK2005: __amsg_exit already defined in msvcrt.lib(MSVCR80.dll)LIBCMT.lib(crt0dat.obj) : error LNK2005: __initterm_e already defined in 
msvcrt.lib(MSVCR80.dll)LIBCMT.lib(crt0dat.obj) : error LNK2005: _exit already defined in msvcrt.lib(MSVCR80.dll)


LIBCMT.lib(fflush.obj) : error LNK2005: _fflush already defined in msvcrt.lib(MSVCR80.dll)LIBCMT.lib(dosmap.obj) : error LNK2005: __errno already defined in 
msvcrt.lib(MSVCR80.dll)LIBCMT.lib(calloc.obj) : error LNK2005: _calloc already defined in msvcrt.lib(MSVCR80.dll)


LIBCMT.lib(realloc.obj) : error LNK2005: _realloc already defined in msvcrt.lib(MSVCR80.dll)LIBCMT.lib(crt0init.obj


) : error LNK2005: ___xi_a already defined in msvcrt.lib(cinitexe.obj)LIBCMT.lib(crt0init.obj) : error LNK2005: ___xi_z already defined in msvcrt.lib


(cinitexe.obj)LIBCMT.lib(crt0init.obj) : error LNK2005: ___xc_a already defined in msvcrt.libcinitexe.obj)


LIBCMT.lib(crt0init.obj) : error LNK2005: ___xc_z already defined in msvcrt.lib(cinitexe.obj)LIBCMT.lib(winxfltr.obj) : error LNK2005: ___CppXcptFilter already defined in 
msvcrt.lib(MSVCR80.dll)LIBCMT.lib(winsig.obj) : error LNK2005: _signal already defined in msvcrt.lib(MSVCR80.dll)


LIBCMT.lib(tidtable.obj) : error LNK2005: __encode_pointer already defined in msvcrt.lib(MSVCR80.dll)LIBCMT.lib(tidtable.obj


) : error LNK2005: __encoded_null already defined in msvcrt.lib(MSVCR80.dll)LIBCMT.lib(tidtable.obj) : error LNK2005: __decode_pointer already defined in 
msvcrt.lib(MSVCR80.dll)LIBCMT.lib(mlock.obj) : error LNK2005: __unlock already defined in msvcrt.lib(MSVCR80.dll)


LIBCMT.lib(mlock.obj) : error LNK2005: __lock already defined in msvcrt.lib(MSVCR80.dll)LIBCMT.lib(setlocal.obj) : error LNK2005: _setlocale already defined in 
msvcrt.lib(MSVCR80.dll)LIBCMT.lib(tzset.obj) : error LNK2005: __tzset already defined in msvcrt.lib(MSVCR80.dll)


LIBCMT.lib(_ctype.obj) : error LNK2005: _isspace already defined in msvcrt.lib(MSVCR80.dll)LIBCMT.lib(_ctype.obj) : error LNK2005: _iscntrl already defined in 
msvcrt.lib(MSVCR80.dll)LIBCMT.lib(atox.obj) : error LNK2005: _atoi already defined in msvcrt.lib(MSVCR80.dll)


LIBCMT.lib(getenv.obj) : error LNK2005: _getenv already d

Re: Multi-line lambda proposal.

2006-05-10 Thread Kaz Kylheku
Antoon Pardon wrote:
> Could you give me an example. Suppose I have the following:
>
> def arg_range(inf, sup):
>
>   def check(f):
>
> def call(arg):
>   if inf <= arg <= sup:
> return f(arg)
>   else:
> raise ValueError
>
> return call
>
>   return check

def arg_range(inf, sup)
  return lambda(f):
return lambda(arg):
  if inf <= arg <= sup:
return f(arg)
  else
raise ValueError

Nice; now I can see what this does: returns a function that, for a
given function f, returns a function which passes its argument arg to f
if the argument is in the [inf, sup] range, but otherwise raises a
ValueError. The English description pops out from the nested lambda.

The names in the inner-function version only serve to confuse. The
function check doesn't check anything; it takes a function f and
returns a validating function wrapped around f.

In fact, an excellent name for the outer-most inner function is that of
the outer function itself:

def range_checked_function_maker(inf, sup):

  def range_checked_function_maker(f):

def checked_call_of_f(arg):
  if inf <= arg <= sup:
return f(arg)
  else:
raise ValueError

return checked_call_of_f

  return range_checked_function_maker

This alone makes a good case for using an anonymous function: when you
have a function which does nothing but return an object, and that
function has some noun as its name, it's clear that the name applies to
the returned value.

This:

  def forty_two():
return 42

is not in any way made clearer by:

  def forty_two():
forty_two = 42
return forty_two

:)

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


Re: reusing parts of a string in RE matches?

2006-05-10 Thread BartlebyScrivener
I have to at least try :)

s = "abababababababab"

for x in range(len(s)):
... try:
... s.index("aba", x, x + 3)
... except ValueError:
... pass

rd

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


Re: interactive shell -- reload definitions?

2006-05-10 Thread Jack Diederich
On Wed, May 10, 2006 at 10:00:38AM -0700, malv wrote:
> This is a question that comes up almost continuously for at least six
> years now.
> For Python users having to deal with major real-life applications, this
> may make them think twice about the future suitability of Python as a
> competitive development tool.
> Ruby is featuring a software modify and go feature. Lisp is, even VB
> does. In the design of Smalltalk this used to be one of the major
> considerations.
> 
> Plenty of posts will turn up doing a search on "reload". The following
> references summarize some of these problems:
> http://groups.google.com/group/comp.lang.python/browse_frm/thread/efba62d227ba4794/41f57f366affd057?q=Hung+Jung+Lu+reload&rnum=2#41f57f366affd057
> http://groups.google.com/group/comp.lang.python/browse_frm/thread/efba62d227ba4794/41f57f366affd057?q=Hung+Jung+Lu+reload&rnum=2#41f57f366affd057
> 
> In fact, doing a reload usually will not accomplish what one is looking
> for. Class instances should also be upgraded on reload(), preferably
> automatically. This can be accomplished as shown by Michael Hudson in:
> http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/160164
> Variants on this theme exist which seem to be broken.

reload() cannot always do exactly what you want it to do because what
you want it to do isn't always the same.  Upgrading instances to the
new definition of the class may be handy sometimes but what is the
'right' thing to do here?

# test.py version 1
class A:
  def __init__(self, val):
self.hello_wolrd = val
  def __str__(self):
return self.hello_world

# test.py version 2
class A:
  def __init__(self, val):
self.himom = val
  def __str__(self):
return self.himom

reload() can never know that 'hello_world' was renamed to 'himom'
so if you upgrade the class of existing instances str(ob) will explode.
reload() is only handy for interactive use.  If you try to use it in any
non-trivial production program you will get burned.  It can never be
made magic enough.

> Given the persistent push of Ruby, I would strongly recommend that a
> workable integrated solution will be found for Reload & Go in Python,
> taking priority on many way out features of rather low practicality for
> many  programmers.

Link?  Google finds lots of unrelated stuff because reload is a common
word.  

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


Re: Is Welfare Part of Capitalism?

2006-05-10 Thread Dr. Who
Technically, I would call it a manfesto.  The manifesto module is
probably the most facinating module in Python since it's the only one
whose functions consist entirely of doc strings followed by a pass and
do no useful work.

Jeff

Tim Daneliuk wrote:
> [EMAIL PROTECTED] wrote:
> > This article is dedicated to:
> >
> 
> 
> 
> But I am still confused:  Is this a statement or an expression?

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


python sqlite3 api question

2006-05-10 Thread [EMAIL PROTECTED]
Hi,
is it possible to pass args through the api which are the same as the
args you can use on the sqlite3 command line?
What I'm talking about is the .mode or .output commands which you can
enter via the sqlite3 cli so I can dynamically change were the output
goes.
Ta

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


Re: Python's regular expression?

2006-05-10 Thread Dave Hughes
Dave Hansen wrote:

> On Wed, 10 May 2006 06:44:27 GMT in comp.lang.python, Edward Elliott
> <[EMAIL PROTECTED]> wrote:
> 
> 
> > 
> > Would I recommend perl for readable, maintainable code?  No, not
> > when better options like Python are available.  But it can be done
> > with some effort.
> 
> I'm reminded of a comment made a few years ago by John Levine,
> moderator of comp.compilers.  He said something like "It's clearly
> possible to write good code in C++.  It's just that no one does."

Reminds me of the quote that used to appear on the front page of the
ViewCVS project (seems to have gone now that they've moved and renamed
themselves to ViewVC). Can't recall the attribution off the top of my
head:

"[Perl] combines the power of C with the readability of PostScript"

Scathing ... but very funny :-)


Dave.

-- 

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


unittest: How to fail if environment does not allow execution?

2006-05-10 Thread Kai Grossjohann
I wrote a test case that depends on a certain file existing in the
environment.  So, I guess I should test that the file exists in the
setUp method.  But what if it doesn't exist?  How do I fail in that case?

I would like to emit an error message explaining what is wrong.

tia,
Kai
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: A critic of Guido's blog on Python's lambda

2006-05-10 Thread jayessay
"Michele Simionato" <[EMAIL PROTECTED]> writes:

> jayessay wrote:
> > "Michele Simionato" <[EMAIL PROTECTED]> writes:
> >
> > > Ken Tilton wrote:
> > > > I was not thinking about the thread issue (of which I know little). The
> > > > big deal for Cells is the dynamic bit:
> > > >
> > > > (let ((*dependent* me))
> > > >  (funcall (rule me) me))
> > > >
> > > > Then if a rule forces another cell to recalculate itself, *dependent*
> > > > gets rebound and (the fun part) reverts back to the original dependent
> > > > as soon as the scope of the let is exited.
> > >
> > > Python 2.5 has a "with" statement (yes, the name is Lispish on purpose)
> > > that could be used to implement this. See
> > > http://www.python.org/dev/peps/pep-0343
> >
> > You are mistaken.  In particular, VAR doesn't have dynamic scope.
> >
> 
> I said "it could be used to implement this", and since in a previous
> post on mine in this
> same thread I have shown how to implement thread local variables in
> Python I figured
> out people would be able to do the exercise for themselves.

I was saying that you are mistaken in that pep-0343 could be used to
implement dynamically scoped variables.  That stands.


/Jon

-- 
'j' - a n t h o n y at romeo/charley/november com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Can Python installation be as clean as PHP?

2006-05-10 Thread Edward Elliott
XBello wrote:
> It's possible to work with php just with these single file? Maybe I'm
> doing the wrong thing, because to start to program I needed to install
> a web server too (a large bunch of files). 

PHP can be run from the command line too.  On ubuntu/debian it's available
by installing the php4-cli package.  Not sure about other systems, I didn't
see any any obvious links on the php website.

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


Re: A critic of Guido's blog on Python's lambda

2006-05-10 Thread Joe Marshall

Alex Martelli wrote:
> Joe Marshall <[EMAIL PROTECTED]> wrote:
>...
> > The problem is that a `name' is a mapping from a symbolic identifier to
> > an object and that this mapping must either be global (with the
> > attendant name collision issues) or within a context (with the
> > attendant question of `in which context').
>
> Why is that a problem?  Even for so-called "global" names, Python
> supports a structured, hierarchical namespace, so there can never be any
> collision betwen the "globals" of distinct modules (including modules
> which happen to have the same name but live in distinct packages or
> subpackages) -- I did mention that names could usefully be displayed in
> some strcutured form such as apackage.somemodule.thefunction but perhaps
> I was too tangential about it;-).

Can you refer to inner functions from the global context?  Suppose I
have this Python code:

def make_adder(x):
def adder_func(y):
sum = x + y
return sum
return adder_func

Can I refer to the inner adder_func in any meaningful way?


>
>
> > Matthias Felleisen once suggested that *every* internal function should
> > be named.  I just said `continuations'.  He immediately amended his
> > statement with `except those'.
>
> If I used continuations (I assume you mean in the call/cc sense rather
> than some in which I'm not familiar?) I might feel the same way, or not,
> but I don't (alas), so I can't really argue the point either way for
> lack of real-world experience.

I meant continuations as in the receiver function in
continuation-passing-style.  If you have a function that has to act
differently in response to certain conditions, and you want to
parameterize the behavior, then one possibility is to pass one or more
thunks to the function in addition to the normal arguments.  The
function acts by selecting and invoking one of the thunks.  A classic
example is table lookup.  It is often the case you wish to proceed
differently depending upon whether a key exists in a table or not.
There are several ways to provide this functionality.  One is to have a
separate `key-exists?' predicate.  Another is to have a special return
value for `key not found'.  Another is to throw an exception when a key
is not found.  There are obvious advantages and drawbacks to all of
these methods.  By using continuation-passing-style, we can
parameterize how the table lookup proceeds once it determines whether
or not the key is found.  We have the lookup procedure take two thunks
in addition to the key.  If the key is found, the first thunk is
invoked on the associated value.  If the key is not found, the second
thunk is invoked.  We can subsume all the previous behaviors:

(define (key-exists? key table)
  (lookup key table
 (lambda (value) #t) ;; if found, ignore value, return true
 (lambda () #f)))  ;; if not found, return false.

(define (option1 key table)
  (lookup key table
(lambda (value) value)
(lambda () 'key-not-found)))

(define (option2 key table)
  (lookup key table
(lambda (value) value)
(lambda () (raise 'key-not-found-exception

(define (option3 key table default-value)
  (lookup key table
(lambda (value) value)
(lambda () default-value)))

The unnamed functions act in this regard much like a `local label'.  We
wrap two chunks of code in a lambda and the lookup function `jumps' to
the appropriate chunk.  (If the compiler knows about thunks, the
generated assembly code really will have local labels and jump
instructions.  It can be quite efficient.)

This may look odd and cumbersome, but with a little practice the
lambdas fade into the background and it becomes easy to read.

My point with Matthias, however, was that defining all these
continuations (the thunks) as named internal functions was not only
cumbersome, but it obscured the control flow.  Notice:

(define (named-option3 key table default-value)
  (define (if-found value)
 value)
  (define (if-not-found)
 default-value)
  (lookup key table if-found if-not-found))

When we enter the function, we skip down to the bottom (past the
internal definitions) to run lookup, which transfers control to a
function defined earlier in the code.

There are many reasons to avoid this style in Python, so this probably
won't win you over, but my point is that there are times where
anonymous functions have an advantage over the named alternative and
that disallowing anonymous functions can be as cumbersome as
disallowing anonymous integers.

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


Re: interactive shell -- reload definitions?

2006-05-10 Thread malv
This is a question that comes up almost continuously for at least six
years now.
For Python users having to deal with major real-life applications, this
may make them think twice about the future suitability of Python as a
competitive development tool.
Ruby is featuring a software modify and go feature. Lisp is, even VB
does. In the design of Smalltalk this used to be one of the major
considerations.

Plenty of posts will turn up doing a search on "reload". The following
references summarize some of these problems:
http://groups.google.com/group/comp.lang.python/browse_frm/thread/efba62d227ba4794/41f57f366affd057?q=Hung+Jung+Lu+reload&rnum=2#41f57f366affd057
http://groups.google.com/group/comp.lang.python/browse_frm/thread/efba62d227ba4794/41f57f366affd057?q=Hung+Jung+Lu+reload&rnum=2#41f57f366affd057

In fact, doing a reload usually will not accomplish what one is looking
for. Class instances should also be upgraded on reload(), preferably
automatically. This can be accomplished as shown by Michael Hudson in:
http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/160164
Variants on this theme exist which seem to be broken.

Given the persistent push of Ruby, I would strongly recommend that a
workable integrated solution will be found for Reload & Go in Python,
taking priority on many way out features of rather low practicality for
many  programmers.

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


Re: A critic of Guido's blog on Python's lambda

2006-05-10 Thread Boris Borcic
Ken Tilton wrote:
> 
> 
> Boris Borcic wrote:
>> Ken Tilton wrote:
>>
>>> "Now if you are like most people, you think that means X. It does not."
>>
>>
>> As far as natural language and understanding are concerned, "to mean" 
>> means conformity to what most people understand, Humpty Dumpties 
>> notwithstanding.
> 
> Nonsense.

:)

> You are confusing that quality of natural language with most 
> people's quality of being sloppy readers,  or in your case, a sloppy
> thinker.  Misapplying an analogy is not a question of usage -- when I
> said spreadsheet and they thought of spreadsheets, so far so good, 
> right?

No, as Adam Jones pointed out. Like Bush speaking of "crUSAde" after 9/11.

> -- it just sloppiness and laziness.
> 
> I do it, too, all the time. :)

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


  1   2   3   >