Re: GUIs: wxPython vs. Tkinter (and others)

2004-12-10 Thread Paul Rubin
Mike Meyer <[EMAIL PROTECTED]> writes:
> I've never tried doing animation in TkInter. Qt provides timer devices
> that you can use to drive animations. I suspect that doing the same in
> TkInter would be noticably more difficult.

Tkinter supports some kind of event that runs n millisecond (n is a
parameter) after you call the method.  You can use that to create a
timing loop.  That's more or less what you have to do anyway, if you
want to run your tkinter gui in a separate thread from the rest of
your application.  Tkinter isn't thread-safe, so you have to do
something like periodically check a queue from the tkinter thread.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: New versions breaking extensions, etc.

2004-12-10 Thread Mike Meyer
"Jive" <[EMAIL PROTECTED]> writes:

> "Nick Coghlan" <[EMAIL PROTECTED]> wrote in message
> news:[EMAIL PROTECTED]
>> To this date, no-one has cared enough about the problem to put in the
> effort
>> required to make the C API version agnostic. Given that the API almost
> always
>> remains *source* compatible, within a month or two of a new Python
> release, the
>> extension developers have generally tweaked their build environments to
> also
>> produce binaries for the new release.
>
> It would be a Good Thing to put a stop to that requirement, no?

Actually, there's a problem on Unix that may not exist on
Windows. Python is installed in /lib/python/. This
lets us have multiple versions of Python installed at the same time,
which is a good thing.

Now, installed packages and extensions go in
/lib/python/site-packages. This means that you can't
use *any* of the previously installed packages in the new
version, even if they were pure python. Since I use TMDA, my mail
stopped working when I installed python 2.4.

The real solution is a database of installed packages (which may well
be needed for the apt-get/CPAN functionality that people want) so that
a single python script can fetch and install all the installed
packages.

  http://www.mired.org/home/mwm/
Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Deadlock detection

2004-12-10 Thread Mike Meyer
Adam DePrince <[EMAIL PROTECTED]> writes:

> On Mon, 2004-12-06 at 06:21, Duncan Grisby wrote: 
>> Hi,
>> 
>> Does anyone know of a deadlock detector for Python?  I don't think it
>> would be too hard to hook into the threading module and instrument
>> mutexes so they can be tested for deadlocks. I've googled around but I
>> haven't found anything.
>
> In general, accurate deadlock detection is intractable.  Like many
> problems of this class you have two choices - either reduce the scope of
> the problem to a non-general one or try a heuristic to guess.  

I've recently been involved in a thread on another list that dealt
with the problems of programming with threads. There are people
approaching the problems (including deadlocks) by providing constructs
for threading that mean you can't write such code. At least, that's
the idea.

http://www.jot.fm/issues/issue_2004_04/article6 was posted as one
such solution. I'm not convinced it works, but the paper only
discusses half the solution.

http://www.mired.org/home/mwm/
Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: New versions breaking extensions, etc.

2004-12-10 Thread JanC
Jive schreef:

> P.s.  Does anyone know how to make Outlook Express leave my damned
> line-ends alone?  If I want line-ends. I know where to find the ENTER
> key. 

Google for "oe-quotefix", but the best solution is to use a proper 
newsreader.   ;-)


-- 
JanC

"Be strict when sending and tolerant when receiving."
RFC 1958 - Architectural Principles of the Internet - section 3.9
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: GUIs: wxPython vs. Tkinter (and others)

2004-12-10 Thread Mike Meyer
"Erik Johnson" <[EMAIL PROTECTED]> writes:

> I am looking for some input on GUI libraries.

Since you said others, I'll recommend PyQt. Major downside with it is
that it costs money on Windows.

> o What features does wxPython offer that Tkinter cannot (and vice
> versa)?

I don't know about wxPython, but PyQt includes it's own threading
facility, plus hooks to talk to databases. It also has a widget for
creating Windows "wizards" for walking through a set of options.

> o Is the general programming methodology pretty much the same between
> the two (e.g., the general program structure - using callbacks & Frames,
> etc. is the same, it's just a question of calling different widgets with
> their own arguments)?

Not for Qt. It has the notion of SLOTs and SIGNALs. You connect a
signal from an object to a slot or signal on another (or the same)
object. You can, for example, connect a signal from a slider widget to
a slot on a digital display widget, thus causing the display to change
as you move the slider.

At the python level, slots are just callable objects. At the
C++ level, slots are magic methods of objects. Signals are usually
associated with GUI events, but Python can emit them for whatever
reason it wants. It's possible to connect C++ signals to C++
slots/signals in Python, meaning that Python won't be involved when
that signal is emitted.

> o Do you have a strong preference for one over the other (or some other
> toolkit)? Why?

I strongly prefer PyQt TkInter. PyQt provides a higher level of
abstraction.

> o Is animation and graphics particularly better suited to one over the
> other?

I've never tried doing animation in TkInter. Qt provides timer devices
that you can use to drive animations. I suspect that doing the same in
TkInter would be noticably more difficult.

  http://www.mired.org/home/mwm/
Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: String operations

2004-12-10 Thread Terry Hancock
On Wednesday 01 December 2004 04:20 pm, Anoop Rajendra wrote:
> os.execvp("condor_q",["condor_q","-l","-constraint",'"ProjectId==\\\"anoopr_samadams.fnal.gov_161903_30209\\\""'])
> 
> doesnt work. Its definately a problem with one of the million
> backslashes and quotes present, but I'm not able to figure it out.
> What am I doing wrong?

Honestly, I'm not sure, but try the following:

1) Paste the questionable string onto a print statement (in the
  interactive interpreter), and get python to tell you what it made
  of what you wrote:

  print '"ProjectId==\\\"anoopr_samadams.fnal.gov_161903_30209\\\""'

2) Try using a "raw string", which won't try to interpret the backslashes:

  r'''"ProjectId==\"anoopr_samadams.fnal.gov_161903_30209\""'''

3) Use triple-quotes (as I did above) instead of escaping your quotation
   marks: in Python you can actually quote with 'a', "a", '''a''', or """a""". 
The
   triple quotes interpret newlines literally, but they also interpret both
   single and double quotation marks as literal characters, which can be
   convenient.

That should get you there with a little tinkering.

Cheers,
Terry


--
Terry Hancock ( hancock at anansispaceworks.com )
Anansi Spaceworks  http://www.anansispaceworks.com

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


Re: Drawing Cogwheels and Combinatoric diagrams

2004-12-10 Thread Terry Hancock
On Wednesday 01 December 2004 10:39 am, Andrew James wrote:
> Gentlemen,
> I'm looking for a graphing or drawing python package that will allow me 
> to draw complex geometric shapes. I need to be able to create shapes 
> like cogwheels and Venn diagrams:
> 
> http://encyclopedia.thefreedictionary.com/Venn
> 
> The library must support alpha blending and the ability to return x,y 
> co-ordinates for a shape, as I want to draw an imagemap on top of parts 
> of the shape.
> 
> Can PIL do this, or do I need to go the way of GnuPlot or Gri? Can 
> anyone give me an example of a complex shape drawn like this?

Although I believe PIL can do some of this in principle, it isn't really
designed for it.  You might want to look into Skencil. Although it is
usually regarded as a GUI application, it is also a python vector
graphics package.  See http://skencil.org.

The one thing I think will be a problem is the alpha-blending, as
Skencil either doesn't support it or hasn't for very long (so you'd
need the very latest version).  However, you can, of course, use
PIL to alpha blend graphics after they've been rastorized, which
might work for you.

Cheers,
Terry

--
Terry Hancock ( hancock at anansispaceworks.com )
Anansi Spaceworks  http://www.anansispaceworks.com

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


Re: New versions breaking extensions, etc.

2004-12-10 Thread Jive
P.s.  Does anyone know how to make Outlook Express leave my damned line-ends
alone?  If I want line-ends. I know where to find the ENTER key.



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


Re: newbie questions

2004-12-10 Thread Mike Meyer
Adam DePrince <[EMAIL PROTECTED]> writes:

> Alright.  Now, as Erik pointed out if you assign to the variable the
> computer will add that to the local name space.  This happens at
> "compile" time (which is right after you hit enter twice at the CPython
> command line.) 
>
> For an example of this:
>
 a = 0
 def b():
> ... print a
> ...
 def c():
> ... print a
> ... a = 1
> ...
 b()
> 0
 c()
> Traceback (most recent call last):
>   File "", line 1, in ?
>   File "", line 2, in c
> UnboundLocalError: local variable 'a' referenced before assignment
>
> In b(), a was taken as being from the line above.  In c, it was from the
> local name space.
>
> So, how do we affect what you want?

I *have* to point out here that you can write c as:

>>> a = 2
>>> def c():
...  global a
...  print a
...  a = 1
... 
>>> c()
2
>>> 

The one (and so far only) place you can declare a variable in Python.

  http://www.mired.org/home/mwm/
Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: New versions breaking extensions, etc.

2004-12-10 Thread Jive

"Nick Coghlan" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
> Jive wrote:
> > Can someone explain to me why Python 2.4 on MS Windows has these
backward
> > compatibility problems?  What am I missing?
>
> The problem is the Python C/API. At the moment, it exposes things directly
(like
> data structures) that may change size between major version releases.

Okay.  That could be fixed.

> The other
> issue is that the interpreter and the extensions may be linked to
different
> versions of the Microsoft runtime.

Doesn't Microsoft have an answer for that?  There are (at last count) nine
skillion ActiveX
components in the wild.  Surely Microsoft didn't blast them into oblivion
with dot-net -- did it?

>
> This is a solvable problem, but it would require:
>1. Major additions to the C/API - a "Python Major Version Agnostic" API
that
> hides all data structures behind opaque pointers, never passes file
descriptors
> between the interpreter and the extension and never gets Python to delete
memory
> allocated by the extension (or vice-versa)

I remember having trouble with that last bit once.  But I seem to recall
there was an easy
answer.  Something to do with the main ap and the DLL using the same heap or
some
such thing.

>2. Rewriting extensions to use the new API functions instead of the
current
> major version specific ones.

That's a one-time thing, for those who choose to do it.  Certainly the old
API
would still be available.

>
> Such an API is likely to be both harder to work with and slower, simply
due to
> the limitations of C.
>
> To this date, no-one has cared enough about the problem to put in the
effort
> required to make the C API version agnostic. Given that the API almost
always
> remains *source* compatible, within a month or two of a new Python
release, the
> extension developers have generally tweaked their build environments to
also
> produce binaries for the new release.

It would be a Good Thing to put a stop to that requirement, no?

>
> In the current case (Python 2.4), the transition from msvcrt to msvcrt71,
and
> the poor quality of the free development tools offered by Microsoft has
> exacerbated the problem on Windows.

No doubt.  I don't understand what the deal is with msvcr71 and all that,
but I have
figured out that it's a dirty rotten shame.  If you google for msvcr71, you
will
get pages and pages of links to plaintive cries for help.  We are not alone.

> The Python developers are looking at
> improving the documentation and support for building extensions with
Windows
> compilers other than Visual Studio .Net 2003 (mainly MinGW and the free MS
tools).
>

That would be good.   But is using VC++ 6.0 right out?  As it stands, I can
no longer
build extensions that will run with a standard dot-net Python 2.4 release.
Or at least I don't
know how.  And if I build 2.4 under VC++ 6.0 and distribute that around the
company, it's not
clear to me if  we can then use new third party extensions.  Some
documentation
clearing it all up would be very helpful.  Maybe it exists somewhere
already.  This is
a Microsoft problem, not a Python problem.

Like I said, dirty rotten shame.

Thinking it over, I'm wondering why the Python crowd went with dot-NET in
the first place.
Surely the world would be a better, happier place without MS jerking
everyone around.
We work our fingerprints to the bone writing code to make their stinking
little OS do something
useful, and what have they ever given us in return? -- Besides the
aquaducts?

Jive



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


Re: Help beautify ugly heuristic code

2004-12-10 Thread Stuart D. Gathman
On Fri, 10 Dec 2004 22:03:20 +, JanC wrote:

> Stuart D. Gathman schreef:
> 
>> I have a function that recognizes PTR records for dynamic IPs.  There

> Did you also think about ISPs that use such a PTR record for both dynamic 
> and fixed IPs?

There seems to be a lot of misunderstanding about this.  I am not blocking
anyones mail because they have a dynamic looking PTR.  I simply don't
accept such a PTR as MTA authentication.  You see, MTAs *SHOULD* provide a
fully qualified domain as their HELO name which resolves to the IP of the
MTA.  Sadly, however, many internet facing MTAs don't do this, but I
accept a meaningful PTR as a substitute.  I also waive the requirement for
MTA authentication if the MAIL FROM has an SPF record
(http://spf.pobox.com).

So, if your MTA complies with RFC HELO recommendations, you'll have no
trouble sending me mail. You can even use a dynamic IP with a dynamic DNS
service.

I 'do* block PTR names of "." or "localhost".  I would like to block all
single word HELO names - but there are too many clueless mail admins out
there.  People seem to be unsure of what to send for HELO.

-- 
  Stuart D. Gathman <[EMAIL PROTECTED]>
Business Management Systems Inc.  Phone: 703 591-0911 Fax: 703 591-6154
"Confutatis maledictis, flamis acribus addictis" - background song for
a Microsoft sponsored "Where do you want to go from here?" commercial.

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


htmldata 1.0.4 - Manipulate HTML documents via data structure

2004-12-10 Thread C. Barnes

htmldata 1.0.4 is available.

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

The htmldata module allows one to translate HTML
documents back and forth to list data structures.
This allows for programmatic reading and writing
of HTML documents, with much flexibility.

Functions are also available for extracting
and/or modifying all URLs present in the HTML
or stylesheets of a document.

Version 1.0.4 is a bugfix release offering:
 * Python 2.0-2.4 support (thanks to Paul Clinch
   for the Python 2.2 patch)
 * Properly working XHTML parsing.
 * Miscellaneous other fixes (see the changelog
   for details).

I have found this library useful for writing
robots, for "wrapping" all of the URLs on
websites inside my own proxy CGI script, for
filtering HTML, and for doing flexible wget-like
mirroring.

It keeps things as simple as possible, so it
should be easy to learn.

 - Connelly Barnes




__ 
Do you Yahoo!? 
Send holiday email and support a worthy cause. Do good. 
http://celebrity.mail.yahoo.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: New versions breaking extensions, etc.

2004-12-10 Thread Nick Coghlan
Jive wrote:
Can someone explain to me why Python 2.4 on MS Windows has these backward
compatibility problems?  What am I missing?
The problem is the Python C/API. At the moment, it exposes things directly (like 
data structures) that may change size between major version releases. The other 
issue is that the interpreter and the extensions may be linked to different 
versions of the Microsoft runtime.

This is a solvable problem, but it would require:
  1. Major additions to the C/API - a "Python Major Version Agnostic" API that 
hides all data structures behind opaque pointers, never passes file descriptors 
between the interpreter and the extension and never gets Python to delete memory 
allocated by the extension (or vice-versa)
  2. Rewriting extensions to use the new API functions instead of the current 
major version specific ones.

Such an API is likely to be both harder to work with and slower, simply due to 
the limitations of C.

To this date, no-one has cared enough about the problem to put in the effort 
required to make the C API version agnostic. Given that the API almost always 
remains *source* compatible, within a month or two of a new Python release, the 
extension developers have generally tweaked their build environments to also 
produce binaries for the new release.

In the current case (Python 2.4), the transition from msvcrt to msvcrt71, and 
the poor quality of the free development tools offered by Microsoft has 
exacerbated the problem on Windows. The Python developers are looking at 
improving the documentation and support for building extensions with Windows 
compilers other than Visual Studio .Net 2003 (mainly MinGW and the free MS tools).

Although key extension developers could always try asking the PSF to buy them a 
Visual Studio license ;)

