Re: Doc suggestions (was: Why "class exceptions" are not deprecated?)

2006-03-31 Thread Fredrik Lundh
[EMAIL PROTECTED] wrote:

> > (and probably for no thanks),
>
> Do you think you know me well enough from a
> handful of usenet postings to conclude that?

yes.  anyone who's been involved with open source project long
enough has seen enough people like you to know you.  you're not
unique, in any way.





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


Re: DO NOT USE JAVA BECAUSE IT IS NOT OPEN SOURCE

2006-03-31 Thread Furious George

Luc The Perverse wrote:
> <[EMAIL PROTECTED]> wrote in message
> news:[EMAIL PROTECTED]
> > Programing Languiges Are Ment to be free. That is why i am starting The
> > Coo De Tar thats french for Blow of state it is a flash/java
> > alternative and if you are going to use a server side languige use
> > Perl,Python or better yet Ruby. What is the point of a languige without
> > a standerd and without a open source distrabution. Coo De Tar will be
> > released as a api for perl,python and ruby. Java sucks because it IS
> > NOT FREE. I AM A GNU GUY I BELEVE THAT SOFTWARE MUST AND SHALL BE
> > FREE!! do not use java because it is an oxymoron
> >
>
> Dear Mr Troll,
>
> There are GNU implementations of JVM and compiler.

Dumbass!  If you knew anything you would know that GNU stands for "GNU
is Not Upen source."  That is why the Coo De Tar project is vital.  It
uses a "WINDOWS Is Nifty, Dependable, Open, and WINDOWS Source"
(WINDOWS) license which is uber-open source.

>
> And just because Sun's Java is not GNU does not mean it is not free.

Sun's JAVA is uber-proprietary.

> 
> Now go get a life.

Check your calendar!

> 
> --
> LTP
> 
> :)

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


Re: a question on re

2006-03-31 Thread Marco Wahl
Hi,

> i tried to search 2 patterns
>
> pat1 = re.compile("blah")
> pat2 = re.compile("blah2")
>
>
> if i do
> if re.findall(pat1,something) and re.findall(pat2,something):
>do something
>
> if does not work
>
> but when i do a nest if,
>
> if re.findall(pat1,something) :
>if re.findall(pat2,something):
>do something
>
> it works..
>
> please advise on why the first code doesnt work.

it's not perfectly clear to me what you mean with 'doesnt work'.

The two if parts

> if re.findall(pat1,something) and re.findall(pat2,something):
>do something

and

> if re.findall(pat1,something) :
>if re.findall(pat2,something):
>do something

look equivalent to me.  Could you please reveal your
value for text-string 'something'?  Further I suggest
to replace the 'do something'-parts with 'print 42'.


Best wishes  Marco

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


Python 2.5 licensing: stop this change

2006-03-31 Thread Steve Holden
As the only director of the Python Software Foundation to vote against a 
recent Board motion to implement the change in licensing terms described in

   http://pyfound.blogspot.com/2006/04/python-25-licensing-change.html

I would like to place on record my protest against this change. I think 
it will harm the Python language and ultimately be counter-productive, 
reducing the user base and discouraging open source programmers from 
contributing to the code base.

If you disagree with this proposed change it's not too late to do 
something about it. If this change goes ahead it will be the end of 
Python as we know it.

regards
  Steve
-- 
Steve Holden   +44 150 684 7255  +1 800 494 3119
Holden Web LLC/Ltd www.holdenweb.com
Love me, love my blog holdenweb.blogspot.com

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


Python, VB math simple problem

2006-03-31 Thread Mr X






Hi looking for help with what should be a fairly simple Python problem, relating to VB inter-operability.

Got a great response from a fellow named Matt at [EMAIL PROTECTED], pointed me in some good directions - some areas, concerns still foggy on, the below thread is included any feedback on this simple dilemma

would be very appreciated.



Thanks,



D



thread follows below;





 

To: 	[EMAIL PROTECTED]	   

Subject: 	Problem with Python math functions and VB	   

Date: 	3/30/2006 9:39:28 PM	   

 Download Message Display Headers Printer Friendly 			 

Previous | Next 



Wondering if you might either know how to solve the following.



I've a background in Visual Basic, and am using an old version, 4.0, it compiles to a smaller executable which I prefer. I find myself in an odd situation, needing a very simple yet powerful capability of Python for a VB app

Im working on.



Simply, a large 300 digit number is divided by a smaller number ranging from 1 to 3 digits. I.e;



This large 300 digit number is generated as a string from the VB app, and I want to input this somehow

from the VB app directly to Python for simple math operations.



Where; x = 300 digit number, y = divisor ( say '37')





x / 37



I want to divide x by y but I want the remainder of this division to at least 3 or 4 decimal places, so my Python script at the command line;



x %y /y. = z



So now I want to take the resultant, the full number plus its remainder, and I want to round this number up

to the next highest number and divide it by the same constant;



z rounded up to next highest number (never the lowest)



so



z /y = z Long



Remove the 'L' at the end, round up the last digit of z = Z



Then;



Z %y /y. = a



Then I want the last five digits of z (not Z) and a truncated at the end, so the last digit before

the decimal point and the four digits past the decimal point printed to a text file.



I want to be able to open the text file with the VB app and use this data as inputs.

==



Ok, so here is my dilemma, I know VERY litle about Python and a fair bit about VB.



Ideally, I'd love to be able to simply have some extremely small executable that just accepts inputs

does the calculations above and then spits out the outputs. If it were possible to write some

simple lines of math code in Python and then compile these scripts in Python to a Windows

compatible executable,that would be fantastic.



If I could simply have my VB app, 'call' the name of the tiny Python executable, and then the Python executable

just automatically looked for a named text file (created by the VB app) and extracted the 300 digit number from this, then performed the calcs, then spit this data out as a new text file name it created, which I could then use the VB app to open and read from, THAT would be ideal.



However, I don't know if Python can compile scripts to an exe? If it can how could I find out how to do this?



If it doesn't, how could I get VB to directly pass commands to the Python command line and then automatically

extract the outputs? Shelling out from VB to Python would be tough to the command line I think, since the Python command line uses the 'Edit / Mark, Paste' approach to inserting, copy inputs, outputs and this would be virtually untenable, as far as I can tell to automate in a VB shell out routine.



So basically, how the heck can I access Pythons ability to perform simple calculations on very large numbers, easily, from within VB 4.0 ? There must be a way, it seems like such a simple think to do, especially since the actual math operations are so simple, straight forward, and would never change.



Any ideas?







--

Matthew,  thanks for your response. 



<-Original Message-> 

>From: Matthew Dixon Cowles

>Sent: 3/31/2006 9:41:18 AM

>To: [EMAIL PROTECTED]

>Cc: [EMAIL PROTECTED]

>Subject: Re: [Python-Help] Problem with Python math functions and VB



>I'm sure that there's a way to do that, but I'm not familiar with 

>Visual Basic and I don't know what inter-process communication 

>facilities it offers. 



Is there a person or group you might direct me to that has worked with this 

inter-process communication between VB and Python?



>I don't think that Python is going to be able to do that for you out 

>of the box. Hundreds of digits of floating-point precision is a lot. 



Could you explain that a bit more, sorry Im not sure what you mean

by 'out of the box' ?  If I run the Python command line screen in windows

and manually type out a very large number, say 180 digits; where 'X' = very large number;



X %37 /37.



returns what Im after, value wise.  but of course I don't want to do this manually each time

for every dividend.



>You might find that one of the Python modules that let you use an 

>extended-precision library would do what you want. GMPY is one: 



>http://gmpy.sourceforge.net/ 


Python, VB math simple problem

2006-03-31 Thread Mr X






Hi looking for help with what should be a fairly simple Python problem, relating to VB inter-operability.

Got a great response from a fellow named Matt at [EMAIL PROTECTED], pointed me in some good directions - some areas, concerns still foggy on, the below thread is included any feedback on this simple dilemma

would be very appreciated.



Thanks,



D



thread follows below;





 

To: 	[EMAIL PROTECTED]	   

Subject: 	Problem with Python math functions and VB	   

Date: 	3/30/2006 9:39:28 PM	   

 Download Message Display Headers Printer Friendly 			 

Previous | Next 



Wondering if you might either know how to solve the following.



I've a background in Visual Basic, and am using an old version, 4.0, it compiles to a smaller executable which I prefer. I find myself in an odd situation, needing a very simple yet powerful capability of Python for a VB app

Im working on.



Simply, a large 300 digit number is divided by a smaller number ranging from 1 to 3 digits. I.e;



This large 300 digit number is generated as a string from the VB app, and I want to input this somehow

from the VB app directly to Python for simple math operations.



Where; x = 300 digit number, y = divisor ( say '37')





x / 37



I want to divide x by y but I want the remainder of this division to at least 3 or 4 decimal places, so my Python script at the command line;



x %y /y. = z



So now I want to take the resultant, the full number plus its remainder, and I want to round this number up

to the next highest number and divide it by the same constant;



z rounded up to next highest number (never the lowest)



so



z /y = z Long



Remove the 'L' at the end, round up the last digit of z = Z



Then;



Z %y /y. = a



Then I want the last five digits of z (not Z) and a truncated at the end, so the last digit before

the decimal point and the four digits past the decimal point printed to a text file.



I want to be able to open the text file with the VB app and use this data as inputs.

==



Ok, so here is my dilemma, I know VERY litle about Python and a fair bit about VB.



Ideally, I'd love to be able to simply have some extremely small executable that just accepts inputs

does the calculations above and then spits out the outputs. If it were possible to write some

simple lines of math code in Python and then compile these scripts in Python to a Windows

compatible executable,that would be fantastic.



If I could simply have my VB app, 'call' the name of the tiny Python executable, and then the Python executable

just automatically looked for a named text file (created by the VB app) and extracted the 300 digit number from this, then performed the calcs, then spit this data out as a new text file name it created, which I could then use the VB app to open and read from, THAT would be ideal.



However, I don't know if Python can compile scripts to an exe? If it can how could I find out how to do this?



If it doesn't, how could I get VB to directly pass commands to the Python command line and then automatically

extract the outputs? Shelling out from VB to Python would be tough to the command line I think, since the Python command line uses the 'Edit / Mark, Paste' approach to inserting, copy inputs, outputs and this would be virtually untenable, as far as I can tell to automate in a VB shell out routine.



So basically, how the heck can I access Pythons ability to perform simple calculations on very large numbers, easily, from within VB 4.0 ? There must be a way, it seems like such a simple think to do, especially since the actual math operations are so simple, straight forward, and would never change.



Any ideas?







--

Matthew,  thanks for your response. 



<-Original Message-> 

>From: Matthew Dixon Cowles

>Sent: 3/31/2006 9:41:18 AM

>To: [EMAIL PROTECTED]

>Cc: [EMAIL PROTECTED]

>Subject: Re: [Python-Help] Problem with Python math functions and VB



>I'm sure that there's a way to do that, but I'm not familiar with 

>Visual Basic and I don't know what inter-process communication 

>facilities it offers. 



Is there a person or group you might direct me to that has worked with this 

inter-process communication between VB and Python?



>I don't think that Python is going to be able to do that for you out 

>of the box. Hundreds of digits of floating-point precision is a lot. 



Could you explain that a bit more, sorry Im not sure what you mean

by 'out of the box' ?  If I run the Python command line screen in windows

and manually type out a very large number, say 180 digits; where 'X' = very large number;



X %37 /37.



returns what Im after, value wise.  but of course I don't want to do this manually each time

for every dividend.



>You might find that one of the Python modules that let you use an 

>extended-precision library would do what you want. GMPY is one: 



>http://gmpy.sourceforge.net/ 


Re: Pickle or Mysql

