Re: Python evolution: Unease

2005-01-06 Thread David Fraser
Alex Martelli wrote:
Carlos Ribeiro <[EMAIL PROTECTED]> wrote:
   ...
wish I could simply plug & play DBAPI modules in a totally seamlessly
way. Anyone who tried know how far are we of this dream.

If you manage to get there, you'll start fighting against the different
dialects of SQL supported by the various back-ends, as is well known by
anybody who tried, say, ODBC or ADO, which do manage good plug&play of
their components but still can't solve the real hard one:-(
I've found I can get by nicely by just supporting stock standard bottom 
end SQL and not using any database-specific features. Just requires a 
little wrapper code for some functions

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


Re: SuSE 9.1: updating to python-2.4

2005-01-10 Thread David Fraser
Torsten Mohr wrote:
Hi,
along with my distribution SuSE 9.1 came python 2.3.3.
I'd like to update to 2.4 now, is this an easy thing to do
or will lots of installed modules refuse to work then?
Is there an easy way to find out what i need to update?
Thanks for any hints,
Torsten.
What you probably want to do is install python2.4 alongside python2.3.3 
as an alternate installation, since a lot of other programs in SuSE 
probably depend on having python2.3.3 and won't work with the upgrade.

Have a look at the RPMs on the python 2.4 downloads page and see if you 
can install them OK (I just did this fine for python 2.3 on whitebox linux).

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


Re: how to find site-packages path (Michael Hoffman) - use distutils

2005-01-19 Thread David Fraser
Philippe C. Martin wrote:
I actually target Unix and windows so pyexe won't cut it I'm afraid -
same issue with Inno.
As far as the site-package target, I don't fully understand your
relunctancy. Just as my potential users might not own a compiler, they
might not be computer proficient enough to easily understand how to
change the sys.path. So until I have found a clean cross platform
solution I'm going to have to stick to site-packages.
Hi Philippe
You may want to have a look at 
https://sourceforge.net/tracker/?func=detail&atid=305470&aid=793070&group_id=5470

This was originally a patch to distutils which enabled removing the 
source (i.e. only distributing compiled files). I have now attached a 
file there which enables you to do the same thing, but without patching 
distutils - it just wraps functions etc from outside.

Basically you call allow_distutils_remove_source in the module and it 
does the neccessary changes. Then you get a --remove-source options to 
most of the commands. You can also selectively override what gets 
removed if you want by changing the is_removable function

I hope this is useful for what you're wanting to do
David
--
http://mail.python.org/mailman/listinfo/python-list


Re: Accessing MDB files on Windows

2005-01-20 Thread David Fraser
Jorge Luiz Godoy Filho wrote:
Jorge Luiz Godoy Filho, Quarta 19 Janeiro 2005 14:25, wrote:

Thanks!  I'm looking at it.

Worked like a charm!  And just now I noticed who's the author of the
recipe ;-)
You may also be interested in using a DB-API compatible driver for ADO - 
 see for example http://adodbapi.sourceforge.net/
That way if you want to switch to a different database you can more 
easily...

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


Re: module for 'po' files

2005-01-26 Thread David Fraser
Sara Fwd wrote:
 Hi all
Is there a module for processing & handling  '.po'
files in python?
If you want to do anything beyond standard gettext (which is handled by 
the gettext module) there's lots of code at translate.sourceforge.net ...

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


Re: [ANN] Spike Asset Manager release 0.13

2005-01-31 Thread David Fraser
mh wrote:
Fredrik-
This is a known issue.  The tool currently only looks in certain
locations or hints rather then spidering the whole hard drive (which
could take a bit of time).  If you have installed in a non-standard
location (or are using a platform or version of software that hasn't
been tested against) the tool won't find the component.
One way around this is manually enter more "hints" but this doesn't
scale.  I'm open to suggestions for handling this in a better way.
matt
ps-I assume you are running on windows.  Where is python installed on
your machine?
Windows also has package management in the form of Windows Installer, it 
would be better to use that on windows than simply look in locations...

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


Re: [Python-Announce] cfgparse v01_00 released

2005-01-31 Thread David Fraser
Dan Gass wrote:
I'm pleased to announce the initial release of cfgparse (V01_00)
 
Background
-
cfgparse is a more convenient, flexible, and powerful module for
parsing configuration files than the standard library ConfigParser
module. cfgparse uses a more declarative style modelled after the
popular optparse standard library module.

cfgparse can optionally cooperate with the optparse module to provide
coordination between command line and configuration file options. In
addition, the cooperation can be used to allow the user to control
features of the parser from the command line.
I like this, its really nice that it fits well with optparse.
I read through the docs, mostly it seems very logical, the following 
things stood out to me as not really fitting:

http://cfgparse.sourceforge.net/cfgparse-round-trip-set.html
It doesn't seem logical that in order to modify the option in the 
desired section correctly, you need to pass the config file in. The keys 
argument in the option itself should be able to determine this.

http://cfgparse.sourceforge.net/node24.html
The use of  and  for quoting seems obscure. Would it not be better 
to use pythonic triple-quoted strings?
On first glance they look like markup tags rather than multi-line 
continuations (particularly  looks like "bold").

The fact that lines without an equals sign are ignored seems a bit 
lenient ...

It also seems strange how different the structure is between the 
ini-style and the Python-style formats:
http://cfgparse.sourceforge.net/cfgparse-python.html

driver = 'ethernet'
path = { 'DEFAULT' : '192.168.0.99',
 'DEV0': '192.168.0.0',
 'DEV1': '192.168.0.1' }
Is equivalent to:
[DEFAULT]
driver = 'ethernet'
path = 192.168.0.99
[DEV0]
path = 192.168.0.0
[DEV1]
path = 192.168.0.1
I wonder whether it would be better to use Python classes to represent 
the same thing:

class DEFAULT:
  driver = 'ethernet'
  path = '192.168.0.99'