Cheers,
Nick.
--
Nick Coghlan   |   [EMAIL PROTECTED]   |   Brisbane, Australia
---
http://boredomandlaziness.skystorm.net
--
http://mail.python.org/mailman/listinfo/python-list


Re: New versions breaking extensions, etc.

2004-12-10 Thread News M Claveau /Hamster-P
Hi !

But, if Python is as much sensitive to the passage of an external software,
version 6 (obsolete) with a version 7 (obsolete also), it is worrying.

Michel Claveau


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


Re: Ideas for projects

2004-12-10 Thread John Hunter
> "Phillip" == Phillip Bowden <[EMAIL PROTECTED]> writes:

Phillip> I feel that I've learned the language pretty well, but
Phillip> I'm having trouble thinking of a medium to large project
Phillip> to start.  

Some of these may be on the "large" side, but

 - Provide a full-feature, mostly specification complete python pdf
   parser.

 - Write a proper python package manager that recursively handles
   dependencies across platforms (CPAN/apt-get for python).

 - Enhance GUI integration.  Ie, allow python code targetting one GUI
   environment to be used in a different one (contribute to anygui?)
 
 - Add 3D graphics to matplotlib (nudge, nudge, my own project).
   Integrate VTK?

 - Contribute a full-featured wavelets analysis package for python 

 - Add internationalization support to your favorite python package
   which lacks it.

 - Add client side python support to mozilla and/or XUL

 - Write a python app that crawls python-list USENET posts looking for
   book or GUI-toolkit recommendations and automatically responds with
   links to FAQs and google groups.  Be sure to include "google is
   your friend" in every response.

 - Contribute to the ipython rewrite effort so that python finally has
   an interactive shell across platforms worth its salt that has a
   chance of being included in the standard library.

 - Solve the problems with the global interpreter lock and give python
   a proper security model that will satisfy everyone with a hardcore
   Java and C++ background.  Implement a proper Rational class and
   support date string formatting over the range of dates that the
   datetime module supports.  Provide a full featured timezone module
   for the standard library.  Support compile time type identification
   for runtime optimizations.

If any or all of these have already been done, my apologies to the
respective authors.

JDH
 


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


Re: sources for DOS-16bit

2004-12-10 Thread Adam DePrince
On Fri, 2004-12-10 at 16:30, Peter Hansen wrote:
> McBooCzech wrote:
> > I am looking for Python binaries for DOS-16bit
> > Not for Win-16bit or DOS-32 which are the only DOS availabele sources
> > on Python official site and on the other sites as well!!!
> > I will prefere sources for Borland C 3.x.
> > 
> > I was trying to use Python 1.0.1 (16python.exe file) for my
> > application,
> > but I realized it doesn't work on NEC V25 CPU (8086/8088 compatible
> > CPU developed by NEC).
> > 
> > I was involved in to our school computer "research" :) and we need
> > this piece of code to reach our goal.
> > 
> > We have to demonstrate the power of the free software (mainly its
> > compatiblity for different platforms)!!!
> > 
> > Can you please search your archives or route me somewhere?
> 
> Does it have to be Python?  There are other languages that
> are arguably as portable, and certainly more compact.  Lua,
> for example, has been ported to quite small devices.  See
> http://www.lua.org/ for more on that, but note there are
> other options as well.  Python's not the only "free portable
> software" around, though it's the best in many ways.


You may want to consider some of the programming languages of the day.  
Pascal comes to mind; it was popular when the 8086 was "The Machine to
Own" (tm).  Much as Java of a decade and a half later had "bytecode",
there was a byte code for pascal called "p-code" courtesy of UCSD.   
Look at  wikipedia.org for the "pascal programming language."   There
are executables and source code files for lots of pascal compilers. 
IMHO this is your best chance at getting a complex program into a
limited machine.

For more insight, look at uClinux and elks.  They are both linux
derivatives for small machines like the 8086.  

BTW, how much RAM does your machine have?   Also, remember that if your
chip is anything like the V20 or V30 from NEC it also can emulate the
8080 (which the Z80 is a clone of.)  I have no clue how to use this
mode.

I might be recalling this incorrectly, but the V20 and V30 do have one
incompatibility with the 8086.  There is an op code called AAD.  It was
intended to help with BCD (base 10) arithmetic and would basically
perform the operation 10 * X + Y.  The value 10 happened to be encoded
into the op code.  The 8086, when executing this operation, would pull
the value from the op code.  The V20-V30 would pull it from a constants
table.  So, using any value other than 10 would result in the operation
K * X + Y for some unsigned 4 bit value; on the V20-V30 it was an
undefined operation.  What this an accident?  I don't know, but a lot of
assembly coders came to depend on the one or two CPU cycles it would
save over a proper mul and add.  One or two cycles per array reference
was a big thing back then ... 

Anyhow, sorry about babbling on about this non-python related nonsense
and good luck.

Adam DePrince 


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


Re: Wrapper objects

2004-12-10 Thread Nick Coghlan
[EMAIL PROTECTED] wrote:
The wrapper objects needs to work as dictionary keys, to support
printing, concatenation/addition, getitem/setitem and such things...
In that case, identifying exactly which operations you want to support, and 
using a metaclass based approach like mine or Bengt's should work.

However, I highly recommend the 'opt-in' approach to delegating magic methods. 
As Bengt discovered, there are a number of them that can break your class badly 
if you inadvertently delegate them (e.g. if you delegate __new__ or __init__, 
your class cannot be instantiated).

The Python Language Reference can tell you which methods need to be delegated to 
support a given operation: http://docs.python.org/ref/specialnames.html

The delegation may still not be completely transparent, since the delegated 
methods may not know how to deal with your wrapper objects. So you may require 
calls to methods like int() or str() in your application code to make the types 
work out correctly.

Cheers,
Nick.
--
Nick Coghlan   |   [EMAIL PROTECTED]   |   Brisbane, Australia
---
http://boredomandlaziness.skystorm.net
--
http://mail.python.org/mailman/listinfo/python-list


Re: building python extensions with .net sdk compiler?

2004-12-10 Thread Grumman
I got this insane message, how did you solve this "problem" ?

running install
running build
running build_py
running build_ext
error: The .NET Framework SDK needs to be installed before building 
extensions for Python.
-

Or does anyone know why i get this message, the .net sdk is about 100Mb, 
no fun !
The message says what it says. You have to install the .net SDK to use 
this. You'll also need the Platform SDK if you don't have it already 
installed. (And its a *lot* bigger than the .net sdk)

And then you'll find out that you either need to hack 
distutils/msvccompiler.py, or your registry.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Compiling Python 2.4 extensions with free VC++ Toolkit

2004-12-10 Thread Grumman
Jody Burns > wrote:
Hi all,
I've been wondering if there's anything on the drawing board about 
patching distutils/msvccompiler.py so that it can compile Python 
extensions using the free Visual C++ toolkit instead of the entire 
Visual C++ development environment.

I know it's possible, because I was able to compile and install PyCrypto 
2.0 for Python 2.4 today.  I did this by commenting out the part of 
msvccompiler that checks for VS library paths and manually adding them 
to my LIB environment variable.

Been messing around with that myself earlier today.
I just added the registry keys that msvccompiler.py was looking for. And 
pointed them to the toolkit and sdk paths. Worked just fine.

It worked to build PIL 1.1.4 for python 2.4 today, although without 
freetype2 support. Probably just needs some minor tweaking to get it in 
there as well.

I'll have to grab the source of some other extensions, and see how they 
turn out as well.
--
http://mail.python.org/mailman/listinfo/python-list


Re: newbie questions

2004-12-10 Thread Adam DePrince
On Fri, 2004-12-10 at 22:17, Erik Johnson wrote:
> > do yo have any idea of what is causing this problem?
> > is it possible to do self.SortiesAnimeTitreLabel = [] to reset the var?
> (it
> > seems to work outside of the sub, but I believe that the var I'm erasing
> is
> > not the one I want but a local copy.
> 
> 
> Yeah.  I'm no Python guru, but I have a pretty good idea. Your intuition
> is correct - you're killing a local copy. Functions (and methods) have their
> own namespace. Variables declared within a function are local that that
> function's name space, as well as formal variables that appear on the
> function declartion (definition) line.
> 
> >>> z = 'z'
> >>> def f(x):
> ...   print dir()
> ...   del x
> ...   print dir()
> ...
> >>> z
> 'z'
> >>> f(z)
> ['x']
> []
> >>> z
> 'z'
> >>>
> 
> Secondly, within a class method, x and self.x are two different things.
> The first is just a variable within the method namespace, the second is an
> object attribute.  So, for your example, there probably is no reason to go
> kill each list element individually (unless perhaps other code is accessing
> that list NOT through the object.) Within an object method, if you honestly
> don't want to kill the variable, you could just say:
> 
> self.SortiesAnimeTitreLabel = []
> 
> and that replaces that object's list with an empty one. Unless there are
> other references to that same list, hte garbage collector will take it.
> Other code accessing the list through this object's handle will see the new,
> empty list, which I think is what you want in this case.
> 
> HTH,
> -ej

At risk of encouraging a "newbie" from partaking in the hideous and vile
vice of "programming by side effect" there is a way to make python do
almost what you want.

First, lets look at the "is" operator.  is is like ==, but instead of
answering the question "are these objects equivalent," it asks "are they
actually the same object."  

>>> a = []
>>> b = []
>>> a is b  # They are different objects
False
>>> a == b  # They have the sample value
True
>>> b = a   # Now we are assigning to b the same object as a.  
# There are two references to it.
>>> a is b
True

Alright.  Now, as Erik pointed out if you assign to the variable the
computer will add that to the local name space.  This happens at
"compile" time (which is right after you hit enter twice at the CPython
command line.) 

For an example of this:

>>> a = 0
>>> def b():
... print a
...
>>> def c():
... print a
... a = 1
...
>>> b()
0
>>> c()
Traceback (most recent call last):
  File "", line 1, in ?
  File "", line 2, in c
UnboundLocalError: local variable 'a' referenced before assignment

In b(), a was taken as being from the line above.  In c, it was from the
local name space.

So, how do we affect what you want?  Now promise me that you will never,
ever do this in code you consider yourself proud of.  Realize I'm
sharing this in the same spirit that kids in a drivers ed class might
view gory accident pictures.

Fortunately for you, lists are mutable.  Assigning to a auto-magically
makes it part of your local name space, hiding the global a.  But, if
you don't assign to a, you can still access it.  And because you can
access it you can mutate it.

>>> a = [1]
>>> def b():
... a.append( 2 )
...
>>> def c():
... a[0] = 0 # Yes, an assignment, but not to a
...
>>> def d():
... a[:] = [] 
...
>>> b()
>>> a
[1, 2]
>>> c()
>>> a
[0, 2]
>>> d()
>>> a
[]
>>>

Now forgive me ... what you really want to do is follow Erik's advice.




Adam DePrince 


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


RE: CGI zombies with Apache 1.3 on Linux

2004-12-10 Thread Robert Brewer
I wrote:
> I've Googled extensively, but can't figure out what might be 
> causing my Python CGI app to zombie (yes, Tibia, the one I
> just announced ;).

Never mind for now. I think it was a mistake in my httpd.conf. My
TransferLog didn't pipe to the correct handler, which meant access &
error events weren't being logged, which I *think* caused the children's
parents to wait forever if there was an unhandled exception. I'll be
back if it happens again. ;)


Robert Brewer
MIS
Amor Ministries
[EMAIL PROTECTED]
--
http://mail.python.org/mailman/listinfo/python-list


Re: Deadlock detection

2004-12-10 Thread Adam DePrince
On Mon, 2004-12-06 at 06:21, Duncan Grisby wrote: 
> Hi,
> 
> Does anyone know of a deadlock detector for Python?  I don't think it
> would be too hard to hook into the threading module and instrument
> mutexes so they can be tested for deadlocks. I've googled around but I
> haven't found anything.

In general, accurate deadlock detection is intractable.  Like many
problems of this class you have two choices - either reduce the scope of
the problem to a non-general one or try a heuristic to guess.  

As I recall, deadlock prevention is similar to the halting problem; the
only question you can answer is "which category am I in:"

A) I know for sure there are no deadlocks
B) I don't know, maybe there are, maybe there arn't.  

In the halting problem, the answer to your question is B until you
actually halt, in which case the answer to your problem is obvious.  

Here is a quick and dirty heuristics to filter some programs as being in
bin A or bin B.

First, for bin B.  Instrument your mutex so that every time you lock, it
creates a directed edge in a global system wide graph from your current
mutex (mutex_N) to the next to most recently locked mutex you are
currently holding for the locking thread.   If your graph becomes
cyclic, you might be in bin B (well, you were never in bin A to being
with.)  Throw a "I've lost faith in my inability to deadlock" exception.

If you can *prove* that there is a strict topological order between
nested mutex invocations, then you are in bin A.  The degree of rigor in
your proof is up to you, your level of comfort and how many people die
if your code deadlocks (your personal website and medical instruments
have different standards.)