2006-03-31 Thread Rene Pijlman
[EMAIL PROTECTED]:
>Can I use Pickle to store about 500,000 key value pairs.. 

Performance would be horrible. Use a BTree in ZODB instead:
http://www.zope.org/Wikis/ZODB/guide/node6.html#SECTION00063

>or should I use mySql.

You should use a relational database, such as PostgreSQL, when you want to
model your data as relations (tables) instead of objects, or when you want
to use SQL, or when another application needs to access the data that only
speaks SQL, or ...

-- 
René Pijlman
-- 
http://mail.python.org/mailman/listinfo/python-list


a question on re

2006-03-31 Thread eight02645999
hi

i tried to search 2 patterns

pat1 = re.compile("blah")
pat2 = re.compile("blah2")


if i do
if re.findall(pat1,something) and re.findall(pat2,something):
   do something

if does not work

but when i do a nest if,

if re.findall(pat1,something) :
   if re.findall(pat2,something):
   do something

it works..

please advise on why the first code doesnt work. 
thanks

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


Should any() and all() take a key= argument?

2006-03-31 Thread Steve R. Hastings
The list.sort() method accepts a "key=" parameter to let you specify a
function that will change the way it sorts.  In Python 2.5, min() and
max() now accept a "key=" parameter that changes how the functions decide
min or max.

Should any() and all() take a key= argument?

Example:

>>> lst = [2, 4, 42]
>>> any(lst, key=lambda x: x == 42)
True
>>> all(lst, key=lambda x: x % 2 == 0)
True

The above could be done with generator expressions:

>>> any(x == 42 for x in lst)
True
>>> all(x % 2 == 0 for x in lst)
True


I kind of like the key= option.  The need isn't as strong as with
.sort(), min(), and max(), but consistency can be a good thing.  I'd
personally like to see key= anywhere it makes sense.
-- 
Steve R. Hastings"Vita est"
[EMAIL PROTECTED]http://www.blarg.net/~steveha

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


Re: any() and all() on empty list?

2006-03-31 Thread Steve R. Hastings
On Fri, 31 Mar 2006 16:29:00 -0800, Paul Rubin wrote:
> I think "S and all(S)" is the right way to express that, if that's
> what's intended.

I still would like a standard function, because "S and all(S)" does not
work with iterators.  I proposed one possible function, truecount(S), that
returns a tuple of how many were true and how many there were total.  Then
you could do

true_count, count = truecount(S)

if count and true_count == count:
  # nonempty list and all are true


And S could be an iterator or generator function expression.

You can easily write your own truecount() but it would be nice to have
something like that as standard.  I don't much like the name "truecount"
though; I'm open to suggestions for a better name.
-- 
Steve R. Hastings"Vita est"
[EMAIL PROTECTED]http://www.blarg.net/~steveha

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


Re: Exception handling....dumb question?

2006-03-31 Thread Ben Finney
"kbperry" <[EMAIL PROTECTED]> writes:

> In Python,
> When using the default except (like following)
>
> try:
> some code that might blow up
>
> except:
> print "some error message"

This will catch *every* exception, and throw it away before it gets to
your "print" statement.

This is almost never a good idea. You should catch *specific*
exceptions that you know you can deal with at that point in the code.

import logging
try:
foo = 12 / 0
except ZeroDivisionError, e:
print "You *knew* this was going to happen: '%s'" % e
logging.error(str(e))

This allows all other exceptions to propogate back through the call
stack.

More information on 'try':

http://docs.python.org/ref/try.html>

