Re: multiple file deletes using ftp.delete

2007-01-20 Thread Drew
On Jan 19, 11:16 pm, "Drew" <[EMAIL PROTECTED]> wrote:
> Hi all
> I'm fairly new to python so please forgive my lack of comprehension of
> the obvious.
>
> I'm writing a script to ftp files to a server. This script will run
> weekly. Part of the script first deletes the previous weeks files. The
> problem is I'm never sure of the exact number and full name of the
> files that need to be deleted. All the files start with the same string
> but have different extensions (eg drew.1 drew.2 drew.tmp drew.hlp). So
> I was wondering if anybody knows how to use a wild card similar to * in
> UNIX to do the delete? Something like:
>
> ftp.delete("drew.*")
>
> Any help or suggestions would be greatly appreciated.
>
> Drew Dowling

I should have summed if up thus: I'm trying to find a way to issue the
ftp mdelete command in python.

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


Does eval has the same features as Perl's?

2007-01-20 Thread Jm lists
Hello members,

I want to know does the "eval" in python have the same features as in
Perl (capture errors)?

For example,in perl I can wrote:

$re = eval { 1 / 0 };

Though 1/0 is a fatal error but since it's in "eval" block so the perl
interpreter doesn't get exit.

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


Re: Code reformater?

2007-01-20 Thread Mario Wehbrink
Vincent Delporte schrieb in comp.lang.python:

Hi

>   When I copy/paste Python code from the web, every so often,
> the TABs are wrong, which means that the code won't work and I have to
> manually reformat the code.
>
> Is there a code reformater that can parse the code to make it right?

It may help to look at the settings of your editor. I think Vim (and
surely emacs) can help you with that.

(look at :help retab, paste, expandtab in (g)Vim)

Mario


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


Re: PQueue and Python 2.5

2007-01-20 Thread Martin v. Löwis
Berteun Damman schrieb:
> I haven't got a clue how to investigate this, but I would be willing to
> help if someone has any ideas.

There are a number of problems in this code; the most significant one is
the incorrect usage of memory management API. In pqueue_dealloc, the
call PyMem_DEL(pqp) should read PyObject_DEL(pqp), as the object was
allocated with PyObject_NEW. Because this was a common error once,
Python up to 2.4 detected that error and silently corrected it (at some
runtime cost); Python 2.5 now has removed this work-around.

I'll contact the author.

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


Re: Does eval has the same features as Perl's?

2007-01-20 Thread Steven D'Aprano
On Sat, 20 Jan 2007 17:30:24 +0800, Jm lists wrote:

> Hello members,
> 
> I want to know does the "eval" in python have the same features as in
> Perl (capture errors)?
> 
> For example,in perl I can wrote:
> 
> $re = eval { 1 / 0 };
> 
> Though 1/0 is a fatal error but since it's in "eval" block so the perl
> interpreter doesn't get exit.

How hard would it be to actually try it?

>>> eval("1/0")
Traceback (most recent call last):
  File "", line 1, in 
  File "", line 1, in 
ZeroDivisionError: integer division or modulo by zero

It took about three seconds to actually test it.

eval has many security risks -- as a rule, you should never pass strings
you've got from the user to eval, unless you want the user to p0wn your
computer. It is harder than you might think to make eval safe -- you
should seriously consider it an advanced tool, not a basic tool. As a
newbie, you should work under the following rule:

"If I think I need to use eval, I'm probably wrong."

I've been using Python for seven or eight years, and I don't think I've
ever used eval in serious code.

Now, suppose you find yourself wanting to use eval. You've considered the
above rule carefully, and decided that it doesn't apply in this case.
You've been careful to use it only on safe strings, not arbitrary strings
from users. How do you use eval so it captures errors?

try:
eval("1/0")
except ZeroDivisionError: # capture only one error
pass


or something like this:

try:
eval("something or other goes here")
except Exception: # capture any error
pass



-- 
Steven.

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


Re: Py 2.5 on Language Shootout

2007-01-20 Thread bearophileHUGS
[EMAIL PROTECTED]:
> In reality the choice would be C++ because of OO and STL.

I have seen that when Python+Psyco are too much slow, D language is a
good sweet half point between Python and C++ :-) Fast as C++ and with a
simpler syntax and semantics (Pyrex isn't bad, but D gives high-level
things at higher speed). And in the future ShedSkin and RPython may
become options too.

Bye,
bearophile

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


Re: Does eval has the same features as Perl's?

2007-01-20 Thread Jm lists
Thank you.I'm just learning Python and want to make something clear to me.:)

2007/1/20, Steven D'Aprano <[EMAIL PROTECTED]>:
> On Sat, 20 Jan 2007 17:30:24 +0800, Jm lists wrote:
>
> > Hello members,
> >
> > I want to know does the "eval" in python have the same features as in
> > Perl (capture errors)?
> >
> > For example,in perl I can wrote:
> >
> > $re = eval { 1 / 0 };
> >
> > Though 1/0 is a fatal error but since it's in "eval" block so the perl
> > interpreter doesn't get exit.
>
> How hard would it be to actually try it?
>
> >>> eval("1/0")
> Traceback (most recent call last):
>   File "", line 1, in 
>   File "", line 1, in 
> ZeroDivisionError: integer division or modulo by zero
>
> It took about three seconds to actually test it.
>
> eval has many security risks -- as a rule, you should never pass strings
> you've got from the user to eval, unless you want the user to p0wn your
> computer. It is harder than you might think to make eval safe -- you
> should seriously consider it an advanced tool, not a basic tool. As a
> newbie, you should work under the following rule:
>
> "If I think I need to use eval, I'm probably wrong."
>
> I've been using Python for seven or eight years, and I don't think I've
> ever used eval in serious code.
>
> Now, suppose you find yourself wanting to use eval. You've considered the
> above rule carefully, and decided that it doesn't apply in this case.
> You've been careful to use it only on safe strings, not arbitrary strings
> from users. How do you use eval so it captures errors?
>
> try:
> eval("1/0")
> except ZeroDivisionError: # capture only one error
> pass
>
>
> or something like this:
>
> try:
> eval("something or other goes here")
> except Exception: # capture any error
> pass
>
>
>
> --
> Steven.
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Match 2 words in a line of file

2007-01-20 Thread Steven D'Aprano
On Fri, 19 Jan 2007 22:57:37 -0800, Rickard Lindberg wrote:

> Daniel Klein wrote:
> 
>> 2) This can be resolved with
>>
>> templine = ' ' + line + ' '
>> if ' ' + word1 + ' ' in templine and ' ' + word2 + ' ' in templine:
> 
> But then you will still have a problem to match the word "foo" in a
> string like "bar (foo)".

That's a good point for a general word-finder application, but in the case
of the Original Poster's problem, it depends on the data he is dealing
with and the consequences of errors.

If the consequences are serious, then he may need to take extra
precautions. But if the consequences are insignificant, then the fastest,
most reliable solution is probably a simple generator:

def find_new_events(text):
for line in text.splitlines():
line = line.lower() # remove this for case-sensitive matches
if "event" in line and "new" in line:
yield line

To get all the matching lines at once, use list(find_new_events(test)).

This is probably going to be significantly faster than a regex.

So that's three possible solutions:

(1) Use a quick non-regex matcher, and deal with false positives later;

(2) Use a slow potentially complicated regex; or

(3) Use a quick non-regex matcher to eliminate obvious non-matches, then
pass the results to a slow regex to eliminate any remaining false
positives.


Which is best will depend on the O.P.'s expected data. As always, resist
the temptation to guess which is faster, and instead use the timeit module
to measure it.


-- 
Steven.

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


pywin32 for Windows x64

2007-01-20 Thread Bernard Lebel
Hello,

Softimage has gracefully released an x64 build of the pywin32
extension, free for download.

http://webrel2.softimage.com/open/products/xsi/v6/pywin32-207.win64-py2.4.exe


(if that link doesn't work, go to
http://www.softimage.com/downloads/XSI6_EssAdv/default.aspx, and look
for Python 64)



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


RE: OT Annoying Habits (Was: when format strings attack)

2007-01-20 Thread Michael . Coll-Barth

::CLAP CLAP::

thank you!

I have been in the newsgroups for over 12 years and I never cared about the 
top/bottom post silliness.  All I care about is that the message is clearly 
written.  Everything else is doggerel.

> -Original Message-
> From: Carroll, Barry
> 
> Personally, I don't think top-posting is the most annoying newsgroup
> habit.  I think it's making a big fuss about minor inconveniences.  

::CLAP CLAP::

thank you!

I have been in the newsgroups for over 12 years and I never cared about the 
top/bottom post silliness.  All I care about is that the message is clearly 
written.  Everything else is doggerel.


The information contained in this message and any attachment may be
proprietary, confidential, and privileged or subject to the work
product doctrine and thus protected from disclosure.  If the reader
of this message is not the intended recipient, or an employee or
agent responsible for delivering this message to the intended
recipient, you are hereby notified that any dissemination,
distribution or copying of this communication is strictly prohibited.
If you have received this communication in error, please notify me
immediately by replying to this message and deleting it and all
copies and backups thereof.  Thank you.

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


Re: OT Annoying Habits (Was: when format strings attack)