class DEV0(DEFAULT):
  path = '192.168.0.0'
class DEV1(DEFAULT):
  path = '192.168.0.1'
This seems to me to bear more logical structure resemblance to the 
ini-style format.

Otherwise really cool!
David
--
http://mail.python.org/mailman/listinfo/python-list


Re: Suggesion for an undergrad final year project in Python

2005-02-01 Thread David Fraser
Sridhar wrote:
Hi,
I am doing my undergrade CS course.  I am in the final year, and would
like to do my project involving Python.  Our instructors require the
project to have novel ideas.  Can the c.l.p people shed light on this
topic?
You could write a Python program that writes novels.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Is there a market for python developers?

2005-02-03 Thread David Fraser
Mabon Dane wrote:
I am new to python and took my first attempts at working with this
language today.  Is there a market for people who work with Python?
Slavery is outlawed in most parts of the world these days :-)
--
http://mail.python.org/mailman/listinfo/python-list


Re: Weekly Python Patch/Bug Summary

2005-02-04 Thread David Fraser
Kurt B. Kaiser wrote:
Patch / Bug Summary
___
Patches :  284 open ( +4) /  2748 closed ( +1) /  3032 total ( +5)
Bugs:  804 open ( +1) /  4812 closed (+13) /  5616 total (+14)
RFE :  167 open ( +0) /   142 closed ( +1) /   309 total ( +1)
I wonder if it would be possible to include the status of the closed 
bugs ... if a patch has been refused thats very different to it being 
included. I usually end up opening the page to see what has happened, 
would be nice if it was in the mail...

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


Re: Commerical graphing packages?

2005-02-14 Thread David Fraser
Erik Johnson wrote:
I am wanting to generate dynamic graphs for our website and would rather
not invest the time in developing the code to draw these starting from
graphics primitives. I am looking for something that is... "fairly robust"
but our needs are relatively modest: X-Y scatter plots w/ data point
symbols, multiple data set X-Y line plots, bar charts, etc.
Preferably this would come from a company that can provide support &
decent documentation, and a package that can be installed without a bunch of
extra hassle (e.g., needs Numeric Python, needs to have the GD library
installed, needs separate JPEG encoders, font libraries, etc.)
I am aware of ChartDirector (http://www.advsofteng.com/ ) which
explicitly supports python and seems to be about the right level of
sophistication. I don't really know of any other packages in this space, do
you? I am seeking feedback and reccomendations from people who have used
this package or similar ones. I am particularly interested to hear about any
limitations or problems you ran into with whatever package you are using.
Thanks for taking the time to read my post! :)
It's worth checking out matplotlib as well although it may not meet all 
your criteria ... but have a look, its a great package
--
http://mail.python.org/mailman/listinfo/python-list


Re: [EVALUATION] - E02 - Support for MinGW Open Source Compiler

2005-02-14 Thread David Fraser
Ilias Lazaridis wrote:
I'm a newcomer to python:
[EVALUATION] - E01: The Java Failure - May Python Helps?
http://groups-beta.google.com/group/comp.lang.python/msg/75f0c5c35374f553
-
I've download (as suggested) the python 2.4 installer for windows.
Now I have problems to compile python extension that some packages 
depend on.

I use the MinGW open-source compiler.
-
My questions:
a) Why does the Python Foundation not provide additionally a binary 
version, compiled with MinGW or another open-source compiler?

b) Why does the Python Foundation not ensure, that the python 
source-code is directly compilable with MinGW?

c) Why are the following efforts not _directly_ included in the python 
source code base?

http://jove.prohosting.com/iwave/ipython/pyMinGW.html
above link found in this thread:
http://groups-beta.google.com/group/comp.lang.python/msg/c9f0444c467de525
d) Is it really neccessary that I dive into such adventures, to be able 
to do the most natural thing like: "developing python extensions with 
MinGW"?

http://starship.python.net/crew/kernr/mingw32/Notes.html
e) Is there any official statement available regarding the msvcr71.dll 
and other MS licensing issues?

[see several threads "[Python-Dev] Is msvcr71.dll re-redistributable?"]
http://mail.python.org/pipermail/python-dev/2005-February/thread.html
f) Are there any official (Python Foundation) statements / rationales 
available, which explain why the MinGW compiler is unsupported, although 
parts of the community obviously like to use it?

http://groups-beta.google.com/group/comp.lang.python/msg/dc3474e6c8053336
-
I just want to understand.
Thankfull for any pointer to official documents / statements.
[google is _not_ a fried here. I like to have a stable development 
environment, which is supported by the official projects, thus it can 
pass quality-assurance without beeing afraid about every next release.]

Just to add to all the other answers:
Don't just complain, submit patches and work at keeping them maintained. 
If this is done for a while it may be more of an argument for having 
them included

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


Re: - E02 - Support for MinGW Open Source Compiler

2005-02-14 Thread David Fraser
Pat wrote:
Wow!  I must say, I'm less than impressed with the responses so far.  I
know Ilias can give the impression that he is just trolling, but I can
assure you he is not.  At least, not in this case.  ;-)
So in an effort to make some headway, I'm going to try to summarize the
current state of affairs.  The bottom line is that compiling C
extension modules on the Windows platform for Python 2.4 is, today, a
royal pain in the ass.  Period.  Here's why.
The main challenge is that extensions must be compiled using the same
runtime dll as that used by the Python interpreter itself.
Actually compiling extensions with mingw seems to work fine. Have you 
tried it?

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


Re: - E02 - Support for MinGW Open Source Compiler