-- 
 \  "When we call others dogmatic, what we really object to is |
  `\their holding dogmas that are different from our own."  -- |
_o__)   Charles Issawi |
Ben Finney

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


Re: running IDLE from another program?

2006-03-31 Thread John Salerno
Kent Johnson wrote:
> John Salerno wrote:
>> Kent Johnson wrote:
>>> You probably don't need to do that. Just run the file in python 
>>> directly. I don't know UE, but when you configure an external tool, tell 
>>> it to run python.exe and pass the current file as a command line parameter.
>>>
>> I've tried a lot of combinations for the command line to execute, but 
>> nothing is working. What format should it be in? Should it look like this:
>>
>> C:\Python24\python.exe module   ?
> 
> C:\Python24\python.exe D:\full\path\to\myprogram.py
> 
> There is a post on the UltraEdit forum from JohnJSal, is that not you? 
> Whoever it is got this working...
> http://www.ultraedit.com/index.php?name=Forums&file=viewtopic&t=2732&highlight=python
> 
> Kent

Yes, that's me. :) But all that that post accomplished was getting me to 
run the file itself, as if I had double-clicked on it. This isn't what I 
want. I want it to run in a 'debug' type of environment like IDLE so I 
can see any error messages.

I tried your suggestion and seems to half-way work. But it doesn't open 
the program in a different environment (such as IDLE), it just opens the 
output in a new text window in UE. Here's the output:

['qIQNlQSLi', 'eOEKiVEYj', 'aZADnMCZq', 'bZUTkLYNg', 'uCNDeHSBj', 
'kOIXdKBFh', 'dXJVlGZVm', 'gZAGiLQZx', 'vCJAsACFl', 'qKWGtIDCj']
Traceback (most recent call last):
   File "C:\Python24\myscripts\challenge\small_letter.py", line 15, in ?
 raw_input()
EOFError: EOF when reading a line


The list is the output from the script. I don't know why the end of file 
error is raised though, because it wouldn't have been raised if I ran 
the file in IDLE. So something still isn't quite right.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: recursion and linked lists

2006-03-31 Thread John Salerno
I V wrote:


> Note that print gets called after _each_ time that printBackward
> returns. So, as the different calls to printBackward return, they print
> whatever 'head' was set to in that invocation. Now, logically enough,
> the last call to printBackward is the first to return, so the last
> value of 'head' is printed first, and so in in the reverse order of the
> list.

Oh, that helps! Now I'm starting to understand when exactly it returns 
each time.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How to search HUGE XML with DOM?

2006-03-31 Thread Sullivan WxPyQtKinter
Perhaps what you have said is correct. But XML is more direct for
programmers and readers in my view point.

bayerj 写道:

> Mind, that XML documents are not more flexible than RDBMS.
>
> You can represent any XML document in a RDBMS. You cannot represent any
> RDBMS in an XML document. RDBMS are (strictly spoken) relations and XML
> documents are trees. Relations are superior to trees, at least
> mathematically speaking.
>
> Once you have set up your system in a practicable way (e.G. not needing
> to create a new table via SQL Queries for a new type of node, which
> would be a pain) SQL is far superior to XML.
>
> Anyway, cElementTree seems to be the best way to go for you now. Its
> performance is untopped by any other python xml library, as far as I
> know.

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

Re: DO NOT USE JAVA BECAUSE IT IS NOT OPEN SOURCE

2006-03-31 Thread Roedy Green
On 31 Mar 2006 20:59:16 -0800, [EMAIL PROTECTED] wrote, quoted or
indirectly quoted someone who said :

>Programing Languiges Are Ment to be free. That is why i am starting The
>Coo De Tar thats french for Blow of state it is a flash/java
>alternative and if you are going to use a server side languige use
>Perl,Python or better yet Ruby. What is the point of a languige without
>a standerd and without a open source distrabution. Coo De Tar will be
>released as a api for perl,python and ruby. Java sucks because it IS
>NOT FREE. I AM A GNU GUY I BELEVE THAT SOFTWARE MUST AND SHALL BE
>FREE!! do not use java because it is an oxymoron

If you can't even spell, how do you hope to create a language better
than Java?  

Oxymoron?  Look that up in the dictionary. 

Why NOT open source?  Check how many upturned turtle icons there are
in the Java glossary next to free software.  Without money coming in
to support it, the project dies when the original author gets bored.

Java has a standard, see the JLS see
http://mindprod.com/jgloss/jls.html
What it lacks is an INDEPENDENT standards body. However Java is  in
much tighter shape than C++, SQL or any of the languages that DO have
a standards body.

-- 
Canadian Mind Products, Roedy Green.
http://mindprod.com Java custom programming, consulting and coaching.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: running IDLE from another program?

2006-03-31 Thread Kent Johnson
John Salerno wrote:
> Kent Johnson wrote:
>>You probably don't need to do that. Just run the file in python 
>>directly. I don't know UE, but when you configure an external tool, tell 
>>it to run python.exe and pass the current file as a command line parameter.
>> 
> I've tried a lot of combinations for the command line to execute, but 
> nothing is working. What format should it be in? Should it look like this:
> 
> C:\Python24\python.exe module   ?

C:\Python24\python.exe D:\full\path\to\myprogram.py

There is a post on the UltraEdit forum from JohnJSal, is that not you? 
Whoever it is got this working...
http://www.ultraedit.com/index.php?name=Forums&file=viewtopic&t=2732&highlight=python

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


Re: Exception handling....dumb question?

2006-03-31 Thread kbperry
Thanks guys!  I appreciate the help.

I have a Python book, but it didn't mention this at all.  I also tried
looking through the online docs to no avail.

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


Re: logging producing redundant entries

2006-03-31 Thread Kent Johnson
Jed Parsons wrote:
> 
> Thanks, Kent and Peter,
> 
> Definitely making progress here.  I've got propagate = 0, and am testing 
> for handlers before doing any addHandler business.  (The handlers test 
> seems to make the most difference.)
> 
> I'm down to two entries per time now!  And prodding Zope to reload the 
> module doesn't cause the number to increase.

Do you have a second module that is setting up the same logging?

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


Re: running IDLE from another program?

2006-03-31 Thread BartlebyScrivener
John,

If your file has the .py or .pyc extension on it, it should just run at
the command line from its own directory, assuming your environment and
path variables are set correctly.

I use NoteTab which has a different way of doing it, but basically you
should be able to run:

c:\mydir>script.py

You don't need the python.exe on the commandline.

rick

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


Re: DO NOT USE JAVA BECAUSE IT IS NOT OPEN SOURCE

2006-03-31 Thread Luc The Perverse
<[EMAIL PROTECTED]> wrote in message 
news:[EMAIL PROTECTED]
> Programing Languiges Are Ment to be free. That is why i am starting The
> Coo De Tar thats french for Blow of state it is a flash/java
> alternative and if you are going to use a server side languige use
> Perl,Python or better yet Ruby. What is the point of a languige without
> a standerd and without a open source distrabution. Coo De Tar will be
> released as a api for perl,python and ruby. Java sucks because it IS
> NOT FREE. I AM A GNU GUY I BELEVE THAT SOFTWARE MUST AND SHALL BE
> FREE!! do not use java because it is an oxymoron
>

Dear Mr Troll,

There are GNU implementations of JVM and compiler.

And just because Sun's Java is not GNU does not mean it is not free.

Now go get a life.

--
LTP

:) 


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


Re: DO NOT USE JAVA BECAUSE IT IS NOT OPEN SOURCE

2006-03-31 Thread atbusbook
A Propriatary Languige Is An Oxymorron A propriatary OS is An
Oxymoron Take Pro-DOS for example A Knock-off of MS-DOG, the worst
operating system it did not use ONE IOTA OF MS CODE BUT IT was a
sucsefull knockoff. same thing will happen to JAVA


__
GEORGE ROGERS

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


DO NOT USE JAVA BECAUSE IT IS NOT OPEN SOURCE

2006-03-31 Thread atbusbook
Programing Languiges Are Ment to be free. That is why i am starting The
Coo De Tar thats french for Blow of state it is a flash/java
alternative and if you are going to use a server side languige use
Perl,Python or better yet Ruby. What is the point of a languige without
a standerd and without a open source distrabution. Coo De Tar will be
released as a api for perl,python and ruby. Java sucks because it IS
NOT FREE. I AM A GNU GUY I BELEVE THAT SOFTWARE MUST AND SHALL BE
FREE!! do not use java because it is an oxymoron

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


Re: Looking for a language/framework

2006-03-31 Thread Gregor Horvath

> 
> But what you overlook is SQL's strength:
> 
> SQL can be translated into _very_ efficient query plans w/o changing
> the SQL.  SQL's query optimizers (more properly, de-pessimizers) give

Premature optimization is the root of all evil.

On the top level of an appliciation the goal is to only have problem or
domain specific code.
Middelware or ORM is a way to this goal because it encapsulates and
hides the technical details of persistence and helps for cleaner code.

-- 
Mit freundlichen Grüßen,
  Ing. Gregor Horvath, Industrieberatung & Softwareentwicklung
  http://www.gregor-horvath.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Pickle or Mysql

2006-03-31 Thread Paul Rubin
[EMAIL PROTECTED] writes:
> So, Is Shelve a perfect solution (besides Mysql), to store large
> key/value pairs, and which are updated frequently by multiple clients.

No, shelve is for use within a single process.  With multiple clients
and frequent updates, you need a real database and some knowledge
about how to use one.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: best way to index numerical data ?

2006-03-31 Thread Liu Jin
> "Jack" == Jack  <[EMAIL PROTECTED]> writes:
> Hi I have a lot of data that is in a TEXT file which are numbers
> does anyone have a good suggestion for indexing TEXT numbers
> (zip codes, other codes, dollar amounts, quantities, etc). since
> Lucene and other indexers are really optimized for Alpha
> character indexing. What approaches are typically taken in
> computer science for example to index text numbers..hash maps or
> something else ??

Lucene is not optimized for Alpha character indexing. It's for natural
language indexing. The assumption is that the dictionary is relatively
small (say, <1M words for English), and doesn't grow linearly with the
amount of text being indexed. If your data fits into this model,
Lucene can effeciently index it, no matter what the characters are.

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


Re: Pickle or Mysql

2006-03-31 Thread amaltasb
So, Is Shelve a perfect solution (besides Mysql), to store large
key/value pairs, and which are updated frequently by multiple clients.

Thanks

Paul Rubin wrote:
> [EMAIL PROTECTED] writes:
> > Can I use Pickle to store about 500,000 key value pairs.. or should I
> > use mySql. Which one is best for performance, as the key value pair
> > increases.
>
> That's an awfully large pickle.  Maybe you want shelve.  If there
> are frequent updates, multiple clients, etc., then yes, use a database
> like mysql.

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


Re: recursion and linked lists

2006-03-31 Thread I V
John Salerno wrote:
> The printable value of node1 is 1, node2 is 2 and node 3 is 3.
>
> node1.next is node2, node2.next is node3 and node3.next is None.
>
> This might be painfully obvious, but I don't understand when the print
> statement is getting called. If you call printBackward with node1, then
> you skip the if statement, head becomes node1, tail becomes node2 and
> then you call printBackward again with node2. During this call you call
> printBackward again with node 3 and then the next time the if statement
> returns. So when does the print happen, and how does it print 3
> different values? It seems like you wouldn't get to it until the last
> time printBackward returns, and 'head' at that point would be 3, which

Each time printBackward gets called, it has it's own separate 'head'
variable. We could imagine they're all separate variables head1 for the
first time printBackward is called, head2 for the second, and so on.
The first time printBackwards gets called, it's local 'head' variable
(head1) gets set to 1, and so on.

> is the first number printed. But doesn't it stop at this point? Where do
> 2 and 1 come from?

Note that print gets called after _each_ time that printBackward
returns. So, as the different calls to printBackward return, they print
whatever 'head' was set to in that invocation. Now, logically enough,
the last call to printBackward is the first to return, so the last
value of 'head' is printed first, and so in in the reverse order of the
list. Maybe this will help you visualize what is going on:

call printBackward with arg [1, 2, 3]
head1 = 1
call printBackward with arg [2, 3]
head2 = 2
call  printBackward with arg [3]
head3 = 3
call printBackward with arg None
return
print head3 ( == 3)
return
print head2 (== 2)
return
print head1 (== 1)
return

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


Re: Pickle or Mysql

2006-03-31 Thread Paul Rubin
[EMAIL PROTECTED] writes:
> Can I use Pickle to store about 500,000 key value pairs.. or should I
> use mySql. Which one is best for performance, as the key value pair
> increases.

That's an awfully large pickle.  Maybe you want shelve.  If there
are frequent updates, multiple clients, etc., then yes, use a database
like mysql.
-- 
http://mail.python.org/mailman/listinfo/python-list


recursion and linked lists

2006-03-31 Thread John Salerno
Can someone explain to me how this works:

def printBackward(list):
   if list == None: return
   head = list
   tail = list.next
   printBackward(tail)
   print head,


 >>> printBackward(node1)
3 2 1


The printable value of node1 is 1, node2 is 2 and node 3 is 3.

node1.next is node2, node2.next is node3 and node3.next is None.

This might be painfully obvious, but I don't understand when the print 
statement is getting called. If you call printBackward with node1, then 
you skip the if statement, head becomes node1, tail becomes node2 and 
then you call printBackward again with node2. During this call you call 
printBackward again with node 3 and then the next time the if statement 
returns. So when does the print happen, and how does it print 3 
different values? It seems like you wouldn't get to it until the last 
time printBackward returns, and 'head' at that point would be 3, which 
is the first number printed. But doesn't it stop at this point? Where do 
2 and 1 come from?

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


Pickle or Mysql

2006-03-31 Thread amaltasb
Can I use Pickle to store about 500,000 key value pairs.. or should I
use mySql. Which one is best for performance, as the key value pair
increases.

Thanks

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


Re: Looking for a language/framework

2006-03-31 Thread Ravi Teja
Agreed. Mine was hardly a complete list.

Another bit I lost is keeping data operations close to the database. I
am more likely to use multiple languages/frameworks over the same
database than change databases for the same application. I actually
prefer functions and procedures within the DB (even if I have to use a
non-standard language extension) than implementing them in multiple
clients (No, I don't want to toss in middleware unless I have to).

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


Logging and threading

2006-03-31 Thread usenet
I'm having some problems getting the logging module to work with the
threading module.  I've narrowed the problem down to the following
code:

import logging, threading

update_log = logging.getLogger('update_log')
update_log.addHandler(logging.FileHandler("/tmp/update_log"))

class dlThread(threading.Thread):
def __init__(self):
threading.Thread.__init__(self)

def run(self):
ul = logging.getLogger('update_log')
ul.warn("log this")
print "finished"

t = dlThread()
t.start()

When executed, I receive the following exception:

Traceback (most recent call last):
  File "/usr/local/lib/python2.4/logging/__init__.py", line 735, in
emit
self.stream.write(fs % msg)
ValueError: I/O operation on closed file

The exception isn't fatal though, as the print "finished" line is
executed.  Alternately, if I run dlThread.run directly everything works
as I would expect, albeit without the multithreading.  Since the
logging module is advertised as being threadsafe, I suspect there's
something basic I don't understand about threads.

-Alex

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


Re: a simple regex question

2006-03-31 Thread John Salerno
Justin Azoff wrote:
> John Salerno wrote:
>> Ok, I'm stuck on another Python challenge question. Apparently what you
>> have to do is search through a huge group of characters and find a
>> single lowercase character that has exactly three uppercase characters
>> on either side of it. Here's what I have so far:
>>
>> pattern = '([a-z][A-Z]{3}[a-z][A-Z]{3}[a-z])+'
>> print re.search(pattern, mess).groups()
>>
>> Not sure if 'groups' is necessary or not.
>>
>> Anyway, this returns one matching string, but when I put this letter in
>> as the solution to the problem, I get a message saying "yes, but there
>> are more", so assuming this means that there is more than one character
>> with three caps on either side, is my RE written correctly to find them
>> all? I didn't have the parentheses or + sign at first, but I added them
>> to find all the possible matches, but still only one comes up.
>>
>> Thanks.
> 
> I don't believe you _need_ the parenthesis or the + in that usage...
> 
> Have a look at http://docs.python.org/lib/node115.html
> 
> It should be obvious which method you need to use to "find them all"
> 

But would findall return this match: aMNHiRFLoDLFb  ??

There are actually two matches there, but they overlap. So how would 
your write an RE that catches them both?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: smtplib "authentication required" error

2006-03-31 Thread Timothy Grant
On 31 Mar 2006 18:20:27 -0800, [EMAIL PROTECTED]
<[EMAIL PROTECTED]> wrote:
> In using a simple smtp routine:
>
> # begin example
> >>> import smtplib
> >>> server = smtplib.SMTP('outgoing.verizon.net')
> >>> server.sendmail('[EMAIL PROTECTED]', '[EMAIL PROTECTED]',
> """To: [EMAIL PROTECTED]
> From: [EMAIL PROTECTED]
> Subject: Shakespeare Quote
>
> Tis like the breath of an unfeed lawyer...
> """)
> >>> server.quit()
> # end example
>
> I find the following error:
>
>raise SMTPSenderRefused(code, resp, from_addr)
> smtplib.SMTPSenderRefused: (550, '5.7.1 Authentication Required',
> '[EMAIL PROTECTED]')
>
>
> I have attempted to incorporate into the interactive session:
>
> server.login = ('userid', 'password')   # the same ones I use in my
> email program

I had some trouble with this not too long ago. I don't know what kind
of authentication your mail server requires, but to send through gmail
I had to do the following.

s = smtplib.SMTP('smtp.gmail.com')
s.set_debuglevel(1)
s.ehlo()
s.starttls()
s.ehlo()
s.login('foo', 'bar')
s.sendmail(from_address, to_addresses, msg)
s.close()

Hope that helps.

--
Stand Fast,
tjg.
-- 
http://mail.python.org/mailman/listinfo/python-list


why doesn't is work?a script to backup a directory

2006-03-31 Thread obeeker
"""there is threee directories,one of these is used for the base
directory,decided by the user, default is d0"""

import shutil


#the three directories
d0='D:/Program Files/eb/mb/S'
d1='O:/eb/mb/S'
d2='P:/S/eb/mb/S'

#to backup
def update(base):
l=[d0,d1,d2]
l.remove(base)

for i in l:
shutil.rmtree(i)

for i in l:
shutil.copytree(base,i)

#use the base directory to invoke the update() func
def updateNow(base):
try:
if base=='d1':
update(d1)
elif base=='d2':
update(d2)
else:
update(d0)

except:
print "sth is wrong"
else:
print "OK!"

#promt user which is the base
if __name__ == '__main__':
print 'd0=',d0
print 'd1=',d1
print 'd2=',d2
base=raw_input("your base/standard directory is d0 d1 or d2  ?\n")
print base
updateNow(base)

raw_input('press Return>')

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


Re: a simple regex question

2006-03-31 Thread Justin Azoff

John Salerno wrote:
> Ok, I'm stuck on another Python challenge question. Apparently what you
> have to do is search through a huge group of characters and find a
> single lowercase character that has exactly three uppercase characters
> on either side of it. Here's what I have so far:
>
> pattern = '([a-z][A-Z]{3}[a-z][A-Z]{3}[a-z])+'
> print re.search(pattern, mess).groups()
>
> Not sure if 'groups' is necessary or not.
>
> Anyway, this returns one matching string, but when I put this letter in
> as the solution to the problem, I get a message saying "yes, but there
> are more", so assuming this means that there is more than one character
> with three caps on either side, is my RE written correctly to find them
> all? I didn't have the parentheses or + sign at first, but I added them
> to find all the possible matches, but still only one comes up.
>
> Thanks.

I don't believe you _need_ the parenthesis or the + in that usage...

Have a look at http://docs.python.org/lib/node115.html

It should be obvious which method you need to use to "find them all"

-- 
- Justin

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


smtplib "authentication required" error

2006-03-31 Thread [EMAIL PROTECTED]
In using a simple smtp routine:

# begin example
>>> import smtplib
>>> server = smtplib.SMTP('outgoing.verizon.net')
>>> server.sendmail('[EMAIL PROTECTED]', '[EMAIL PROTECTED]',
"""To: [EMAIL PROTECTED]
From: [EMAIL PROTECTED]
Subject: Shakespeare Quote

Tis like the breath of an unfeed lawyer...
""")
>>> server.quit()
# end example

I find the following error:

   raise SMTPSenderRefused(code, resp, from_addr)
smtplib.SMTPSenderRefused: (550, '5.7.1 Authentication Required',
'[EMAIL PROTECTED]')


I have attempted to incorporate into the interactive session:

server.login = ('userid', 'password')   # the same ones I use in my
email program

But I get the same error result. My objective is to have a simple way
to send email from the command line. To do this I will write a script
which can read in a file and send it to the address on top of the file.
What is the procedure for authentication?

Using the KMail email program (Linux, KDE desktop), I send mail through
my Verizon account. Under the Configure KMail / Accounts / Modify
Account / Extras tab, I clicked "Check what the server supports" and it
came back 'no encryption' and 'cleartext'. So it doesn't seem that it
would involve complex procedures.

Any help welcome.

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


Re: Can I control Video Card by using Python under linux?

2006-03-31 Thread Ravi Teja
Here's a wrapper for V4L.

http://antonym.org/libfg

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


Re: Exception handling....dumb question?

2006-03-31 Thread Trent Mick
[kbperry wrote]
> In Python,
> When using the default except (like following)
> 
> try:
> some code that might blow up
> 
> except:
> print "some error message"


>>> try:
... 1/0
... except:
... import traceback
... traceback.print_exc()
...
Traceback (most recent call last):
  File "", line 2, in ?
ZeroDivisionError: integer division or modulo by zero


Or, if you are using the logging module:

>>> import logging
>>> log = logging.getLogger("myscript")
>>> logging.basicConfig()
>>>
>>> try:
... 1/0
... except:
... log.exception("whoa!")
...
ERROR:myscript:whoa!
Traceback (most recent call last):
  File "", line 2, in ?
ZeroDivisionError: integer division or modulo by zero


Cheers,
Trent

-- 
Trent Mick
[EMAIL PROTECTED]
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Find similar images using python

2006-03-31 Thread Ravi Teja
Finding similar images is not at all a trivial task. Entire PhD
dissertations have been committed to it. The solutions are still very
unreliable as of yet. If you want to find more, you can read the
research out of the ongoing Image CLEF track. I worked with them
briefly a couple of years ago in context of medical images.

http://ir.shef.ac.uk/imageclef/

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


Re: any() and all() on empty list?

2006-03-31 Thread Paul Rubin
Ron Adam <[EMAIL PROTECTED]> writes:
> The 'not not S' is just a conversion to bool. Is the following less
> contorted to you?
> 
>  >>> bool([])
> False

Oh ok.  Yes, bool(S) is much less contorted than "not not S".

> 'Is all True' isn't the same as 'Has all True'.  As I said, I'm not
> questioning the mathematical meaning of the set relation 'is all
> True', but wondering weather or not an alternate relation 'has all
> True' would be better for use as a flow control test.
> 
> Do you have some examples uses since it's obvious to you?

# go out drinking when I'm finished with today's work
if all (task.done() for task in self.things_to_do_today()):
   self.go_out_drinking()

If I didn't have anything to do today, that should result in going out
drinking immediately.

> I just have a feeling we will see a lot of "S and all(S)" expressions
> being used.  Maybe that's not so bad,  but I would prefer to not have
> to do that if it turns out to the standard idiom for all testing
> within a loop.

I think "S and all(S)" is the right way to express that, if that's
what's intended.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Doc suggestions (was: Why "class exceptions" are not deprecated?)

2006-03-31 Thread Paul Boddie
[EMAIL PROTECTED] wrote:
> Ed Singleton wrote:
> >
> > Ideas can come from anyone and they do come from anyone all the time,
> > and as such they are fairly worthless unless acted upon.
>
> That is pretty obvious.  The question is about who does
> the acting.  Your position seems to be that
> only those that act have a right to present ideas.  This
> is bogus for a whole bunch of reasons:

At this point, I have to say that this post reveals a pretty good
insight into the nature of community dynamics.

> - It is exceptional case when people go off and do something
>   by themselves and produce good results.  The power of
>   free software lies in its collaborative nature.

Indeed. Which is why it can be puzzling sometimes to see certain
communities and movements put all their money on one horse, to use a
common analogy. People should feel encouraged to do offbeat or
tangential stuff, especially if it costs the other people nothing more
than an act of encouragement.

> - Many changes are too big or pervasive, and need
>   cooperation from many people (or at least agreement.)
> - Even small changes often need help from others
>   (sometimes just information)
> - People can have a good idea, even if they are not capable
>   of implementing it.

And consider a combination of these factors: there are several
different resources for proposing amendments to the Python
documentation; to make a standard replacement for the documentation,
you need consensus; to make a better replacement, you either need
people to use your resource to propose improvements, or you need to be
able to collaborate with all the other resources/mechanisms, and thus
you need standardisation. No-one has all the technical, social and
political answers, nor should they be asked to come up with them all.

Having people proposing changes to the documentation and having tools
available to make such changes convenient both solve important issues,
but various social and political issues remain. If we ignore these
potentially unsolved issues, though, noting that Fredrik and others
have provided technical solutions, it'd probably be for the best if
those people perceived to be complaining were just encouraged to use
such solutions rather than being made to feel stupid because they don't
have the technical abilities to solve that one aspect of the wider
problem.

> - This is particularly true in documentation and ui where
>   the lowly user is, in many respects, the expert.
> - Even if an idea is not good, it can start someone else
>   thinking and their idea may be good.

Indeed. People who don't feel able to contribute to one part of a
solution shouldn't be discouraged from contributing where they can.
Perhaps it has been difficult to field documentation updates within the
current workflow, and perhaps it is more productive for the maintainers
to not encourage certain levels or kinds of suggestions or improvements
since they would end up with a lot of editing and administrative work,
but the technical impediments are not the fault of those willing to
contribute - if people lose sight of that, then...

> - Without outside ideas and critisism the core
>   development group can become "inbred" and loose touch
>   with the user community.

Well, there was the "smug" label brought up some time ago. I'd argue
that certain parts of the community could subsequently be labelled as
"rattled" due to certain arguable trends in technology adoption, and
perhaps the python.org redesign brought all this to the fore. And on
that subject, perhaps I'd better get back to looking at that particular
set of tools...

Paul

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


Re: Exception handling....dumb question?

2006-03-31 Thread Rune Strand

kbperry wrote:
> In Python,
> When using the default except (like following)
>
> try:
> some code that might blow up
>
> except:
> print "some error message"
>
>
> Is there a way to show what error it is throwing?
>
> Like in Java, you can do
> catch (Exception e){
> System.out.println(e);
> }
>
> Or something like that.
>
> Is there an equivalent way to do this in Python?

see sys.exc_info( )

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


Re: Exception handling....dumb question?

2006-03-31 Thread Felipe Almeida Lessa
Em Sex, 2006-03-31 às 15:51 -0800, kbperry escreveu:
> Is there a way to show what error it is throwing?
> 
> Like in Java, you can do
> catch (Exception e){
> System.out.println(e);
> }
> 
> Is there an equivalent way to do this in Python?

>>> try:
... print 1/0
... except Exception, e:
... print '*', e.__class__, '*'
... print '*', e, '*'
...
* exceptions.ZeroDivisionError *
* integer division or modulo by zero *


-- 
Felipe.

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

Exception handling....dumb question?

2006-03-31 Thread kbperry
In Python,
When using the default except (like following)

try:
some code that might blow up

except:
print "some error message"


Is there a way to show what error it is throwing?

Like in Java, you can do
catch (Exception e){
System.out.println(e);
}

Or something like that.

Is there an equivalent way to do this in Python?

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


Re: a simple regex question

2006-03-31 Thread John Salerno
John Salerno wrote:
> Ok, I'm stuck on another Python challenge question. Apparently what you 
> have to do is search through a huge group of characters and find a 
> single lowercase character that has exactly three uppercase characters 
> on either side of it. Here's what I have so far:
> 
> pattern = '([a-z][A-Z]{3}[a-z][A-Z]{3}[a-z])+'
> print re.search(pattern, mess).groups()
> 
> Not sure if 'groups' is necessary or not.
> 
> Anyway, this returns one matching string, but when I put this letter in 
> as the solution to the problem, I get a message saying "yes, but there 
> are more", so assuming this means that there is more than one character 
> with three caps on either side, is my RE written correctly to find them 
> all? I didn't have the parentheses or + sign at first, but I added them 
> to find all the possible matches, but still only one comes up.
> 
> Thanks.

A quick note: I found nine more matches by using findall() instead of 
search(), but I'm still curious how to write the RE so that it works 
with search, especially since findall wouldn't have returned overlapping 
matches. I guess I didn't write it to properly check multiple times.
-- 
http://mail.python.org/mailman/listinfo/python-list


a simple regex question

2006-03-31 Thread John Salerno
Ok, I'm stuck on another Python challenge question. Apparently what you 
have to do is search through a huge group of characters and find a 
single lowercase character that has exactly three uppercase characters 
on either side of it. Here's what I have so far:

pattern = '([a-z][A-Z]{3}[a-z][A-Z]{3}[a-z])+'
print re.search(pattern, mess).groups()

Not sure if 'groups' is necessary or not.

Anyway, this returns one matching string, but when I put this letter in 
as the solution to the problem, I get a message saying "yes, but there 
are more", so assuming this means that there is more than one character 
with three caps on either side, is my RE written correctly to find them 
all? I didn't have the parentheses or + sign at first, but I added them 
to find all the possible matches, but still only one comes up.

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


Re: running IDLE from another program?

2006-03-31 Thread John Salerno
Kent Johnson wrote:
> John Salerno wrote:
>> If I want to write my code in a separate text editor (I like UltraEdit) 
>> but then press a single button to have that code run in the IDLE 
>> environment, is that possible? I know that you can configure UE to run 
>> external tools, but I can't figure out how to run IDLE this way, because 
>> when I check on its properties to find it's file path, it is just the 
>> Python directory itself.
> 
> You probably don't need to do that. Just run the file in python 
> directly. I don't know UE, but when you configure an external tool, tell 
> it to run python.exe and pass the current file as a command line parameter.
> 
> Kent

I've tried a lot of combinations for the command line to execute, but 
nothing is working. What format should it be in? Should it look like this:

C:\Python24\python.exe module   ?

or module.ext? With or without the path of the file?

I think some of the problem might be that I need to fix the module 
search path also, but I don't know which format the UE tool needs to 
execute the command.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: logging producing redundant entries

2006-03-31 Thread Jed Parsons


Thanks, Kent and Peter,

Definitely making progress here.  I've got propagate = 0, and am testing 
for handlers before doing any addHandler business.  (The handlers test 
seems to make the most difference.)

I'm down to two entries per time now!  And prodding Zope to reload the 
module doesn't cause the number to increase.

It's a good thing for Zope to reload modules when you touch them, but I 
didn't anticipate that this would be a side-effect.

Thanks again for your help.  Cheers,
j

Kent Johnson wrote:
> Jed Parsons wrote:
>> Thanks, Peter and alex23,
>>
>> The metalog test shows that the code is only being executed once at a time.
>>
>> And if I take those lines and put them in a shell script (fixing the 
>> FileHandler - sorry about the bad copy there), they work as expected, 
>> producing a single log entry.
>>
>> So I'm left with:
>>
>> - logging code that works properly in isolation in a shell script
>> - zope extension code that gets called only once (metalog test)
>> - logging code produces multiple entries when executed in extension
>> - logging code seems to produce more and more entries over time
>>
>> Am I somehow accumulating a growing list of loggers by having this code 
>> at the top of a zope Extension?  If I cause the extension to be 
>> re-evaluated, do I somehow attach another logger?  (I'm grasping at 
>> straws...)
> 
> It sounds like Zope is reloading your extension. Each time it is 
> reloaded you will attach another logger.
>> I've tried the following to only call getLogger once, but it doesn't 
>> seem to help:
>>
>> try:
>>  _logger
>> except NameError:
>>  _logger = logging.getLogger('login')
>>  etc...
> 
> No, that won't work if it really is a reload, _logger will never be 
> defined. Can you put the logging setup somewhere else, in a module that 
> is only loaded once? Or inspect _logger.handlers to see if it already 
> contains a FileHandler to your log file, and only add it if it is not 
> there already.
> 
> Kent

-- 
Jed Parsons   Industrial Light + Magic  (415) 746-2974

grep(do{for(ord){(!$_&&print"$s\n")||(($O+=(($_-1)%6+1)and
grep(vec($s,$O++,1)=1,1..int(($_-6*6-1)/6}},(split(//,
"++,++2-27,280,481=1-7.1++2,800+++2,8310/1+4131+1++2,80\0.  What!?")));
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Find similar images using python

2006-03-31 Thread Scott David Daniels
Christos Georgiou wrote:
>  I did make a module based on imgseek, and together with PIL,
> I manage my archive of email attachments (it's incredible how many
> different versions of the same picture people send you: gif, jpg
> in different sizes etc) and it works fairly well.
> 
> E-mail me if you want the module, I don't think I have it currently online
> anywhere.

This sounds like a great recipe for the cookbook:
 http://aspn.activestate.com/ASPN/Cookbook/Python

-- 
-Scott David Daniels
[EMAIL PROTECTED]
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Newbie: splitting dictionary definition across two .py files

2006-03-31 Thread Ben Finney
"Karthik Gurusamy" <[EMAIL PROTECTED]> writes:

> Ben Finney wrote:
>> That sounds like a very confusing architecture, and smells very
>> much like some kind of premature optimisation. What leads you to
>> that design? It's very likely a better design can be suggested to
>> meet your actual requirements.
>
> So effectively I'm writing a python script as a poor man's make file.
> [...]
> I'm not really worried about optimizations at this time; just want a
> cleaner solution to my problem.

There is SCons, a much-improved build system written in Python, that
may interest you.

http://www.scons.org/>

The build configurations are written in Python, so it seems to be
quite similar to what you're currently working toward.

-- 
 \ "The reward of energy, enterprise and thrift is taxes."  -- |
  `\   William Feather |