2007-01-20 Thread Dane Jensen
On Friday 19 January 2007 22:51, Hendrik van Rooyen wrote:
> "Steven D'Aprano" <[EMAIL PROTECTED]> wrote:
> > Or perhaps I should say:
> >
> > .snoitnevnoc
> > hsilgnE tpada )ylbissop revenehw( dluohs ew os dna ,naitraM ton
> > ,puorgswen egaugnal hsilgnE na no er'ew ,segaugnal hcus era ereht fi neve
> > tuB
>
> First I thought it was Welsh or Cornish or something.
>
> Then it was like being in my first year of school again-
> reading letter by letter.  Never realised how difficult it is.
>
> I suppose it will improve with practice.

Not to steer this topic even futher off topic, but this is something that's 
been on my mind lately...

The biggest problem with it that the letters were forwards and not also 
backwards (and the parens). But then, it's my understanding that as a 
left-handed person, reading and writing backwards is far easier for me than 
for the majority that is right-handed. Have any other lefties found that the 
case? 

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


Re: PQueue and Python 2.5

2007-01-20 Thread Giovanni Bajo
On 20/01/2007 11.29, Martin v. Löwis wrote:

>> I haven't got a clue how to investigate this, but I would be willing to
>> help if someone has any ideas.
> 
> There are a number of problems in this code; the most significant one is
> the incorrect usage of memory management API. In pqueue_dealloc, the
> call PyMem_DEL(pqp) should read PyObject_DEL(pqp), as the object was
> allocated with PyObject_NEW. Because this was a common error once,
> Python up to 2.4 detected that error and silently corrected it (at some
> runtime cost); Python 2.5 now has removed this work-around.

And by the way, this is also a FAQ:

http://effbot.org/pyfaq/why-does-my-c-extension-suddenly-crash-under-2.5.htm

and even explained in the Misc/NEWS of Python 2.5.
-- 
Giovanni Bajo
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Match 2 words in a line of file

2007-01-20 Thread Alex


egc> how do i write a regexp for this.. or better yet shd i even be using
egc> regexp or is there a better way to do this
"A team of engineers were faced with a problem; they decided to handle
it with regular expressions. Now they had two problems"


Regular expressions are not always the best solution. Others have
pointed out how it can work with "if word in line", this approach will
do if you're dealing with simple cases.


Take a look at this discussion, it is very informative:
http://blogs.msdn.com/oldnewthing/archive/2006/05/22/603788.aspx

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


RE: OT Annoying Habits (Was: when format strings attack)

2007-01-20 Thread Nick Maclaren

In article <[EMAIL PROTECTED]>,
"Carroll, Barry" <[EMAIL PROTECTED]> writes:
|> 
|> My thanks to Aahz and the others who responded.  I also did some
|> Googling on my own.  I found out that top-posting is the norm in the
|> e-mail world.  Bottom- and inline-posting are the norm in the newsgroup
|> world. =20

Sorry, even that is not so.  I have been using Email since the 1960s,
and top-posting has been used only by the inconsiderate.

Note that, when you include a complete document in a message (whether
Email or anything else), then you should put it at the bottom.  Rather
like an appendix.  But top-posting when you are responding to Email
is as discourteous as top-posting when you are responding to newsgroups.

|> So I concede the point, and I'm bottom-posting like a good citizen. =20

Excellent!


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


Re: OT Annoying Habits (Was: when format strings attack)

2007-01-20 Thread Neil Cerutti
On 2007-01-20, Nick Maclaren <[EMAIL PROTECTED]> wrote:
>
> In article <[EMAIL PROTECTED]>,
> "Carroll, Barry" <[EMAIL PROTECTED]> writes:
>|> 
>|> My thanks to Aahz and the others who responded.  I also did some
>|> Googling on my own.  I found out that top-posting is the norm in the
>|> e-mail world.  Bottom- and inline-posting are the norm in the newsgroup
>|> world. =20
>
> Sorry, even that is not so.  I have been using Email since the 1960s,
> and top-posting has been used only by the inconsiderate.

...or the beleaguered. Since my school's IT switched to Exchange,
correct email composition is really annoying.

The only way to do it is to manually cut into a real editor, and
then past back in the entire message. This is not worth the
hassle for interoffice communication, since everyone else is
stuck with stupid top-posting, too.

It's been an interesting journey, from some unix-based terminal
email, to Lotus Notes (ARRGH!), then a happy time using IMAP, and
now back to (ARRGH!).

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


Re: OT Annoying Habits (Was: when format strings attack)

2007-01-20 Thread rzed
Dane Jensen <[EMAIL PROTECTED]> wrote in
news:[EMAIL PROTECTED]: 

> On Friday 19 January 2007 22:51, Hendrik van Rooyen wrote:
>> "Steven D'Aprano" <[EMAIL PROTECTED]> wrote:
>> > Or perhaps I should say:
>> >
>> > .snoitnevnoc
>> > hsilgnE tpada )ylbissop revenehw( dluohs ew os dna ,naitraM
>> > ton ,puorgswen egaugnal hsilgnE na no er'ew ,segaugnal hcus
>> > era ereht fi neve tuB
>>
>> First I thought it was Welsh or Cornish or something.
>>
>> Then it was like being in my first year of school again-
>> reading letter by letter.  Never realised how difficult it is.
>>
>> I suppose it will improve with practice.
> 
> Not to steer this topic even futher off topic, but this is
> something that's been on my mind lately...
> 
> The biggest problem with it that the letters were forwards and
> not also backwards (and the parens). But then, it's my
> understanding that as a left-handed person, reading and writing
> backwards is far easier for me than for the majority that is
> right-handed. Have any other lefties found that the case? 

How would anybody know? As a left-hander, I have found it easy 
enough to read backwards, but then, being left-handed forces a 
certain habit of adaptability in any case. Maybe that makes it 
easier to read backward, but that is not a task I'm often called 
on to do. It takes practice regardless.

This subthread reminds me of my *highly secure* plaintext 
encryption system that would render the sentence



as 



I think it looks vaguely Esperantonic (Esperantoid? Esperantic?), 
if anything. 

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


Re: The proper use of QSignalMapper

2007-01-20 Thread borntonetwork
David, thanks for your help. Unfortunately, all attempts of making this
solution work have failed. I would be interested to know if anyone has
used QSignalMapper successfully in a similar situation. For any
interested, I worked around the problem using a closure, which seems a
bit cleaner from a coding point of view, although I don't have any idea
if it is more efficient or not:

def makeHandler(self, idx):
def handler(state):
print 'The state is:', str(state), 'for checkbox object',
str(idx)
return handler

Each iteration then created a new function based on the closure:

self.handlers = []
for idx in range(1, maxIngredients+1):
wName = 'chkProductIngredientsDelete_'+str(idx)
w = self.__dict__[wName]
self.handlers.append(self.makeHandler(idx - 1))
self.window.connect(w, QtCore.SIGNAL("stateChanged(int)"),
self.handlers[idx - 1])

So now the output when each checkbox is clicked is something like this:

The state is: 2 for checkbox object 0
The state is: 2 for checkbox object 1
...



David Boddie wrote:
> borntonetwork wrote:
> > Thanks, David, for you help.
> >
> > When I change the slot function to what you show in your second
> > example, I get the same results: nothing.
>
> This may be due to something I missed in your code. When you
> connect the signal from the signal mapper to your class, you
> need to specify the signal as a C++ signature as well:
>
> self.connect(self.signalMapper, QtCore.SIGNAL(
>  "mapped(int)"),
>  self.deleteProductIngredient)
>
> The second example should now work.
>
> Looking at the first example, which uses SLOT() rather than specifying
> a Python method, the following might be due to the way you call
> connect, though it is surprising:
>
> > When I change it to what you
> > have in your first example, I get the following:
> >
> > Object::connect: No such slot QApplication::map()
> > Object::connect:  (sender name:   'chkProductIngredientsDelete_1')
> > Object::connect:  (receiver name: 'main.py')
>
> [...]
>
> It looks like you should try something like this:
>
>  self.connect(w, QtCore.SIGNAL("stateChanged(int)"),
>   self.signalMapper,
>   QtCore.SLOT("map()"))
>
> I can't understand why calling self.app.connect() would cause the
> connection to be attempted between self.signalMapper and self.app.
>
> Maybe someone on the PyQt/PyKDE mailing list would be able to
> explain the behaviour you're seeing:
> 
>   http://mats.imk.fraunhofer.de/mailman/listinfo/pykde
> 
> David

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


Re: when format strings attack

2007-01-20 Thread [EMAIL PROTECTED]
I will give the formatting a try.  I noticed another formatting thing I
wasn't looking for.  It is possible to have a \n at the end of a word
or at least that is how it is shown and fixed through python 2.5.  I
had an error where 36\n isn't a number.  easy to fix though.


Jeremy Sanders wrote:
> Steven D'Aprano wrote:
>
> > os.system('dir -l %s' % 'text.txt')
> >
> >
> > Now, there is a security risk: you might set command1 yourself, and
> > allow the user to set args. If command1 is an external application
> > with a security hole, and the user provides arguments that trigger that
> > bug, then naturally your application will inherit whatever security
> > vulnerabilities the external application suffers from. No surprises there.
>
> There are also big risks like this
>
> filename = 'foo; rm importantfile'
> cmd = 'ls %s' % filename
> os.system(cmd)
> 
> oops!
> 
> -- 
> Jeremy Sanders
> http://www.jeremysanders.net/

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


Re: Py 2.5 on Language Shootout

2007-01-20 Thread Carl Friedrich Bolz
[EMAIL PROTECTED] wrote:
 >>> Looking over the benchmarks, one gains the impression that Python is a
 >>> slow language.
 >> What does that even mean - a slow language?
 >>
 >
 > The alioth benchmarks provide a set of numbers by which
 > languages may be compared.

Wrong. The benchmarks provide a set of numbers by which
_implementations_ of languages can be compared. After all, it is
possible that someone implements a magic-pixie-dust-interpreter that
executes Python programs several orders of magnitude fastes than
CPython. Or you could say that C is slow because if you use CINT, a C
interpreter ( http://root.cern.ch/root/Cint.html ) to execute it, it is
slow.

Cheers,

Carl Friedrich Bolz

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


Re: OT Annoying Habits (Was: when format strings attack)

2007-01-20 Thread Roel Schroeven
Paul Rubin schreef:
> No.  Top posting has always been an aberrance.  It first appeared in
> Usenet when Usenet (a word whose etymology comes from "Unix" and
> "network") started attracting Microsoft Windows users, who were in the
> habit of using Windows products that top-posted.  That happened fairly
> far along in Usenet's evolution

Yep. The time when things started to go wrong is sometimes pinpointed as 
september 1993 and referred to as "Eternal September" 
(http://en.wikipedia.org/wiki/Eternal_September).

-- 
If I have been able to see further, it was only because I stood
on the shoulders of giants.  -- Isaac Newton

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


Re: Py 2.5 on Language Shootout

2007-01-20 Thread Ramon Diaz-Uriarte
On 1/20/07, Carl Friedrich Bolz <[EMAIL PROTECTED]> wrote:
> [EMAIL PROTECTED] wrote:
>  >>> Looking over the benchmarks, one gains the impression that Python is a
>  >>> slow language.
>  >> What does that even mean - a slow language?
>  >>
>  >
>  > The alioth benchmarks provide a set of numbers by which
>  > languages may be compared.
>
> Wrong. The benchmarks provide a set of numbers by which
> _implementations_ of languages can be compared. After all, it is
> possible that someone implements a magic-pixie-dust-interpreter that
> executes Python programs several orders of magnitude fastes than
> CPython. Or you could say that C is slow because if you use CINT, a C
> interpreter ( http://root.cern.ch/root/Cint.html ) to execute it, it is
> slow.


Yeah, but this is hair-splitting. Except for Jython, IronPython, and
Stackless, I think when we say "Python is slow/fast" we think CPython
(otherwise, we qualify the implementation). For that matter it is
often said "the GIL ..."; oh, but wait, Stackless ...

With other languages (e.g., Common Lisp) the separation between the
language and the implementation is key because, to begin with, there
is something external from, and independent of, any particular
implementation. That is not the case with Python.

And the example of CINT is hair-splitting to the nth power.To begin
with, I do not think CINT implements the full standard C. But even if
it were, when people think of C they rarely think of CINT.

I think readers understood the previous poster.

Best,

R.
>
> Cheers,
>
> Carl Friedrich Bolz
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>


-- 
Ramon Diaz-Uriarte
Statistical Computing Team
Structural Biology and Biocomputing Programme
Spanish National Cancer Centre (CNIO)
http://ligarto.org/rdiaz
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: OT Annoying Habits (Was: when format strings attack)

2007-01-20 Thread Roel Schroeven
Carroll, Barry schreef:
> Secondly, can someone point me to the Standard Usenet Convention that
> mandates against top-posting.  This is not sarcasm; I would really like
> to see it.  You see, I recently returned to Usenet after a LONG absence.
> When I was last a regular Usenet citizen the Internet was new, GUI
> interfaces were experimental and the World Wide Web didn't exist yet.
> Newsreader software was text-based.  Top-posting was the common
> practice, because it was the most convenient: you didn't have to page
> through an arbitrarily large number of messages, most of which you'd
> already read umpteen times, to get to the new stuff you were interested
> in.  

I started to use the Internet and Usenet around 1992 or 1993, and at the 
time 'Netiquette' was a very common word. Amongst others it recommends 
inline replying (as opposed to both top-posting and bottom-posting), in 
spirit if not in exact wording.

The Wikipedia article on Netiquette 
(http://en.wikipedia.org/wiki/Netiquette) mentions it with as many words:
"Quoting should be interspersed, with a response that follows the 
relevant quoted material. The result should read like a conversation, 
with quotes indented to aid in skimming. A common mistake is to put all 
new text above the quoted material, without trimming any irrelevant 
text. This results in a message that is much harder to follow and is 
much less clear in context."

All groups I read at the time used that convention. In my experience it 
was only in more recent times that people started to use top-posting, 
and then only in newsgroups, forums, etc. that didn't originate in the 
original Internet culture.

> So I'd really like to know what the standard is now.  I like to know
> which rules I'm choosing to break.  ;^)

You could do worse than RFC 1855 (http://www.dtcc.edu/cs/rfc1855.html) 
and the above mentioned Wikipedia article. Both cover many other issues 
regarding online behavior. There's also 
http://wiki.ursine.ca/Top_Posting which just covers quoting practices.

But note that inline replying isn't as wide-spread as I think it ought 
to be. Places that don't have roots in Internet or Unix culture are much 
more likely to accept and even encourage top-posting.

-- 
If I have been able to see further, it was only because I stood
on the shoulders of giants.  -- Isaac Newton

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


scipy.optimize.lbfgsb help please!!!

2007-01-20 Thread mclaugb
Does anyone out there have a piece of code that demonstrates the use of the 
lbfgsb multivariate, bounded solver in the scipy.optimize toolkit?  An 
example would get me started because my code below does not seem to work.
Thanks alot,
Bryan


I have tried to use the LBFGSB optimisation algorithm with these parameters:

xstart = [20,-20]


x, f, d = lbfgsb.fmin_l_bfgs_b(Permmin, x0, Jacobi, params, 0, 
[(0,100),(0,-50)] , 10, 1e7, 1e-5, 1e-8, -1, 500)

I am getting this error:

 "   x, f, d = lbfgsb.fmin_l_bfgs_b(Permmin, x0, Jacobi, params, 0, 
[(.001,100),(-50,-.001)] , 10, 1e7, 1e-5, 1e-8, -1, 500)
  File "C:\Python24\lib\site-packages\scipy\optimize\lbfgsb.py", line 197, 
in fmin_l_bfgs_b
isave, dsave)
ValueError: failed to initialize intent(inout) array -- expected elsize=8 
but got 4 -- input 'l' not compatible to 'd'
"

Permmin is a function that simply returns a vector array [xmin, ymin]

Jacobi returns an array [[A,B],[C,D]] which is the 2x2 Jacobi matrix

The rest of the parameters seem okay... 


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


Re: confused on python rpc with apache, is it possible?

2007-01-20 Thread krishnakant Mane
> Use mod_python with some xmlrpc handler. There is more than one around.
> Google for them. That way you can keep Apache for both Python and PHP.
>
I am confused.
I have some documents on xml-rpc but none of them mentioned apache.
Krishnakant.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: confused on python rpc with apache, is it possible?

2007-01-20 Thread Diez B. Roggisch
krishnakant Mane schrieb:
>> Use mod_python with some xmlrpc handler. There is more than one around.
>> Google for them. That way you can keep Apache for both Python and PHP.
>>
> I am confused.
> I have some documents on xml-rpc but none of them mentioned apache.

There is nothing an apache will do for you - except from possibly 
proxing python.

Go read up upon xmlrpc and python, possibly doing it with twisted, but 
there are other options.

Don't bother with the apache.

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


Re: **argv can't work

2007-01-20 Thread Roel Schroeven
Steven D'Aprano schreef:
> Its because of an evil terrorist plot. I suggest you invade Belgium, that
> should fix it.

Please notify me in time so I can emigrate before it's too late.

-- 
If I have been able to see further, it was only because I stood
on the shoulders of giants.  -- Isaac Newton

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


Re: The proper use of QSignalMapper

2007-01-20 Thread David Boddie
On Saturday 20 January 2007 16:03, borntonetwork wrote:

> David, thanks for your help. Unfortunately, all attempts of making this
> solution work have failed. I would be interested to know if anyone has
> used QSignalMapper successfully in a similar situation.

Looking again at what you originally wrote, and looking at your
solution below, I don't think it's really appropriate to use a
QSignalMapper for this purpose. (That's what I understood from the
signature of the deleteProductIngredient() method you had in your
original code.)

What you appear to want is a way of being notified about state
changes to widgets that also identifies the individual widget
that changed. You can do that by connecting the individual widgets
to the same slot and call sender() to find out which object emitted
the signal; for example:

# ...

for idx in range(1, maxIngredients+1):
wName = 'chkProductIngredientsDelete_'+str(idx)
w = self.__dict__[wName]
self.connect(w, QtCore.SIGNAL("stateChanged(int)"),
 self.deleteProductIngredient)

  def deleteProductIngredient(self, state):
  """Delete a product ingredient."""
  print self.sender(), "changed state to", state

What QSignalMapper does is collect signals from different objects,
assigning an ID to each of them, and emits a single signal with
an ID whenever it receives a signal from one of those objects.
In other words, it allows the actions of a group of objects to be
described by a parameter but discards the signal's arguments.
It's most useful for things like collections of push buttons where
you only need to know that they were clicked.

> For any interested, I worked around the problem using a closure,
> which seems a bit cleaner from a coding point of view, although
> I don't have any idea if it is more efficient or not:

[...]

> Each iteration then created a new function based on the closure:

[...]

It's good to know that you got something working in the end. There's
also another solution that involves QSignalMapper, but it may not make
the resulting code any simpler.

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


Re: Code reformater?

2007-01-20 Thread Siggi

"Vincent Delporte" wrote:
> Hello
>
> When I copy/paste Python code from the web, every so often,
> the TABs are wrong, which means that the code won't work and I have to
> manually reformat the code.
>
> Is there a code reformater that can parse the code to make it right?
>
> Thanks.

Maybe my thread "help: code formatter, 08/01/2007 helps a little? Here are
some of the answers:

*
Why don't you just write one? :)
Seriously: Try.
*
Tools\scripts\reindent.py in your Python distribution.
*
Why, yes, there is:
 http://lacusveris.com/PythonTidy/PythonTidy.python
*
tabnanny ?


siggi




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


Win GUI application: avoiding DOS console

2007-01-20 Thread Siggi
Hi all,

how do I avoid the DOS console show-up when starting a WinXP GUI application 
with mouseclick on the respective Python file?

I had this with my previous Python installation; it is very simple, 
something with a "-i" somewhere in the open command of the  MS Windows data 
types "PY" and "PYW". But after a new Python installation, this was lost, 
and I cannot find the instruction what to do.

Please help!

Thanks,

siggi 


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


Re: Win GUI application: avoiding DOS console

2007-01-20 Thread Bruno Desthuilliers
Siggi a écrit :
> Hi all,
> 
> how do I avoid the DOS console show-up when starting a WinXP GUI application 
> with mouseclick on the respective Python file?

rename yourfile.py to yourfile.pyw
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: OT Annoying Habits (Was: when format strings attack)

2007-01-20 Thread John Machin

[EMAIL PROTECTED] wrote:
[snip]

> The information contained in this message and any attachment may be
> proprietary, confidential, and privileged or subject to the work
> product doctrine and thus protected from disclosure.  If the reader
> of this message is not the intended recipient, or an employee or
> agent responsible for delivering this message to the intended
> recipient, you are hereby notified that any dissemination,
> distribution or copying of this communication is strictly prohibited.
> If you have received this communication in error, please notify me
> immediately by replying to this message and deleting it and all
> copies and backups thereof.  Thank you.

... and while we're talking about annoyances ...

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


Re: OT Annoying Habits

2007-01-20 Thread Jorge Godoy
"John Machin" <[EMAIL PROTECTED]> writes:

> [EMAIL PROTECTED] wrote:
> [snip]
>
>> The information contained in this message and any attachment may be
>> proprietary, confidential, and privileged or subject to the work
>> product doctrine and thus protected from disclosure.  If the reader
>> of this message is not the intended recipient, or an employee or
>> agent responsible for delivering this message to the intended
>> recipient, you are hereby notified that any dissemination,
>> distribution or copying of this communication is strictly prohibited.
>> If you have received this communication in error, please notify me
>> immediately by replying to this message and deleting it and all
>> copies and backups thereof.  Thank you.
>
> ... and while we're talking about annoyances ...

For those there is always http://www.goldmark.org/jeff/stupid-disclaimers/
:-) 


Be seeing you,
-- 
Jorge Godoy  <[EMAIL PROTECTED]>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Py 2.5 on Language Shootout

2007-01-20 Thread Isaac Gouy

[EMAIL PROTECTED] wrote:
> Isaac Gouy wrote:
> > [EMAIL PROTECTED] wrote:
> > > Alioth is a great site for selecting the language in which to implement
> > > primitives. Usually it's C.
> >
> > And for selecting a language for which you might need to implement
> > primitives in C :-)
>
> Well if you like C so much, just do it in C. ":-)"

iirc I've never written a program in C or C++ (although I may have
fixed one or two that someone else wrote).


>
> >
> > >
> > > Two of the alioth benchmarks, Partial-sums and Spectral-norm, could be
> > > done using Numarray, or would be done with Numarray if most of the
> > > program was in Python and there was a need to implement a similar
> > > numerical procedure. The speed would be up near the compiled language
> > > benchmarks. However the specific wording of these benchmarks prohibits
> > > this approach. Spectral-norm must pretend the dataset is infinite, and
> > > Partial-sums has to be implemented in a simple dumb loop.
> >
> > And we wouldn't use a naïve recursive algorithm to find fibonnaci
> > numbers ... unless we were interested in recursion for its own sake.
> >
> > Maybe the author of spectral-norm was interested in function calls.
> > Maybe the author of partial-sums was interested in simple dumb loops
> > and simple dumb Math.
>
> I am not disputing this. I think you take my point though.

I'm confident in my ability to misunderstood the point someone intended
to make - I think your point is some variation on 'we wouldn't write
the program like that' '"real-world" programs aren't like that'.


>
> >
> >
> > > Looking over the benchmarks, one gains the impression that Python is a
> > > slow language.
> >
> > What does that even mean - a slow language?
> >
>
> The alioth benchmarks provide a set of numbers by which
> languages may be compared.

Unless we notice that sometimes there's more than one language
implementation for some languages; unless we notice that sometimes
there's more than one program for the same language implementation.
(Unless we read the bold text on the homepage.)


>
> >
> > > My first serious Python programming exercise involved converting a 900
> > > line Bash Shell program to a 500 line Python program, with a speedup
> > > factor of 17. Using Python allowed an OO structure and advanced
> > > containers, meaning the program was more maintainable and portable,
> > > which were the main aims of the exercise. The speedup was a surprising
> > > and welcome side benefit. I think it was mosly because the Python
> > > byte-code interpreter is probably an order of magnitude faster than
> > > Bash's direct interpretation, and because in Python system calls to
> > > recurse directories and create symbolic links were not forked to
> > > separate processes. In fact I would guess that the overall speed of the
> > > Python program would be little less than a C program, given that most
> > > of the time would be spent in system calls.
> >
> > /I would guess/
>
> I don't have the time, or interest, to recode it in C to find out.
> In reality the choice would be C++ because of OO and STL.
> Perhaps traversing and linking a tree containing about 1000 files would
> not
> take a full second. I might be wrong. All i know is, its a lot faster
> than Bash.
>
> >
> > > Its almost possible to make a large Python program arbitrarily fast by
> > > profiling it and implementing slow bits as primitives. Size is probably
> > > of greater concern.
> >
> > We could read that simply as - /it's not possible/ to make a large
> > Python program arbitrarily fast. Is that what you meant?
>
> No. I meant that if my Python program is too big in terms of its
> execution memory
> requirements, then that would be a difficult issue to deal with. Rather
> than
> optimizing execution hotspots, I might have to use another language.
> 
> Cheers,
>  P.S. Alioth is a great site.

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


Re: confused on python rpc with apache, is it possible?

2007-01-20 Thread krishnakant Mane
On 20/01/07, Diez B. Roggisch <[EMAIL PROTECTED]> wrote:
>
> There is nothing an apache will do for you - except from possibly
> proxing python.
>
> Go read up upon xmlrpc and python, possibly doing it with twisted, but
> there are other options.
>
> Don't bother with the apache.

well in that case I don't need apache.
can I do xml-rpc using the default libraries that come with every
python installer?
is there some added advantage of using twisted?
Krishnakant.
-- 
http://mail.python.org/mailman/listinfo/python-list


python packages and __name__ query.

2007-01-20 Thread krishnakant Mane
hello all,
I had previously mentioned my doubt and confusion about having a
main() to be an entry point in my python based software.
I am still having a particular doubt.
I use cx freze for creating a python executable.  my software is
essentially a package containing a few modules and one file where I
created the main() function.
if needed and suggested by experts I may as well put it in my
__init__.py file of the package.
coming back to the point.  where do I put the following code
if __name__ == "__main__":
   main()

I have 5 modules in my package each doing a specific task.
and a file that contains the main() function.  the 5 modules and the
exec.py file all are in the same package.  if it is a wrong practice
please correct me.
so plese clear my doubt given the above situation.
Krishnakant.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: confused on python rpc with apache, is it possible?

2007-01-20 Thread Diez B. Roggisch
> 
> well in that case I don't need apache.
> can I do xml-rpc using the default libraries that come with every
> python installer?

Yes, and a simple look in the API docs would have convinced you of that. 
I suggest you start googling and reading.

> is there some added advantage of using twisted?

Certainly, but it comes with added burden of using and understanding a 
complex framework. Here also applies: read the docs.

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


Re: how to mimik a main() function to start a program with entry point?

2007-01-20 Thread Joshua J. Kugler
krishnakant Mane wrote:

> hello all.
> I have one simple query and may be that's to stupid to answer but I am
> not finding the answer any ways.
> I have a set of modules in my package and out if which one is my
> actual starting point to my entire program.  say for example I have an
> entire database application ready and I want a main (as in java or c)
> to initiate the program and may be bring up a login screen and then
> pass the control on to the main window.
> if I am giving raw source code that is easy because I will tell user
> to run the command ./xyz.py which has that function.
> but if I freze it into an executable with py2exe for example , how do
> I solve this problem?
> thanks.
> Krishnakant.

See http://www.artima.com/weblogs/viewpost.jsp?thread=4829
by GvR himself.

j

-- 
Joshua Kugler
Lead System Admin -- Senior Programmer
http://www.eeinternet.com
PGP Key: http://pgp.mit.edu/  ID 0xDB26D7CE

-- 
Posted via a free Usenet account from http://www.teranews.com

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

Re: Py 2.5 on Language Shootout

2007-01-20 Thread Isaac Gouy

Ramon Diaz-Uriarte wrote:
> On 1/20/07, Carl Friedrich Bolz <[EMAIL PROTECTED]> wrote:
> > [EMAIL PROTECTED] wrote:
> >  >>> Looking over the benchmarks, one gains the impression that Python is a
> >  >>> slow language.
> >  >> What does that even mean - a slow language?
> >  >>
> >  >
> >  > The alioth benchmarks provide a set of numbers by which
> >  > languages may be compared.
> >
> > Wrong. The benchmarks provide a set of numbers by which
> > _implementations_ of languages can be compared. After all, it is
> > possible that someone implements a magic-pixie-dust-interpreter that
> > executes Python programs several orders of magnitude fastes than
> > CPython. Or you could say that C is slow because if you use CINT, a C
> > interpreter ( http://root.cern.ch/root/Cint.html ) to execute it, it is
> > slow.
>
>
> Yeah, but this is hair-splitting. Except for Jython, IronPython, and
> Stackless, I think when we say "Python is slow/fast" we think CPython
> (otherwise, we qualify the implementation). For that matter it is
> often said "the GIL ..."; oh, but wait, Stackless ...

When we say "Python is slow/fast" what does "slow/fast" mean?


>
> With other languages (e.g., Common Lisp) the separation between the
> language and the implementation is key because, to begin with, there
> is something external from, and independent of, any particular
> implementation. That is not the case with Python.
>
> And the example of CINT is hair-splitting to the nth power.To begin
> with, I do not think CINT implements the full standard C. But even if
> it were, when people think of C they rarely think of CINT.

And that's why the existence of CINT is such a stark reminder of the
separation between the language and the implementation. When people
think of C what do they think of - gcc? tiny-c? intel c? microsoft c?
some mythical C implementation?


>
> I think readers understood the previous poster.
>
> Best,
>
> R.
> >
> > Cheers,
> >
> > Carl Friedrich Bolz
> >
> > --
> > http://mail.python.org/mailman/listinfo/python-list
> >
>
>
> --
> Ramon Diaz-Uriarte
> Statistical Computing Team
> Structural Biology and Biocomputing Programme
> Spanish National Cancer Centre (CNIO)
> http://ligarto.org/rdiaz

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


Re: Win GUI application: avoiding DOS console

2007-01-20 Thread Siggi
Thanks, but I don't mean that, I am looking for the method keeping *.py.

"Bruno Desthuilliers" <[EMAIL PROTECTED]> schrieb im 
Newsbeitrag news:[EMAIL PROTECTED]
> Siggi a écrit :
>> Hi all,
>>
>> how do I avoid the DOS console show-up when starting a WinXP GUI 
>> application with mouseclick on the respective Python file?
>
> rename yourfile.py to yourfile.pyw 


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

Re: Win GUI application: avoiding DOS console

2007-01-20 Thread Jarek Zgoda
Siggi napisał(a):

> how do I avoid the DOS console show-up when starting a WinXP GUI application 
> with mouseclick on the respective Python file?
> 
> I had this with my previous Python installation; it is very simple, 
> something with a "-i" somewhere in the open command of the  MS Windows data 
> types "PY" and "PYW". But after a new Python installation, this was lost, 
> and I cannot find the instruction what to do.

Run it using pythonw.exe instead of python.exe (check in file types
properties window).

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


Re: urllib2 and transfer-encoding = chunked

2007-01-20 Thread Nikita the Spider
In article <[EMAIL PROTECTED]>,
 [EMAIL PROTECTED] wrote:

> Haha!  My mistake.
> 
> The error is that when a web server is chunking a web page only the
> first chunk appears to be acquired by the urllib2.urlopen call.  If you
> check the headers, there is no 'Content-length' (as expected) and
> instead there is 'transfer-encoding' = 'chunked'.  I am getting about
> the first 30Kb, and then nothing else.
> 
> I don't get a ValueError like described at the following post:

Hi jdvolz,
What error *do* you get? Or is it that no error is raised; you're just 
not getting all of the data? If it is the latter, then the sending 
server might be at fault for not properly following the chunked transfer 
protocol. One way to find out would be to fire up Ethereal and see 
what's coming down the wire. 

> I am having errors which appear to be linked to a previous bug in
> urllib2 (and urllib) for v2.4 and v2.5 of Python.  Has this been fixed?
>  Has anyone established a standard workaround?  I keep finding old
> posts about it, that basically give up and say "well it's a known bug."

Can you give us some pointers to some of these old posts? And tell us 
what version of Python you're using.

-- 
Philip
http://NikitaTheSpider.com/
Whole-site HTML validation, link checking and more
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: spidering script

2007-01-20 Thread Nikita the Spider
In article <[EMAIL PROTECTED]>,
 "David Waizer" <[EMAIL PROTECTED]> wrote:

> Hello..
> 
> I'm  looking for a script (perl, python, sh...)or program (such as wget) 
> that will help me get a list of ALL the links on a website.
> 
> For example ./magicscript.pl www.yahoo.com and outputs it to a file, it 
> would be kind of like a spidering software..

David,
In addition to others' suggestions about Beautiful Soup, you might also 
want to look at the HTMLData module:

http://oregonstate.edu/~barnesc/htmldata/

-- 
Philip
http://NikitaTheSpider.com/
Whole-site HTML validation, link checking and more
-- 
http://mail.python.org/mailman/listinfo/python-list


pyparsing Combine without merging sub-expressions

2007-01-20 Thread Steven Bethard
Within a larger pyparsing grammar, I have something that looks like::

 wsj/00/wsj_0003.mrg

When parsing this, I'd like to keep around both the full string, and the 
AAA_ substring of it, so I'd like something like::

 >>> foo.parseString('wsj/00/wsj_0003.mrg')
 (['wsj/00/wsj_0003.mrg', 'wsj_0003'], {})

How do I go about this? I was using something like::

 >>> digits = pp.Word(pp.nums)
 >>> alphas = pp.Word(pp.alphas)
 >>> wsj_name = pp.Combine(alphas + '_' + digits)
 >>> wsj_path = pp.Combine(alphas + '/' + digits + '/' + wsj_name +
 ... '.mrg')

But of course then all I get back is the full path::

 >>> wsj_path.parseString('wsj/00/wsj_0003.mrg')
 (['wsj/00/wsj_0003.mrg'], {})

I could leave off the final Combine and add a parse action::

 >>> wsj_path = alphas + '/' + digits + '/' + wsj_name + '.mrg'
 >>> def parse_wsj_path(string, index, tokens):
 ... wsj_name = tokens[4]
 ... return ''.join(tokens), wsj_name
 ...
 >>> wsj_path.setParseAction(parse_wsj_path)
 >>> wsj_path.parseString('wsj/00/wsj_0003.mrg')
 ([('wsj/00/wsj_0003.mrg', 'wsj_0003')], {})

But that then allows whitespace between the pieces of the path, which 
there shouldn't be::

 >>> wsj_path.parseString('wsj / 00 / wsj_0003.mrg')
 ([('wsj/00/wsj_0003.mrg', 'wsj_0003')], {})

How do I make sure no whitespace intervenes, and still have access to 
the sub-expression?

Thanks,

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


Re: confused on python rpc with apache, is it possible?

2007-01-20 Thread fumanchu
krishnakant Mane wrote:
> can I do xml-rpc using the default libraries that come with every
> python installer?

You can, but others have packaged them up to make it easier. CherryPy
includes an xmlrpc tool (and has no dependencies other than standard
Python).

You can see an example of what your code would look like in the
"setup_server" portion of
http://www.cherrypy.org/browser/trunk/cherrypy/test/test_xmlrpc.py

Further resources on using CherryPy's xml-rpc are just a Google away.
Note that some of these may use different syntax as they target
different versions of CherryPy (but the basics are the same).
http://www.google.com/search?q=cherrypy+xmlrpc


Robert Brewer
System Architect
Amor Ministries
[EMAIL PROTECTED]

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


Re: Py 2.5 on Language Shootout

2007-01-20 Thread Ramon Diaz-Uriarte
On 20 Jan 2007 11:34:46 -0800, Isaac Gouy <[EMAIL PROTECTED]> wrote:
>
> Ramon Diaz-Uriarte wrote:
> > On 1/20/07, Carl Friedrich Bolz <[EMAIL PROTECTED]> wrote:
> > > [EMAIL PROTECTED] wrote:
> > >  >>> Looking over the benchmarks, one gains the impression that Python is 
> > > a
> > >  >>> slow language.
> > >  >> What does that even mean - a slow language?
> > >  >>
> > >  >
> > >  > The alioth benchmarks provide a set of numbers by which
> > >  > languages may be compared.
> > >
> > > Wrong. The benchmarks provide a set of numbers by which
> > > _implementations_ of languages can be compared. After all, it is
> > > possible that someone implements a magic-pixie-dust-interpreter that
> > > executes Python programs several orders of magnitude fastes than
> > > CPython. Or you could say that C is slow because if you use CINT, a C
> > > interpreter ( http://root.cern.ch/root/Cint.html ) to execute it, it is
> > > slow.
> >
> >
> > Yeah, but this is hair-splitting. Except for Jython, IronPython, and
> > Stackless, I think when we say "Python is slow/fast" we think CPython
> > (otherwise, we qualify the implementation). For that matter it is
> > often said "the GIL ..."; oh, but wait, Stackless ...
>
> When we say "Python is slow/fast" what does "slow/fast" mean?
>

Oh, well, I have no idea. I guess you'd have to define what "speed"
and, if that is a single number, then we can just rank languages. We'd
probably never agree on how to obtain a single number. But I think
most of us, when looking at the shootout, can see that there are some
languages that, for most of the programs, are consistently faster than
the rest, and others that are consistently slower. But really, I think
the shootout page has large, detailed and  statements about the
perils and pitfalls of measuring these things. (And I do not go to the
shootout to hear the oracle tell me which language I should use in my
next project).



>
> >
> > With other languages (e.g., Common Lisp) the separation between the
> > language and the implementation is key because, to begin with, there
> > is something external from, and independent of, any particular
> > implementation. That is not the case with Python.
> >
> > And the example of CINT is hair-splitting to the nth power.To begin
> > with, I do not think CINT implements the full standard C. But even if
> > it were, when people think of C they rarely think of CINT.
>
> And that's why the existence of CINT is such a stark reminder of the
> separation between the language and the implementation. When people
> think of C what do they think of - gcc? tiny-c? intel c? microsoft c?
> some mythical C implementation?
>
>

Really, this ain't my war. Sure, there are two things: the language
and the implementation. But, for practical purposes, when most people
today say Python they mean CPython, whereas if the say Scheme, they
certainly need to say _which_ Scheme (I think only PLT is in the
official shootout page; there are others in the beta tests). If people
want to mean Jython or Stackless, they just say that. As for C, I
think people will need to qualify what exactly they mean.

I think all these issues do not really lead to confusion for most of
us; certainly not if you go to the shootout page. But as I said, this
ain't my war. I was simply pointing out that correcting one poster for
talking about languages when referring to python was hair splitting.

And I think we are all running in circles, because I guess we all
agree. This is turning into what in Spain (a country of catholic
tradition) we call a discussion about "the sex of the angels" (el sexo
de los angeles), i.e., whether angels are male or female or something
else. Since sexing angels is not my area of expertise, I'll just shut
up (I actually don't really know why I even said anything about this
issue; please, forgive my chatiness).

Best,

R.


> >
> > I think readers understood the previous poster.
> >
> > Best,
> >
> > R.
> > >
> > > Cheers,
> > >
> > > Carl Friedrich Bolz
> > >
> > > --
> > > http://mail.python.org/mailman/listinfo/python-list
> > >
> >
> >
> > --
> > Ramon Diaz-Uriarte
> > Statistical Computing Team
> > Structural Biology and Biocomputing Programme
> > Spanish National Cancer Centre (CNIO)
> > http://ligarto.org/rdiaz
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>


-- 
Ramon Diaz-Uriarte
Statistical Computing Team
Structural Biology and Biocomputing Programme
Spanish National Cancer Centre (CNIO)
http://ligarto.org/rdiaz
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: python packages and __name__ query.

2007-01-20 Thread Gabriel Genellina
"krishnakant Mane" <[EMAIL PROTECTED]> escribió en el mensaje 
news:[EMAIL PROTECTED]

> I use cx freze for creating a python executable.
cx_freeze is almost irrelevant here; all the following considerations are 
about your application structure, it doesnt matter if you use cx_freeze 
later (or any other tool).

>  my software is
> essentially a package containing a few modules and one file where I
> created the main() function.
> if needed and suggested by experts I may as well put it in my
> __init__.py file of the package.
No, usually the main function is outside the package. The package is a 
library, and main() *uses* that library, as a client.

> coming back to the point.  where do I put the following code
> if __name__ == "__main__":
>   main()
I would say, "In the main script, obviously :)" But since you're asking it 
may not be so obvious...
It appears that your main script is exec.py - so there should be it.
I suppose you run your application this way:
exec.py -some -options file.ext
(perhaps a bare exec.py is enough) so using the idiom above, inside exec.py 
you can detect when someone is running it as a script.

> I have 5 modules in my package each doing a specific task.
> and a file that contains the main() function.  the 5 modules and the
> exec.py file all are in the same package.  if it is a wrong practice
> please correct me.
exec.py is not a good name, since this is the "public" entry point to your 
application, and should be more meaningful.
Usually it is not inside the package, just uses it.
I suggest you look into other Python applications, to see how they are 
layered.

-- 
Gabriel Genellina 


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


Re: Does eval has the same features as Perl's?

2007-01-20 Thread Paddy

Jm lists wrote:

> Hello members,
>
> I want to know does the "eval" in python have the same features as in
> Perl (capture errors)?
>
> For example,in perl I can wrote:
>
> $re = eval { 1 / 0 };
>
> Though 1/0 is a fatal error but since it's in "eval" block so the perl
> interpreter doesn't get exit.
>
> Thanks again.
Hi Jim,
If your new to Python and coming from Perl then your question above
needs knowledge of Python Exceptions, and the try statement.

if you had variables x and y and wanted to compute x/y but if y was
zero print some message and continue, then you would most likely do
something like:

x = 1
y = 0
try:
  z = x / y
except ZeroDivisionError:
  print "This leads to a divide by zero error!"


There is more info in the tutorial chapter 8.

- Paddy.

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


Re: Py 2.5 on Language Shootout

2007-01-20 Thread Isaac Gouy

Ramon Diaz-Uriarte wrote:
> On 20 Jan 2007 11:34:46 -0800, Isaac Gouy <[EMAIL PROTECTED]> wrote:
> >
> > Ramon Diaz-Uriarte wrote:
> > > On 1/20/07, Carl Friedrich Bolz <[EMAIL PROTECTED]> wrote:
> > > > [EMAIL PROTECTED] wrote:
> > > >  >>> Looking over the benchmarks, one gains the impression that Python 
> > > > is a
> > > >  >>> slow language.
> > > >  >> What does that even mean - a slow language?
> > > >  >>
> > > >  >
> > > >  > The alioth benchmarks provide a set of numbers by which
> > > >  > languages may be compared.
> > > >
> > > > Wrong. The benchmarks provide a set of numbers by which
> > > > _implementations_ of languages can be compared. After all, it is
> > > > possible that someone implements a magic-pixie-dust-interpreter that
> > > > executes Python programs several orders of magnitude fastes than
> > > > CPython. Or you could say that C is slow because if you use CINT, a C
> > > > interpreter ( http://root.cern.ch/root/Cint.html ) to execute it, it is
> > > > slow.
> > >
> > >
> > > Yeah, but this is hair-splitting. Except for Jython, IronPython, and
> > > Stackless, I think when we say "Python is slow/fast" we think CPython
> > > (otherwise, we qualify the implementation). For that matter it is
> > > often said "the GIL ..."; oh, but wait, Stackless ...
> >
> > When we say "Python is slow/fast" what does "slow/fast" mean?
> >
>
> Oh, well, I have no idea. I guess you'd have to define what "speed"
> and, if that is a single number, then we can just rank languages. We'd
> probably never agree on how to obtain a single number. But I think
> most of us, when looking at the shootout, can see that there are some
> languages that, for most of the programs, are consistently faster than
> the rest, and others that are consistently slower. But really, I think
> the shootout page has large, detailed and  statements about the
> perils and pitfalls of measuring these things. (And I do not go to the
> shootout to hear the oracle tell me which language I should use in my
> next project).

That's wise ;-)

Yes the shootout page has statements about the perils and pitfalls of
measuring these things - it's encouraging that at least one person has
noticed :-)


>
>
>
> >
> > >
> > > With other languages (e.g., Common Lisp) the separation between the
> > > language and the implementation is key because, to begin with, there
> > > is something external from, and independent of, any particular
> > > implementation. That is not the case with Python.
> > >
> > > And the example of CINT is hair-splitting to the nth power.To begin
> > > with, I do not think CINT implements the full standard C. But even if
> > > it were, when people think of C they rarely think of CINT.
> >
> > And that's why the existence of CINT is such a stark reminder of the
> > separation between the language and the implementation. When people
> > think of C what do they think of - gcc? tiny-c? intel c? microsoft c?
> > some mythical C implementation?
> >
> >
>
> Really, this ain't my war. Sure, there are two things: the language
> and the implementation. But, for practical purposes, when most people
> today say Python they mean CPython, whereas if the say Scheme, they
> certainly need to say _which_ Scheme (I think only PLT is in the
> official shootout page; there are others in the beta tests). If people
> want to mean Jython or Stackless, they just say that. As for C, I
> think people will need to qualify what exactly they mean.
>
> I think all these issues do not really lead to confusion for most of
> us; certainly not if you go to the shootout page. But as I said, this
> ain't my war. I was simply pointing out that correcting one poster for
> talking about languages when referring to python was hair splitting.
>
> And I think we are all running in circles, because I guess we all
> agree. This is turning into what in Spain (a country of catholic
> tradition) we call a discussion about "the sex of the angels" (el sexo
> de los angeles), i.e., whether angels are male or female or something
> else. Since sexing angels is not my area of expertise, I'll just shut
> up (I actually don't really know why I even said anything about this
> issue; please, forgive my chatiness).


In England the corresponding expression is "Counting Angels on a
Pinhead"
http://dannyayers.com/2001/misc/angels.htm

>
> Best,
>
> R.
>
>
> > >
> > > I think readers understood the previous poster.
> > >
> > > Best,
> > >
> > > R.
> > > >
> > > > Cheers,
> > > >
> > > > Carl Friedrich Bolz
> > > >
> > > > --
> > > > http://mail.python.org/mailman/listinfo/python-list
> > > >
> > >
> > >
> > > --
> > > Ramon Diaz-Uriarte
> > > Statistical Computing Team
> > > Structural Biology and Biocomputing Programme
> > > Spanish National Cancer Centre (CNIO)
> > > http://ligarto.org/rdiaz
> >
> > --
> > http://mail.python.org/mailman/listinfo/python-list
> >
>
>
> --
> Ramon Diaz-Uriarte
> Statistical Computing Team
> Structural Biology and Biocomputing Programme
> Spanish Nation

Re: scipy.optimize.lbfgsb help please!!!

2007-01-20 Thread Robert Kern
mclaugb wrote:
> Does anyone out there have a piece of code that demonstrates the use of the 
> lbfgsb multivariate, bounded solver in the scipy.optimize toolkit?  An 
> example would get me started because my code below does not seem to work.

You will probably get better/faster/more answers on the scipy-user mailing list.

  http://www.scipy.org/Mailing_Lists

> Permmin is a function that simply returns a vector array [xmin, ymin]

This is your problem. The function to minimize must return a scalar, not a
vector. This is not a multi-objective optimizer.

-- 
Robert Kern

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

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


Re: regexp qns

2007-01-20 Thread James Stroud
[EMAIL PROTECTED] wrote:
> James Stroud wrote:
> 
>>[EMAIL PROTECTED] wrote:
>>
>>>hi
>>>suppose i have a string like
>>>
>>>test1?test2t-test3*test4*test5$test6#test7*test8
>>>
>>>how can i construct the regexp to get test3*test4*test5 and
>>>test7*test8, ie, i want to match * and the words before and after?
>>>thanks
>>>
>>
>>
>>py> import re
>>py> s = 'test1?test2t-test3*test4*test5$test6#test7*test8'
>>py> r = re.compile(r'(test\d(?:\*test\d)+)')
>>py> r.findall(s)
>>['test3*test4*test5', 'test7*test8']
>>
>>James
> 
> 
> thanks !
> I check the regexp doc it says:
> """
> (?:...)
> A non-grouping version of regular parentheses. Matches whatever
> regular expression is inside the parentheses, but the substring matched
> by the group cannot be retrieved after performing a match or referenced
> later in the pattern.
> """
> but i could not understand this : r'(test\d(?:\*test\d)+)'. which
> parenthesis is it referring to? Sorry, could you explain the solution ?
> thanks
> 

The outer parentheses are the grouping operator. These are saved and 
accessible from a match object via group() or groups() methods. The "\d" 
part matches a single digit 0-1. The (?:) construct is used to make 
a non-grouping operator that is not itself remembered for access through 
the group() or groups() methods. The expression can also reference 
earlier groups, but not groups specified with the non-grouping operator.

You may want to note that this is the most specific regular expression 
that would match your given example.

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


Re: scipy.optimize.lbfgsb help please!!!

2007-01-20 Thread mclaugb
Just to clarify--this is a multivariate algorithm.  I changed the function 
Permmin to simply take the absolute value of (xmin, ymin) so that it returns 
one value.  Unfortunately, the error remains--it still returns this error:

" x, f, d = lbfgsb.fmin_l_bfgs_b(Permmin, x0, Jacobi, params, 
bounds=[(.001,100),(-50,-.001)] , maxfun=500)
  File "C:\Python24\lib\site-packages\scipy\optimize\lbfgsb.py", line 197, 
in fmin_l_bfgs_b
isave, dsave)
ValueError: failed to initialize intent(inout) array -- expected elsize=8 
but got 4 -- input 'l' not compatible to 'd'"



"Robert Kern" <[EMAIL PROTECTED]> wrote in message 
news:[EMAIL PROTECTED]
> mclaugb wrote:
>> Does anyone out there have a piece of code that demonstrates the use of 
>> the
>> lbfgsb multivariate, bounded solver in the scipy.optimize toolkit?  An
>> example would get me started because my code below does not seem to work.
>
> You will probably get better/faster/more answers on the scipy-user mailing 
> list.
>
>  http://www.scipy.org/Mailing_Lists
>
>> Permmin is a function that simply returns a vector array [xmin, ymin]
>
> This is your problem. The function to minimize must return a scalar, not a
> vector. This is not a multi-objective optimizer.
>
> -- 
> Robert Kern
>
> "I have come to believe that the whole world is an enigma, a harmless 
> enigma
> that is made terrible by our own mad attempt to interpret it as though it 
> had
> an underlying truth."
>  -- Umberto Eco
> 


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


Re: scipy.optimize.lbfgsb help please!!!

2007-01-20 Thread Robert Kern
mclaugb wrote:
> Just to clarify--this is a multivariate algorithm. 

Yes. That means that the domain of the objective function is multivariate. The
image is still a scalar.

  RR^n -f-> RR

> I changed the function 
> Permmin to simply take the absolute value of (xmin, ymin) so that it returns 
> one value.  Unfortunately, the error remains--it still returns this error:

Let's take this to the scipy-user list. Can you reduce your code down to a
small, complete example that demonstrates the problem? Without more information,
we can't help you. Also, we'll need to know what version of scipy you are using.

-- 
Robert Kern

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

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


Re: scipy.optimize.lbfgsb help please!!!

2007-01-20 Thread Robert Kern
mclaugb wrote:
> " x, f, d = lbfgsb.fmin_l_bfgs_b(Permmin, x0, Jacobi, params, 
> bounds=[(.001,100),(-50,-.001)] , maxfun=500)
>   File "C:\Python24\lib\site-packages\scipy\optimize\lbfgsb.py", line 197, 
> in fmin_l_bfgs_b
> isave, dsave)
> ValueError: failed to initialize intent(inout) array -- expected elsize=8 
> but got 4 -- input 'l' not compatible to 'd'"