2005-02-15 Thread David Fraser
Pat wrote:
Actually, no.  We ran into some issues with Python 2.4 that caused us
to return to Python 2.3.5.  But I would really like to upgrade to
Python 2.4.  So I started researching the subject before I did
anything.
If you are telling me that minGW can compile extensions that are
compatible with the Python 2.4 that uses msvcr71.dll, then that is good
news indeed.  Is there anything that needs to be configured or patched
to make this happen?  And how does minGW know which dll to link?  What
if I have both versions of Python installed - 2.3.5 and 2.4?  Is there
an easy way to detect this and switch between the two dlls?
If I'm asking questions already answered elsewhere, I'd love a link to
that resource, if you have it.
I use MinGW myself to compile extensions for Python 2.3.x so you should 
have no problems there. And it seems like from the rest of the thread 
that it works for Python 2.4 as well.
But please just download it, try it out, and report any problems in a 
separate thread here - I'm sure you'll find people more than willing to 
help. The actual error messages etc will yield more valuable discussion 
than any speculation now - or you might find it just working

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


Re: [EVALUATION] - E02 - ULTIMATE RECIPE TO RESOLVE ALL ISSUES

2005-02-18 Thread David Fraser
Stephen Kellett wrote:
In message <[EMAIL PROTECTED]>, Ilias Lazaridis 
<[EMAIL PROTECTED]> writes

This thread proofs simply the inability of this community [1] to focus 
on a simple essence.

Incorrect analysis. This thread proves that you have no concept of how 
to interact with the community. If you had done what many people asked 
you to do, which is do some work yourself, then ask questions about the 
few answers you didn't discover yourself, you would have got lots of 
helpful answers. You were told this many times by many people. Also on 
the odd occasion someone did proffer some on-topic advice, sometimes in 
long articles that must have taken some time to produce you'd dismiss 
the article with "It is not on topic, I have not read it". How could you 
know if it is not on topic if you don't read it? Apart from the gross 
rudeness in such an attitude it demonstrates your arrogance, selfishness 
and utter contempt for those replying to you.

And then you have the gall to blame your failure on others...
Next you'll be telling me the world is flat and held up by an infinite 
array of tortoises.
Actually I suspect Ilias is trying to carry out his own sort of 'survey' 
on how various communities respond to questions asked in the kind of way 
he asked them ... See his web site.

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


Re: Google Technology

2005-03-01 Thread David Fraser
[EMAIL PROTECTED] wrote:
I am just wondering which technologies google is using for gmail and
Google Groups???
The short answer:
They use computer technology!!! :-)
David
--
http://mail.python.org/mailman/listinfo/python-list


Re: How to upgrade python on Redhat?

2005-03-09 Thread David Fraser
[EMAIL PROTECTED] wrote:
This question applies specifically to RHEL 3.0 (actually Whitebox), but
also generally to Redhat and probably pretty much every distribution
that uses python for distribution-related tasks (configuration
managers, rpm package management, yum, etc).
So I want to upgrade to python 2.4 on Whitebox 3.0. Ideally I would
like python to live in /usr/bin and replace the python 2.2 that ships
with RHEL entirely. This gets pretty infeasable when you consider how
many packages depend on python 2.2:
cd /usr/lib/python2.2/site-packages
rpm -qf * | sort | uniq
alchemist-1.0.27-1
authconfig-4.3.7-1
ethereal-0.10.3-0.30E.1
file Ft is not owned by any package
file _xmlplus is not owned by any package
kudzu-1.1.22.2-1
libuser-0.51.7-1
libxml2-python-2.5.10-6
mod_python-3.0.3-3.ent
newt-0.51.5-1
parted-1.6.3-29
pygtk2-1.99.16-8
pyOpenSSL-0.5.1-8
pyorbit-1.99.3-5
python-2.2.3-5
python-optik-1.4.1-2
pyxf86config-0.3.5-1
redhat-config-printer-gui-0.6.47.3.19-1
rhnlib-1.5-1.1.WB1
rhpl-0.110.4-1
rpm-python-4.2.2-0.14.WB1
up2date-4.3.19-1.WB1
As best I can tell, I have 2 options:
1) Install python 2.4 from source over /usr/bin/python. Rebuild *all*
of the packages listed above from srpms and reinstall them.
2) Give up and install python 2.4 in /usr/local. This leaves me in the
awkward situation of having to ensure that all our in-house scripts,
all the time use /usr/local/bin/python.
I don't suppose there is a simple, rpm package based approach to fixing
this?
The solution is found on the download page, basically you get the 
python2.4 rpm and install it alongside your existing python, and run 
your in-house scripts with /usr/bin/env python2.4:

# Q) Is it safe to install these RPMs on a Red Hat system? Will they 
over-write the system python and cause problems with other Red Hat 
applications that expect a different version of Python?
# A) The RPMs that start with "python2.4" are built to not interfere 
with the system Python. They install as "/usr/bin/python2.4" and will 
not conflict with the system Python unless you are running on a system 
that ships the a version of Python which has the same major/minor number.

To invoke the interpreter with these packages, you will explicitly have 
to run "python2.4". Note that all Python RPMs provided by Python.org and 
Red Hat provide a "/usr/bin/python2.4" (or similar, with major/minor 
number), even if they also provide "/usr/bin/python". So, yes, it should 
be safe.

Note that you may need to build and install a second copy of any 
packages which you need access to with the supplemental version of 
Python. You can build packages of these files for the Python 2.4 
interpreters for packages which use Distutils, by using the command 
"python2.4 setup.py bdist_rpm".
--
http://mail.python.org/mailman/listinfo/python-list


Re: Help on creating a HTML by python

2004-11-30 Thread David Fraser
sepgy wrote:
Can anyone help me to use a python to create an HTML photo gallery
generator. When it's finished, it will be able find all the picture
files (i.e. .jpg, .gif. .png files) in any given folder on the
computer, automatically create smaller thumbnails for each image, and
then generate a complete HTML file that displays a clickable image
gallery. When viewed in a web browser, the HTML file will display the
thumbnails in a neatly formatted table, and if you click on one of the
thumbnails the full-size image will appear.
Note that with the EXIF.py tool you can extract existing thumbnails 
stored inside JPEG or TIFF files without generating them yourself, which 
is much faster.
Most digital cameras nowadays generate these thumbnails...

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