_o__)  |
Ben Finney

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


Re: Looking for a language/framework

2006-03-31 Thread Scott David Daniels
Ravi Teja wrote:
>> ... I've never seen an "object-relational mapping" (technical term for
>> cruft that tries to avoid people having to learn and use SQL) which
>> doesn't drive me into a murderous, foam-at-mouth rage in a very
>> short time -- I *WANT* my SQL, I *LOVE* SQL, it's *WAY* more powerful
>> and suitable for access to data than all those simulated "OO DB" people
>> lay on top of it
> 
> I for one don't have any particular love for SQL. For most purposes I
> don't want to be bothered with its details. However, I am disillusioned
> with ORMs. With SQL and old school database management, I had tools
> such as QBEs, ERD managers to visually manage much of the details (I
> perform better with pictures than text) and even if others disagree, it
> worked well for me. Now with ORMs, I am back to code again. Granted, it
> appears cleaner most of the time but I want to be able to not see it at
> all

But what you overlook is SQL's strength:

 SQL can be translated into _very_ efficient query plans w/o changing
the SQL.  SQL's query optimizers (more properly, de-pessimizers) give
performance which can be tuned w/o touching the SQL.  SQL, a language
which is truly ugly, not quite standardized, and otherwise quite clunky,
does manage to let you say more of what you want without specifying how
to get it.  This separation of result spec from query plan is what makes
makes those optimizers work.  The ORMs put objects on top of the DB, but
in a way that either (A) violates the object model in that everything
must be of the _same_ type in a table (good-bye duck-typing), or
(B) gives up on most any attempt to get optimized access -- the DB
becomes a persistent store, without the normal SQL feature of "our DB
admin can tune this up to fly like a peregrine in full stoop."  A
query planner for well-insulated objects just doesn't have enough
information about what it can and cannot rewrite, so it doesn't know
how to estimate how much I/O one plan will cost as opposed to another.