Not everybody trusts themselves.  There are a number of alternative
approaches, including having a single global critical section lock
(ancient linux smp code) or designing your mutex operation to imply the
release of all held locks.  Of course, if you must hold more than one
lock at a time, your mutex function can take a list of locks that it
will atomically apply.  The proper design of this is left as an exercise
for the reader.

Unless you thought of this from the beginning, retrofitting safe locks
into your existing large project will be expensive.  The next
possibility won't work for python, but it is useful to keep in mind.

The halting problem has a small caveat, it is applicable to "general"
Turing machines.  Place restrictions on your Turing machine that makes
it not a Turing machine and the problem goes away.  In real time systems
(oh my, cat < aborted.phd.thesis.tex > mail [EMAIL PROTECTED] ) where you
have to compute the longest time any piece of code will take to execute
this sort of analysis is common place. Get rid of function pointers
(including weakly typed OOPLs like Python.)  You don't have to worry
about limiting loop counts like in a RTL, because we arn't interested in
timing information.  Oh, and ditch recursion.  Maybe you don't have to,
but I'm not sure.

Now walk through your code taking each possible path.  You can collapse
loops to each meaningful combination (depends on the nature of your
languages loop construct), collapse paths that don't have any mutex
operations.  You get the idea.  

Unless mutex calls are rare, or your code simple, you might spend a
while.  Largely this problem is intractable, even with simplifications,
but it is done which is why safety critical programs are (well, should
be) small and their languages not very expressive (as in finite state
machine, and not in the "but my computer is a FSM sense.") 




Adam DePrince 

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


Re: Civilization IV uses Python for scripting

2004-12-10 Thread Carl Banks
Terry Ready wrote:
> "*Civilization IV* [Sid Meier's latest, due out next year] has been
> designed to fully support the mod community. The game is written
using
> flexible XML data files and the Python scripting language so modders
will
> have no trouble at all creating their own personalized worlds, units,
> techniques, and historical events. Advanced modders will even be able
to
> control the AI."

Advancement: PYTHON
Requires: Computers, Mythology
Effect:
* Increases revenue generated by capitalization by 300%
* Makes two unhappy citizens happy
* Renders all Wonders of the World in all other countries completely
obsolete
* Boosts production of Research Lab by 150%
* Gives all military units a 200% increase in attack power, 100%
increase in defense, and a tenfold increase in accuracy
* Decreases corruption by 50% in every city.
* Decreases the maintenance costs of the following buildings by 1:
- Airport
- Bank
- Factory
- Harbour
- Hydro Plant
- Mass Transit
- Nuclear Plant
- Power Plant
- SDI Defense
- Stock Exchange
- University
* Scientists' science output increased by 50%
* Entertainers luxury output increased by 50%
* Automatically decreases the morale in every city of all countries
that have PERL advance but not PYTHON by 50%


-- 
CARL BANKS

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


Re: newbie questions

2004-12-10 Thread Erik Johnson
> do yo have any idea of what is causing this problem?
> is it possible to do self.SortiesAnimeTitreLabel = [] to reset the var?
(it
> seems to work outside of the sub, but I believe that the var I'm erasing
is
> not the one I want but a local copy.


Yeah.  I'm no Python guru, but I have a pretty good idea. Your intuition
is correct - you're killing a local copy. Functions (and methods) have their
own namespace. Variables declared within a function are local that that
function's name space, as well as formal variables that appear on the
function declartion (definition) line.

>>> z = 'z'
>>> def f(x):
...   print dir()
...   del x
...   print dir()
...
>>> z
'z'
>>> f(z)
['x']
[]
>>> z
'z'
>>>

Secondly, within a class method, x and self.x are two different things.
The first is just a variable within the method namespace, the second is an
object attribute.  So, for your example, there probably is no reason to go
kill each list element individually (unless perhaps other code is accessing
that list NOT through the object.) Within an object method, if you honestly
don't want to kill the variable, you could just say:

self.SortiesAnimeTitreLabel = []

and that replaces that object's list with an empty one. Unless there are
other references to that same list, hte garbage collector will take it.
Other code accessing the list through this object's handle will see the new,
empty list, which I think is what you want in this case.

HTH,
-ej


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


RE: Tibia 0.1 DOM-based website editor

2004-12-10 Thread Robert Brewer
Gabriel Cooper wrote:
> Robert Brewer wrote:
> 
> >I assume you're using the demo? My copy of Firefox has an 
> error browser
> >under Tools->Javascript Console. Does the double-click 
> report any error
> >there? Make sure you clear the list before trying, since 
> errors from all
> >other webpages gt dumped in the same list.
> >  
> >
> I was using the demo on your site as Admin, but it looks like your 
> server is overloaded now as the pages no longer load... Ah well. ;)

Sorry about that; I think it was entirely unrelated. Please try again if
you have the time.

NOTICE: I've been convinced to follow convention and have renamed the
file back to tibia.py. So if you download it again, or try the demo, use
that extension instead of .tba

Thanks to Oleg Broytmann, I've also fixed the CGI bug when __file__ is
not defined (it now uses sys.argv[0]). This should fix any error
messages anyone was getting about relative paths or "ascending the
tree".

Download: http://www.aminus.org/rbre/tibia/tibia.py
Demo: http://www.aminus.org/rbre/tibia/demo/tibia.py
SVN: svn://casadeamor.com/tibia/trunk revision 37
Bugs: http://www.casadeamor.com/FogBugz

Thanks to all who have tried it out!


Robert Brewer
MIS
Amor Ministries
[EMAIL PROTECTED]
--
http://mail.python.org/mailman/listinfo/python-list


Re: collaborative editing

2004-12-10 Thread Mike Meyer
Robert Kern <[EMAIL PROTECTED]> writes:

> Personally, I loathe writing at any length inside a Web browser and
> prefer to use a real editor at all times.

:-). w3m invokes $VISUAL on a temp file when you edit a TEXTAREA. It's
*so* nice to be able to insert a file instead of cutting and pasting
it.

  http://www.mired.org/home/mwm/
Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: New versions breaking extensions, etc.

2004-12-10 Thread Robert
VS7 is a really a vastly different beastie than VS6.


On 12/10/04 9:31 PM, in article [EMAIL PROTECTED],
"Jive" <[EMAIL PROTECTED]> wrote:

> Can someone explain to me why Python 2.4 on MS Windows has these backward
> compatibility problems?  What am I missing?  Why won't extensions compiled
> to run with 2.3 also work with 2.4?  Why does it matter whether a component
> was compiled with VC++ 6.0 or 7.1?  I've been using MS stuff for 6 years.
> Before I started using Python, I don't remember ever having a program tell
> me I had to use an OLDER version of something to make the program work.
> Newer, maybe, but older, never.   I had to revert to Python 2.3 because I
> have applications that will not run under Python 2.4.
> 
> Although I have been a full-time software developer since the late 70's, I
> don't know much about Microsoft stuff.  (Amazing trick that, eh?) But I've
> been reading some things on the MS web pages that say dot-NET and all that
> should NOT break existing stuff.
> http://msdn.microsoft.com/library/en-us/vclib/html/_crt_c_run.2d.time_librarie
> s.asp I
> don't pretend to understand it all, but certainly one would not expect MS to
> screw things up too badly on purpose.  The value of MS Windows lies in the
> applications that it can run.  That's part of the genius of the Evil Genius.
> He understood when others didn't that when Joe Blow in his basement develops
> a program to run under MS Windows, Joe Blow is making money for the E.G.,
> and it doesn't cost the E.G. a penny.
> 
> In my own small domain,  I cannot even consider coming out with new releases
> that are not drop-in replacements for what went before.  Customers won't go
> for it.   It's an absolute deal-breaker.
> 
> What puzzles me is that, apparently, the incompatibility of Python 2.4 and
> extensions built for 2.3 did not come as a nasty surprise.  I get the
> impression that it was expected.  Can someone explain that to me?
> 
> I hope this doesn't sound like I'm complaining.  I think Python is great.
> And the price can't be beat!
> 
> 

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


New versions breaking extensions, etc.

2004-12-10 Thread Jive
Can someone explain to me why Python 2.4 on MS Windows has these backward
compatibility problems?  What am I missing?  Why won't extensions compiled
to run with 2.3 also work with 2.4?  Why does it matter whether a component
was compiled with VC++ 6.0 or 7.1?  I've been using MS stuff for 6 years.
Before I started using Python, I don't remember ever having a program tell
me I had to use an OLDER version of something to make the program work.
Newer, maybe, but older, never.   I had to revert to Python 2.3 because I
have applications that will not run under Python 2.4.

Although I have been a full-time software developer since the late 70's, I
don't know much about Microsoft stuff.  (Amazing trick that, eh?) But I've
been reading some things on the MS web pages that say dot-NET and all that
should NOT break existing stuff.
http://msdn.microsoft.com/library/en-us/vclib/html/_crt_c_run.2d.time_libraries.asp
 I
don't pretend to understand it all, but certainly one would not expect MS to
screw things up too badly on purpose.  The value of MS Windows lies in the
applications that it can run.  That's part of the genius of the Evil Genius.
He understood when others didn't that when Joe Blow in his basement develops
a program to run under MS Windows, Joe Blow is making money for the E.G.,
and it doesn't cost the E.G. a penny.

In my own small domain,  I cannot even consider coming out with new releases
that are not drop-in replacements for what went before.  Customers won't go
for it.   It's an absolute deal-breaker.

What puzzles me is that, apparently, the incompatibility of Python 2.4 and
extensions built for 2.3 did not come as a nasty surprise.  I get the
impression that it was expected.  Can someone explain that to me?

I hope this doesn't sound like I'm complaining.  I think Python is great.
And the price can't be beat!


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


RE: CGI zombies with Apache 1.3 on Linux

2004-12-10 Thread Robert Brewer
Erik Max Francis wrote:
> Robert Brewer wrote:
> 
> > I've Googled extensively, but can't figure out what might 
> be causing my
> > Python CGI app to zombie (yes, Tibia, the one I just 
> announced ;). The
> > cgi bit looks like this:
> 
> Zombies are caused by forking a subprocess and the parent not 
> waiting on 
> it.  Does your system (sometimes) spin off a subprocess?

That's what I can't figure out. The app serves web pages via CGI, and
calls .read and .write on files in the same directory. It also calls
urllib.urlopen once in a while, and uses PIL's Image.open and .save. Oh,
and os.walk. Other than that, it's all text processing.

The subprocesses are children of apache processes (when I use "ps axf").
There's also a "[sh] " process sitting around which is a child
of apache.

Any ideas?


Robert Brewer
MIS
Amor Ministries
[EMAIL PROTECTED]
--
http://mail.python.org/mailman/listinfo/python-list


Civilization IV uses Python for scripting

2004-12-10 Thread Terry Reedy
According to PCGamer, Jan05, p52:

"*Civilization IV* [Sid Meier's latest, due out next year] has been 
designed to fully support the mod community.  The game is written using 
flexible XML data files and the Python scripting language so modders will 
have no trouble at all creating their own personalized worlds, units, 
techniques, and historical events.  Advanced modders will even be able to 
control the AI."

Other commercial games have use Python as an undocumented private scripting 
language, but this is the first I know of that will also make it the user 
scripting language -- presumably with documentation of the user-usable 
functions, classes, and methods.

Terry J. Reedy



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


Re: socket.makefile & AF_UNIX

2004-12-10 Thread Jamie Saker
>If you're trying to create a Unix socket then mknod() isn't what
>you need.  You probably want to create a socket and bind() it to
>the log file:

>filename = 'snort_alert'
> s = socket(AF_UNIX, SOCK_DGRAM)
> s.bind(filename)

Interesting - I tried this with a local test_log and it worked, creating:

srwxr-xr-x  1 field users   0 Dec 10 19:26 test_log=

which looks like my /dev/log device.

>The call to bind() will probably fail if the socket file already
>exists,

Indeed it does.

> If it's binary then you might need to use s.recv().

Makes sense. Thanks Michael. I'd expect socket.makefile is probably less 
encountered than most aspects of socket (according to google, it sure seemed 
so!).

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


Re: Distutils vs. Extension header files

2004-12-10 Thread Mike Meyer
[EMAIL PROTECTED] (David M. Cooke) writes:

> vincent has the solution (you need to specify them in MANIFEST.in),
> but I'll add my 2 cents.

Yup. That solved the problem.