Re: Python Win32 Silent Install

2004-12-02 Thread David Fraser
Thomas Heller wrote:
"Matt Gerrans" <[EMAIL PROTECTED]> writes:

Looks like the installer for the Win32 extensions has changed from Wise to 
distutils, so now my automated silent installations don't work anymore. 
Anyone know if the distutils binary installer can be run silently?I 
haven't been able find a command line reference for distutils binaries (I'm 
still sifting through http://www.python.org/doc/current/dist/, though...).

There are no command line options for the distutils created installer,
and silent installation is not possible.

What I've often done is combine other people's extensions into my 
package by importing stuff from their distutils setup scripts. Now that 
pywin32 is using distutils this should be possible too :-)

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


Re: date diff calc

2004-12-02 Thread David Fraser
Peter Hansen wrote:
Tim Peters wrote:
[Peter Hansen]
I think Skip was intending that the format string be mandatory,
to avoid such ambiguity.  

It's still a bottomless pit -- ask Brett, who implemented the Python
strptime .  

True, I did overlook timezones at the time.
On the other hand, that's because *my* use cases for "simple"
fromstring() behaviour are all involving local time.  When
I'm interested in non-local time, I would be happy having
to specify that behaviour in a more complex manner.
OTOH, is that what people really want?  For all I know,
rfc822.getdate() or rfc822.getdate_tz() are what's really wanted, or
maybe some DWIM thing like Zope's date guessers.

To each his own, although I think there's a hope here that
for those who might need/want a really simple solution,
95% of people have this in mind (pseudo-code):
class datetime.date:
def fromstring(format, string):
ts = time.mktime(time.strptime(string, format))
return datetime.date.fromtimestamp(ts)
Hear, hear, the above would be great!
--
http://mail.python.org/mailman/listinfo/python-list


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

2004-12-02 Thread David Fraser
Robin Becker wrote:
Cameron Laird wrote:
QOTW:  "... why does Microsoft try so hard to protect its sources?"
.
2.4 is final, buildable under Windows in at least a couple of 
ways, improved, ...
http://www.brunningonline.net/simon/blog/archives/001657.html

asyncore, Twisted, the Python core...--do you understand how
they relate to TLS, serial-port usage, GUI-oriented event
processing, and so on?
http://groups.google.com/groups?th=752ebdb8b57fa3f3
Ian Bicking and others describe the meaning of "Python 3000".
http://groups.google.com/groups?frame=left&th=8f9b6a3959888f2b
Reading without blocking is possible--with care.
http://groups.google.com/groups?frame=left&th=78654cfc06d2fbbe
Josiah Carlson and Paul McGuire explain decorators.
http://groups.google.com/groups?th=5bfb80b43887bc1f
Nick Coghlan knows sick ways to spell "file".
http://groups.google.com/groups?frame=right&th=e562a771d1c827c9
Python works in Frontier.
http://radio.weblogs.com/0100039/2004/11/30.html#a626

...
For some reason I can't seem to make use of the google links. When I use 
the above eg

http://groups.google.com/groups?frame=right&th=e562a771d1c827c9
I get a not found google page with url
http://groups-beta.google.com/groups?frame=right&th=e562a771d1c827c9
really wanted to spell file in a sickly manner :)
Apparently this is due to a Google "upgrade"
See the slashdot story:
http://slashdot.org/article.pl?sid=04/12/02/149210&tid=217&tid=95
The important thing is that you (or I) can still access them at 
groups.google.co.uk:

http://groups.google.co.uk/groups?frame=right&th=e562a771d1c827c9
etc
Maybe the URLs on the web page could be adjusted?
David
--
http://mail.python.org/mailman/listinfo/python-list


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

2004-12-03 Thread David Fraser
Rocco Moretti wrote:

For some reason I can't seem to make use of the google links. When I 
use the above eg

http://groups.google.com/groups?frame=right&th=e562a771d1c827c9
I get a not found google page with url
http://groups-beta.google.com/groups?frame=right&th=e562a771d1c827c9
really wanted to spell file in a sickly manner :)

It seems Google recently redid their groups interface. By searching for 
"group:comp.lang.python Coghlan" on http://groups.google.com, I was able 
to find the probable post (Sort by Date, titled "Restricted Execution on 
the cheap", about four down)
Nicely, google seems to have reverted their main google groups page to 
the original system, and left the new one at groups-beta.google.com

I'm sorry I'm not able to give a direct URL, but it seems they've 
switched over to a horrendously long, stateful URL system which doesn't 
lend itself to direct linkage.
Doesn't seem stateful to me, just has different thread / message ids to 
the old system:

http://groups-beta.google.com/group/comp.lang.python/browse_thread/thread/1db72429a2b05ce0/2c1679d365ffe9dd#2c1679d365ffe9dd
The syntax is thread/$threadid/$messageid#$messageid
At least for me, these URLs are transferable between computers / browsers
You can also access the message directly:
http://groups-beta.google.com/group/comp.lang.python/msg/2c1679d365ffe9dd
David
--
http://mail.python.org/mailman/listinfo/python-list


Re: inheritance problem with 2 cooperative methods

2004-12-03 Thread David Fraser
Dan Perl wrote:
Here is a problem I am having trouble with and I hope someone in this group 
will suggest a solution.  First, some code that works.  3 classes that are 
derived from each other (A->B->C), each one implementing only 2 methods, 
__init__ and setConfig.
---
#!/usr/bin/python
class A (object):
   def __init__(self):
  super(A, self).__init__()
  self.x = 0
   def setConfig(self, config):
  self.x += config['x']

class B (A):
   def __init__(self):
  super(B, self).__init__()
  self.y = 0
   def setConfig(self, config):
  super(B, self).setConfig(config)
  self.y += config['y']
class C (B):
   def __init__(self):
  super(C, self).__init__()
  self.z = 0
   def setConfig(self, config):
  super(C, self).setConfig(config)
  self.z += config['z']
config = {'x':1, 'y':2, 'z':3}
alpha = A()
alpha.setConfig(config)
print alpha.x
beta = B()
beta.setConfig(config)
print beta.x, beta.y
beta.setConfig(config)
print beta.x, beta.y
gamma = C()
gamma.setConfig(config)
print gamma.x, gamma.y, gamma.z
gamma.setConfig(config)
print gamma.x, gamma.y, gamma.z
--
The output from that code is:
1
1 2
2 4
1 2 3
2 4 6
So far, so good!  But let's assume that I want to change the __init__ 
methods so that they take a configuration as an argument so the objects are 
created and configured in one step, like this:
alpha = A(config)

How can the code be changed to implement this?  It is tempting to modify the 
__init__ methods like this:
class A (object):
   def __init__(self, config):
  super(A, self).__init__(config)
  self.x = 0
  A.setConfig(self, config)

However, if implemented this way, the output is:
1
2 2
3 4
3 4 3
4 6 6
This shows that setConfig gets called more than once because both __init__ 
and setConfig are cooperative methods.

I have been thinking about this for a day now and I cannot find a good 
solution.  I imagine this would be a common problem and that there would be 
a recipe somewhere, but I couldn't find one (I looked in the Python 
Cookbook).  I've thought of creating 2 separate methods instead of 
setConfig, one that does the "local" configuration and another one that 
takes care of invoking super.  But I don't like the idea of creating 2 
methods in each class and I haven't been able to think of a way to solve the 
problem with just one change in the base class that would be inherited by 
all the subclasses.