And also tell us your platform. I suspect this is a 64-bit problem.

-- 
Robert Kern

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

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


Re: The proper use of QSignalMapper

2007-01-20 Thread borntonetwork
How simple. I will remember that sender() function for future
reference.
Thanks, David.

David Boddie wrote:
> On Saturday 20 January 2007 16:03, borntonetwork wrote:
>
> > David, thanks for your help. Unfortunately, all attempts of making this
> > solution work have failed. I would be interested to know if anyone has
> > used QSignalMapper successfully in a similar situation.
>
> Looking again at what you originally wrote, and looking at your
> solution below, I don't think it's really appropriate to use a
> QSignalMapper for this purpose. (That's what I understood from the
> signature of the deleteProductIngredient() method you had in your
> original code.)
>
> What you appear to want is a way of being notified about state
> changes to widgets that also identifies the individual widget
> that changed. You can do that by connecting the individual widgets
> to the same slot and call sender() to find out which object emitted
> the signal; for example:
>
> # ...
>
> for idx in range(1, maxIngredients+1):
> wName = 'chkProductIngredientsDelete_'+str(idx)
> w = self.__dict__[wName]
> self.connect(w, QtCore.SIGNAL("stateChanged(int)"),
>  self.deleteProductIngredient)
>
>   def deleteProductIngredient(self, state):
>   """Delete a product ingredient."""
>   print self.sender(), "changed state to", state
>
> What QSignalMapper does is collect signals from different objects,
> assigning an ID to each of them, and emits a single signal with
> an ID whenever it receives a signal from one of those objects.
> In other words, it allows the actions of a group of objects to be
> described by a parameter but discards the signal's arguments.
> It's most useful for things like collections of push buttons where
> you only need to know that they were clicked.
>
> > For any interested, I worked around the problem using a closure,
> > which seems a bit cleaner from a coding point of view, although
> > I don't have any idea if it is more efficient or not:
>
> [...]
>
> > Each iteration then created a new function based on the closure:
>
> [...]
>
> It's good to know that you got something working in the end. There's
> also another solution that involves QSignalMapper, but it may not make
> the resulting code any simpler.
> 
> David

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