> depends = [...] is used in building (it's like dependencies in make).
> If one of those files change, distutils will rebuild the extension.
> But that's all distutils does with it. It's braindead including stuff
> in the source distribution, including depends, data files, and other
> stuff you'd think it would do. When in doubt, add it to MANIFEST.in.

That pretty much sucks. I've filed a bug report (1083299) about it. If
I find time, I'll look into a fixing it myself.

http://www.mired.org/home/mwm/
Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: PIL for Windows for Python 2.4

2004-12-10 Thread Steve Holden
Fuzzyman wrote:
If you're determined enough there are instructions here :
http://www.vrplumber.com/programming/mstoolkit/
These will get you the Visual Studio 7 tools (free releases of) and
tell you how to configure distutils to use it.
Hefty downloads though, do not attempt this without broadband !
Regards,
Fuzzy
http://www.voidspace.org.uk/atlantibots/pythonutils.html
Wow! I already installed the oolkit Compiler, and now it seems I need to 
install 646MB of SDK. Make that "you have to be *really, really* 
determined".

Think I might wait a bit longer.
regards
 Steve
--
http://www.holdenweb.com
http://pydish.holdenweb.com
Holden Web LLC +1 800 494 3119
--
http://mail.python.org/mailman/listinfo/python-list


GUIs: wxPython vs. Tkinter (and others)

2004-12-10 Thread Erik Johnson

I am looking for some input on GUI libraries. I want to build a
Python-driven GUI, but don't really understand the playing field very well.
I have generally heard good things about wxPython. I happen to already own
John Grayson's book about Tkinter programming, so that is rather handy if I
decide to use Tkinter. I have done some things slightly more involved than
"Hello World" in Tkinter - I have never used wxPython. So, basically the
points I am looking to have illuminated are:

o What features does wxPython offer that Tkinter cannot (and vice
versa)?
o Is the general programming methodology pretty much the same between
the two (e.g., the general program structure - using callbacks & Frames,
etc. is the same, it's just a question of calling different widgets with
their own arguments)?
o Do you have a strong preference for one over the other (or some other
toolkit)? Why?
o Are there any platform and/or performance issues I should be aware of?
o Is animation and graphics particularly better suited to one over the
other?
o Other important contrasts/similarities I should be aware of?

So... I know this question must come up fairly often. I did do a search
for "wxPython" and "Tkinter" - of the articles I currently have visibility
of, I saw one bug in wxPython discussed and nothing about Tkinter. Anything
else than can contribute to a "bird's eye view" understanding of the two (or
other) toolkits would be appreciated.

Thanks for taking the time to read my post.

Sincerely,
-ej


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


OT-Test

2004-12-10 Thread frau_Gertrude
Ver si aparece la frau



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


Dr. Dobb's Python-URL! - weekly Python news and links (Dec 10)

2004-12-10 Thread Josiah Carlson
QOTW:  "I still think this is a silly idea, but at least it doesn't track mud
all over Python's nice clean rugs." -- Michael J. Fromberger

http://groups-beta.google.com/group/comp.lang.python/browse_thread/thread/dde861393aa5a68/eb3a5e53f9743413

"Basically, in tk, canvases are for vector drawing; in other toolkits, they're
more for bitmap drawing. And this makes quite a difference..." -- Eric Brunel


Lovers of the eric3 editor get a new 3.5.1 release.
http://mail.python.org/pipermail/python-list/2004-November/252450.html

Lovers of the Wing IDE editor get a new 2.0.1 release.
http://mail.python.org/pipermail/python-list/2004-December/253698.html

Sometimes the `struct` module's use and structure aren't obvious to the
new user.  Tim Peters and Peter Hanson help clarify.
http://mail.python.org/pipermail/python-list/2004-November/252741.html

A company in New York is looking for a Python deveoper for Zope work.
I know there has to be someone in NYC with that kind of experience.
http://mail.python.org/pipermail/python-list/2004-December/252840.html

Locks, mutexes, Semaphores - Oh My!  Discussion of when to use what.
Hint: they are basically the same, only speed and internal implementation
really set them apart.  RLock, Condition, Event, etc., add functionality.
http://mail.python.org/pipermail/python-list/2004-December/252869.html

Gordon Williams asks about set intersections.  Raymond Hettinger
confirms that set intersection with the `set` module does the right
thing.
http://mail.python.org/pipermail/python-list/2004-December/253142.html

A nice one-liner for DNA recombinations.  Be careful with the size of
your input, you don't want to go and segfault with a 512M element list...
http://mail.python.org/pipermail/python-list/2004-December/252970.html

Armin Ringo releases Psyco 1.3, for those of us who like our Python to
execute faster.  Support for Python 2.1-2.4 is included, as well as more
support for local variables.
http://mail.python.org/pipermail/python-list/2004-December/253234.html

Alia Khouri asks "why no python setup.py uninstall?" and gets basically
no response.  It brings up the topic of Python package management, which
has been discussed before.
http://mail.python.org/pipermail/python-list/2004-December/253316.html
http://python.org/peps/pep-0301.html

Andre Roberge asks for advice on naming a new (claimed better) version
of "Guido van Robot", which is an instructional tool for new programmers.
http://mail.python.org/pipermail/python-list/2004-December/253453.html



Everything Python-related you want is probably one or two clicks away in
these pages:

Python.org's Python Language Website is the traditional
center of Pythonia
http://www.python.org
Notice especially the master FAQ
http://www.python.org/doc/FAQ.html

PythonWare complements the digest you're reading with the
marvelous daily python url
 http://www.pythonware.com/daily  
Mygale is a news-gathering webcrawler that specializes in (new)
World-Wide Web articles related to Python.
 http://www.awaretek.com/nowak/mygale.html 
While cosmetically similar, Mygale and the Daily Python-URL
are utterly different in their technologies and generally in
their results.

comp.lang.python.announce announces new Python software.  Be
sure to scan this newsgroup weekly.

http://groups.google.com/groups?oi=djq&as_ugroup=comp.lang.python.announce

Brett Cannon continues the marvelous tradition established by 
Andrew Kuchling and Michael Hudson of intelligently summarizing
action on the python-dev mailing list once every other week.
http://www.python.org/dev/summary/

The Python Package Index catalogues packages.
http://www.python.org/pypi/

The somewhat older Vaults of Parnassus ambitiously collects references
to all sorts of Python resources.
http://www.vex.net/~x/parnassus/   

Much of Python's real work takes place on Special-Interest Group
mailing lists
http://www.python.org/sigs/

The Python Business Forum "further[s] the interests of companies
that base their business on ... Python."
http://www.python-in-business.org

Python Success Stories--from air-traffic control to on-line
match-making--can inspire you or decision-makers to whom you're
subject with a vision of what the language makes practical.
http://www.pythonology.com/success

The Python Software Foundation (PSF) has replaced the Python
Consortium as an independent nexus of activity.  It has official
responsibility for Python's development and maintenance. 
http://www.python.org/psf/
Among the ways y

newbie questions

2004-12-10 Thread houbahop
Hello everyone,
I'm new to python dev, and there are some things I don't understand 
about arrays and subs

In my code, I have an array of strings (in the main function)

   self.SortiesAnimeTitreLabel = []

then I pass this array to a sub that fill it it ( using.append('blabla') :

   self.InstancierLabelsTitre(self.SortiesAnimeTitreLabel)

then, I need to reset this var, and this is my problem, I have created an 
other sub to reset and it doesn't seems to work, like if the parameter was 
pass by value instead of by reference. here is the sub :


def RAZVarAnimesDuJour(self,oSortiesAnimeTitreLabel):
   for i in xrange(len(oSortiesAnimeTitreLabel)):
   del oSortiesAnimeTitreLabel[i]

it doesn't emty my var (i don't want to destroy the var, just make it like 
if it just have been created

do yo have any idea of what is causing this problem?
is it possible to do self.SortiesAnimeTitreLabel = [] to reset the var? (it 
seems to work outside of the sub, but I believe that the var I'm erasing is 
not the one I want but a local copy.


Thank you for your help.
Dominique. 


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


thread/queue bug

2004-12-10 Thread phil
>You have the source to Queue.py in your standard library
>folder.  Why not throw a few more print statements into
>its __init__ and see what you learn?
Yeah I put some print statements in init and it seems
to complete.
>Are you by any chance running on a new version of the
>Linux kernel, where the threading model has changed?
>(Or was it just RedHat 9.0?)
RedHat 7.2, 2.4.20 kernel.  Get the same hangup on
Win2000 Pro. Which leads me to believe it has nothing
to do with kernel threads.
Well its an anomaly.  I sent to bug list.
Probably never see it again.
I think some sort of semaphore thingy, which I know
nothing about, is sneaking in under unreproducible
conditions.  I'm moving on.
I'm love python for multi-thread, simple socket programming
and lots of reasons.  This is the first thing that's looked
like a bug in 5 years (1.5), I'm not worried.
Thanks for your help.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Compiling Python 2.4 extensions with free VC++ Toolkit

2004-12-10 Thread Jody Burns
My bad, I misread his post.  I don't know how to compile Python without 
Visual Studio.

--Jody
Mike C. Fletcher wrote:
Jody Burns wrote (with Peter):
See Mike C. Fletcher's post and 
http://www.vrplumber.com/programming/mstoolkit/ for a way to do it 
very easily (you have to be able to use the GNU patch tool, but that's 
not difficult at all).

--Jody

...
not been able to get into hacking on the core of Python because

...
-Peter

Keep in mind that the recipe there is for building *extensions*, not 
core Python.  There's a pointer from my page to a post by someone who 
seemed to have built core Python with the Toolkit, but my page isn't 
going to help Peter much with hacking on core Python.

Just an FYI,
Mike

 Mike C. Fletcher
 Designer, VR Plumber, Coder
 http://www.vrplumber.com
 http://blog.vrplumber.com
--
http://mail.python.org/mailman/listinfo/python-list


Re: from vb6 to Python

2004-12-10 Thread stevev
Try PythonCard.  It should provide the easiest learning curve given
your VB background.

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


Re: problem with datetime

2004-12-10 Thread Bob
Thanks.  That did it.  And I know better than to use the module name.
Bob

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


Re: Ideas for projects

2004-12-10 Thread Terry Hancock
On Wednesday 08 December 2004 09:29 pm, Phillip Bowden wrote:
> I feel that I've learned the language pretty well, but I'm having 
> trouble thinking of a medium to large project to start.  What are some 
> projects that you have written in the past with Python?

I would recommend going to Sourceforge and doing a search for
projects that list Python as their programming language. You'll
find lots of open source projects in Python, and maybe a few you'd
be interested in pursuing.  There are lots of projects that need 
help, and some are quite fascinating projects, depending on your
interests.

http://sourceforge.net/

You might also want to try the same sort of thing at

http://nongnu.org/

Except there, they shoot you if you say "open source", even if
you are in fact using the GPL license, as I found out the hard
way.  Fair warning.

Cheers,
Terry

--
Terry Hancock ( hancock at anansispaceworks.com )
Anansi Spaceworks  http://www.anansispaceworks.com

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


Re: socket.makefile & AF_UNIX

2004-12-10 Thread Michael Fuhr
Jamie Saker <[EMAIL PROTECTED]> writes:

> In the makefile operation on socket (pydoc socket.socket.makefile... using 
> AF_UNIX, allowing you to create a file object to correspond to a socket) I've 
> got an sample program (goal: open up unix file socket object for snort's 
> alert_unixsock output mode to dump to. later, take data written into file 
> object and process) as follows:

If you're trying to create a Unix socket then mknod() isn't what
you need.  You probably want to create a socket and bind() it to
the log file:

filename = 'snort_alert'
s = socket(AF_UNIX, SOCK_DGRAM)
s.bind(filename)

The call to bind() will probably fail if the socket file already
exists, so you might want to unlink it first (or make sure you clean
up by unlinking it whenever you exit).

Whether it's appropriate to call makefile() and use methods like
readline() depends on the format of the data that the other end
will send.  If it's binary then you might need to use s.recv().

-- 
Michael Fuhr
http://www.fuhr.org/~mfuhr/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Unicode docstrings in PyMethodDef?

2004-12-10 Thread "Martin v. Löwis"
Craig Ringer wrote:
 > For the use of anybody asking the same question later: There doesn't
appear to be a nice way to make docstrings unicode, or not one I could
find.
I don't know whether you'ld consider it "nice": you need to put an
__doc__ attribute into the function object. There is currently no C
API involving char* to do so, so it might not be that nice.
Regards,
Martin
--
http://mail.python.org/mailman/listinfo/python-list


Re: How do I do this? (eval() on the left hand side)

2004-12-10 Thread Carl Banks
> From my point of view, they're basically identical, and
> although I find Carl's approach slightly less explicit
> and harder to read (mainly the uncommon __import__ call,
> but it's not a big deal), I can't see why either of them
> would be considered evil.

Of course, when I said evil, I didn't mean evil, I meant Evil(tm).  I
suspect Nick meant so as well.

Personally, I just think __import__(__name__) is a bit more honest than
globals() for a simple reason.

What are you doing?  You're changing module attributes.  Well, here's
the module object.  You're using setattr on the module object to set
module attributes.

What are you doing?  You're changing module attributes.  Well, here's
the module's dict.  You're using dictionary access on the modules dict
to set modules attributes.

It's a bit more honest to set module attributes using setattr than dict
access, I would say.  That's why I prefer it.  I admit, it's pretty
weak.  (But then again, so is __import__ being uncommon. :)  It's not a
big deal which you choose, as you say.  Although I don't use globals()
in this way, I do modify object dicts to get the effect of changing
object attributes from time to time (mostly to take advantage of dict
methods, which I could see being a reason to use globals() as well).
-- 
CARL BANKS

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


Re: How do I do this? (eval() on the left hand side)

2004-12-10 Thread Peter Hansen
Carl Banks wrote:
It's a bit more honest to set module attributes using setattr than dict
access, I would say.  
Granted.
But I think it's also more honest to change a module's dict by
using globals() than by using a setattr call. <0.500 wink>
-Peter
--
http://mail.python.org/mailman/listinfo/python-list


Re: thread/queue bug

2004-12-10 Thread Peter Hansen
phil wrote:
Uses no locks.
It does use locks implicitly, though, since even just
importing threading will do that, and creating a Queue
does too.
I am mystified, I have written probably 100,000 lines
of Python and never seen a thread just lock up and quit
running.  It happens on a Queue() statement so my suspicion
is a bug.  ??
You have the source to Queue.py in your standard library
folder.  Why not throw a few more print statements into
its __init__ and see what you learn?
I have kludged around it by putting all the thread/queue stuff
in the main program and import the stuff I don't want to
distribute.  But mysteries haunt your dreams, sooo...
#!/usr/local/bin/python
[snip source]
I cobbled together a "working" version of your code
and ran it just fine, whether imported or run directly.
No lockups.  On Windows XP.
Are you by any chance running on a new version of the
Linux kernel, where the threading model has changed?
(Or was it just RedHat 9.0?)
I don't know the details, but I know folks have had trouble
with this and Python...  For example, I found this
reference to the issue:
http://groups.google.ca/groups?th=fe9a064ffeb38adc&seekm=bpi438%24qta%2408%241%40news.t-online.com#link2
-Peter
--
http://mail.python.org/mailman/listinfo/python-list


Re: Wrapper objects

2004-12-10 Thread redhog
>Well, that could be a feature, depending on what your use case is.
>Or you could make a method for adding methods, I suppose.
>A perfectly transparent wrap of obj would be to do nothing ;-)
>What do you actually want to do?

Actually, the very best would if only type(), isinstance() and the
is-keyword could an object and a wrapped version of it apart.

I've thought of using a weakdict instaed, problem is, it would be a
little bit too transparent for my purpose as the only way to tell an
object and a wrapped version of it apart would be by my own functions
which would do lookups in that dict. Secondly, it would only allow for
one comment per object dopy, which would fail horribly for e.g. numbers
(there are hundreds of uses of the number 1, which all needs different
comments for the number).

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


Re: Compiling Python 2.4 extensions with free VC++ Toolkit

2004-12-10 Thread Mike C. Fletcher
Jody Burns wrote (with Peter):
See Mike C. Fletcher's post and 
http://www.vrplumber.com/programming/mstoolkit/ for a way to do it 
very easily (you have to be able to use the GNU patch tool, but that's 
not difficult at all).

--Jody
...
not been able to get into hacking on the core of Python because

...
-Peter

Keep in mind that the recipe there is for building *extensions*, not 
core Python.  There's a pointer from my page to a post by someone who 
seemed to have built core Python with the Toolkit, but my page isn't 
going to help Peter much with hacking on core Python.

Just an FYI,
Mike

 Mike C. Fletcher
 Designer, VR Plumber, Coder
 http://www.vrplumber.com
 http://blog.vrplumber.com
--
http://mail.python.org/mailman/listinfo/python-list


ANNOUNCE: PyPHP, Python programming using the PHP web framework

2004-12-10 Thread Antony Lesuisse
PyPHP the python php bridge
===

Download it at http://lesuisse.net/pyphp-0.1.tgz

WARNING this is experimental !

Summary:


PyPHP enables Python programming in the PHP web framework.
PyPHP is not yet another Python Web framework, it is the PHP web framework made
available to Python programmers.

With PyPHP you get the best of both Python and PHP world:
- The power, cleanness and robustness of the Python language
- The much used, developped and maintained PHP framework

The most useful PHP framework features you get access to are:
- Session management (using pickle you are be able to store your python objects
  in the PHP sessions)
- Persistent database connections
- HTTP authentification
- Ouput buffering and header/cookie management

While most python programmers would favor the Python Standard Library to the
PHP functions library, PyPHP allows PHP programmers to use the PHP functions
from their Python code and brings new features to the Python programmers.


Quickstart:
---

Hello world in pyphp, hello.php:

---

from pyphp import php

print "Hello World"
---

Accessing php functions, test.php:

---

# vim:syntax=python:
from pyphp import php

php.header("Content-Type: text/plain")
print "Hello from python\n"
print php.explode("/","/etc/passwd")
php.eval("print_r($_SERVER);")


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


request for book-recommendation

2004-12-10 Thread patrick c.d.
hi,

does here anyone of ya geeks know a book teaching you how to handle gtk,
web-dev with mysql-db-connection and scripting under gnu/linux with phyton?

i'm german (hhaarr) but due to my efficiency-course in english (shool) i
want to learn english by learning phyton ;-)

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


Re: from vb6 to Python

2004-12-10 Thread Gerhard Häring
MarcoL wrote:
Hello,
I am a VB6 programmer and I would like to learn a new high level 
language (instead of restarting from scratch with .NET), wich is 
opensource and cross-platform, in order to develop cross-platform 
business applications
I think Python is the most suitable language for the scope.
My question are:

- Which version of python is more suitable for creating cross-platform 
GUI's? I've herard of PyGTK, wxPython, PyQT, tk, Anygui..
It's a matter of taste. I like wxPython best. It would probably be 
different if PyQT was also open-source on win32.

- What is the best IDE/RAD for Python (written in Python and OpenSource)
You should check out ERIC/Qt. If you need to target Windows, then you 
can consider buying a win32 Qt/PyQt license.

The best IDE I've seen so far is WingIDE (commercial).
- Does exist a tool (written in Python and OpenSource) like Crystal 
Report for creating business reports?
Reportlab is the closest I know.
- Does exist a tool (written in Python and OpenSource) for makeing 
tables, view, querys, relation of a database and generate the SQL script?
Rekall is the closest.
- Is it possible, from Python, to work with sqlite? And with MsAccess?
Yes.
pysqlite (http://pysqlite.org/), and pyado, if by MsAccess you mean 
using the JET engine via ADO.

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


thread/queue bug

2004-12-10 Thread phil
And sorry I got ticked, frustrating week
>And I could help more, being fairly experienced with
>threading issues and race conditions and such, but
>as I tried to indicate in the first place, you've
>provided next to no useful (IMHO) information to
>let anyone help you more than this
This is about 5% of the code.
Uses no locks.
I am mystified, I have written probably 100,000 lines
of Python and never seen a thread just lock up and quit
running.  It happens on a Queue() statement so my suspicion
is a bug.  ??
I have kludged around it by putting all the thread/queue stuff
in the main program and import the stuff I don't want to
distribute.  But mysteries haunt your dreams, sooo...
#!/usr/local/bin/python
# pnetx.py
from threading import *
from time import *
from Queue import Queue
from socket import *
import sys
import os
# glob is a DUMMY CLASS
glob.listenq = Queue(1000)
def listener():
while 1:
msg,addrport = listenersocket.recvfrom(BUFSIZE)
addr = addrport[0]
glob.listenq.put (( msg,addr),1)
if msg == 'DIE': break

def procmsgs():
while 1:
msg,addr = glob.listenq.get(1)
if msg == 'DIE': break
wds = msg.split(';')
if wds[0] == 'S': recvsucc(msg); continue
if wds[0] == 'E': recvevent(msg); continue
if wds[0] == 'ACK': recvack(msg[4:]); continue
if wds[0] == 'MONITOR':
  if addr not in monitorlist:
print 'This line ALWAYS PRINTS'
queuelist.append( Queue(0) )
## The above fails if this code is imported
## It doesn't matter whether it is imported
##as .py or .pyc
## also mq = Queue(0); queuelist.append(mq) # fails
print 'This line ALWAYS PRINTS if i execute this source'
print 'but NEVER PRINTS if I import '
print 'this source from a 1 line program'
print 'Thats weird'
monitoron.append( 1 )
monitorlist.append( addr )
queuelist = [Queue(0)]
listenersocket = socket(AF_INET,SOCK_DGRAM)
listenersocket.bind(ListenAddr)
procm = Thread(target=procmsgs)
procm.start()
listenr = Thread(target=listener)
listenr.start()
## Then start a bunch of other threads and queuea.
Don't spend a lot of time on this, not worth it.
I just thought someone might have experienced
something similar.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Zip with a list comprehension

2004-12-10 Thread Carl Banks
Matt Gerrans wrote:
> This is probably so easy that I'll be embarrassed by the answer.
While
> enhancing and refactoring some old code, I was just changing some
map()s to
> list comprehensions, but I couldn't see any easy way to change a
zip() to a
> list comprehension.Should I just let those sleeping dogs lie?
(list
> comprehensions seem more readable than map(), but if the list
comprehension
> that does the equivalent of zip() is less expressive than zip(), I'll
stick
> with zip()).

I don't recall seeing zip on the list of things that were considered
bad for Python 3K, probably because it's not functional programming (a
la map, reduce, and filter) but rather just list manipulation.

I can't think of a good way to replace zip with a list comp, and I
doubt there is such a way.  Think about it: a list comp is semantically
equivalent to a certain for loop (or loops, perhaps with some if-blocks
in there as well).  A list comp can do only what a for loop can do,
nothing more.

Well, zip was created to address a deficiency in for-looping, namely
that it was unwieldy to loop through two lists side-by-side.  I suspect
that, if there were a simple way to accomplish what zip does in a list
comp, there would have also been an easy way to do it with for loops,
and therefore zip would not have had any reason to exist.

So, unless the BDFL waves his magic wand and adds some new syntax for
for loops (unlikely), I think you can operate under the assumption that
zip will be Python 3000 Certified (tm).

Having said that, you might want to consider using itertools.izip
instead.  It works just like zip, but returns an iterator instead of a
list.  Good for those length-ten-million lists you wanted to iterate
side-by-side.


-- 
CARL BANKS

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


Re: Help beautify ugly heuristic code

2004-12-10 Thread JanC
Stuart D. Gathman schreef:

> I have a function that recognizes PTR records for dynamic IPs.  There
> is no hard and fast rule for this - every ISP does it differently, and
> may change their policy at any time, and use different conventions in
> different places.  Nevertheless, it is useful to apply stricter
> authentication standards to incoming email when the PTR for the IP
> indicates a dynamic IP (namely, the PTR record is ignored since it
> doesn't mean anything except to the ISP).  This is because Windoze
> Zombies are the favorite platform of spammers.

Did you also think about ISPs that use such a PTR record for both dynamic 
and fixed IPs?

-- 
JanC

"Be strict when sending and tolerant when receiving."
RFC 1958 - Architectural Principles of the Internet - section 3.9
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: collaborative editing

2004-12-10 Thread Doug Holton
Michele Simionato wrote:
Suppose I want to write a book with many authors via the Web. The book has 
a hierarchical structure with chapter, sections, subsections, subsubsections, 
etc. At each moment it must be possible to print the current version of the 
book in PDF format. There must be automatic generation of the table of contents,
indices, etc. Conversions to many formats (Latex, DocBook, etc.) would be
welcome. Does something like that already exists? Alternatively, I would need
some hierarchical Wiki with the ability of printing its contents in an
structured way. 
You want a wiki engine.  There are many to choose from, some of which 
have all the features you want.
See for example Atlassian Confluence.  We are using it to create 
documentation for boo ( http://boo.codehaus.org ).  This page for 
example has child pages and you can export pages to html, pdf, or xml.
http://docs.codehaus.org/display/BOO/Recipes
http://docs.codehaus.org/spaces/exportspace.action?key=BOO

I think the PHP/MySQL-based Tiki wiki has similar features, too.
http://tikiwiki.org/tiki-index.php
--
http://mail.python.org/mailman/listinfo/python-list


Re: UrlLib2 Proxy and Https

2004-12-10 Thread j_belbo
I have made some tests with Curl and this proxy setting is correct
It's seems that there is a problem with HTTPS and urllib2 + proxy
Bye,
Jacobo
"Tom" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED]
> > I would like to access an HTTPS site via a proxy
> > The following code is working for HTTP://www.hotmail.com but not for
HTTPS
> > I have try with other sites without success
> >
> >   l_proxy_info = {
> >  'user' : mylogin,
> >  'pass' : mypassword,
> >  'host' : myproxy,
> >  'port' : 8080
> >   }
>
> I have no idea if this is your problem, but you are aware that https is
> usually on port 443, not 80 or 8080 like http?
>
> HTH
>
> Tom


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


from vb6 to Python

2004-12-10 Thread MarcoL
Hello,
	I am a VB6 programmer and I would like to learn a new high level 
language (instead of restarting from scratch with .NET), wich is 
opensource and cross-platform, in order to develop cross-platform 
business applications
I think Python is the most suitable language for the scope.
My question are:

- Which version of python is more suitable for creating cross-platform 
GUI's? I've herard of PyGTK, wxPython, PyQT, tk, Anygui..

- What is the best IDE/RAD for Python (written in Python and OpenSource)
- Does exist a tool (written in Python and OpenSource) like Crystal 
Report for creating business reports?

- Does exist a tool (written in Python and OpenSource) for makeing 
tables, view, querys, relation of a database and generate the SQL script?

- Is it possible, from Python, to work with sqlite? And with MsAccess?
Thanks for your patience and your help.
Marco.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Distutils vs. Extension header files

2004-12-10 Thread David M. Cooke
Mike Meyer <[EMAIL PROTECTED]> writes:

> I've got a package that includes an extension that has a number of
> header files in the directory with the extension. They are specified
> as "depends = [...]" in the Extension class. However, Distutils
> doesn't seem to do anything with them.
>
> If I do an sdist, the include files aren't added to the tarball.
>
> If I do a bdist_rpm, the source files get copied into the build
> directory and the build starts, but the header files aren't copied
> with the source file, so the build fails with a missing header file.
>
> I find it hard to believe that this is a bug in distutils, so I'd
> appreciate it if someone could tell me what I'm doing wrong.

vincent has the solution (you need to specify them in MANIFEST.in),
but I'll add my 2 cents.

depends = [...] is used in building (it's like dependencies in make).
If one of those files change, distutils will rebuild the extension.
But that's all distutils does with it. It's braindead including stuff
in the source distribution, including depends, data files, and other
stuff you'd think it would do. When in doubt, add it to MANIFEST.in.

-- 
|>|\/|<
/--\
|David M. Cooke
|cookedm(at)physics(dot)mcmaster(dot)ca
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Rationale behind the deprecation of __getslice__?

2004-12-10 Thread Steven Bethard
Nick Coghlan wrote:
Steven Bethard wrote:
Carl Banks wrote:
Wouldn't it work to have __getslice__ call __getitem__?  And, since
that would be too much of a performance hit, have it check whether its
type is list (or str or tuple), and only call __getitem__ if it is not
(i.e., only for subclasses).  I don't think that would be too bad.
Subclasses would still be free to override __getslice__, but wouldn't
have to.

Yeah, that doesn't seem like it would be too bad.  Probably someone 
would have to actually run some benchmarks to see what kind of 
performance hit you get...  But it would definitely solve the OP's 
problem...

It might be better handled at construction time - if the class supplied 
to __new__ is a subclass of the builtin type, swap the __getslice__ 
implementation for one which delegates to __getitem__.
Yeah, that seems like the minimally invasive solution...  I looked a bit 
at the listobject.c code, but I think the patch for this one is a bit 
over my head...

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


Re: How do I do this? (eval() on the left hand side)

2004-12-10 Thread Peter Hansen
Carl Banks wrote:
Nick Coghlan wrote:
to that module is far more evil than playing with globals() ;)
I'd say using globals() is far eviler.  
I don't understand either of you. ;-)
From my point of view, they're basically identical, and
although I find Carl's approach slightly less explicit
and harder to read (mainly the uncommon __import__ call,
but it's not a big deal), I can't see why either of them
would be considered evil.
Changing a module's contents via globals() is a very common
and surely benign thing to do.
-Peter
--
http://mail.python.org/mailman/listinfo/python-list


Re: thread/queue bug

2004-12-10 Thread Peter Hansen
phil wrote:
I've never before on any group seen anyone told they
had a mental block, because they were fishing for info.
I'm sorry if I offended you by using that term.  That
wasn't my intention.  Communications can be difficult
in an online forum.  For example, I would normally find
the phrase "fishing for info" to be offensive, but in
this case I'll assume we got off on the wrong foot and
that there are some different thought patterns involved,
and I'm sure you didn't intend to offend any more than
I did.
My intention with "mental block" was to emphasize as
strongly as I could my conviction that your problem
has *nothing* to do with the fact that you have a .pyc
file instead of a .py, and to encourage you to search
elsewhere, to find another way of getting more information
about the problem.
The one key difference that I can see on the face of
it is that a .pyc, being already compiled, doesn't
need a compilation phase the way a .py file would if
it didn't already have an up-to-date .pyc file
present.
I really doubt this small difference in time is the
source of the trouble, but it's possible.  On the
other hand, when you run with the .py file, if you
run a second time and it still fails, then this is
even less likely to be the problem because it will
compile the .py file only the first time, and the
second time it will use the .pyc file just like
when you don't even have the .py file around.
And I could help more, being fairly experienced with
threading issues and race conditions and such, but
as I tried to indicate in the first place, you've
provided next to no useful (IMHO) information to
let anyone help you more than this... sorry.  (And,
again, no offense intended by that statement.)
-Peter
--
http://mail.python.org/mailman/listinfo/python-list


Re: collaborative editing

2004-12-10 Thread MMM
Michele Simionato wrote:
> Suppose I want to write a book with many authors via the Web. The
book has
> a hierarchical structure with chapter, sections, subsections,
subsubsections,
> etc. At each moment it must be possible to print the current version
of the
> book in PDF format. There must be automatic generation of the table
of contents,
> indices, etc. Conversions to many formats (Latex, DocBook, etc.)
would be
> welcome. Does something like that already exists? Alternatively, I
would need
> some hierarchical Wiki with the ability of printing its contents in
an
> structured way.
>
>
> Michele Simionato
Tkae a look at 
http://www.infrae.org/products/silva/

Regards,
Mikhail

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


Re: sources for DOS-16bit

2004-12-10 Thread Peter Hansen
McBooCzech wrote:
I am looking for Python binaries for DOS-16bit
Not for Win-16bit or DOS-32 which are the only DOS availabele sources
on Python official site and on the other sites as well!!!
I will prefere sources for Borland C 3.x.
I was trying to use Python 1.0.1 (16python.exe file) for my
application,
but I realized it doesn't work on NEC V25 CPU (8086/8088 compatible
CPU developed by NEC).
I was involved in to our school computer "research" :) and we need
this piece of code to reach our goal.
We have to demonstrate the power of the free software (mainly its
compatiblity for different platforms)!!!
Can you please search your archives or route me somewhere?
Does it have to be Python?  There are other languages that
are arguably as portable, and certainly more compact.  Lua,
for example, has been ported to quite small devices.  See
http://www.lua.org/ for more on that, but note there are
other options as well.  Python's not the only "free portable
software" around, though it's the best in many ways.
-Peter
--
http://mail.python.org/mailman/listinfo/python-list


Re: Wrapper objects

2004-12-10 Thread redhog
As to what I want to use this for, I today have a huge program in which
several objects are wrapped up with comments (made up by some DOMish
structre) which are displayed to the user at various times. For
example, a list of users may be represented as as comment "List of
users" and a python list of elements, each being a user id (represented
as an integer), with a comment being the username. This means the list
is usable both for user-output and for machine-handling. Hm, this
wasn't prolly such a good example, but hopefully, it shows enought of
the idea...

Tody, the comment-value-pair is an ordinary object with two member
variables, and there are two functions, getComment and getValue, which
extracts a comment if its argument is such an object, or None
otherwise, and the wrapped value if its argument is such an object, and
the argument itself otherwize, respectively.

This means my code is literally filled with calls to getValue(), which
I would like to be able to remove by making the comment-value pair more
transparent.

The wrapper objects needs to work as dictionary keys, to support
printing, concatenation/addition, getitem/setitem and such things...

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


thread/queue bug

2004-12-10 Thread phil
>Wow, amazing!  Imagine that... asking for elaboration when
>someone posts unclear confusing questions and extraneous
>information.  The noive!
I would be happy to elaborate. No one asked to me to elaborate.
I was simply told I didn't give enough information.
I wasn't given an idea of what additional information
was needed or some clue as to how to better phrase my question.
>I also find it remarkable that so many different people are
>all doing the same thing to you.  It must be a conspiracy.
>Certainly not a problem with, say, you...
I didn't say so many people are doing the same thing to me.
Some language support groups make me feel like I am asking
stupid questions in a stupid way, not all.  And the Linux
and FreeBSD support groups never do.  In fact it seems
on those groups the more newbie and inadequate your questions
are the more patience and help you get.
I've never before on any group seen anyone told they
had a mental block, because they were fishing for info.
I have a genuine problem here, which I have no clue how to approach,
and I am very sorry I started a flame over protocol.
THAT has certainly never happened to me before. signing off.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Wrapper objects

2004-12-10 Thread redhog
Ah, thanks. I didn't think of the possibility of creating a list of
methods that needed wrapping, and wrapping them uppon creation of the
wrapper object. Mainly I think, becaus it seems to me as such an uggly
workaround for a misdesign in Python. Also, if the wrapped object gets
some extra methods/callable member variables added "after the fact",
those will not get wrapped (this is however not a common thing to
happen, it just annoys me that it won't work).

As to what I want to use this for, I today have a huge program in which
several objects are wrapped up with comments (made up by some DOMish
structre) which are displayed to the user at various times. For
example, a list of users may be represented as as comment "List of
users" and a python list of elements, each being a user id (represented
as an integer), with a comment being the username. This means the list
is usable both for user-output and for machine-handling. Hm, this
wasn't prolly such a good example, but hopefully, it shows enought of
the idea...

Todya, the comment-value-pair is an ordinary object with two member
variables, and there are two functions, getComment and getValue, which
extracts a comment if its argument is such an object, or None
otherwise, and the wrapped value if its argument is such an object, and
the argument itself otherwize, respectively.

This means my code is literally filled with calls to getValue(), which
I would like to be able to remove by making the comment-value pair more
transparent.

Anyway, I do have some questions about your implementation:

If "if inst is None: return self" to protect for infinite recursion
when looking up self.__dict__?

What is the reason to give func to the MethodDesc property object, why
does its __get__ method have to do

if func: return func.__get__(self.thing, type(self.thing))

?

What is the reason to neither wrap, nor just copy, any of __getattr__,
__getattribute__, __setattr__, '__new__' or '__init__'? Especially
__getattr__, __getattribute__ and __setattr__ seems to need at least
some type of wrapping (but perheaps some special one)?
Regards,
Egil Möller

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


Re: Clarification of two concepts (or maybe one?)

2004-12-10 Thread Fredrik Lundh
Eddie Parker wrote:

> What I’m looking for, is a way to turn a python ‘application’, into a
> ‘stand-alone’ application. i.e., you don’t need the Python interpreter,
> libraries, etc, installed on your hard drive. (I’m OK with .py files
> existing – I just don’t want to have to bother the user to install more then
> just my app).

you cannot run Python without a Python interpreter -- but you can ship the
interpreter DLL and the necessary library components with your app, and
you can use bundling tools to reduce the number of files to a minimum:

http://effbot.org/zone/python-compile.htm
http://www.python.org/cgi-bin/moinmoin/DistributionUtilities

 



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


A puzzle Re: Decorators for multimethods

2004-12-10 Thread Roman Suzi

For those who want to exercize Python skills, there is a problem
below for defining multimethod g with as simple syntax as possible:

@MULTIMETHOD
def g(x, y):
@PART(Foo, Foo)
def m1(a, b): return 'foofoo'

@PART(Foo, Bar)
def m2(a, b): return 'foobar'

@PART(Bar, Foo)
def m3(a, b): return 'barfoo'


What are definitions of MULTIMETHOD and PART in this case?
(if such are at all possible).

My best result was with

class G(MMCLASS):
  def define(self):
@self.PART(Foo, Foo)
def m1(a, b): return 'foofoo'

@self.PART(Foo, Bar)
def m2(a, b): return 'foobar'

@self.PART(Bar, Foo)
def m3(a, b): return 'barfoo'

g = G()

where

class MMCLASS(Multimethod.Generic):
 def __init__(self):
  Multimethod.Generic.__init__(self)
  def PART(*args):
def make_multimethod(func):
  mm = Multimethod.Method(tuple(args), func)
  print func
  self.add_method(mm)
  return mm
return make_multimethod
  self.PART = PART
  self.define()


On Fri, 10 Dec 2004, Roman Suzi wrote:

>
>hi!
>
>I've found one more nice use case for decorators. I feel multimethods
>could be made even nicier by defining multimethods inside special
>class. But I have not figured out how to do it yet.
>
>#!/bin/env python2.4
>if "We have Neel Krishnaswami module Multimethod.py":
>
>import Multimethod
>
>class Foo: pass
>
>class Bar(Foo): pass
>
>def multimethod(g, *args):
>  def make_multimethod(func):
>mm = Multimethod.Method(tuple(args), func)
>g.add_method(mm)
>return mm
>  return make_multimethod
>
>g = Multimethod.Generic()
>
>@multimethod(g, Foo, Foo)
>def m1(a, b): return 'foofoo'
>
>@multimethod(g, Foo, Bar)
>def m2(a, b): return 'foobar'
>
>@multimethod(g, Bar, Foo)
>def m3(a, b): return 'barfoo'
>
>try:
>print 'Argtypes ', 'Result'
>print 'Foo, Foo:', g(Foo(), Foo())
>print 'Foo, Bar:', g(Foo(), Bar())
>print 'Bar, Foo:', g(Bar(), Foo())
>print 'Bar, Bar:', g(Bar(), Bar())
>except Multimethod.AmbiguousMethodError:
>print 'Failed due to AmbiguousMethodError'
>
>
>Sincerely yours, Roman Suzi
>

Sincerely yours, Roman Suzi
-- 
[EMAIL PROTECTED] =\= My AI powered by GNU/Linux RedHat 7.3
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Unicode docstrings in PyMethodDef?

2004-12-10 Thread Craig Ringer
On Wed, 2004-12-08 at 13:43, Craig Ringer wrote:
> Hi folks
> 
> I'm currently working on a fairly well internationalised app that embeds
> a Python intepreter. I'd like to make the docstrings translatable, but
> am running into the issue that the translation function returns unicode
> data.

For the use of anybody asking the same question later: There doesn't
appear to be a nice way to make docstrings unicode, or not one I could
find. I ended up just changing the sysdefaultencoding to utf-8 because
that solved a bunch of other problems in the app too. A fairly drastic
step, to be sure, but OK because it's an embedded interpreter that
doesn't have to worry about compatibility with most existing Python
scripts (except libs/modules, which should AFAIK consider not accepting
utf a bug). The change from the default Python behaviour has been
clearly documented.

In particular, now users can easily use literals in any language they
choose (except some arabit and indic languages and thai) in the embedded
Python console, and have everything work as they expect.

If this is the wrong approach, someone please yell at me - but only if
you can tell me the right one.

--
Craig Ringer

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


Re: sources for DOS-16bit

2004-12-10 Thread Paul Rubin
"McBooCzech" <[EMAIL PROTECTED]> writes:
> before I decided to bother you by e-mail, I spent days (not kidding)
> searching on the Internet. I am looking for Python binaries for
> DOS-16bit

I think this is hopeless.  Python is too memory hungry for that.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: thread/queue bug

2004-12-10 Thread Peter Hansen
phil wrote:
You know, I get this all the time on language support groups.
All of my Linux support groups, if they don't understand, say
why and ask for elaboration.  
Wow, amazing!  Imagine that... asking for elaboration when
someone posts unclear confusing questions and extraneous
information.  The noive!
I also find it remarkable that so many different people are
all doing the same thing to you.  It must be a conspiracy.
Certainly not a problem with, say, you...
--
http://mail.python.org/mailman/listinfo/python-list


Re: Tibia 0.1 DOM-based website editor

2004-12-10 Thread Gabriel Cooper

Robert Brewer wrote:
I assume you're using the demo? My copy of Firefox has an error browser
under Tools->Javascript Console. Does the double-click report any error
there? Make sure you clear the list before trying, since errors from all
other webpages gt dumped in the same list.
 

I was using the demo on your site as Admin, but it looks like your 
server is overloaded now as the pages no longer load... Ah well. ;)
--
http://mail.python.org/mailman/listinfo/python-list