Anyone has any ideas?  Thanks.
What about using an attribute in the base class to remember whether 
initial config has been done? This seems to work:

#!/usr/bin/python
class A (object):
   def __init__(self, config):
  self.x = 0
  self.configinitialized = False
  super(A, self).__init__()
  if not self.configinitialized:
self.setConfig(config)
   def setConfig(self, config):
  self.x += config['x']
  self.configset = True
class B (A):
   def __init__(self, config):
  self.y = 0
  super(B, self).__init__(config)
   def setConfig(self, config):
  super(B, self).setConfig(config)
  self.y += config['y']
class C (B):
   def __init__(self, config):
  self.z = 0
  super(C, self).__init__(config)
   def setConfig(self, config):
  super(C, self).setConfig(config)
  self.z += config['z']
config = {'x':1, 'y':2, 'z':3}
alpha = A(config)
print alpha.x
beta = B(config)
print beta.x, beta.y
beta.setConfig(config)
print beta.x, beta.y
gamma = C(config)
print gamma.x, gamma.y, gamma.z
gamma.setConfig(config)
print gamma.x, gamma.y, gamma.z
--
http://mail.python.org/mailman/listinfo/python-list


Re: We what judge the language using which question?

2004-12-03 Thread David Fraser
hlddn wrote:
unicode or other?
we what judge?
thank all
You need to usually know the encoding from the context, otherwise you'll 
have to guess. In this regard I find http://www.eki.ee/letter/ helpful

But if you want more details, you'll need to provide a clearer question ...
David
--
http://mail.python.org/mailman/listinfo/python-list


Re: VC++ 6.0 and 2.4

2004-12-09 Thread David Fraser
Jive wrote:
Theoretically, if I messed around with the 2.4 project until I got it to
build under MS VC++ 6.0, would the python.exe play correctly with version
2.4 .pyd extensions?
It should play correctly with version 2.4 .pyd extensions that have been 
built with MS VC++ 6.0.

David
--
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: building python extensions with .net sdk compiler?

2004-12-11 Thread David Fraser
Grumman wrote:
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.
So using MinGW seems like the better option ... is it working for Python 
2.4?

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


Re: Python To Send Emails Via Outlook Express

2004-12-25 Thread David Fraser
[EMAIL PROTECTED] wrote:
Hey guys, I'm just thankful the answer has been found and hope this
helps someone else. To everyone (especially Lenard) that responded to
my request for help, thank you!!
Merry Christmas everyone!!!
God bless
Ian
Thanks Ian, Why not post this to the python-win32 mailing list as well, 
then maybe your changes can be incorporated into pywin32?

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


Re: build a static executable program with python

2004-12-30 Thread David Fraser
Torsten Mohr wrote:
Hi,
i'd like to build an executable file that is linked with
a python library and executes a script via PyRun_SimpleString
or similar functions.
Is there a static library of python available, so the users
don't need to install python?
What about DLL modules, do i just need to compile them
as a static lib, link them together with my program and
call their init function?
What about python modules, can i just use a tool like
"freeze" or "py2exe" to break up the import hierarchy
and call them before my script?
Is there some more information about building a static
executable available?
Thanks for any hints,
Torsten.
Just have a look at py2exe, it does basically what you're asking for - 
see the link to the wiki from the py2exe home page for more information...

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


Re: Python limericks (was Re: Text-to-speech)

2005-03-23 Thread David Fraser
Michael Spencer wrote:
How about a category for executable limericks?
That was my thought too...
for programmer in search_of("elegance"):
  if programmer.needs("an experience"):
print "whitespace counts much"
if Van_Rossum is Dutch:
  print "Dictators are made by benevolence"
And an attempt at a self-replicating one that uses far too many 
syllables in the last line:

rhymes = 'for line in ["rhymes", "fines"]:\n '
fines = 'print line, "=", `eval(line)`\n'
for line in ["rhymes", "fines"]:
  print line, "=", `eval(line)`
whine='whine=%s;print rhymes, fines, whine%%`whine`';print rhymes, 
fines, whine%`whine`

This can actually be pronounced as a proper limerick as follows: always 
pronounce = as "is" and ; as "so", don't pronounce any other 
punctuation, and cheat by pronouncing the first string in the last line 
as "junk" :-)