--Scott David Daniels
[EMAIL PROTECTED]
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: running IDLE from another program?

2006-03-31 Thread [EMAIL PROTECTED]
what i do is open idle, import the codefile i've begun to write, and
then write a function:
def r():
reload(codefile)

then when I want to run it after changes, I just call the function
manually in idle.

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


Re: QOTW... (was: Doc suggestions (was: Why "class exceptions" are not deprecated?))

2006-03-31 Thread rurpy

[EMAIL PROTECTED] wrote:
> > "Ed" == Ed Singleton <[EMAIL PROTECTED]> writes:
>
> Ed> Go to the wiki, make the changes you want, and feel good about
> Ed> yourself for once.
>
> +1 QOTW.

I suggest leaving off the "for once".  Otherwise, it is just
another gratuitous insult, of the kind there is already too
many of in this newsgroup.

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


Re: Doc suggestions (was: Why "class exceptions" are not deprecated?)

2006-03-31 Thread rurpy
Ed Singleton wrote:
> On 30 Mar 2006 16:30:24 -0800, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote:
> >
> > What are you saying?  Ideas must come only from those
> > with the time and skill to implement them?  No one else
> > need apply?
>
> Ideas can come from anyone and they do come from anyone all the time,
> and as such they are fairly worthless unless acted upon.

That is pretty obvious.  The question is about who does
the acting.  Your position seems to be that
only those that act have a right to present ideas.  This
is bogus for a whole bunch of reasons:
- It is exceptional case when people go off and do something
  by themselves and produce good results.  The power of
  free software lies in its collaborative nature.
- Many changes are too big or pervasive, and need
  cooperation from many people (or at least agreement.)
- Even small changes often need help from others
  (sometimes just information)
- People can have a good idea, even if they are not capable
  of implementing it.
- This is particularly true in documentation and ui where
  the lowly user is, in many respects, the expert.
- Even if an idea is not good, it can start someone else
  thinking and their idea may be good.
- Without outside ideas and critisism the core
  development group can become "inbred" and loose touch
  with the user community.
- Putting restrictions on who can contribute ideas is
  often just human psycological desire for exclusion and
  control.
- Using an open forum like usenet means you *will*
  get ideas and critisism from "unworthy" people.  Group
  think and intimidation can reduce but not eliminate it.

> If you want
> someone else to do the acting upon for you, for free

This is what is tripping you up.  You interpret my
critisism as a demand that "you" (plural) do something.
First it is not a demand.  It is (to use your terminology
below), a gift.  You want to ignore it?  Fine.  You
want to delete all documentation and say, "well that
will teach to complain!"  Fine.  You want to add it
to actual or mental list of things to think about.
Fine.  You want to encourage people to discuss it
leading (hopefully) to someone doing something
about it?  Fine.

I was once involved periperaly in the UI part of a
software project.  The hardest part was finding out
what problems users had with the ui and documentation.
The company had a bunch of very expensive engineers
and tech writers sit down with a group of potential
users (also expensive), for several weeks, studying
what problems the users had, what was confusing or
not clear, what was liked and not liked.  Obtaining
this info was very expensive.  The results were
excellent.

I suggest when that kind of info is offered to you
for free on usenet, you might want to take advantage
of it.

> (and probably for no thanks),

Do you think you know me well enough from a
handful of usenet postings to conclude that?

> then it has to be one hell of an amazing idea that no one
> else has ever had (which, trust me, you won't have, and neither,
> probably, will I).

I definately won't, but you (with low probability) might?
Well, at least your digs are more subtle than Fredrik's. :-)