Re: How do I do this? (eval() on the left hand side)

2004-12-10 Thread Carl Banks
Nick Coghlan wrote:
> Well, aside from the detail that modifying a module's contents via a
reference
> to that module is far more evil than playing with globals() ;)
>
> Even if that module is the one you're running in. . .

It seems to me that that which makes modifying a module's contents via
a reference evil makes modifying them via globals() equally evil.  The
only thing is, modifying them through a module reference is explicit
and straightforward, whereas modifying the contents via globals() is an
implicit, backhanded trick that relies on certain behind-the-scenes
behavior.

I'd say using globals() is far eviler.  So I must disagree with your
good-natured objection.  Unless there's some practical weakness of
using references that I am unaware of.
-- 
CARL BANKS
(Yes, I know eviler is not a word.)

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


Zip with a list comprehension

2004-12-10 Thread Matt Gerrans
This is probably so easy that I'll be embarrassed by the answer.   While 
enhancing and refactoring some old code, I was just changing some map()s to 
list comprehensions, but I couldn't see any easy way to change a zip() to a 
list comprehension.Should I just let those sleeping dogs lie?   (list 
comprehensions seem more readable than map(), but if the list comprehension 
that does the equivalent of zip() is less expressive than zip(), I'll stick 
with zip()).

 


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