rhymes is for line in rhymes fines
fines is print line is eval line
for line in rhymes fines
  print line is eval line
whine is junk so print rhymes fines whine whine
David
--
http://mail.python.org/mailman/listinfo/python-list


Re: MinGW building with Python 2.4

2005-03-23 Thread David Fraser
mrstephengross wrote:
Ok, I know there are already a million posts on this group about
getting Python to build with MinGW. I've been through many of them, and
have still not found a good comprehensive way to accomplish this.
I've got Cygwin 5.1 with GCC 3.3.3 on it. I'm using Python 2.4.
Note: You invoke the mingwin compiler *indirectly*, by running gcc with
the -mno-cygwin option.
So first of all, I tried exporting CC='gcc -mno-cygwin', configuring,
and making. You end up getting file-not-found errors, because some of
the include files aren't present for mingw.
Next: I tried pymingw: didn't work :(
Any ideas?
Since the only official way to do this is pymingw, you should at least 
give feedback of the steps you followed, and what didn't work

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


Re: distutils: package data

2005-03-30 Thread David Fraser
Qiangning Hong wrote:
I am writing a setup.py for my package.  I have a pre-compiled
myextmod.pyd file in my package and I want the distutils to
automatically copy it to
C:\Python23\Lib\site-packages\mypackage\myextmod.pyd.
I try to add the following parameter to setup():
   data_file = [('mypackage', ['mypackage/myextmod.pyd'])],
but it installs the pyd file to C:\Python23\mypackage\myextmod.pyd,
this is not what I want.
And I don't want to specify the path in data_file to the absolution
path 'C:\Python23\Lib\site-packages\mypackage', for portability, of
course.
Any hints?
Actually you probably want to look at describing the .pyd as an 
Extension. Then you can even give distutils the instructions to build 
it, and as a side effect you can install it to the right location
This may not be what you want though

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


Re: Installing Python 2.4 on Linux

2005-04-06 Thread David Fraser
Edward Diener wrote:
I can install Python 2.4 on the Fedora 3 Linux system, but after I do a 
number of Linux utilities and commands, like yum, stop working because 
they were dependent on the Python 2.3 installation. What happens is that 
Python 2.4 replaces the /usr/bin/python module with the Python 2.4 
version. If I replace /usr/bin/python with the Python 2.3 version 
executable, which is still on my system, that all the aforesaid modules 
depend on, they start working again, but I can no longer execute 
modules, like IDLE, which was part of my Python 2.4 distribution.

What is the solution to this ? The operating system was installed with 
Python 2.3 and the development libraries but no tools, doc, or 
otherwise. I have installed Python 2.4 with all the RPMs and copied down 
the Python 2.4 documentation to my machine ( since python24-docs.rpm 
gives one very little ). I would naturally like to use Python 2.4 
without killing all the commands that depend on Python 2.3. No doubt 
these commands have their modules in the site libraries for Python 2.3. 
Of course I would love to update these dependencies to use Python 2.4 
but newer RPMs for these commands do not exist.

I do not know whether this is a Python problem or a Fedora 3 problem but 
I thought I would ask here first and see if anybody else had the same 
problem. I imagine the problem might exist on other Linux systems.
Actually the Fedora RPMS supplied on the Python website are fine:
http://www.python.org/2.4.1/rpms.html
Quoting from that page:
# Q) Is it safe to install these RPMs on a Red Hat system? Will they over-write 
the system python and cause problems with other Red Hat applications that 
expect a different version of Python?
# A) The RPMs that start with "python2.4" are built to not interfere with the system 
Python. They install as "/usr/bin/python2.4" and will not conflict with the system Python 
unless you are running on a system that ships the a version of Python which has the same 
major/minor number.
To invoke the interpreter with these packages, you will explicitly have to run "python2.4". Note 
that all Python RPMs provided by Python.org and Red Hat provide a "/usr/bin/python2.4" (or similar, 
with major/minor number), even if they also provide "/usr/bin/python". So, yes, it should be safe.
Note that you may need to build and install a second copy of any packages which you need access to with the supplemental version of Python. You can build packages of these files for the Python 2.4 interpreters for packages which use Distutils, by using the command "python2.4 setup.py bdist_rpm". 
This is by far the preferred way to install a different version of 
Python to the default version provided with a distribution, as you don't 
then conflict with packages that require the default version.

Also, it is better to do it like this using real packages than to rename 
files manually. I have used the above successfully on Fedora Core 3 (and 
other similar versions on other distro versions), if it doesn't work for 
you there is a source RPM available to rebuild from

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


Re: Why does StringIO discard its initial value?

2005-04-12 Thread David Fraser
Raymond Hettinger wrote:
[Leif K-Brooks]
The obvious workaround is to call buffer.write() with the initial value
instead of passing it to StringIO's constructor,

More than just a workaround, it is the preferred approach.
That makes is easier to switch to cStringIO where initialized objects are
read-only.
Others may find this helpful ; it's a pure Python wrapper for cStringIO 
that makes it behave like StringIO in not having initialized objects 
readonly. Would it be an idea to extend cStringIO like this in the 
standard library? It shouldn't lose performance if used like a standard 
cStringIO, but it prevents frustration :-)

David
class StringIO:
def __init__(self, buf = ''):
if not isinstance(buf, (str, unicode)):
buf = str(buf)
self.len = len(buf)
self.buf = cStringIO.StringIO()
self.buf.write(buf)
self.buf.seek(0)
self.pos = 0
self.closed = 0
def __iter__(self):
return self
def next(self):
if self.closed:
raise StopIteration
r = self.readline()
if not r:
raise StopIteration
return r
def close(self):
"""Free the memory buffer.
"""
if not self.closed:
self.closed = 1
del self.buf, self.pos
def isatty(self):
if self.closed:
raise ValueError, "I/O operation on closed file"
return False
def seek(self, pos, mode = 0):
if self.closed:
raise ValueError, "I/O operation on closed file"
self.buf.seek(pos, mode)
self.pos = self.buf.tell()
def tell(self):
if self.closed:
raise ValueError, "I/O operation on closed file"
return self.pos
def read(self, n = None):
if self.closed:
raise ValueError, "I/O operation on closed file"
if n == None:
  r = self.buf.read()