Re: Py 2.5 on Language Shootout

2007-01-20 Thread Fuzzyman

Carl Friedrich Bolz wrote:

> [EMAIL PROTECTED] wrote:
>  >>> Looking over the benchmarks, one gains the impression that Python is a
>  >>> slow language.
>  >> What does that even mean - a slow language?
>  >>
>  >
>  > The alioth benchmarks provide a set of numbers by which
>  > languages may be compared.
>
> Wrong. The benchmarks provide a set of numbers by which
> _implementations_ of languages can be compared. After all, it is
> possible that someone implements a magic-pixie-dust-interpreter that
> executes Python programs several orders of magnitude fastes than
> CPython. Or you could say that C is slow because if you use CINT, a C
> interpreter ( http://root.cern.ch/root/Cint.html ) to execute it, it is
> slow.

If you rephrase your argument to read 'it is never useful to discuss
the comparative speed of langauges' then hopefully the error should be
obvious. But then to discuss the speed of languages rather than
implementations would be a generalisations, and generalisations are
always wrong... ;-)

Fuzzyman
http://www.voidspace.org.uk/python/articles.shtml

> 
> Cheers,
> 
> Carl Friedrich Bolz

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


Re: Code reformater?

2007-01-20 Thread Gabriel Genellina

At Saturday 20/1/2007 14:37, Siggi wrote:


> When I copy/paste Python code from the web, every so often,
> the TABs are wrong, which means that the code won't work and I have to
> manually reformat the code.
>
> Is there a code reformater that can parse the code to make it right?
>
> Thanks.

Maybe my thread "help: code formatter, 08/01/2007 helps a little? Here are
some of the answers:

*
Why don't you just write one? :)
Seriously: Try.
*
Tools\scripts\reindent.py in your Python distribution.
*
Why, yes, there is:
 http://lacusveris.com/PythonTidy/PythonTidy.python
*
tabnanny ?


As the indentation *is* significant in python, none of the above can 
help if you lose the indentation. Try to reconstruct this:


def foo():
if a>0:
if b>0:
print 1
print 2
else:
return 3
return 4

The tools may help to make the indentation consistent (tabs/8 
spaces/4 spaces/2 spaces mixed) or look better, but not to make it right.



--
Gabriel Genellina
Softlab SRL 







__ 
Preguntá. Respondé. Descubrí. 
Todo lo que querías saber, y lo que ni imaginabas, 
está en Yahoo! Respuestas (Beta). 
¡Probalo ya! 
http://www.yahoo.com.ar/respuestas 

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

A solution to the MSVCRT vs MSVCR71 problem?

2007-01-20 Thread sturlamolden