Re: Zip with a list comprehension

2004-12-10 Thread Steven Bethard
Matt Gerrans wrote:
This is probably so easy that I'll be embarrassed by the answer.   While 
enhancing and refactoring some old code, I was just changing some map()s to 
list comprehensions, but I couldn't see any easy way to change a zip() to a 
list comprehension.Should I just let those sleeping dogs lie?   (list 
comprehensions seem more readable than map(), but if the list comprehension 
that does the equivalent of zip() is less expressive than zip(), I'll stick 
with zip()).
Hmmm...  I couldn't do any better than:
>>> seqs = [(1, 2, 3), (4, 5, 6, 7)]
>>> zip(*seqs)
[(1, 4), (2, 5), (3, 6)]
>>> [tuple(seq[i] for seq in seqs)
...  for i in range(min(len(seq) for seq in seqs))]
[(1, 4), (2, 5), (3, 6)]
I think I'll stick with zip. ;)
I too have been trying to make my code more conformant with Python 3000 
recommendations (e.g. removing maps in favor of LCs or GEs, replacing 
lambdas with named functions, etc.) but I've left zip pretty much alone.

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


sources for DOS-16bit

2004-12-10 Thread McBooCzech
Hi all,

before I decided to bother you by e-mail, I spent days (not kidding)
searching on the Internet. I am looking for Python binaries for
DOS-16bit
Not for Win-16bit or DOS-32 which are the only DOS availabele sources
on Python official site and on the other sites as well!!!
I will prefere sources for Borland C 3.x.