else:
  r = self.buf.read(n)
self.pos = self.buf.tell()
return r
def readline(self, length=None):
if self.closed:
raise ValueError, "I/O operation on closed file"
if length is not None:
r = self.buf.readline(length)
else:
r = self.buf.readline(length)
self.pos = self.buf.tell()
return r
def readlines(self):
if self.closed:
raise ValueError, "I/O operation on closed file"
lines = self.buf.readlines()
self.pos = self.buf.tell()
return lines
def truncate(self, size=None):
if self.closed:
raise ValueError, "I/O operation on closed file"
self.buf.truncate(size)
self.pos = self.buf.tell()
self.buf.seek(0, 2)
self.len = self.buf.tell()
self.buf.seek(self.pos)
def write(self, s):
if self.closed:
raise ValueError, "I/O operation on closed file"
origpos = self.buf.tell()
self.buf.write(s)
self.pos = self.buf.tell()
if origpos + len(s) > self.len:
  self.buf.seek(0, 2)
  self.len = self.buf.tell()
  self.buf.seek(self.pos)
def writelines(self, lines):
if self.closed:
raise ValueError, "I/O operation on closed file"
self.buf.writelines(lines)
self.pos = self.buf.tell()
self.buf.seek(0, 2)
self.len = self.buf.tell()
self.buf.seek(self.pos)
def flush(self):
if self.closed:
raise ValueError, "I/O operation on closed file"
self.buf.flush()
def getvalue(self):
if self.closed:
raise ValueError, "I/O operation on closed file"
return self.buf.getvalue()
--
http://mail.python.org/mailman/listinfo/python-list


Re: Why does StringIO discard its initial value?

2005-04-15 Thread David Fraser
Raymond Hettinger wrote:
[David Fraser]
Others may find this helpful ; it's a pure Python wrapper for cStringIO
that makes it behave like StringIO in not having initialized objects
readonly. Would it be an idea to extend cStringIO like this in the
standard library? It shouldn't lose performance if used like a standard
cStringIO, but it prevents frustration :-)

IMO, that would be a step backwards.  Initializing the object and then
writing to it is not a good practice.  The cStringIOAPI needs to be as
file-like as possible.  With files, we create an emtpy object and then
starting writing (the append mode for existing files is a different story).
Good code ought to maintain that parallelism so that it is easier to
substitute a real file for a writeable cStringIO object.
This whole thread (except for the documentation issue which has been
fixed) is about fighting the API rather than letting it be a guide to good
code.
If there were something wrong with the API, Guido would have long
since fired up the time machine and changed the timeline so that all
would be as right as rain ;-)
But surely the whole point of files is that you can do more than either 
creating a new file or appending to an existing one (seek, write?)

The reason I wrote this was to enable manipulating zip files inside zip 
files, in memory. This is on translate.sourceforge.net - I wanted to 
manipulate Mozilla XPI files, and replace file contents etc. within the 
XPI. The XPI files are zip format that contains jars inside (also zip 
format). I needed to alter the contents of files within the inner zip files.

The zip classes in Python can handle adding files but not replacing 
them. The cStringIO is as described above.

So I created extensions to the zipfile.ZipFile class that allow it to 
delete existing files, and add them again with new contents (thus 
replacing them).

And I created wStringIO so that I could do this all inplace on the 
existing zip files.

This all required some extra hacking because of the dual-layer zip files.
But all this as far as I see would have been really tricky using the 
existing zipfile and cStringIO classes, which both assume (conceptually) 
that files are either readable or new or merely appendable (for zipfile).

The problem for me was not that cStringIO classes are too similar to 
files, it was that they are too dissimilar. All of this would work with 
either StringIO (but too slow) or real files (but I needed it in memory 
because of the zipfiles being inside other zip files).

Am I missing something?
David
--
http://mail.python.org/mailman/listinfo/python-list


Re: need help in PySparse

2005-04-18 Thread David Fraser
monocalibro wrote:
Hello all!
I need ready-for-use installable version of PySparse (for FiPy), because I
can't compile it with MingW. Or, may be, somebody knows step-by-step
instruction to complie this package under Win32 using Mingw?
Best regards

At least describe the web site you got it from, the versions of Python 
and MinGW you are using, and the errors you got when you tried to build it.

See here for more info on how to ask questions:
http://www.catb.org/~esr/faqs/smart-questions.html
David
--
http://mail.python.org/mailman/listinfo/python-list


Re: Apache mod_python

2005-04-18 Thread David Fraser
Dan wrote:
I've been writing a server application in Python.  The app listens on
a socket and interfaces to a database.
Now I'd like to write a web application to also access the database.
It seems natural to use Python.  I've installed mod_python (Debian
libapache2-mod-python2.3, mod_python 3.1.3-4).
My question is, how mature/stable is mod_python?  Is it suitable for a
production environment?  The documentation is a bit lacking, and I've
found some errors in the demo example where it looks like the link
should work, but it doesn't. (Could well be something I'm doing.).
I've also noted that there's still work being done on it.
Hi Dan
mod_python is quite mature and stable and usable in a production 
environment. However it is fairly low level and a lot of people like to 
add another framework on top of it.
If you point out the documentation problems you're having then people 
can say whether you're making a mistake or there is really an error

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


Re: poll: does name conventions in python matters?