This question has been asked many times, and last time I was accused of
spreading FUD. So now I will rather propose a solution.

The reason for the problem is as follows:

The binary installer for Python built by te python.org team is compiled
with Microsoft Visual Studio 2003. It is linked with the C runtime
msvcrt71.dll. The copyright to msvcrt71.dll is owned by Microsoft, and
it is not an integral part of the Windows operating system. This leads
to two distinct problems:

Problem 1: You want to use a particular compiler to build a Python
extension library, but it links with the wrong CRT. Typical examples
are MinGW, Microsoft Visual C++ 6.0 and Microsoft Visual C++ Express.
There is a remedy for MinGW, but not for the other two.

Problem 2: You want to distribute a program created Py2Exe, but has no
license for Visual Studio 2003. You are therefore not allowed to
redistribute msvcrt71.dll. But without this DLL your program will not
work. As a side note: Visual Studio 2003 is out of sale, so if you
don't have it already you may be out of luck.

The solution: modify the IAT of to use the correct binary.

The process is really simple:

Solution to problem 1:

Compile with your compiler or choice, never mind which CRT are used.
Use a 'dumpbin' program, find all references to msvcrt in the binary
DLL file. Create a dll with name "py_crt" that exports these functions
but redirects them to msvcrt71. That is, in the file py_crt.def we put
something like