I was trying to use Python 1.0.1 (16python.exe file) for my
application,
but I realized it doesn't work on NEC V25 CPU (8086/8088 compatible
CPU developed by NEC).

I was involved in to our school computer "research" :) and we need
this piece of code to reach our goal.

We have to demonstrate the power of the free software (mainly its
compatiblity for different platforms)!!!

Can you please search your archives or route me somewhere?


I will really appreciate your answer and help
Petr Jakes
Gymnasium student
Jicin
Czech republic

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


Decorators for multimethods

2004-12-10 Thread Roman Suzi

hi!

I've found one more nice use case for decorators. I feel multimethods
could be made even nicier by defining multimethods inside special
class. But I have not figured out how to do it yet.

#!/bin/env python2.4
if "We have Neel Krishnaswami module Multimethod.py":

import Multimethod

class Foo: pass

class Bar(Foo): pass

def multimethod(g, *args):
  def make_multimethod(func):
mm = Multimethod.Method(tuple(args), func)
g.add_method(mm)
return mm
  return make_multimethod

g = Multimethod.Generic()

@multimethod(g, Foo, Foo)
def m1(a, b): return 'foofoo'

@multimethod(g, Foo, Bar)
def m2(a, b): return 'foobar'

@multimethod(g, Bar, Foo)
def m3(a, b): return 'barfoo'

try:
print 'Argtypes ', 'Result'
print 'Foo, Foo:', g(Foo(), Foo())
print 'Foo, Bar:', g(Foo(), Bar())
print 'Bar, Foo:', g(Bar(), Foo())
print 'Bar, Bar:', g(Bar(), Bar())
except Multimethod.AmbiguousMethodError:
print 'Failed due to AmbiguousMethodError'


Sincerely yours, Roman Suzi
-- 
[EMAIL PROTECTED] =\= My AI powered by GNU/Linux RedHat 7.3
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: CGI zombies with Apache 1.3 on Linux

2004-12-10 Thread Erik Max Francis
Robert Brewer wrote:
I've Googled extensively, but can't figure out what might be causing my
Python CGI app to zombie (yes, Tibia, the one I just announced ;). The
cgi bit looks like this:
Zombies are caused by forking a subprocess and the parent not waiting on 
it.  Does your system (sometimes) spin off a subprocess?

--
Erik Max Francis && [EMAIL PROTECTED] && http://www.alcyone.com/max/
San Jose, CA, USA && 37 20 N 121 53 W && AIM erikmaxfrancis
  Defeat is a school in which truth always grows strong.
  -- Henry Ward Beecher
--
http://mail.python.org/mailman/listinfo/python-list


Clarification of two concepts (or maybe one?)

2004-12-10 Thread Eddie Parker








Sorry, I’ve tried to search the web on this,
but I’m still a little fuzzy. I was hoping a quick e-mail might clear
this up.


What I’m looking for, is a way to turn a python ‘application’,
into a ‘stand-alone’ application. i.e., you don’t need the
Python interpreter, libraries, etc, installed on your hard drive. (I’m OK
with .py files existing – I just don’t want to have to bother the
user to install more then just my app). 

 

One alternative is to embed the Python interpreter in
a C++ app, and then just call the entry point... But I’m curious if there’s
a better way?

 

On the unrelated (or maybe related) concept, the words
“python freezing” keeps buzzing around my subconscious. I’m
not sure if this item can help me in any such way, but I can’t find any
good articles on what this phenomenon *is*.
Can anyone point me to a definitive web page that describe this, or indicate if
it *is* in fact what I’m
looking for? (I’m probably way off base on this one).

 

Anyhow, your help is most appreciated! Thank you!

 

-e-








---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.788 / Virus Database: 533 - Release Date: 01/11/2004
 
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: Fun with Outlook and MAPI

2004-12-10 Thread Chris
Alas, I dont think that there is much you can do to prevent the 
confirmation dialogs with Outlook's MAPI dll. MS added them in a 
service pack as an anti-virus measure, so no work-around. Not all 
clients show these anoying dialogs though. Thunderbird definately 
doesn't.
There is actually a workaround. You're using Simple MAPI which has a 
nice easy interface. The confirmation dialogs are only for Simple MAPI. 
Using Extended MAPI can work around the problem but its a lot more tricky.
See the initial discussion here: 
http://aspn.activestate.com/ASPN/Mail/Message/Python-win32/2160646

This code has now been included in pywin32 somehow but I can't remember 
where and its late. Should also be a cookbook entry. Maybe Google can 
help :-)
Cool.  I'll take a look an' see if I can get it to work.  MAPI has 
turned out to be a major PITA.  Especially when trying to learn it and 
Python at the same time. :)

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


capwords (WAS: [Newby] question about modules)

2004-12-10 Thread Steven Bethard
Jon wrote:
As far as I can tell from the online docs, "capwords" should be defined in
the built-in "regex" module.  Why is it telling me that capwords is not
defined?
Hmm... are you looking instead for "capwords" from the string module?
>>> s = """\
... Well, he's...
... he's, ah...
... probably pining for the fjords."""
>>> import string
>>> print string.capwords(s)
Well, He's... He's, Ah... Probably Pining For The Fjords.
>>> print s.title()
Well, He'S...
He'S, Ah...
Probably Pining For The Fjords.
Note that there are a few subtle differences between string.capwords and 
str.title -- string.capwords capitalizes only at whitespace boundaries 
(and replaces runs of whitespace with spaces), while str.title 
capitalizes at alphanumeric boundaries.

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


Re: Fun with Outlook and MAPI

2004-12-10 Thread Chris
Will McGugan wrote:
I'm trying to send an e-mail through outlook.  So far I've gotten it 
to work with the mail script at 
http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/149461  My 
only problem is that when I call Resolve() and Send(), I get 
confirmation dialogs.  I will be sending out quite a few e-mails at a 
time, and would rather not have the user have to click yes for every 
single one.  Does anyone know a workaround?  I know about smtplib, but 
I would prefer to simply make what I have work.  Thanks.
Alas, I dont think that there is much you can do to prevent the 
confirmation dialogs with Outlook's MAPI dll. MS added them in a service 
pack as an anti-virus measure, so no work-around. Not all clients show 
these anoying dialogs though. Thunderbird definately doesn't.
Unfortunately, I don't have the option of installing Thunderbird.
Chris
--
http://mail.python.org/mailman/listinfo/python-list


Re: Fun with Outlook and MAPI

2004-12-10 Thread Will McGugan
David Fraser wrote:
Alas, I dont think that there is much you can do to prevent the 
confirmation dialogs with Outlook's MAPI dll. MS added them in a 
service pack as an anti-virus measure, so no work-around. Not all 
clients show these anoying dialogs though. Thunderbird definately 
doesn't.


There is actually a workaround. You're using Simple MAPI which has a 
I stand corrected.
Will McGugan
--
http://mail.python.org/mailman/listinfo/python-list


thread/queue bug

2004-12-10 Thread phil
> 4. The fact that you have a .pyc file instead of a .py
> file very likely has *nothing* to do with any threading
> problem you are facing, so I suggest you get past that mental
> block and look elsewhere.
Well, I tried to make it clear that the ONLY difference between
working and not working was the pnetx.pyc when imported did not
work when
#!/usr/bin/python
# pnet.py, exists only to import pnetx.py
import pnetx.py
Otherwise the program has worked fine for months.
I don't think its a mental block, its the ONLY difference.
It freezes on the following statement:
mq = Queue(0)
and I haven't a clue why.  All the other threads continue to run.
> 5. Sorry I can't be more help.  You don't give anyone much
> to go on.  All that stuff about "Queue(0)" and "listenq"
> is pretty much meaningless to us, you know...
You know, I get this all the time on language support groups.
All of my Linux support groups, if they don't understand, say
why and ask for elaboration.  I tried to explain what was going on,
without incuding the source.  I have about 200 man hours in the source
and I bet it would take longer to understand it.
If my explanation was insufficient, I'm sorry.
ALSO, you did not respond to my email, so I didn't know how to reply.
There is nothing on the archives page which gives me a clue as to
how to respond.
SO, if there is ZERO chance there is some sort of inadvertent lock
occuring in saved byte code, I just kludge around and move on.
Maybe 2.4
Thanks.
--
http://mail.python.org/mailman/listinfo/python-list


Re: [Newby] question about modules

2004-12-10 Thread Steven Bethard
Jon wrote:
The following four lines of code:
import sys, os, re
sentence = raw_input("Enter a sentence:  ")
capwords (sentence)
print sentence
gives me the following error:  NameError: name 'capwords' is not defined
As far as I can tell from the online docs, "capwords" should be defined in
the built-in "regex" module.  Why is it telling me that capwords is not
defined?
Which docs are you looking at?  I couldn't find documentation for a 
capwords method or class...  Checking at the interactive prompt:

>>> import regex
__main__:1: DeprecationWarning: the regex module is deprecated; please 
use the re module
>>> dir(regex)
['__doc__', '__name__', 'casefold', 'compile', 'error', 'get_syntax', 
'match', 'search', 'set_syntax', 'symcomp']
>>> import re
>>> dir(re)
['DOTALL', 'I', 'IGNORECASE', 'L', 'LOCALE', 'M', 'MULTILINE', 'S', 'U', 
'UNICODE', 'VERBOSE', 'X', '__all__', '__builtins__', '__doc__', 
'__file__', '__name__', 'compile', 'engine', 'error', 'escape', 
'findall', 'finditer', 'match', 'purge', 'search', 'split', 'sub', 
'subn', 'template']

I don't see an object named capwords in either module.
What are you trying to do?  If you just want to capitalize words, 
str.title() is probably the easier way to do this:

>>> s = "i wanted to be a lumberjack!"
>>> s.title()
'I Wanted To Be A Lumberjack!'
Steve
--
http://mail.python.org/mailman/listinfo/python-list


Re: question about modules

2004-12-10 Thread Reinhold Birkenfeld
Jon wrote:
> Hi Jeff,
> 
> That makes sense -- thanks.  However now when I use "re.capwords (sentence)"
> I get a different error message:
> 
> AttributeError: 'module' object has no attribute 'capwords'
> 
> Each of the other two suggested implimentations produce a similar error
> message.  Is there something even more basic that I am failing to do?  I'm
> using the IDLE GUI in WinXP, Python release 2.4...

The 'capwords' function seems to be defined in the "string" module, not
the "re" module.

Reinhold

-- 
[Windows ist wie] die Bahn: Man muss sich um nichts kuemmern, zahlt fuer
jede Kleinigkeit einen Aufpreis, der Service ist mies, Fremde koennen
jederzeit einsteigen, es ist unflexibel und zu allen anderen Verkehrs-
mitteln inkompatibel.   -- Florian Diesch in dcoulm
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Compiling Python 2.4 extensions with free VC++ Toolkit

2004-12-10 Thread Jody Burns
See Mike C. Fletcher's post and 
http://www.vrplumber.com/programming/mstoolkit/ for a way to do it very 
easily (you have to be able to use the GNU patch tool, but that's not 
difficult at all).

--Jody
Peter Hansen wrote:
None, other than to note that if you and/or others were able to
solve this and make it "easy" for those less VC++-savvy, you
might significantly decrease the bar for those of us who have
not been able to get into hacking on the core of Python because
of being stuck in the MS world yet not willing to shell out more
cash to billg...  maybe, just maybe, that would get a few more
people out there reviewing patches and maybe fixing bugs.
-Peter
--
http://mail.python.org/mailman/listinfo/python-list


Re: UrlLib2 Proxy and Https

2004-12-10 Thread Tom
I would like to access an HTTPS site via a proxy
The following code is working for HTTP://www.hotmail.com but not for HTTPS
I have try with other sites without success
  l_proxy_info = {
 'user' : mylogin,
 'pass' : mypassword,
 'host' : myproxy,
 'port' : 8080
  }
I have no idea if this is your problem, but you are aware that https is 
usually on port 443, not 80 or 8080 like http?

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


Re: question about modules

2004-12-10 Thread Jon
Hi Jeff,

That makes sense -- thanks.  However now when I use "re.capwords (sentence)"
I get a different error message:

AttributeError: 'module' object has no attribute 'capwords'

Each of the other two suggested implimentations produce a similar error
message.  Is there something even more basic that I am failing to do?  I'm
using the IDLE GUI in WinXP, Python release 2.4...

Thanks!
Jon


"Jeffrey Maitland" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
> Jon writes:
>
> > Hi,
> >
> > The following four lines of code:
> >
> > import sys, os, re
> > sentence = raw_input("Enter a sentence:  ")
> > capwords (sentence)
> > print sentence
> >
> > gives me the following error:  NameError: name 'capwords' is not defined
> >
> > As far as I can tell from the online docs, "capwords" should be defined
in
> > the built-in "regex" module.  Why is it telling me that capwords is not
> > defined?
> >
> > I am completely new to Python so my apologies for such a basic question!
> >
> > Thanks,
> > Jon
> >
> >
> > -- 
> > http://mail.python.org/mailman/listinfo/python-list
>
> Hello Jon,
>
> The reason for that is you only imported the module(class/object) now to
use
> its methodes you need to call the object.
>
> in this case to fix the problem you are having you would have to do it
> either one of these methodes (unless there are more that I am not aware
of)
> 1/
> import sys, os, re
> sentence = raw_input("Enter a sentence:  ")
> re.capwords (sentence) # <-- notice the re.capwords this
>   # calling the capword method of the re module.
> print sentence
>
> 2/
> import sys, os
> from re import * # < import all methods of re and allow them to be
> #   used locally
> sentence = raw_input("Enter a sentence:  ")
> capwords (sentence)
> print sentence
> # this imports all the methodes in the re module so they can be used
> # localy.
>
> or
> import sys, os
> from re import capwords  # < import only capwords method of re
> sentence = raw_input("Enter a sentence:  ")
> capwords (sentence)
> print sentence
> # this import only imports the capwords methode of the re module
>
>
> I hope this helps you some and if i used the incorrect terminology I am
> sorry and I hope someone points it out to me.
>
> Jeff Maitland


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


Re: [Newby] question about modules

2004-12-10 Thread James Stroud
Is it in "regex" or "re"? If in "re" then:

re.capwords(sentence)

If in "regex", then:

regex.capwords(sentence)