2005-04-19 Thread David Fraser
vegetax wrote:
in python it is common to see naming
inconsistencies ,methods,modules,packages,classes with names in every
posible style:
thisisalongmethod
ThisIsALongMethod
thisIsALongMethod
this_is_a_long_method
and even This_Is_A_Long_Method
All over the place,even within one module!
classic static languages dont really need naming conventions, on the other
side dynamic languages must have it(in my opinion),since there is a lot of
syntax variability and very short constructors, a clear example is what
does this means?
c = Required(2)
is it a method which returns an object or is it a class constructor?
this kind of situation greatly decrease readability.
whats your opinion on the matter?
If you really worry about it, why don't you capitalise your English? :-)
David
--
http://mail.python.org/mailman/listinfo/python-list


Re: Behaviour of str.split

2005-04-20 Thread David Fraser
Greg Ewing wrote:
Will McGugan wrote:
Hi,
I'm curious about the behaviour of the str.split() when applied to 
empty strings.

"".split() returns an empty list, however..
"".split("*") returns a list containing one empty string.

Both of these make sense as limiting cases.
Consider
 >>> "a b c".split()
['a', 'b', 'c']
 >>> "a b".split()
['a', 'b']
 >>> "a".split()
['a']
 >>> "".split()
[]
and
 >>> "**".split("*")
['', '', '']
 >>> "*".split("*")
['', '']
 >>> "".split("*")
['']
The split() method is really doing two somewhat different things
depending on whether it is given an argument, and the end-cases
come out differently.
You don't really explain *why* they make sense as limiting cases, as 
your examples are quite different.

Consider
>>> "a*b*c".split("*")
['a', 'b', 'c']
>>> "a*b".split("*")
['a', 'b']
>>> "a".split("*")
['a']
>>> "".split("*")
['']
Now how is this logical when compared with split() above?
David
--
http://mail.python.org/mailman/listinfo/python-list


Re: Behaviour of str.split

2005-04-20 Thread David Fraser
Bengt Richter wrote:
On Wed, 20 Apr 2005 10:55:18 +0200, David Fraser <[EMAIL PROTECTED]> wrote:

Greg Ewing wrote:
Will McGugan wrote:

Hi,
I'm curious about the behaviour of the str.split() when applied to 
empty strings.

"".split() returns an empty list, however..
"".split("*") returns a list containing one empty string.

Both of these make sense as limiting cases.
Consider
>>> "a b c".split()
['a', 'b', 'c']
>>> "a b".split()
['a', 'b']
>>> "a".split()
['a']
>>> "".split()
[]
and
>>> "**".split("*")
['', '', '']
>>> "*".split("*")
['', '']
>>> "".split("*")
['']
The split() method is really doing two somewhat different things
depending on whether it is given an argument, and the end-cases
come out differently.
You don't really explain *why* they make sense as limiting cases, as 
your examples are quite different.

Consider
"a*b*c".split("*")
['a', 'b', 'c']
"a*b".split("*")
['a', 'b']
"a".split("*")
['a']
"".split("*")
['']
Now how is this logical when compared with split() above?

The trouble is that s.split(arg) and s.split() are two different functions.
The first is 1:1 and reversible like arg.join(s.split(arg))==s
The second is not 1:1 nor reversible: '<>'.join(s.split()) 
== s ?? Not usually.
I think you can do it with the equivalent whitespace regex, preserving the 
splitout whitespace
substrings and ''.joining those back with the others, but not with split(). 
I.e.,
 >>> def splitjoin(s, splitter=None):
 ... return (splitter is None and '<>' or 
splitter).join(s.split(splitter))
 ...
 >>> splitjoin('a*b*c', '*')
 'a*b*c'
 >>> splitjoin('a*b', '*')
 'a*b'
 >>> splitjoin('a', '*')
 'a'
 >>> splitjoin('', '*')
 ''
 >>> splitjoin('a bc')
 'a<>b<>c'
 >>> splitjoin('a b')
 'a<>b'
 >>> splitjoin('  b')
 'b'
 >>> splitjoin('')
 ''
 >>> splitjoin('*','*')
 '*'
Note why that works:
 >>> '*'.split('*')
 ['', '', '', '', '', '']
 >>> '*a'.split('*')
 ['', 'a']
 >>> 'a*'.split('*')
 ['a', '']
 >>> splitjoin('*a','*')
 '*a'
 >>> splitjoin('a*','*')
 'a*'
Thanks, this makes sense.
So ideally if we weren't dealing with backward compatibility these 
functions might have different names... "split" (with arg) and 
"spacesplit" (without arg)
In fact it would be nice to allow an argument to "spacesplit" specifying 
the characters regarded as 'space'
But all not worth breaking current code :-)

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


Re: counting using variable length string as base

2008-04-01 Thread David Fraser
On Mar 31, 8:18 pm, "Gabriel Genellina" <[EMAIL PROTECTED]>
wrote:
> En Mon, 31 Mar 2008 09:30:00 -0300, Graeme Glass <[EMAIL PROTECTED]>
> escribió:
>
> > On Mar 27, 11:01 am, Peter Otten <[EMAIL PROTECTED]> wrote:
> >> a b c aa ab ac ba bb bc ca cb cc aaa aab aac aba abb abc aca acb acc
> >> baa bab
> >> bac bba bbb bbc bca bcb bcc
>
> > Here is a cool solution we came up with during a little interactive
> > session at our local meet up.
> > (http://www.python.org.za/pugs/cape-town/cape-town)
>
> > s = 'abcdef'
> > ["".join([s[j] for j in range(len(s)) if x & (1 << j)]) for x in
> > range(1,2**len(s)) ]
>
> But it's doesn't generate the right sequence, and a lot of elements are
> missing. For 'abc':
> ['a', 'b', 'ab', 'c', 'ac', 'bc', 'abc']
> It lacks ba, bb, ca, cb, cc, all b??, all c?? - see the sequence quoted
> above.

Indeed, the following shold do the trick although it's fairly
inefficient:
n=(len(s)+1) ; z = [''] + list(s) ; all =
sorted(dict.fromkeys("".join(z[(x/(n**j))%n] for j in range(n)) for x
in range(1,n**n)))

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