EXPORTS
malloc=msvcr71.malloc
free=msvcr71.free
etc.

Compile the DLL py_crt.dll and then open your pyd file in binary mode.
Exchange all occurances of the string "msvcrt" (or any other CRT name)
with "py_crt". Now your binary should work just fine. What you need to
make sure is just that the name of the proxy has the same number of
letters as the CRT your compiler linked. So if it is msvcrt81.dll, e.g.
use something like py_crt81.dll instead of py_crt.dll.

Solution to problem 2:

This would be the opposite, involving modifying Python25.dll and all
pyd and dll files gathered by Py2Exe to use msvcrt.dll instead of
msvcr71.dll. One could e.g. create a DLL called py_cr71.dll that
redirects CRT calls to msvcrt.dll or any other CRT of choice. In
py_cr71.def we would then have:

EXPORTS
malloc=msvcrt.malloc
free=msvcrt.free
etc.

And then it is simply a matter of modifying the binaries to load
py_cr71.dll instead of msvcrt71.dll.

What we need to make this work:

1. A dumpbin facility similar to the one that ships with Visual Studio
that can be freely distributed.

2. A python script that parses the output from dumpbin, creates the
proxy and redirects the CRT. (I already have such a script working.)

Finally, a setup script (setup.py) could automate this task for
"problem 1" above.