> Everyone knows how to improve open source software, but what good is
> that to anyone?  Making the improvements is worth hell of a lot and
> that's why the people who do develop a lot of kudos in the community
> (it's about the only payment they get for it, and they do deserve it).

Of course they do.  But that does not extend to
being silent about problems.

> If you have an idea, then good for you, but make some small attempt to
> do something about it yourself.

Prehaps you missed my post where I suggested a concrete
textual correction.  And offered to change the source
myself if the developers are too busy?  Or perhaps you
missed the patches I submitted to correct other issues
with the docs that have been sitting there for four
months?

> I'm not much of an expert in anything yet, but I had an idea, and then
> managed to put the documents in a wiki, which was at least trying to
> do something.  Fredrik beat me to it and did a much better job, but
> even so I feel quite proud that I did something and tried to move
> things on, rather than just post to a mailing list and hope someone
> else does it.

I'm sorry, I don't buy your "just do it" philosophy.
For one, its often not possible.  (E.g. my offer to
make a doc correction if given cvs access.)  For another,
"just do it" without thought, discussion with others,
etc will most often lead to a half-assed solution, or
a waste of time because everyone else rejects the work.

And you are misrespresenting me by saying "...just
post to a mailing list and hope someone else does it."
I offered in many previous posts and the post you
responded to, to actually do some work.

> > Whenever anyone criticizes anything about free software
> > there are three automatic responses:
> >
> > 1. You are an idiot if you can't understand / have a problem with that.
> > 2. 

Re: best way to index numerical data ?

2006-03-31 Thread benwbrewster
here is a sample of a .txt file :
I want to search for the whole number. If possible, fuzzy search would
be nice too, but not mandatory..
1975|Y|35136|72|1927|||3|005503|003|19870301|19950301|14416887|151|2301|100039292|N|84|F|50||10|A|100|Y|037|Y|89005|3042|M|S|P|

Thanks!
Jack

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


Re: best way to index numerical data ?

2006-03-31 Thread benwbrewster
here is a sample of a .txt file :
I want to search for the whole number. If possible, fuzzy search would
be nice too, but not mandatory..
1975|Y|35136|72|1927|||3|005503|003|19870301|19950301|14416887|151|2301|100039292|N|84|F|50||10|A|100|Y|037|Y|89005|3042|M|S|P|

Thanks!
Jack

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


Re: Newbie: splitting dictionary definition across two .py files

2006-03-31 Thread Karthik Gurusamy
Ben Finney wrote:
> [EMAIL PROTECTED] writes:
>
> > I'm fairly new to python. I like to define a big dictionary in two
> > files and use it my main file, build.py
> >
> > I want the definition to go into build_cfg.py and build_cfg_static.py.
>
> That sounds like a very confusing architecture, and smells very much
> like some kind of premature optimisation. What leads you to that
> design? It's very likely a better design can be suggested to meet your
> actual requirements.


I work in a source tree of 100s of .c files. The make file builds the
various .o files from the .c files. It takes a while to finish on the
first run. When I make changes to a .c file, I need to compile to get
the .o and also quickly fix any compilation errors.  I don't want to
use the make infrastructure, as it takes a while to resolve the
dependencies.


So effectively I'm writing a python script as a poor man's make file.
On the first run of make, I capture the complete stdout. Then use a
script (another python one - build_generate.py)  to grep thru' the
makefile's log to find out the exact gcc command used to get a foo.o
from its foo.c The script also captures the current working directory
-- the make is kind enough to spit out stuff like 'Entering directory
/blah/blah/path/to/binary' It puts out the output in build_cfg.py
(it outputs in stdout, which I redirect)


I could get results of about 0.20 second completion for a .o file, when
the make file easily takes about 20 sec; that's a 100 times speedup.


I'm interested in only a few dozen .o files that I manage.  So I run
the script to generate a dictionary of the form


target_db['foo.o'] = {
'cmd_cwd': r'/blah/blah/path/to/binary',
'cmd_str': r'/path/to/gcc  -o obj-xyz/foo.o
../blah/foo.c',#'redirect': 1,
# I can add any other flags I may think of
# In fact I'm planning to make the cmd_str as a list so that I can
# run a series of commands
}


In my build.py based on the target I give on command line (build.py
foo.o), I find the dictionary entry and using popen2.Popen3, execute
the corresponding cmd_str.


Now for every new source tree I pull or when make-file changes, I want
to rerun the script to generate the new dictionary.


I found build.py can also be used to automate other tasks - say pulling
a source tree. In general to run any command (or list of commands that
you issue from the shell prompt). These other tasks dictionary entries
are static; they don't change when makefiles options changes.  That is
the reason I want to split the dictionary contents in two files.  I
only have to change build_cfg.py everytime make-file changes/I use a
new source tree.


I'm not really worried about optimizations at this time; just want a
cleaner solution to my problem.

Karthik
>
> --
>  \ "If you can't annoy somebody there is little point in writing." |
>   `\  -- Kingsley Amis |
> _o__)  |
> Ben Finney

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


Re: Newbie: splitting dictionary definition across two .py files

2006-03-31 Thread Karthik Gurusamy
Ben Cartwright wrote:
> [EMAIL PROTECTED] wrote:
> > I like to define a big dictionary in two
> > files and use it my main file, build.py
> >
> > I want the definition to go into build_cfg.py and build_cfg_static.py.
> >
> > build_cfg_static.py:
> > target_db = {}
> > target_db['foo'] = 'bar'
> >
> > build_cfg.py
> > target_db['xyz'] = 'abc'
> >
> > In build.py, I like to do
> > from build_cfg_static import *
> > from build_cfg import *
> >
> > ...now use target_db to access all elements. The problem looks like, I
> > can't
> > have the definition of target_db split across two files. I think they
> > reside in different name spaces?
>
> Yes.  As it stands, build_cfg.py will not compile to bytecode
> (NameError: name 'target_db' is not defined).
>
> Unless you're doing something ugly like exec() on the its contents, .py
> files need to be valid before they can be imported.
>
> > Is there any way I can have the same
> > dictionary definition split across two files?
>
> Try this:
>
> # build_cfg_static.py:
> target_db = {}
> target_db['foo'] = 'bar'
>
> # build_cfg.py:
> target_db = {}
> target_db['xyz'] = 'abc'
>
> # build.py:
> from build_cfg_static import target_db
> from build_cfg import target_db as merge_db
> target_db.update(merge_db)
>

Thanks; it works great.

I also found using import inside build_cfg.py also works.

#build_cfg_static.py:
target_db = {}
#.. other dict entry definitions

#build_cfg.py:
from build_cfg_static import *
#.. more dict entry definitions

But I think using two different dictionaries and merging as you have
suggested is a better approach than the above way of an import file
importing another file. But doing the dictionary merge may incur
additional performance cost; but for my dataset size, it should be
okay.

Karthik

> --Ben

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


Re: Looking for a language/framework

2006-03-31 Thread Ravi Teja
> For example, I've never seen an "object-relational mapping" (technical
> term for cruft that tries to avoid people having to learn and use SQL)
> which doesn't drive me into a murderous, foam-at-mouth rage in a very
> short time -- I *WANT* my SQL, I *LOVE* SQL, it's *WAY* more powerful
> and suitable for access to data than all those simulated "OO DB" people
> lay on top of it (of course, that does depend on having a REAL
> relational DB underneath, not, say, MySQL;-).  Other people disagree
> very, very deeply with my preferences (as proven by the existence of a
> begazillion ORMs, including general-purpose ones as well as ones that
> are part of web-application frameworks).

I for one don't have any particular love for SQL. For most purposes I
don't want to be bothered with its details. However, I am disillusioned
with ORMs. With SQL and old school database management, I had tools
such as QBEs, ERD managers to visually manage much of the details (I
perform better with pictures than text) and even if others disagree, it
worked well for me. Now with ORMs, I am back to code again. Granted, it
appears cleaner most of the time but I want to be able to not see it at
all.

Java ORMs are begining to get a lot of these tools now. But I have been
cautious to dip my toes in these cold (verbose, XML infested) waters so
far.

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


Re: Credit card API Sol with python interface

2006-03-31 Thread [EMAIL PROTECTED]
I used a python api for the linkpoint.com processor a few years ago
I think they still have the python api

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


Re: how to comment lot of lines in python

2006-03-31 Thread gene tani

[EMAIL PROTECTED] wrote:
> Like in C we comment like
> /*
> Bunch of lines of code
> */
>

scite has a feature where you modify your delimiter in block comments,
i.e. what comes after "#"

http://scintilla.sourceforge.net/SciTEDoc.html

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


String Matching

2006-03-31 Thread david brochu jr
Hello,
 
I am trying to write a script that takes strings from a text file and searches to see if they are present in another text file...here is the code:
 
import osimport re

search = open("c:\python24\scripts\pii\expected_rules_results.txt")
def find(x): file = open("c:\python24\scripts\pii\dave.txt") regexp = re.compile(x) for line in file.readlines():  if regexp.search(line):   print "Found", x   break 
file.close()  
for x in search: find(x)search.close()
 
Unfortunately the strings I will be searching for contain numerous "*" that cause an error. For example, when try to search for:
http://www.widget.com/personal_firewall.csp/?pin={6}
I get the error message:
Traceback (most recent call last):  File "C:\Python24\scripts\PII\search    find(x)  File "C:\Python24\scripts\PII\search    regexp = re.compile(x)  File "C:\Python24\lib\sre.py", line
    return _compile(pattern, flags)  File "C:\Python24\lib\sre.py", line    raise error, v # invalid expressiosre_constants.error: multiple repeat
 
Anyone know how to get around this?
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: Looking for a language/framework

2006-03-31 Thread walterbyrd
I am presently looking at a commercial product called dbqwiksite. I
generates php code.

I know that sounds lame, but the demos were impressive.

If I could get the product to work like they show in the demos it would
be great.

It uses ODBC to connect to a mysql database; but I can't get it to work.

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


Re: Looking for a language/framework

2006-03-31 Thread walterbyrd
I am presently looking at a commercial product called dbqwiksite. I
generates php code.

I know that sounds lame, but the demos were impressive.

If I could get the product to work like they show in the demos it would
be great.

It uses ODBC to connect to a mysql database; but I can't get it to work.

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


Re: Working with files in a SimpleXMLRPCServer

2006-03-31 Thread Jose Carlos Balderas Alberico
Oops, I'm afraid I replied to Brian only instead of to the whole distribution list. I copy the message I sent to him so that everyone can read it:I'm afraid I cannot use the zlib library provided by Python, since
the ZIP files I'm supposed to send must be password-protected, and I
haven't been able to find a method in the library that let me zip a
file with a password. I could be wrong though...
As for the HTTP server instead of the XML-RPC one... you are
totally right. However, in the specification I was handled to perform
my task, it said explicitely to use the XML-RPC protocol; maybe it has
to do because  there is also some data-bases issues in our application,
and using XML-RPC would be more appropiate. For example, the text file
I'm supposed to zip has its information extracted from a database
table.
Anyway, since those are the constraints I'm facing, I thought
handling the files issue the way I did would be more appropiate. Since
I have never done network programming till now, I'm having difficulties
dealing with it, and I want to know if the solution I chose is
acceptable.
Thank you very much.Cheers, 
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: proposed proposal: set.values()

2006-03-31 Thread Ron Adam
Paul Rubin wrote:
> "Terry Reedy" <[EMAIL PROTECTED]> writes:
>> 1. It is pure duplication that *adds* keystrokes.
>>
> Nobody says you shouldn't use list(s) if you know you're dealing with
> a set.  The idea of s.values() is so you can duck-type between dicts
> and sets.

You could just do the following...


 >>> class vset(set):
...   values = set.copy
...

 >>> s = vset([1,2,3])

 >>> s.values()
vset([1, 2, 3])

 >>> for x in s.values():
...   x
...
1
2
3


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


Re: running IDLE from another program?

2006-03-31 Thread Kent Johnson
John Salerno wrote:
> If I want to write my code in a separate text editor (I like UltraEdit) 
> but then press a single button to have that code run in the IDLE 
> environment, is that possible? I know that you can configure UE to run 
> external tools, but I can't figure out how to run IDLE this way, because 
> when I check on its properties to find it's file path, it is just the 
> Python directory itself.

You probably don't need to do that. Just run the file in python 
directly. I don't know UE, but when you configure an external tool, tell 
it to run python.exe and pass the current file as a command line parameter.

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


Re: best way to index numerical data ?

2006-03-31 Thread Paddy
What do you want to search for in the file?
how big is the file?
What format is the data in the file?

- Paddy.

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


Re: any() and all() on empty list?

2006-03-31 Thread Ant
lol!

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


Re: any() and all() on empty list?

2006-03-31 Thread Ron Adam
Carl Banks wrote:
> Ron Adam wrote:
>> Carl Banks wrote:
>>
>>> In Python, yes and no are the only possible answers.  Probably the only
>>> analogous thing you could do in Python would be for all() to raise
>>> ValueError when passed an empty sequence.
>> There is also 'None' which serves a similar purpose of indicating an
>> invalid value when passing arguments.
> 
> If all() were to return None, then if would essentially be like
> returning False, because an if-statement would treat False and None the
> same (as would most anything else expecting a boolean value).
> 
> The only reasonable way to say "false assumption" in Python is to raise
> an exception.
> 
> 
> Carl Banks

Then maybe None should be evaluated as True so it is consistent with 
all().   ;-)


Not serious of course,  Cheers,
Ron







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


Re: logging producing redundant entries

2006-03-31 Thread Kent Johnson
Jed Parsons wrote:
> Thanks, Peter and alex23,
> 
> The metalog test shows that the code is only being executed once at a time.
> 
> And if I take those lines and put them in a shell script (fixing the 
> FileHandler - sorry about the bad copy there), they work as expected, 
> producing a single log entry.
> 
> So I'm left with:
> 
> - logging code that works properly in isolation in a shell script
> - zope extension code that gets called only once (metalog test)
> - logging code produces multiple entries when executed in extension
> - logging code seems to produce more and more entries over time
> 
> Am I somehow accumulating a growing list of loggers by having this code 
> at the top of a zope Extension?  If I cause the extension to be 
> re-evaluated, do I somehow attach another logger?  (I'm grasping at 
> straws...)

It sounds like Zope is reloading your extension. Each time it is 
reloaded you will attach another logger.
> 
> I've tried the following to only call getLogger once, but it doesn't 
> seem to help:
> 
> try:
>  _logger
> except NameError:
>  _logger = logging.getLogger('login')
>  etc...

No, that won't work if it really is a reload, _logger will never be 
defined. Can you put the logging setup somewhere else, in a module that 
is only loaded once? Or inspect _logger.handlers to see if it already 
contains a FileHandler to your log file, and only add it if it is not 
there already.

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


exception handling in Tkinter

2006-03-31 Thread msoulier
In wxPython I install a top-level exception handler to intercept
exceptions and display them in the GUI.

With Tkinter, I'm trying to do the same.

in __init__

 sys.excepthook = self.ExceptionHandler

def ExceptionHandler(self, type, value, tb):
tblist = traceback.format_tb(tb)
for line in tblist:
text += line
self.errorDialog(text)

But it's not being called on exceptions. Any ideas?

Thanks,
Mike

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


Re: urllib2 through basic auth'ed proxy

2006-03-31 Thread John J. Lee
Alejandro Dubrovsky <[EMAIL PROTECTED]> writes:

> John J. Lee wrote:
> 
> > FWIW, at a glance, Python 2.3.4 has neither of the bugs I mentioned,
> > but the code I posted seems to work with 2.3.4.  I'm not particularly
> > interested in what's wrong with 2.3.4's version or your usage of it
> > (probably both), since bugfix releases for 2.3 are no longer
> > happening, I believe.
> > 
> 
> "ah, yes, that works" on 2.3.4.  Excellent.  (I don't see what's so ugly
> about that code, but i'm mostly accustomed to my own)

supplying a password surely shouldn't be that complicated...


John

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


Re: logging producing redundant entries

2006-03-31 Thread Peter Otten
Jed Parsons wrote:

> Am I somehow accumulating a growing list of loggers by having this code
> at the top of a zope Extension?

I'd rather look after the number of handlers which is probably growing and
causing your problem. Normally it shouldn't matter how often you repeat
the logging.getLogger(name) call as long as the name is always the same.
For easier diagnosis you can include the loggername ("%(name)s") in the
message.

Do you maintain a hierarchy of loggers (names with dots) with a handler for
each logger? Then it might help to set the loggers' 'propagate' attribute
to False.

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


Re: Find similar images using python

2006-03-31 Thread Christos Georgiou
On 29 Mar 2006 05:06:10 -0800, rumours say that "Thomas W"
<[EMAIL PROTECTED]> might have written:

>How can I use python to find images that looks quite similar? Thought
>I'd scale the images down to 32x32 and convert it to use a standard
>palette of 256 colors then compare the result pixel for pixel etc, but
>it seems as if this would take a very long time to do when processing
>lots of images.

I see someone suggested imgseek.  This uses a Haar transform to compare
images (check on it).  I did make a module based on imgseek, and together
with PIL, I manage my archive of email attachments (it's incredible how many
different versions of the same picture people send you: gif, jpg in
different sizes etc) and it works fairly well.

E-mail me if you want the module, I don't think I have it currently online
anywhere.
-- 
TZOTZIOY, I speak England very best.
"Dear Paul,
please stop spamming us."
The Corinthians
-- 
http://mail.python.org/mailman/listinfo/python-list


running IDLE from another program?

2006-03-31 Thread John Salerno
If I want to write my code in a separate text editor (I like UltraEdit) 
but then press a single button to have that code run in the IDLE 
environment, is that possible? I know that you can configure UE to run 
external tools, but I can't figure out how to run IDLE this way, because 
when I check on its properties to find it's file path, it is just the 
Python directory itself.

So not only do I not know where to find the actual file to run IDLE (if 
possible), but I then don't know how to run my code in IDLE (again, if 
possible). I guess I could write a script or macro that opens IDLE with 
a new code window ready, copies and pastes my code from UE into this 
window, then runs that code, but that seems messy, if that would even 
work. And wouldn't it also prompt me to save the file before running it 
in IDLE anyway?

So it comes down to this: is it possible to run code (that was created 
in a separate editor) in IDLE in some kind of automated way?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: how to comment lot of lines in python

2006-03-31 Thread Dave Mandelin
I often use

if 0:
bunch of lines of code

That way, it's very easy to reenable the code, or to add an else, etc.
I can even put things like 'if 0 and USE_FOO_FEATURE' to document what
is being commented out. It's much more flexible than commenting out.

--
Want to play tabletop RPGs over the internet?
Check out Koboldsoft RPZen:http://www.koboldsoft.com

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


Re: re.sub problem

2006-03-31 Thread RunLevelZero
Glad I could help.

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


Re: any() and all() on empty list?

2006-03-31 Thread Carl Banks

Ron Adam wrote:
> Carl Banks wrote:
>
> > In Python, yes and no are the only possible answers.  Probably the only
> > analogous thing you could do in Python would be for all() to raise
> > ValueError when passed an empty sequence.
>
> There is also 'None' which serves a similar purpose of indicating an
> invalid value when passing arguments.

If all() were to return None, then if would essentially be like
returning False, because an if-statement would treat False and None the
same (as would most anything else expecting a boolean value).

The only reasonable way to say "false assumption" in Python is to raise
an exception.


Carl Banks

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


Re: logging producing redundant entries

2006-03-31 Thread Jed Parsons

Thanks, Peter and alex23,

The metalog test shows that the code is only being executed once at a time.

And if I take those lines and put them in a shell script (fixing the 
FileHandler - sorry about the bad copy there), they work as expected, 
producing a single log entry.

So I'm left with:

- logging code that works properly in isolation in a shell script
- zope extension code that gets called only once (metalog test)
- logging code produces multiple entries when executed in extension
- logging code seems to produce more and more entries over time

Am I somehow accumulating a growing list of loggers by having this code 
at the top of a zope Extension?  If I cause the extension to be 
re-evaluated, do I somehow attach another logger?  (I'm grasping at 
straws...)

I've tried the following to only call getLogger once, but it doesn't 
seem to help:

try:
 _logger
except NameError:
 _logger = logging.getLogger('login')
 etc...

Thanks again for any suggestions.  I'm pretty well baffled.
j

Peter Otten wrote:
> Jed Parsons wrote:
> 
>> I'm using the logging module for the first time.  I'm using it from
>> within Zope Extensions.
>>
>> My problem is that, for every event logged, the logger is producing
>> multiple identical entries with the timestamp the same down to the
>> millisecond.
>>
>> Is this something I'm doing wrong?
>>
>> Log snippet:
>>
>> 2006-03-30 16:20:14,173 INFO: Login: Jed Parsons
>> 2006-03-30 16:20:14,173 INFO: Login: Jed Parsons
>> 2006-03-30 16:20:14,173 INFO: Login: Jed Parsons
>> 2006-03-30 16:20:14,173 INFO: Login: Jed Parsons
>> 2006-03-30 16:20:14,173 INFO: Login: Jed Parsons
>> 2006-03-30 16:20:14,173 INFO: Login: Jed Parsons
>> 2006-03-30 16:20:14,173 INFO: Login: Jed Parsons
>> 2006-03-30 16:20:14,173 INFO: Login: Jed Parsons
>>
>> I would like only one of the above lines in my log file; not all those
>> copies.
>>
>> I'm using this simple logging setup at the top of a zope Extension module:
>>
>>  import logging
>>  # basicConfig for python 2.3
>>  logging.basicConfig()
>>  _logger = logging.getLogger("login")
>>  _logger.setLevel(logging.DEBUG)
>>  _handler = logging.FileHandler(LOG_ROOT, 'login.log'))
>>  _formatter = logging.Formatter("%(asctime)s %(levelname)s:
>> %(message)s")
>>  _handler.setFormatter(_formatter)
>>  _logger.addHandler(_handler)
>>
>> So these are global to the module.  The log lines above were produced by
>> what I expected would be a single call to _logger.info() in a function
>> in the module:
>>
>>  _logger.info("Login: %s %s" % (firstname, lastname))
>>
>> Can anyone explain what I'm doing wrong?  Many thanks,
> 
> Please cut and paste -- the FileHandler arguments are wrong and there is an
> extra ')'. As alex23 said, basicConfig() adds a handler, but that logs to
> stderr by default. You seem to be executing the code given above multiple
> times. You can verify that by prepending your snippet with
> 
> f = open("metalog.txt", "a")
> f.write("configuring handler\n")
> f.close()
> 
> If metalog.txt contains multiple lines after your program has terminated
> (you may have to shut down Zope -- don't know about that), a quick fix
> might be
> 
> import logging
> if not logging.root.handlers:
> # your setup code
> 
> Peter

-- 
Jed Parsons   Industrial Light + Magic  (415) 746-2974

grep(do{for(ord){(!$_&&print"$s\n")||(($O+=(($_-1)%6+1)and
grep(vec($s,$O++,1)=1,1..int(($_-6*6-1)/6}},(split(//,
"++,++2-27,280,481=1-7.1++2,800+++2,8310/1+4131+1++2,80\0.  What!?")));
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: member variables in python

2006-03-31 Thread Kent Johnson
PyPK wrote:
> ok I reason I was going with globals is that i use this variable in
> another class something like this along with above
> 
> testflag = 0
> 
> class AA:
>def __init__(...):
> 
>   def methos(self,...):
>global testflag
>testflag = xx
> 
> class BB:
> def __init__(...):
> 
>def method2(..):
>if testflag:
>print "do this"
> is there a better way to access this if we go with what you mentioned
> in another class ..

1. Tell BB about the AA instance when it is created:

class BB:
   def __init__(self, aa):
 self.aa = aa

   def method(self):
 if self.aa.testflag:

2. Pass the flag to BB.method() directly:

   def method(self, testflag):
 if testflag:

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


Re: re.sub problem

2006-03-31 Thread veracon
Thanks a lot! Compiling with re.DOTALL did fix my problem for the most
part; there still are a few problems with my code, but I think I can
fix those myself.

Again, thanks!

> Okay I just woke up and haven't had enough coffee so if I'm off here
> please forgive me.  Are you saying that if there is an emptly line then
> it borks?  If so just use re.S ( re.DOTALL ) and that should take care
> of it.  It will treat the ( . ) special.  Otherwise it ignores new
> lines.

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


Re: How to search HUGE XML with DOM?

2006-03-31 Thread Ivan Vinogradov

On 31-Mar-06, at 11:17 AM, bayerj wrote:

> Mind, that XML documents are not more flexible than RDBMS.
>
> You can represent any XML document in a RDBMS. You cannot represent  
> any
> RDBMS in an XML document. RDBMS are (strictly spoken) relations and  
> XML
> documents are trees. Relations are superior to trees, at least
> mathematically speaking.
>
> Once you have set up your system in a practicable way (e.G. not  
> needing
> to create a new table via SQL Queries for a new type of node, which
> would be a pain) SQL is far superior to XML.
>
> Anyway, cElementTree seems to be the best way to go for you now. Its
> performance is untopped by any other python xml library, as far as I
> know.
>
> -- 
> http://mail.python.org/mailman/listinfo/python-list

If I may hijack this thread for a bit, I'd like to dig deeper into  
this issue :)

Currently my simulation program produces an XML log file with events  
represented as nodes.
Often those files grow to multiple GB size. I like this setup because  
the format is open
and easily parse-able with a variety of tools. So I have a bunch I  
scripts that can analyze
different aspects of the simulation.

I have not much clue about databases, except that they exist,  
somewhat complex, and often
use proprietary formats for efficiency. So any points on whether RDBM- 
based setup
would be better would be greatly appreciated.

Even trivial aspects, such as whether to produce RDBM during the  
simulation, or convert the complete XML log file into one, are not  
entirely clear to me. I gather that RDBM would be much better suited  
for analysis, but what about portability ? Is database file a  
separate entity that may be passed around?

Apologies if this seems like a selfish question, perhaps consider it  
a full disclosure, different set-ups/examples would be appreciated as  
well.

--
Cheers, Ivan

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


Re: how to comment lot of lines in python

2006-03-31 Thread Michael Hobbs
Eric Deveaud wrote:
> [EMAIL PROTECTED] wrote:
>   
>>  Eric Deveaud wrote:
>> 
>>> [EMAIL PROTECTED] wrote:
>>>   
  Like in C we comment like
  /*
  Bunch of lines of code
  */

  Should we use docstring """ """
 
>>> I would say NO.  docstring are displayed by pydoc, thus a pydoc on your
>>> code will display some inconsistent information ;-)
>>>
>>>   
>>  docstrings are a bit of a magical construct.  Not all strings in a
>>  function are docstrings.
>> 
>
>
> yep fogotten that triple quotted strings are considered as docstring
> only if they are the first lines of the module/fonction/class/method 
> excluding the comments lines.
>   
The official rule is that if *any* string is the first line of a 
function/etc, it is considered a docstring. It's just standard 
convention to use the triple quotes for docstrings. As you mentioned, 
you can use triple quotes for any string; likewise, you can use standard 
quotes ( ' or " ) for docstrings as well.

- Mike


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


base64 memory question

2006-03-31 Thread Michele Petrazzo
Hi ng,
I see that after en encoding with base64, the memory used for the
variable that I use for store the encoded data, after deleted, python
keep a part of that memory:

#ls -lh on /tmp/test_zero
#-rw-r--r--  1 michele michele 9,8M 2006-03-31 18:32 /tmp/test_zero


michele:~$ python2.4
Python 2.4.2 (#2, Nov 20 2005, 17:04:48)
[GCC 4.0.3 2005 (prerelease) (Debian 4.0.2-4)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import base64

# Now top say me:
6217 michele   15   0  4412 2536 3336 S  0.0  0.3   0:00.01 python2.4

>>> b = base64.encodestring(open("/tmp/test_zero", "rb").read())

#top:
6217 michele   15   0 39156  36m 3376 S 19.6  4.8   0:00.60 python2.4

>>> del base64, b

#top
6217 michele   15   0 25644  23m 3376 S  0.0  3.1   0:00.61 python2.4

So like I can read from the top, python "forgot" to free that part of
memory. Is this normal? Is there a solution for free that memory?

P.s. The same happen on my win2k machine with py 2.4.2

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


Re: Spawn/Kill Process

2006-03-31 Thread Daniel Nogradi
> I need to write a script that starts an exe and then continues through
> the script. I am able to start the exe file but my script doesn't
> continue because the process I start runs in the background of Windows
> (as it is supposed to). I have tried using both os.system and os.popen
> to get around this but still no luck. It seems as if Python does not
> move to the next line of code UNTIL the program spawned completes
> (which this one never will as it is supposed to continuously run in
> the background). Does anyone know of a way around this so I can spawn
> the program and continue through my script?

You might want to try the spawn* family of functions and pass the
P_NOWAIT mode parameter. You can read all things spawn* here:

http://docs.python.org/lib/os-process.html
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: member variables in python

2006-03-31 Thread bruno at modulix
PyPK wrote:
> ok I reason I was going with globals is that i use this variable in
> another class something like this along with above
> 
> testflag = 0
> 
> class AA:
>def __init__(...):
> 
>   def methos(self,...):
>global testflag
>testflag = xx
> 
> class BB:
> def __init__(...):
> 
>def method2(..):
>if testflag:
>print "do this"

Seems that you're looking for a logging package (hint: there's one in
the standard lib).

> is there a better way to access this if we go with what you mentioned
> in another class ..
> I wanted to avoid globals thats the reason i am looking for better
> solution ..
> 

A general solution would be a combination of
1/ a Singleton or Monostate (for storing application-wide settings) and
2/ a method decorator managing additionnal responsabilities according to
the values of 1.

There are examples of Singleton/Borg/Monostate/whatnot in the Python
cookbook and elsewhere - as usual, google is your friend - and a Q&D
example of decorator doing this kind of jobs in the decorator library
http://wiki.python.org/moin/PythonDecoratorLibrary

My 2 cents
-- 
bruno desthuilliers
python -c "print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for
p in '[EMAIL PROTECTED]'.split('@')])"
-- 
http://mail.python.org/mailman/listinfo/python-list


best way to index numerical data ?

2006-03-31 Thread Jack
Hi I have a lot of data that is in a TEXT file which are numbers does
anyone have a good suggestion for indexing TEXT numbers (zip codes,
other codes, dollar amounts, quantities, etc). since Lucene and other
indexers are really optimized for Alpha character indexing. What
approaches are typically taken in computer science for example to index
text numbers..hash maps or something else ??

Thanks,

Jack

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


Re: member variables in python

2006-03-31 Thread PyPK
I see that.But here in my case the testflags is computed inside the
member function something like

class AA:

def __init__(self):
self.test_flag = 0 # initialize

def methods(self, value):
save_value = _munge(value)
self.test_flag = save_value

Now basically I want use this self.test_flag in another class ..
Basically I wanted to know if there is a better way than what i did
before..not necessarly a member variable way ..just looking for a more
eligant way if there is any..

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


Re: re.sub problem

2006-03-31 Thread RunLevelZero
Okay I just woke up and haven't had enough coffee so if I'm off here
please forgive me.  Are you saying that if there is an emptly line then
it borks?  If so just use re.S ( re.DOTALL ) and that should take care
of it.  It will treat the ( . ) special.  Otherwise it ignores new
lines.

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


Re: wx.checklistbox

2006-03-31 Thread luca72
sorry
appenditems

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


Re: Best IDE for Python?

2006-03-31 Thread Fabio Zadrozny
On 3/31/06, Keith B. Perry <[EMAIL PROTECTED]> wrote:
You are probably right, and I will
definitely take a look at the starter manual.  Hopefully it also
works well on classes that I create?  You got some nice docs there.
Surely does ;-) 


Cheers,

Fabio

Thanks for the tip! 
On 3/31/06, Fabio Zadrozny <
[EMAIL PROTECTED]> wrote:

Well, in pydev you surely can have code-completion on 'math.'I think you got some wrong configuration...  Have you read the getting started manual? (

http://www.fabioz.com/pydev/manual_101_root.html) 

On 31 Mar 2006 07:44:38 -0800, kbperry <

[EMAIL PROTECTED]> wrote:


To me, it just doesn't behave the same way as Eclipse for java.  I haveused the plug-in, and I usually use it on my home machine ( I am stilla student).  For example, in Java eclipse, if you import a module like
math, then if you want to use a math function, you just type math +period, and then all the functions pop up in a scroll menu.  I lovethis.  I am not searching through online documentation...etc just tofind some stupid method/function that I know is there.  It doesn't seem 
to behave like this for PythonI wish it did.I still love programming in Python, though.
--http://mail.python.org/mailman/listinfo/python-list 


 


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

Re: Find similar images using python

2006-03-31 Thread Terry Hancock
Thomas W wrote:

>How can I use python to find images that looks quite similar? Thought
>I'd scale the images down to 32x32 and convert it to use a standard
>palette of 256 colors then compare the result pixel for pixel etc, but
>it seems as if this would take a very long time to do when processing
>lots of images.
>
>Any hint/clue on this subject would be appreciated.
>  
>
This really depends on what is meant by "quite similar".

If you mean "to the human eye, the two pictures are identical",
as in the case of a tool to get rid of trivially-different duplications,
then you can use the technique you propose.  I don't imagine that
you can save any time over that process.  You'd use something
like PIL to do the comparisons, of course -- I suspect you want to
do something like:

1) resize both
2) quantize the colors
3) subtract the two images
4) resize to 1x1
5) threshhold the result (i.e. we've used PIL to sum the differences)

strictly speaking, it might be more mathematically ideal to take
the sum of the difference of the squares of the pixels (i.e. compute
chi-square).  This of course, avoids the painfully slow process of
comparing pixel-by-pixel in a Python loop, which would, of course
be painfully slow.

This is conceptually equivalent to using an "epsilon" to test "equality"
of floating point numbers.

The more general case of matching images with similar content (but
which would be recognizeably different to the human eye), is a much
more challenging cutting-edge AI problem, as has already been
mentioned -- but I was going to mention imgSeek myself (I see someone's
already given you the link).



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


Re: member variables in python

2006-03-31 Thread Fredrik Lundh
"PyPK" wrote:

> hi how do I write this better with member variables rather than global
> as you see below.
>
> eg:
>
> test-flag = 0
>
> class AA:
>def __init__(...):
>
>   def methos(self,...):
>global test-flag
>test-flag = xx
>
> instead of something like above ..how do i put it i terms of member
> variables?

you mean something like

class AA:

def __init__(self):
self.test_flag = 0 # initialize

def methods(self, value):
self.test_flag = value

# ...

aa = AA()
aa.methods(1)
print aa.test_flag

?





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


Re: How to search HUGE XML with DOM?

2006-03-31 Thread bayerj
Mind, that XML documents are not more flexible than RDBMS.

You can represent any XML document in a RDBMS. You cannot represent any
RDBMS in an XML document. RDBMS are (strictly spoken) relations and XML
documents are trees. Relations are superior to trees, at least
mathematically speaking.

Once you have set up your system in a practicable way (e.G. not needing
to create a new table via SQL Queries for a new type of node, which
would be a pain) SQL is far superior to XML.

Anyway, cElementTree seems to be the best way to go for you now. Its
performance is untopped by any other python xml library, as far as I
know.

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


Re: member variables in python

2006-03-31 Thread Grant Edwards
On 2006-03-31, PyPK <[EMAIL PROTECTED]> wrote:

> hi how do I write this better with member variables

Sorry, I don't know what "member variables" are.

> rather than global as you see below.

What you did below isn't global.  It's scope is limited to the
module containing the class.  If you got something that's used
by multiple classes in the module, then module-scope seems like
the logical choice.

> eg:
>
> test-flag = 0
>
> class AA:
>def __init__(...):
>
>   def methos(self,...):
>global test-flag
>test-flag = xx
>
> instead of something like above ..how do i put it i terms of member
> variables?

Dunno.  What are "member varibles"?

-- 
Grant Edwards   grante Yow!  Don't SANFORIZE me!!
  at   
   visi.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: cd burning

2006-03-31 Thread RunLevelZero
I am hopeing something has developed myself.  I have been waiting
awhile.  I simply don't want to use cdrecord or cdrdao.  If I had the
know how I would be working on it but I believe this is a massive
undertaking and rather hard to accomplish.  I do hope this happens very
soon though.  Libburn might be of some use to you? I know FreeBSD
compiled some binding for python but the main libburn site only seems
to officially have ruby binding atm.  http://icculus.org/burn/.

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


Re: How to debug python code?

2006-03-31 Thread pruebauno
[EMAIL PROTECTED] wrote:
> hi,
>I am new to Python programming.I am not getting exactly pdb.Can
> anyone tell me effective  way to debug python code?
>Please give me any example.
>Looking for responce.
>Thank You.
> Sushant

If you are having issues you also might want to try:
http://pychecker.sourceforge.net/
and see if it finds your problem. You might get lucky.

Or just make the bigger install:
http://stani.be/python/spe/blog/
that one already includes pychecker and a python debugger.

Sorry for the noise if you were just looking for instructions for pdb.

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


Re: How to debug python code?

2006-03-31 Thread R. Bernstein
Dennis Lee Bieber <[EMAIL PROTECTED]> writes:

> On 30 Mar 2006 21:18:50 -0800, [EMAIL PROTECTED] declaimed the
> following in comp.lang.python:
> 
> > hi,
> >I am new to Python programming.I am not getting exactly pdb.Can
> > anyone tell me effective  way to debug python code?
> 
>   I think I toyed with pdb back around 1993... Never needed it...
> 
>   Of course, with so many different languages and debuggers in my
> life, I've never found time to master any but the old VMS debugger
> (which is nothing more than a very complex error handler )

That's one reason why in my bash and GNU make debugger (and in
extending pdb), I've stuck to the gdb command set: the effort that is
spent mastering gdb can be transfered in the GNU Make, Bash, *AND*
Python debuggers.
-- 
http://mail.python.org/mailman/listinfo/python-list


  1   2   >