You can also do

from re import *

then you will not have to prefix. But careful not to clutter your namespace.

On Friday 10 December 2004 10:29 am, Jon wrote:
> Hi,
>
> The following four lines of code:
>
> import sys, os, re
> sentence = raw_input("Enter a sentence:  ")
> capwords (sentence)
> print sentence
>
> gives me the following error:  NameError: name 'capwords' is not defined
>
> As far as I can tell from the online docs, "capwords" should be defined in
> the built-in "regex" module.  Why is it telling me that capwords is not
> defined?


-- 
James Stroud, Ph.D.
UCLA-DOE Institute for Genomics and Proteomics
611 Charles E. Young Dr. S.
MBI 205, UCLA 951570
Los Angeles CA 90095-1570
http://www.jamesstroud.com/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Fun with Outlook and MAPI

2004-12-10 Thread David Fraser
Will McGugan wrote:
Chris wrote:
I'm trying to send an e-mail through outlook.  So far I've gotten it 
to work with the mail script at 
http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/149461  My 
only problem is that when I call Resolve() and Send(), I get 
confirmation dialogs.  I will be sending out quite a few e-mails at a 
time, and would rather not have the user have to click yes for every 
single one.  Does anyone know a workaround?  I know about smtplib, but 
I would prefer to simply make what I have work.  Thanks.

Alas, I dont think that there is much you can do to prevent the 
confirmation dialogs with Outlook's MAPI dll. MS added them in a service 
pack as an anti-virus measure, so no work-around. Not all clients show 
these anoying dialogs though. Thunderbird definately doesn't.


There is actually a workaround. You're using Simple MAPI which has a 
nice easy interface. The confirmation dialogs are only for Simple MAPI. 
Using Extended MAPI can work around the problem but its a lot more tricky.
See the initial discussion here: 
http://aspn.activestate.com/ASPN/Mail/Message/Python-win32/2160646

This code has now been included in pywin32 somehow but I can't remember 
where and its late. Should also be a cookbook entry. Maybe Google can 
help :-)

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


Re: Possible to insert variables into regular expressions?

2004-12-10 Thread Steven Bethard
Terry Hancock wrote:
And hey, you could probably use a regex to modify a regex, if you were
really twisted. ;-)
Sorry.  I really shouldn't have said that. Somebody's going to do it now. :-P
Sure, but only 'cause you asked so nicely. =)
>>> import re
>>> def internationalize(expr,
...  letter_matcher=re.compile(r'\[A-(?:Za-)?z\]')):
... return letter_matcher.sub(r'[^\W_\d]', expr)
...
>>> def compare(expr, text):
... def item_str(matcher):
... return ' '.join(matcher.findall(text))
... print 'reg: ', item_str(re.compile(expr))
... print 'intl:', item_str(re.compile(internationalize(expr),
...re.UNICODE))
...
>>> compare(r'\d+\s+([A-z]+)', '1 viola. 2 voilà')
reg:  viola voil
intl: viola voilà
>>> compare(r'\d+\s+([A-Za-z]+)', '1 viola. 2 voilà')
reg:  viola voil
intl: viola voilà
This code converts [A-z] style regexps to a regexp that is suitable for 
use with other encodings.  Note that without the conversion, characters 
like 'à' are not found.

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


Re: Find Items & Indices In A List...

2004-12-10 Thread Bengt Richter
On Fri, 10 Dec 2004 16:27:29 GMT, Steven Bethard <[EMAIL PROTECTED]> wrote:

>[EMAIL PROTECTED] wrote:
>> Hello NG,
>> 
>>   I was wondering if there is a faster/nicer method (than a for loop)
>> that will allow me to find the elements (AND their indices) in a list that
>> verify a certain condition. For example, assuming that I have a list like:
>> 
>> mylist = [0, 1, 1, 1, 1, 5, 6, 7, 8, 1, 10]
>> 
>> I would like to find the indices of the elements in the list that are equal
>> to 1 (in this case, the 1,2,3,4,9 elements are equal to 1). I could easily
>> use a for loop but I was wondering if there is a faster method...
>
>Everyone has already given you the answer (enumerate in a LC or GE), I'd 
>just comment that it's easy enough to extend their answers to any given 
>condition:
>
> >>> def getindices(sequence, predicate):
>...return [i for i, v in enumerate(sequence) if predicate(v)]
>...
> >>> getindices([0,1,1,1,1,5,6,7,8,1,10], bool)
>[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
> >>> def equalsone(v):
>...return v == 1
>...
> >>> getindices([0,1,1,1,1,5,6,7,8,1,10], equalsone)
>[1, 2, 3, 4, 9]
> >>> def f(v):
>...return pow(v, 3, 4) == 3
>...
> >>> getindices([0,1,1,1,1,5,6,7,8,1,10], f)
>[7]
>
Conclusion:
Python is programmer's Lego ;-)

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


Re: Fun with Outlook and MAPI

2004-12-10 Thread Will McGugan
Chris wrote:
I'm trying to send an e-mail through outlook.  So far I've gotten it to 
work with the mail script at 
http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/149461  My only 
problem is that when I call Resolve() and Send(), I get confirmation 
dialogs.  I will be sending out quite a few e-mails at a time, and would 
rather not have the user have to click yes for every single one.  Does 
anyone know a workaround?  I know about smtplib, but I would prefer to 
simply make what I have work.  Thanks.
Alas, I dont think that there is much you can do to prevent the 
confirmation dialogs with Outlook's MAPI dll. MS added them in a service 
pack as an anti-virus measure, so no work-around. Not all clients show 
these anoying dialogs though. Thunderbird definately doesn't.

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


Re: style query: function attributes for return codes?

2004-12-10 Thread holger krekel
[Reinhold Birkenfeld Fri, Dec 10, 2004 at 08:42:10PM +0100]
> holger krekel wrote:
> > class Connection(object): 
> > def __init__(self, **kw): 
> > for name in kw: 
> > assert name in ('good', 'badauth', 'noserver'), name 
> > setattr(self, name, kw[name]) 
> > 
> > def get_connection():
> > if tcp_conn():
> > if server_allows_conn():
> > return Connection(good=True) 
> > else:
> > return Connection(badauth=True) 
> > else:
> > return Connection(noserver=True) 
> 
> That's evil, because "if conn.good" raises an AttributeError instead of
> evaluating to False if the connection is not good. You would have to
> inizialize all three attributes in every construction of a Connection
> object.

Ups, you are right of course.  I somehow managed to delete the line ... 

class Connection(object): 
good = badauth = noserver = False   

thanks for pointing it out. 

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


Re: 2D array

2004-12-10 Thread Adam DePrince
On Wed, 2004-12-08 at 16:22, Steven Bethard wrote:
> Adam DePrince wrote:
> > The use of  None as the default parameter was on purpose; the lack of
> > "magic" in python is often cited in religious wars between python and
> > perl aficionados.  Use of get(something, None) was on purpose, the level
> > of familiarity with the language implied by the original question
> > suggested that the notion of optional parameters, and specifically those
> > of get, may not have been immediately obvious.
> > 
> > As for a[0,0] instead of a[(0,0)] ... the former just *looks* so
> > aesthetically wrong to me that I've never used it, and had forgotten
> > that it was even possible.   
> 
> Sorry, I hadn't meant any of my comments as criticisms -- just wanted to 
> make sure the OP knew about all the options open to them.  I'm used to 
> a[0,0] because I've used numarray a bit, but to each his own, of course. =)

Even if you were, there is certainly no need to apologize.  In
hindsight, my response seems rather naive; as naive perhaps as the
students in my freshman year undergrad C class who having grown up on
Turbo pascal would add to their programs:

#define BEGIN {
#define END {

because it "looked right." 


Adam DePrince 


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


CGI zombies with Apache 1.3 on Linux

2004-12-10 Thread Robert Brewer
I've Googled extensively, but can't figure out what might be causing my
Python CGI app to zombie (yes, Tibia, the one I just announced ;). The
cgi bit looks like this:


def cgi_handler():
import cgi

form = cgi.FieldStorage(keep_blank_values=True)
params = dict([(key, form[key].value) for key in form])

env = os.environ.get
filename = env('PATH_TRANSLATED') or env('SCRIPT_FILENAME')
username = env('AUTH_USER') or env('REMOTE_USER') or
env('LOGON_USER')
app = TibiaApp(params, filename, username)
print "Content-type: %s\n" % app.content_type
print "".join(app.output)


if __name__ == '__main__':
cgi_handler()



Should I be explicitly closing stdout at the end of cgi_handler()? I
don't get a zombie with every request.



Robert Brewer
MIS
Amor Ministries
[EMAIL PROTECTED]
--
http://mail.python.org/mailman/listinfo/python-list


Re: Wrapper objects

2004-12-10 Thread Bengt Richter
On 10 Dec 2004 09:33:51 -0800, [EMAIL PROTECTED] wrote:

>Bengt Richter wrote:
>> On 9 Dec 2004 06:11:41 -0800, [EMAIL PROTECTED] (Egil M?ller) wrote:
>>
>> >So my naive implementation of a wrapper class,
>> >
>> >
>> >class wrapper(object):
>> >def __init__(self, value, otherdata):
>> >self.value =3D value
>> >self.otherdata =3D otherdata
>> >def __getattribute__(self, name):
>> >return getattr(self.value, name)
>> >
>> >
>> >does not work. Any ideas for a solution?
>>
>> This seems to go some way towards it:
>>
[snip ugly wrapper hack]
>> Not tested beyond what you see ;-) This doesn't wrap setting
>attributes on the wrapped object,
>> so setting attributes sets them on the wrapper itself, but that could
>be fixed.
>>
>> Now what was it you wanted to use a wrapper for? ;-)
[...]
>
>
>Ah, thanks. I didn't think of the possibility of creating a list of
>methods that needed wrapping, and wrapping them uppon creation of the
>wrapper object. Mainly I think, becaus it seems to me as such an uggly
>workaround for a misdesign in Python. Also, if the wrapped object gets
It is ugly. I am not satisfied with it, but I wanted to offer some
experimental results that might be useful (if only to decide not to
go that way ;-)
>some extra methods/callable member variables added "after the fact",
>those will not get wrapped (this is however not a common thing to
>happen, it just annoys me that it won't work).
Well, that could be a feature, depending on what your use case is.
Or you could make a method for adding methods, I suppose.
A perfectly transparent wrap of obj would be to do nothing ;-)
What do you actually want to do?
>
>However, I do have some questions about your implementation:
>
>If "if inst is None: return self" to protect for infinite recursion
>when looking up self.__dict__?
What self are you referring to? Anyway, inst is None when you access
a descriptor instance as a class attribute, e.g., MyClass.desc as opposed
to as an attribute of an instance of that class, e.g., MyClass().desc.
Even __dict__ is actually itself a descriptor. Try
type(obj).__dict__['__dict__'].__get__ (on a new style obj instance).
vs type(obj).__dict__.__get__ which doesn't work.

>
>What is the reason to give func to the MethodDesc property object, why
>does its __get__ method have to do
>
>if func: return func.__get__(self.thing, type(self.thing))
>
>?
This is to create a bound method that's bound to the thing, not to the
wrapper object. I guess this could be done at wrapping time instead.
I was just hacking down the path of least resistance ;-)

>
>What is the reason to neither wrap, nor just copy, any of __getattr__,
>__getattribute__, __setattr__, '__new__' or '__init__'? Especially
>__getattr__, __getattribute__ and __setattr__ seems to need at least
>some type of wrapping (but perheaps some special one)?
Sorry, this was to eliminate some problems I had along the way. But __new__
and __init__ have to be kept out of the Wrapper class or they will be
invoked when Wrapper() is done to create the wrapped object.

I have hacked something better, not using def __metaclass__, which isn't
necessary. (I just prepare a cdict similarly, and then use that in
 
Wrapper = type('Wrapped_'+type(thing).__name__, (object,), cdict)

plus playing games to avoid the wrong __init__ and __new__ etc.) 

Also, I just remembered an idea that someone had used to limit
methods in an attempt at security by assigning obj.__class__ with a
compatible class. So that might be an avenue too. Maybe a wrapper could
be a subclass of type(obj), and then just copy method function references
to the wrapper class dict? I'll have to explore that another time...

What is your actual use case? ;-)

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


Re: style query: function attributes for return codes?

2004-12-10 Thread Reinhold Birkenfeld
holger krekel wrote:
> Hi George, 
> 
> [george young Fri, Dec 10, 2004 at 10:45:47AM -0500]
>> [python 2.3.3, x86 linux]
>> I recently found myself writing something like:
>> 
>> def get_connection():
>> if tcp_conn():
>> if server_allows_conn():
>> return 'good_conn'
>> else:
>> return 'bad_auth'
>> else:
>> return 'no_server'
>> 
>> cn = get_connection()
>> if cn == 'good_con': ...
>> 
>> 
>> This is obviously just evil, since a misspelling in the string
>> return is treacherous.
> 
> Right. 
> 
> I usually like to look at such problems from the angle of 
> what is most convenient for the *caller* side? 
> 
> And having to adress function attributes does
> not seem convenient.  I'd probably like to do from 
> the caller side something like: 
> 
> conn = get_connection() 
> if conn.good: 
> ... 
> elif conn.badauth: 
> ... 
> elif conn.noserver: 
> ... 
> 
> which allows you to freely choose and hide your actual
> implementation at the "called" side. Example: 
> 
> class Connection(object): 
> def __init__(self, **kw): 
> for name in kw: 
> assert name in ('good', 'badauth', 'noserver'), name 
> setattr(self, name, kw[name]) 
> 
> def get_connection():
> if tcp_conn():
> if server_allows_conn():
> return Connection(good=True) 
> else:
> return Connection(badauth=True) 
> else:
> return Connection(noserver=True) 

That's evil, because "if conn.good" raises an AttributeError instead of
evaluating to False if the connection is not good. You would have to
inizialize all three attributes in every construction of a Connection
object.

Reinhold


-- 
[Windows ist wie] die Bahn: Man muss sich um nichts kuemmern, zahlt fuer
jede Kleinigkeit einen Aufpreis, der Service ist mies, Fremde koennen
jederzeit einsteigen, es ist unflexibel und zu allen anderen Verkehrs-
mitteln inkompatibel.   -- Florian Diesch in dcoulm
-- 
http://mail.python.org/mailman/listinfo/python-list


  1   2   >