Another variant of the fake-CRT procedure, which would also work, is to
create a fake msvcrt71.dll that redirects to your CRT of choice, and
replace the msvcrt71.dll that came with Python with that. That is
conceptually simpler, as it involves not binary modifications, but
someone might mistake your msvcrt71.dll for the msvcrt71.dll from
Microsoft. Also antivirus-software might not like attempts to load such
a DLL as it would look like your program is hijacked by a trojan
(although it is not).

What do you think?

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


Re: Code reformater?

2007-01-20 Thread Steven D'Aprano
On Sat, 20 Jan 2007 23:51:24 -0300, Gabriel Genellina wrote:

> As the indentation *is* significant in python, none of the above can 
> help if you lose the indentation. Try to reconstruct this:
> 
> def foo():
> if a>0:
> if b>0:
> print 1
> print 2
> else:
> return 3
> return 4
> 
> The tools may help to make the indentation consistent (tabs/8 
> spaces/4 spaces/2 spaces mixed) or look better, but not to make it right.


Sure -- but a heuristic that gets it right *sometimes* may still be
useful, provided the user knows that the code may not be indented
correctly.

There are lots of legal Python blocks where the indentation CAN be
reconstructed correctly, and only a relatively small proportion where it
can't -- the tool could do its best, and warn the user when there are
indents that can't be dealt with. Or even refuse the temptation to guess,
but re-indent whatever parts of the code it is sure about.

Still, it is better not to lose the indentation in the first place.



-- 
Steven.

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


Re: selective logger disable/enable

2007-01-20 Thread Gary Jefferson

Vinay Sajip wrote:
>
> The documentation for Logger - see
>
> http://docs.python.org/lib/node406.html
>
> - shows that there are addFilter() and removeFilter() methods on the
> Logger class which you can use to add or remove filters from individual
> Logger instances. From the above page (entitled "14.5.1 Logger
> Objects"):
>
> addFilter(filt)
> Adds the specified filter filt to this logger.
>
> removeFilter(filt)
> Removes the specified filter filt from this logger.
>
> The parent section of Section 14.5.1, which is Section 14.5, was the
> first search result when I just searched Google for "python logging".


Thanks for the reply Vinay.  I had been reading those docs prior to
posting, but addFilter/removeFilter only work on individual logger
instances and handlers.  I want to globally enable/disable multiple
logger instances, based on their namespaces (see the example I
provided).  I cannot find a way to do this.  I can certainly call
addFilter on every instance of every logger throughout the source code,
but this is more than inconvenient -- it breaks when new modules are
added with their own loggers in their own namespaces (until fixed by
manually adding addFilter() to those instances).

e.g., suppose you have a source tree with a several components that do
network access, and several components that do other things like saving
state to disk, accessing the filesystem, etc.  And suppose you find a
bug that you think is in the networking code.  It would be nice to be
able to GLOBALLY enable just the loggers that belong in the networking
namespace, and disable all others (similar to how Filters are supposed
to work for individual loggers).  And then to be able to do this with
any component, by providing, for example, a command line switch or
environment variable.  Otherwise, the poor programmer is forced to go
and edit every module in the source tree to selectively turn on/off
their respecitve loggers.  Or am I missing something really obvious
about how this is done with the logging module?

thanks,
Gary

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


Re: Code reformater?

2007-01-20 Thread Gabriel Genellina

At Sunday 21/1/2007 00:15, Steven D'Aprano wrote:


On Sat, 20 Jan 2007 23:51:24 -0300, Gabriel Genellina wrote:

> As the indentation *is* significant in python, none of the above can
> help if you lose the indentation. Try to reconstruct this:
>
> def foo():
> if a>0:
> if b>0:
> print 1
> print 2
> else:
> return 3
> return 4
>
> The tools may help to make the indentation consistent (tabs/8
> spaces/4 spaces/2 spaces mixed) or look better, but not to make it right.


Sure -- but a heuristic that gets it right *sometimes* may still be
useful, provided the user knows that the code may not be indented
correctly.

There are lots of legal Python blocks where the indentation CAN be
reconstructed correctly, and only a relatively small proportion where it
can't --


I'd say absolutely the opposite. Try the example above. Or this one, simpler:

def foo():
if a>0:
if b>0:
print 1
print 2

Which level should be 'print 2' assigned to? There are 3 choices. 
What if there is a third print? There are 3, 2, or 1 possibilities, 
depending on where you put the previous one. The same for any other 
statement below.
The problem is, after a colon, you know that a new block begins and 
you must indent, but you don't know when that block ends except in a 
few cases (an else clause, by example, and only if there was a single 
preceding if).



the tool could do its best, and warn the user when there are
indents that can't be dealt with. Or even refuse the temptation to guess,
but re-indent whatever parts of the code it is sure about.


...almost nothing, I'm afraid... :(


Still, it is better not to lose the indentation in the first place.


Sure!


--
Gabriel Genellina
Softlab SRL 







__ 
Preguntá. Respondé. Descubrí. 
Todo lo que querías saber, y lo que ni imaginabas, 
está en Yahoo! Respuestas (Beta). 
¡Probalo ya! 
http://www.yahoo.com.ar/respuestas 

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

Re: A solution to the MSVCRT vs MSVCR71 problem?

2007-01-20 Thread Martin v. Löwis
sturlamolden schrieb:
> Problem 2: You want to distribute a program created Py2Exe, but has no
> license for Visual Studio 2003. You are therefore not allowed to
> redistribute msvcrt71.dll. But without this DLL your program will not
> work. As a side note: Visual Studio 2003 is out of sale, so if you
> don't have it already you may be out of luck.

I believe this problem doesn't exist. Licensees of Python are permitted
to redistribute mscvr71.dll, as long as they redistribute it in order
to support pythonxy.dll. The EULA says

# You also agree not to permit further distribution of the
# Redistributables by your end users except you may permit further
# redistribution of the Redistributables by your distributors to your
# end-user customers if your distributors only distribute the
# Redistributables in conjunction with, and as part of, the Licensee
# Software, you comply with all other terms of this EULA, and your
# distributors comply with all restrictions of this EULA that are
# applicable to you.

In this text, "you" is the licensee of VS 2003 (i.e. me, redistributing
msvcr71.dll as part of Python 2.5), and the "Redistributable" is
msvcr71.dll. The "Licensee Software" is "a software application product
developed by you that adds significant and primary functionality to the
Redistributables", i.e. python25.dll.

IANAL; this is not legal advise.

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