Re: Regexp problem, which pattern to use in split

2004-12-14 Thread Fredrik Lundh
Hans Almåsbakk wrote:

> Is there a relatively hassle-free way to get the csv module working with
> 2.1? The server is running Debian stable/woody, and it also seemed 2.2 can
> coexist with 2.1, when I checked the distro packages, if that is any help.

2.3 and 2.4 can also coexist with 2.1 (use "make altinstall" to leave "python"
alone, so if you're using a pure-Python application, upgrading might be a good
idea.

alternatively, the following module (with a slightly different API) should work
under 2.1:

http://www.object-craft.com.au/projects/csv/

 



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


Re: Why are tuples immutable?

2004-12-14 Thread Gerrit
Fredrik Lundh wrote:
> > I could imagine that anything accepting numerical values for __getitem__
> > (foo[0], foo[1], ...) or that is iterable (foo.next(), foo.next()) could
> > be sensibly used as a formatting rhs. Of course, it is not compatible
> > because "foo %s" % [2, 4] is correct and "foo %s" % (2, 4) is not, but
> > are there other reasons that it has been chosen like this?
> 
> so what should
> 
> "foo %s bar %s" % "24"
> 
> do?

Hmm. Good question (-:

Not possible before Python 3.0, but could __rmod__ play a role here?
str.__mod__ would be something like:
try:
# use other.__rmod__(...) result
except AttributeError:
try:
# use it as an array
except TypeError:
# use string representation

Hm, something else I don't understand in current behaviour:
>>> "foo".__rmod__("testing %s")
'testing foo'
>>> (55).__rmod__("testing %s")
NotImplemented
>>> print (55).__rmod__.__doc__
x.__rmod__(y) <==> y%x

...apparantly not? How should I interpret this?

To answer your question:

"foo %s bar %s" % "24" would do "24".__rmod__("foo %s bar %s") resulting in:

>>> "24".__rmod__("foo %s bar %s")
Traceback (most recent call last):
  File "", line 1, in ?
TypeError: not enough arguments for format string

Would it be possible to use something like this?

regards,
Gerrit.

-- 
Weather in Lulea / Kallax, Sweden 14/12 16:20:
2.0ÂC Broken clouds mostly cloudy wind 7.6 m/s S (34 m above NAP)
-- 
In the councils of government, we must guard against the acquisition of
unwarranted influence, whether sought or unsought, by the
military-industrial complex. The potential for the disastrous rise of
misplaced power exists and will persist.
-Dwight David Eisenhower, January 17, 1961
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Help need with converting Hex string to IEEE format float

2004-12-14 Thread Max M
[EMAIL PROTECTED] wrote:
Each of these numbers is a Hex byte making up a four byte (32 bit
Big-Endian) IEEE float. I have read this data into Python using
readlines and then line.split(). This gives me:
['80', '00', '00', '00']

Oh, programmers loves this kind stuff. You should get tons of answers.
##
st = '80 00 00 00'
import binascii
import struct
s = ''.join([binascii.a2b_hex(s) for s in st.split()])
v = struct.unpack("f", s)[0]
print v
##
regards Max M
--
hilsen/regards Max M, Denmark
http://www.mxm.dk/
IT's Mad Science
--
http://mail.python.org/mailman/listinfo/python-list


Re: while 1 vs while True

2004-12-14 Thread Steve Holden
Fredrik Lundh wrote:
Steve Holden wrote:

It was unfortunate that so many people chose to use that for compatibility, when if they'd used 
the same code that the win32all extensions did they could have retained backward compatibility 
even across a change to constants:

try:
   True
except AttributeError:
   True, False = (1==1), (1!=1)

that doesn't work, though:
$ python2.1 test.py
Traceback (most recent call last):
  File "test.py", line 2, in ?
True
NameError: name 'True' is not defined
Well, OK. But, lest people should think the worse of win32all because of 
my laziness in not finding the exact quote, I should point out that the 
code I meant to quote actually says:

# Pre 2.2.1 compat.
try: True, False
except NameError: True = 1==1; False = 1==0
I believe this should work for all versions up to 2.4, and would also 
work with a 2.5 that made True and False constants. But if anyone can 
prove me wrong it would be you ... :-)

regards
 Steve
--
Steve Holden   http://www.holdenweb.com/
Python Web Programming  http://pydish.holdenweb.com/
Holden Web LLC  +1 703 861 4237  +1 800 494 3119
--
http://mail.python.org/mailman/listinfo/python-list


Re: Emailing in Python

2004-12-14 Thread Fredrik Lundh
Philippe Reynolds wrote:

> I'm learning python...one of my tasks is to send out emails...
> I can send emails to one person at a time but not as groups
>
> Do you think you can help.
>
> Cheers
> Philippe Reynolds
>
> Here is the section of code:
> # me == the sender's email address
> me = '[EMAIL PROTECTED]'
> # you == the recipient's email address
>
> email_list= '[EMAIL PROTECTED], [EMAIL PROTECTED]'

that's a string, not a list.  how about:

email_list= ["[EMAIL PROTECTED]", "[EMAIL PROTECTED]"]

> msg['Subject'] = 'EVENT REPORT'
> msg['From'] = me
> msg['To'] = email_list
>
> # Send the message via our own SMTP server, but don't include the
> # envelope header.
> s = smtplib.SMTP()
> s.connect()
> s.sendmail(me, [email_list], msg.as_string())

and

s.sendmail(me, email_list, msg.as_string())

> s.close()

?

 



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


Regexp problem, which pattern to use in split

2004-12-14 Thread Hans Almåsbakk
Hi,

I have a problem which I believe is seen before:
Finding the correct pattern to use, in order to split a line correctly,
using the split function in the re module.

I'm new to regexp, and it isn't always easy to comprehend for a newbie :)

The lines I want to split are like this:
(The following is one line, even if news client splits it up:)

"abc ",,"-","Doe, John D.",2004,"A long text, which may contain many
characters. Dots, commas, and if I'm real unlucky: maybe even
"-characters","-",32454,, 

These lines are in a csv file exported from excel.
Comma is obviously the separator, but as you can see a comma might
occur between " ", and if that is the case, it should not be (a
separator).
Then I pondered upon a way of using " chars in the splitting aswell,
something like "?,"? . (optional " before and after comma), which of course
also goes wrong. " may and may not occur around the splitting comma, but
that would also match single commas inside quoted text, see example.

Any pointer will be greatly appreciated. Maybe I'm attacking this problem
the wrong way already from the start? (Not that I can see another way
myself :)

Regards
-- 
Hans Almåsbakk
-remove .invalid for correct email
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Help need with converting Hex string to IEEE format float

2004-12-14 Thread Fredrik Lundh
Max M wrote:

> Oh, programmers loves this kind stuff. You should get tons of answers.

data = '80 00 00 00'

import Image
v = Image.fromstring("F", (1, 1), data, "hex", "F;32BF").getpixel((0, 0))

 



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


Re: gather information from various files efficiently

2004-12-14 Thread Simon Brunning
On Tue, 14 Dec 2004 10:40:56 -0500, Peter Hansen <[EMAIL PROTECTED]> wrote:
> Keith Dart wrote:
> > Sigh, this reminds me of a discussion I had at my work once... It seems
> > to write optimal Python code one must understand various probabilites of
> > your data, and code according to the likely scenario.
> 
> And this is different from optimizing in *any* other language
> in what way?

In other languages, by the time you get the bloody thing working it's
time to ship, and you don't have to bother worrying about making it
optimal.

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


Re: Python IDE

2004-12-14 Thread Alex Stapleton
Chris wrote:
What IDE's do y'all recommend for Python?  I'm using PythonWin atm, but 
I'd like something with more functionality.

Chris
Oh god we're all going to die.
But er, ActiveState Komodo is quite nice IIRC (can't use it anymore as 
all my coding is commercial and I don't need it enough to spend that 
much cash on it) but EditPlus is nice once you get it setup but not very 
IDEy. Eclipse with one of the various Python modules is horrible don't 
bother. There is of course always Emacs, but again it's hardly Visual 
Studio (im only talking about the UI, emacs fans please dont flame me)

Personally my vote goes for Komodo, it's at least worth a try with a 
personal liscense.

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


Re: Python IDE

2004-12-14 Thread Fuzzyman
If you're willing to pay for one, Komodo is very good. Especially for
projects.

Regards,

Fuzzy
http://www.voidspace.org.uk/atlantibots/pythonutils.html

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


Re: Help need with converting Hex string to IEEE format float

2004-12-14 Thread Fredrik Lundh
># convert to byte string, via the array module
>import array, struct
>a = array.array("B", [int(c, 16) for c in x])
>v = struct.unpack("!f", )

eh?  should be:

# convert to byte string, via the array module
import array, struct
a = array.array("B", [int(c, 16) for c in x])
v = struct.unpack("!f", a)

 



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


Re: Python IDE

2004-12-14 Thread Chris
What IDE's do y'all recommend for Python?  I'm using PythonWin atm, 
but I'd like something with more functionality.
Oh god we're all going to die.
-chuckle-  Hopefully I don't start off a full fledged war.-grin-
But er, ActiveState Komodo is quite nice IIRC (can't use it anymore as 
all my coding is commercial and I don't need it enough to spend that 
much cash on it) but EditPlus is nice once you get it setup but not very 
IDEy. Eclipse with one of the various Python modules is horrible don't 
bother. There is of course always Emacs, but again it's hardly Visual 
Studio (im only talking about the UI, emacs fans please dont flame me)

Personally my vote goes for Komodo, it's at least worth a try with a 
personal liscense.
Why didn't you like Eclipse?  Was it that the Python modules were bad, 
or just Eclipse in general?  I use it for my Java developement and 
haven't had any problems with it.

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


Re: Python 3.0

2004-12-14 Thread Chris
Okay, color me stupid, but what is everyone referencing when they mention Python 3.0?  I didn't 
see any mention of it on the Python site.
http://www.python.org/peps/pep-3000.html
(which happens to be the first hit if you search for "python 3.0" in the
search box on python.org...)
Okay, I feel dumb now. :)
Chris
--
http://mail.python.org/mailman/listinfo/python-list


Re: Html or Pdf to Rtf (Linux) with Python

2004-12-14 Thread Cameron Laird
In article <[EMAIL PROTECTED]>,
Axel Straschil  <[EMAIL PROTECTED]> wrote:
>Hello!
>
>Sorry Cameron, I was replying, now my folloup ;-):
>
>> Are you trying to convert one document in particular, or automate the
>> process of conveting arbitrary HTML documents?
>
>I have an small CMS System where the customer has the posibility to view
>certain Html-Pages as Pdf, the CMS ist Python based. I also thought
>about
>passing the Url to an external converter Script, but found nothing ;-(
>
>
>> What computing host is available to you--Win*?  Linux?  MacOS?
>> Solaris!?
>
>Linux
>
>> Is Word installed?
>
>No.
>
>> OpenOffice?
>
>Yes.
>
>> Why have you specified Python?
>
>Becouse I like Python ;-)
>The System behind generating the HTML-Code is written in Python.
.
.
.
That's a fine reason to use Python.  It helps me to know, though.

I do a lot of this sort of thing--automation of conversion between
different Web display-formats.  I don't have a one-line answer for
the particular one you describe, but it's certainly feasible.

I'm willing to bet there's an HTML-to-RTF converter available for
Linux, but I've never needed (more accurately:  I have written my
own for special purposes--for my situations, it hasn't been diffi-
cult) one, so I can't say for sure.  My first step would be to 
look for such an application.  Failing that, I'd script OpenOffice
(with Python!) to read the HTML, and SaveAs RTF.

I list a few PDF-to-RTF converters in http://phaseit.net/claird/comp.text.pdf/PDF_converters.html#RTF >.
Again, I think there are more, but haven't yet made the time to 
hunt them all down.
-- 
http://mail.python.org/mailman/listinfo/python-list


Python IDE

2004-12-14 Thread Chris
What IDE's do y'all recommend for Python?  I'm using PythonWin atm, but 
I'd like something with more functionality.

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


Re: while 1 vs while True

2004-12-14 Thread Steven Bethard
Steve Holden wrote:
Interestingly the same error occurs even when attempting sideways access:
Python 2.4 (#60, Nov 30 2004, 11:49:19) [MSC v.1310 32 bit (Intel)] on 
win32
Type "help", "copyright", "credits" or "license" for more information.
 >>> import __builtin__
 >>> __builtin__.None = "Rhubarb"
SyntaxError: assignment to None
And in assignment to something that just looks like it could be None:
>>> class C(object):
... def __init__(self):
... self.None = None
Traceback (  File "", line 3
SyntaxError: assignment to None (, line 3)
Another Steve
--
http://mail.python.org/mailman/listinfo/python-list


Re: RegEx: find all occurances of a single character in a string

2004-12-14 Thread P
Franz Steinhaeusler wrote:
given a string:
st="abcdatraataza"
^   ^ ^ ^ (these should be found)
I want to get the positions of all single 'a' characters.
(Without another 'a' neighbour)
So I tried: 
r=re.compile('[^a]a([^a]') 

but this applies only for 
the a's, which has neighbours.
So I need also '^a' and 'a$'.

Am I doing something wrong? 
Is there a easier solution?
How can I quickly get all these positions?

Thank you in advance.
import re
s='abcdatraataza'
r=re.compile('(?
--
Pádraig Brady - http://www.pixelbeat.org
--
--
http://mail.python.org/mailman/listinfo/python-list


Re: Python IDE

2004-12-14 Thread Alex Stapleton
Why didn't you like Eclipse?  Was it that the Python modules were bad, 
or just Eclipse in general?  I use it for my Java developement and 
haven't had any problems with it.
Just the python stuff really, I've used it for some java stuff and know 
plenty of people that do every day and they all love it for Java, but 
having tried using it for anything else it's next to useless. In fact 
it's worse than a plain editor in some ways when your not using it for Java.
--
http://mail.python.org/mailman/listinfo/python-list


Re: do you master list comprehensions?

2004-12-14 Thread Fredrik Lundh
Steven Bethard wrote:

> > python -m timeit -s "data = [range(10) for _ in range(1000)]"
> "sum(data, [])"
> 10 loops, best of 3: 54.2 msec per loop
>
> > python -m timeit -s "data = [range(10) for _ in range(1000)]" "[w for
> d in data for w in d]"
> 100 loops, best of 3: 1.75 msec per loop
>
> The sum function used in this way (or a loop with a +=) is O(N**2) while the 
> LC is O(N).

also:

timeit -s "data = [range(10) for _ in range(1000)]" "L = sum(data, [])"
10 loops, best of 3: 4.02e+004 usec per loop

timeit -s "data = [range(10) for _ in range(1000)]" "L = [w for d in data for w 
in d]"
1000 loops, best of 3: 1.12e+003 usec per loop

timeit -s "data = [range(10) for _ in range(1000)]" "L = []; map(L.extend, 
data)"
1000 loops, best of 3: 283 usec per loop

timeit -s "data = [range(10) for _ in range(1000)]; from Tkinter import 
_flatten" "L = 
_flatten(data)"
1000 loops, best of 3: 308 usec per loop

(the last one supports arbitrary nestings, the others don't)

 



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


Re: do you master list comprehensions?

2004-12-14 Thread Steven Bethard
Timothy Babytch wrote:
Will Stuyvesant wrote:
data = [['foo','bar','baz'],['my','your'],['holy','grail']]

sum(data, [])
['foo', 'bar', 'baz', 'my', 'your', 'holy', 'grail']
The second parameter passed to sum is just to overrride default
initial value "zero".
It's worth keeping in mind that this solution has the same efficiency 
problems that a loop that =+ strings does:

> python -m timeit -s "data = [range(10) for _ in range(100)]" 
"sum(data, [])"
1000 loops, best of 3: 530 usec per loop

> python -m timeit -s "data = [range(10) for _ in range(100)]" "[w for 
d in data for w in d]"
1 loops, best of 3: 151 usec per loop

> python -m timeit -s "data = [range(10) for _ in range(1000)]" 
"sum(data, [])"
10 loops, best of 3: 54.2 msec per loop

> python -m timeit -s "data = [range(10) for _ in range(1000)]" "[w for 
d in data for w in d]"
100 loops, best of 3: 1.75 msec per loop

The sum function used in this way (or a loop with a +=) is O(N**2) while 
the LC is O(N).

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


Re: lies about OOP

2004-12-14 Thread beliavsky
A paper finding that OOP can lead to more buggy software is at
http://www.leshatton.org/IEEE_Soft_98a.html

Les Hatton "Does OO sync with the way we think?", IEEE Software, 15(3),
p.46-54
"This paper argues from real data that OO based systems written in C++
appear to increase the cost of fixing defects significantly when
compared with systems written in either C or Pascal. It goes on to
suggest that at least some aspects of OO, for example inheritance, do
not fit well with the way we make mistakes."

His comments under "invited feedback" are amusing and confirm my
impression that OOP is partly (but perhaps not entirely) hype:

"I should not that this paper because it criticised OO had an unusually
turbulent review period. 2 reviewers said they would cut their throats
if it was published and 3 said the opposite. The paper was only
published if the OO community could publish a rebuttal. I found this
very amusing as my paper contains significant data. The rebuttal had
none. This sort of thing is normal in software engineering which mostly
operates in a measurement-free zone."

What papers have scientific evidence for OOP?

Paul Graham's skeptical comments on OOP are at
http://www.paulgraham.com/noop.html .

If OOP is so beneficial for large projects, why are the Linux kernel,
the interpreters for Perl and Python, and most compilers I know written
in C rather than C++?

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


Re: subprocess vs. proctools

2004-12-14 Thread Keith Dart
Donn Cave wrote:
Keith Dart <[EMAIL PROTECTED]> wrote:
|>> if exitstatus:
|>>   print "good result (errorlevel of zero)"
|>> else:
|>>  print exitstatus # prints message with exit value
This is indeed how the shell works, though the actual failure value
is rarely of any interest.  It's also in a more general sense how
C works - whether errors turn out to be "true" or "false", in either
case you test for that status (or you don't.)
Python doesn't work that way, there is normally no such thing as
an error return.  An idiomatic Python interface would be
try:
proc = proctools.spawn(command)
proc.wait()
print 'good result'
except proctools.error, ev:
print >> sys.stderr, '%s: %s' % (proc.name, ev.text)

Your first statement is exactly right. One does not always care about 
the return value of an external process. And some programs still return 
an undefined value, even when successful. Therefore, I don't want to 
always have to wrap a call to an external program in a try..except 
block. Thus, it returns an ExitStatus object that you can easily test 
true-false with as in a shell, or get the actual value if you need it. 
Otherwise, just ignore it.


[... list of features ...]
| You always invoke the spawn* functions with a string. This is parsed by 
| a shell-like parser (the shparser module that comes with it), but no 
| /bin/sh is invoked. The parser can handle single and double quotes, and 
| backslash escapes.

It was sounding good up to here.  A lot depends on the quality of
the parser, but it's so easy to support a list of arguments that
gets passed unmodified to execve(), and such an obvious win in the
common case where the command parameters are already separate values,
that an interface where you "always" have to encode them in a string
to be submitted to your parser seems to be ignoring the progress that
os.spawnv and popen2.Popen3 made on this.  Of course you don't need
to repeat their blunders either and accept either string or list of
strings in the same parameter, which makes for kind of a shabby API,
but maybe a keyword parameter or a separate function would make sense.
Actually, an earlier version of proctools did take a list. However, 
after much usage I realized that in most cases what I got was a string 
to begin with. Either from user input or read from a file. I also found 
it easier to construct command-lines using the string-mod operator, 
substituting various attributes into option-value pairs in arbitrary 
ways. I was having to split/parse a string so often I decided to just 
make the Process object parse it itself. The shparser module has been 
perfectly adequate for this, and you can pass to the Process object 
pretty much the same string as you would to a real shell (thus making it 
easier to use for *nix people). I could add a list-input check, but 
likely I would never use it.


--
   \/ \/
   (O O)
-- oOOo~(_)~oOOo
Keith Dart <[EMAIL PROTECTED]>
public key: ID: F3D288E4

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


Re: gather information from various files efficiently

2004-12-14 Thread Steven Bethard
Klaus Neuner wrote:
The straightforward way to solve this problem is to create a
dictionary. Like so:
[...]
a, b = get_information(line)
if a in dict.keys():
dict[a].append(b)
else:
dict[a] = [b]
So I timed the three suggestions with a few different datasets:
> cat builddict.py
def askpermission(d, k, v):
if k in d:
d[k].append(v)
else:
d[k] = [v]
def askforgiveness(d, k, v):
try:
d[k].append(v)
except KeyError:
d[k] = [v]
def default(d, k, v):
d.setdefault(k, []).append(v)
def test(items, func):
d = {}
for k, v in items:
func(d, k, v)

Dataset where every value causes a collision:
> python -m timeit -s "import builddict as bd" "bd.test([(100, i) for i 
in range(1000)], bd.askpermission)"
1000 loops, best of 3: 1.62 msec per loop

> python -m timeit -s "import builddict as bd" "bd.test([(100, i) for i 
in range(1000)], bd.askforgiveness)"
1000 loops, best of 3: 1.58 msec per loop

> python -m timeit -s "import builddict as bd" "bd.test([(100, i) for i 
in range(1000)], bd.default)"
100 loops, best of 3: 2.03 msec per loop

Dataset where no value causes a collision:
> python -m timeit -s "import builddict as bd" "bd.test([(i, i) for i 
in range(1000)], bd.askpermission)"
100 loops, best of 3: 2.29 msec per loop

> python -m timeit -s "import builddict as bd" "bd.test([(i, i) for i 
in range(1000)], bd.askforgiveness)"
100 loops, best of 3: 9.96 msec per loop

> python -m timeit -s "import builddict as bd" "bd.test([(i, i) for i 
in range(1000)], bd.default)"
100 loops, best of 3: 2.98 msec per loop

Datset where one of every 5 values causes a collision:
> python -m timeit -s "import builddict as bd" "bd.test([(i % 5, i) for 
i in range(1000)], bd.askpermission)"
1000 loops, best of 3: 1.82 msec per loop

> python -m timeit -s "import builddict as bd" "bd.test([(i % 5, i) for 
i in range(1000)], bd.askforgiveness)"
1000 loops, best of 3: 1.79 msec per loop

> python -m timeit -s "import builddict as bd" "bd.test([(i % 5, i) for 
i in range(1000)], bd.default)"
100 loops, best of 3: 2.2 msec per loop

So, when there are lots of collisions, you may get a small benefit from 
the try/except solution.  If there are very few collisions, you probably 
would rather the if/else solution.  The setdefault solution patterns 
about like the if/else solution, but is somewhat slower.

I will probably continue to use setdefault, because I think it's 
prettier =) but if you're running into a speed bottleneck in this sort 
of situation, you might consider one of the other solutions.

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


Re: python gui

2004-12-14 Thread Jeff Shannon
zhao wrote:
python 2.4 is released, but the gui package wxpython now is only for
2.3, how long can it can released for 2.4?
 

This has been asked numerous times on the wxPython list in recent 
weeks.  :)  Robin Dunn is reportedly working now on updating his build 
environment and scripts to use VS.NET, and hopes to have wxPython built 
for 2.4 Real Soon Now(tm).

Jeff Shannon
Technician/Programmer
Credit International
--
http://mail.python.org/mailman/listinfo/python-list


Re: lies about OOP

2004-12-14 Thread Paul McGuire
"Steve Holden" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
> Paul McGuire wrote:
>
> > "Jive" <[EMAIL PROTECTED]> wrote in message
> > news:[EMAIL PROTECTED]
> >
> > 
> >
> >>But by '86, the Joy of OOP was widely known.
> >>
> >
> >
> > "Widely known"?  Errr?  In 1986, "object-oriented" programming was
barely
> > marketing-speak.  Computing hardware in the mid-80's just wasn't up to
the
> > task of dealing with OO memory and "messaging" overhead.  Apple Macs
were
> > still coding in C and Forth.  Borland didn't ship Turbo-Pascal with
> > Object-Oriented programming until 1989, and Turbo-C++ shipped in 1991.
> > Smalltalk had been around for 10 years by 1986, but it was still a
> > curiosity, hardly "widely known."  It wasn't until the publication of
David
> > Taylor's "Object Technology: A Manager's Guide" in 1990 that OOP began
to be
> > legitimized to many management decision makers, that it was more than
just
> > "fairy dust" (as Bill Gates had characterized it in an attempt to
discredit
> > Borland's forays into the field).
> >
> Well, that's not true either, and the fact that Bill Gates was
> denigrating it implies that he at least knew about it, even if he chose
> not to adopt it (then: of course nowadays Microsoft call almost all
> their technologies "object oriented"; sometimes this description is as
> accurate as when Gates speaks about "our open Windows environment").
>
> > I would pick the publication of "Design Patterns" in 1995 by the Gang of
> > Four (Gamma, Helm, Johnson, and Vlissides),  to be the herald of when
"the
> > Joy of OOP" would be "widely known."  DP formalized a taxonomy for many
of
> > the heuristics that had evolved only intuitively up until then.  Its
> > emergence reflects a general maturation of concept and practice,
sufficient
> > to say that the Joy of OOP could be said to be "widely known."
> >
> We could all make our own choices, but anyone who's been programming
> *seriously* since the 60s will likely remember Simula as the birth of
> many oft he ideas later picked up by Alan Kay and promoted by the Xerox
> PARC SmallTalk group.
>
> I visited that group in 1981 (after Kay left, unfortunately, and then
> being headed by Adele Goldberg, who is now coincidentally promoting the
> delights of Python at conferences like OSCON), and object-oriented
> programming was certainly something that was being taken pretty
> seriously in the academic world as a potential solution to some serious
> PLIT engineering problems.
>
> The fact that it took the technology a relatively long time to appear
> "in the wild", so to speak, is simply the natural maturation of any new
> technology. Given that UNIX was developed in the early 1970s I'd say it
> took UNIX 20 years to start becoming mainstream. But a lot of people
> knew about it before it *became* mainstream, especially those who had to
> place their technology bets early. The same is true of object-oriented
> concepts.
>
> I guess this is just to say that I'd dispute your contention that
> SmallTalk was a curiosity - unless you define anything of interest
> mostly to the academic world as a curiosity, in which case there's no
> way to overcome your objection. It was the first major implementation of
> an entire system based exclusively on OO programming concepts and, while
> far from ideal, was a seminal precursor to today's object-oriented
systems.
>
> regards
>   Steve
>
> -- 
> Steve Holden   http://www.holdenweb.com/
> Python Web Programming  http://pydish.holdenweb.com/
> Holden Web LLC  +1 703 861 4237  +1 800 494 3119

Good points all.  And yes, I recall the BYTE article on Smalltalk.  I guess
I was just reacting mostly to the OP's statement that "by '86 the Joy of OOP
was widely known".  He didn't say "OOP all began when..." or "OOP was widely
known," which I think still would have been a stretch - he implied that by
'86 OOP was widely recognized as Goodness, to which I disagree.  This was
the year of the first OOPSLA conference, but as PyCon people know, just
having a conference doesn't guarantee that a technology is widely and
joyfully accepted.  Just as my commercial-centric view may understate
academic interest in some topics, an academic-centric view may overestimate
the impact of topics that are ripe for research, or technically "cool," but
little understood or adopted outside of a university setting.

I would characterize the 80's as the transitional decade from structured
programming (which really started to hit its stride when Djikstra published
"Use of GOTO Considered Harmful") to OOP, and that OOP wasn't really
"joyful" until the early-to-mid 90's.

(And I apologize for characterizing Smalltalk as a "curiosity."  I admit my
bias is for software that is widely commercially deployed, and even the most
ardent Smalltalkers will have difficulty citing more than a handful of
applications, compared to C,C++,VB,COBOL,Delphi, etc.  I personally have
seen Smalltalk-based factory control and autom

Re: Python 3.0

2004-12-14 Thread Fredrik Lundh
"Chris" <[EMAIL PROTECTED]> wrote:

> Okay, color me stupid, but what is everyone referencing when they mention 
> Python 3.0?  I didn't 
> see any mention of it on the Python site.

http://www.python.org/peps/pep-3000.html

(which happens to be the first hit if you search for "python 3.0" in the
search box on python.org...)

 



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


Re: pyparsing and 'keywords'

2004-12-14 Thread Berteun Damman
On Tue, 14 Dec 2004 18:39:19 GMT, Paul McGuire
<[EMAIL PROTECTED]> wrote:
>> If I try however to parse the String "if test; testagain; fi;", it does
>> not work, because the fi is interpreted as an expr, not as the end of
>> the if statement, and of course, adding another fi doesn't solve this
>> either.
> The simplest way I can think of for this grammar off the top of my head is
> to use a parse action to reject keywords.

Thank you for your quick and good solution, that did the trick indeed. 

But I'm wondering, isn't it possible to have some sort of lexing phase
which already identifies keywords as such? Or to provide a table with
keywords, which pyparsing is able to automatically recognize? 

So you would be able to do IF = Keyword("if"), just as a Literal now is
created, but now the parser knows this word shouldn't be interpreted any
other way than as a keyword. Or would that be a bad idea?

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


Re: pyparsing and 'keywords'

2004-12-14 Thread Paul McGuire
"Berteun Damman" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
> Hello,
>
> I'm having some problems with pyparsing, I could not find how to tell
> it to view certain words as keywords, i.e. not as a possible variable
> name (in an elegant way),
> for example, I have this little grammar:
>
> terminator = Literal(";")
> expr = Word(alphas)
> body = Forward();
> ifstat = "if" + body + "fi"
> stat = expr | ifstat
> body << OneOrMore(stat + terminator)
> program = body
>
> I.e. some program which contains statements separated by semicolons. A
> statement is either an if [] fi statement or simply a word.
>
> If I try however to parse the String "if test; testagain; fi;", it does
> not work, because the fi is interpreted as an expr, not as the end of
> the if statement, and of course, adding another fi doesn't solve this
> either.
>
> How to fix this?
>
> Thank you,
>
> Berteun
>
Berteun -

The simplest way I can think of for this grammar off the top of my head is
to use a parse action to reject keywords.

keywords = [ "if", "fi", "else", "return" ]
def rejectKeywords(string,loc,tokens):
if tokens[0] in keywords:
raise ParseException(string,loc,"found keyword %s" % tokens[0])
expr.setParseAction( rejectKeywords )

I took a different tack in the idl parser that is included in the pyparsing
examples directory, but it is more extensive.

-- Paul


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


Re: lies about OOP

2004-12-14 Thread Steve Holden
Paul McGuire wrote:
"Steve Holden" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
[some stuff]

Good points all.  And yes, I recall the BYTE article on Smalltalk.  I guess
I was just reacting mostly to the OP's statement that "by '86 the Joy of OOP
was widely known".  He didn't say "OOP all began when..." or "OOP was widely
known," which I think still would have been a stretch - he implied that by
'86 OOP was widely recognized as Goodness, to which I disagree.  This was
the year of the first OOPSLA conference, but as PyCon people know, just
having a conference doesn't guarantee that a technology is widely and
joyfully accepted.  Just as my commercial-centric view may understate
academic interest in some topics, an academic-centric view may overestimate
the impact of topics that are ripe for research, or technically "cool," but
little understood or adopted outside of a university setting.
I would characterize the 80's as the transitional decade from structured
programming (which really started to hit its stride when Djikstra published
"Use of GOTO Considered Harmful") to OOP, and that OOP wasn't really
"joyful" until the early-to-mid 90's.
(And I apologize for characterizing Smalltalk as a "curiosity."  I admit my
bias is for software that is widely commercially deployed, and even the most
ardent Smalltalkers will have difficulty citing more than a handful of
applications, compared to C,C++,VB,COBOL,Delphi, etc.  I personally have
seen Smalltalk-based factory control and automation systems, but they are
rapidly self-marginalizing, and new customers are extremely reluctant to
enfold Smalltalk into an already patchwork mix of technologies, as is
typically found in factory settings.)
Nothing to disagree with here.
regards
 Steve
--
Steve Holden   http://www.holdenweb.com/
Python Web Programming  http://pydish.holdenweb.com/
Holden Web LLC  +1 703 861 4237  +1 800 494 3119
--
http://mail.python.org/mailman/listinfo/python-list


Re: lies about OOP

2004-12-14 Thread Steve Holden
Paul McGuire wrote:
"Steve Holden" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
[some stuff]

Good points all.  And yes, I recall the BYTE article on Smalltalk.  I guess
I was just reacting mostly to the OP's statement that "by '86 the Joy of OOP
was widely known".  He didn't say "OOP all began when..." or "OOP was widely
known," which I think still would have been a stretch - he implied that by
'86 OOP was widely recognized as Goodness, to which I disagree.  This was
the year of the first OOPSLA conference, but as PyCon people know, just
having a conference doesn't guarantee that a technology is widely and
joyfully accepted.  Just as my commercial-centric view may understate
academic interest in some topics, an academic-centric view may overestimate
the impact of topics that are ripe for research, or technically "cool," but
little understood or adopted outside of a university setting.
I would characterize the 80's as the transitional decade from structured
programming (which really started to hit its stride when Djikstra published
"Use of GOTO Considered Harmful") to OOP, and that OOP wasn't really
"joyful" until the early-to-mid 90's.
(And I apologize for characterizing Smalltalk as a "curiosity."  I admit my
bias is for software that is widely commercially deployed, and even the most
ardent Smalltalkers will have difficulty citing more than a handful of
applications, compared to C,C++,VB,COBOL,Delphi, etc.  I personally have
seen Smalltalk-based factory control and automation systems, but they are
rapidly self-marginalizing, and new customers are extremely reluctant to
enfold Smalltalk into an already patchwork mix of technologies, as is
typically found in factory settings.)
Nothing to disagree with here.
regards
 Steve
--
Steve Holden   http://www.holdenweb.com/
Python Web Programming  http://pydish.holdenweb.com/
Holden Web LLC  +1 703 861 4237  +1 800 494 3119
--
http://mail.python.org/mailman/listinfo/python-list


Re: PyQt on MAC OS X

2004-12-14 Thread whamoo
dMichael McGarry <[EMAIL PROTECTED]> wrote:

> > You must use pythonw for graphics application =)
> > So launch the script with pythonw instead of python ;-)
> > 
> Thanks using pythonw did the trick.
> 
> I appreciate everyone's help.

;-) Happy programming with your mac and python


-- 
Whamoo www.rknet.it
Powerd by: MacOsX, Gnu/Linux Debian Sarge,
Amiga Os 3.9, Milk.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python 3.0

2004-12-14 Thread Edward C. Jones
Chris wrote:
Okay, color me stupid, but what is everyone referencing when they 
mention Python 3.0?  I didn't see any mention of it on the Python site.
http://www.python.org/peps/pep-3000.html
(which happens to be the first hit if you search for "python 3.0" in the
search box on python.org...)

Okay, I feel dumb now. :)
Chris
You are not dumb. Many search phrases are obvious if and only if you 
have already seen them.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Python 3.0

2004-12-14 Thread Fredrik Lundh
Edward C. Jones wrote:

> You are not dumb. Many search phrases are obvious if and only if you have 
> already seen them.

or typed them, in this case (did you read the subject before posting? ;-)

 



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


Re: Automate Python-2.4 Installs on Windows

2004-12-14 Thread Michel Claveau - abstraction méta-galactique non triviale en fuite perpétuelle.
+1



Michel Claveau



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


Re: PEP 338: Executing modules inside packages with '-m'

2004-12-14 Thread Martin Bless
[Nick Coghlan <[EMAIL PROTECTED]>]

>Python 2.4's -m command line switch only works for modules directly on 
>sys.path. 

On my Windows machine this command line switch really makes my life so
much easier. I appreciate -m very much. Going further as proposed in
PEP 338 sounds good to me.

One thing I stumbled across with the current implementation:

Why doesn't "python -m abc" work with

./abc/
./abc/__init__.py

assuming ./abc/ is directly on the path? In analogy to normal module
import?

mb - Martin



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


Re: Looking for a coder to do some work

2004-12-14 Thread Brad Clements
Sounds like a generic html based information kiosk.

Anyone can do this pretty easily using embedded IE or Mozilla ActiveX
control wrapped up in Venster. Just run an internal http server in another
thread.. I've done this for desktop apps. Though, full-screen windows I
haven't tried, but should be straightforward.


-- 
Novell DeveloperNet Sysop #5



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


RE: PythonWin Not Updating

2004-12-14 Thread Robert Brewer
Chris wrote:
> I'm working on a program in PythonWin.  The problem I'm 
> running into is that after I make a code change,
> PythonWin doesn't always see it.  Has anyone else
> had this problem?

"See it" in the interactive session? Use reload():

http://docs.python.org/lib/built-in-funcs.html

Otherwise, you'll have to explain a bit more--that's my best guess as to
what your issue is.


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


Re: PythonWin Not Updating

2004-12-14 Thread It's me
It works fine here.

--
It's me

"Chris" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
> I'm working on a program in PythonWin.  The problem I'm running into is
> that after I make a code change, PythonWin doesn't always see it.  Has
> anyone else had this problem?
>
> Chris


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


RE: need some help quickly

2004-12-14 Thread Delaney, Timothy C (Timothy)
Allan Irvine wrote:

> Hope you can help - any thoughts welcome

Here is the best place you can get help for your problem:
http://www.catb.org/~esr/faqs/smart-questions.html

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


Archiving directory without external tools?

2004-12-14 Thread iamlevis3
Does Python have any internal facility for creating recursive archives
of a directory?  I'd like to avoid reliance on extenal tools
(winzip,tar,etc).

Thanks!

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


Re: lies about OOP

2004-12-14 Thread Tomas Christiansen
projecktzero wrote:
> A co-worker considers himself "old school" in that he hasn't seen the
> light of OOP ... He thinks that OOP has more overhead and is slower
> than programs written the procedural way.

He may be right, but consider the alternatives.

Think of an integer. An integer is an object!

You can assign a new integer-value to the object.
You can read the integer-value of the object.
(The integer can be part of complex expressions.)

Usually you are unaware (or don't care) _how_ the object is implemented.
Wether the bits are red, green, turns upside-down or are inverted - you
doesn't really care, as long as it can hold the values that you want it to
hold and be used in the relevant contexts (addition, multiplication, ...).

Some lanugages gives you the choise of many integer-implementations, some
languages gives you only a few choises and some languages gives you only one
choise.

Surely we can agree that the presence of an integer-object is extremely
useful! If you had to do all the integer-stuff in machine code _every_ time,
you would soon be very, very tired of working with integers. There is no
doubt that objects are (or can be) extremely useful, time-saving and very
efficient. Chances are that your own machine-code integer-inplementation is
not nearly as good as the one made by a team of top-tuned programmers (no
offense) programming the integer-implementation "object".

Wether the language should give you the choise of one, some, many or
extremely many integer-implementations, depends entirely on your needs
("what a pervert - he needs an integer!"). Lowering the number of choises of
implementations, rises the chances of having to chose a "not very good"
implementation. Letting the language automaticly chose the right one, frees
your mind to other processes, but at the risk of some kind of run-time
overhead.

---
Tomas

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


Re: Python IDE

2004-12-14 Thread Tomas
"Fuzzyman" <[EMAIL PROTECTED]> wrote in message 
news:[EMAIL PROTECTED]
> If you're willing to pay for one, Komodo is very good. Especially for
> projects.

I would recomend Wing IDE over Komodo. My experience is that Wing IDE has 
far better code completion. And the Source Assistant feature of the 
professional version is very useful.

As for projects, it doesn't support CVS or anything similar. Still, I don't 
miss this feature, because there are other excelent and free CVS clients. I 
use TortoiseCVS, http://www.tortoisecvs.org/, which integrates CVS-support 
in Explorer.

-Tomas 


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


Re: Archiving directory without external tools?

2004-12-14 Thread Fredrik Lundh
<[EMAIL PROTECTED]> wrote:

> Does Python have any internal facility for creating recursive archives
> of a directory?  I'd like to avoid reliance on extenal tools
> (winzip,tar,etc).

import os, sys, zipfile

directory = sys.argv[1]

zip = zipfile. ZipFile(directory + ".zip", "w")

for path, dirs, files in os.walk(directory):
for file in files:
file = os.path.join(path, file)
print file, "..."
zip.write(file)

print "done"

tweak as necessary.

(did you even look in the library reference, btw?)

 



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


Re: How do I convert characters into integers?

2004-12-14 Thread Grant Edwards
On 2004-12-14, Markus Zeindl <[EMAIL PROTECTED]> wrote:

> I want to write a simple encrypter, but I've got a problem:
> How can I convert characters into integers?

$ python
Python 2.3.4 (#2, Aug 19 2004, 15:49:40) 
[GCC 3.4.1 (Mandrakelinux (Alpha 3.4.1-3mdk)] on linux2
Type "help", "copyright", "credits" or "license" for more
information.
>>> ord('A')
65

-- 
Grant Edwards   grante Yow!  .. does your DRESSING
  at   ROOM have enough ASPARAGUS?
   visi.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How do I convert characters into integers?

2004-12-14 Thread Paul Rubin
Markus Zeindl <[EMAIL PROTECTED]> writes:

> Now I get every character with a loop:
> 
> buffer = ""
> for i in range(len(message)):
>ch = message[i-1:i]

You mean 
  ch = message[i]
what you have does the wrong thing when i = 0.

> Here is the problem. I got a string with one character and I
> want his ascii representain, for "a" -> 97
> but I want to calculate like iCh = iCh+3 or something else.

iCh = ord(ch)

> The next step is how I convert it back to an char and append it
> to the buffer, but that' no problem.

ch = chr(iCh)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: New versions breaking extensions, etc.

2004-12-14 Thread "Martin v. Löwis"
Jive wrote:
But it makes no difference, no?  The problem is that both Python.exe and the
extensions are *compiled* to link with a *particular* crt. 
No, that is not (really) the case. They are compiled to link with
msvcrt.lib, which could, at link time, then become msvcrt.dll,
msvcrt40.dll, or msvcr71.dll.
(How "dyanamic" is that?)
The actual code of the DLL is not provided until run-time - only
at run-time, the precise implementation of the CRT routines is
available - and it indeed may vary from system to system, as different
versions of msvcrt40.dll might be installed (or of python24.dll, for
that matter).
We could probably kluge around the problem if it were not for the
fact that one crt might perversely define some struct, (FILE, for example),
with difference layouts in different crt DLL's. Right?
Wrong. struct FILE binds us the the MS CRT (so the Borland or glibc CRTs
are incompatible), but struct FILE has stayed the same for more than 10
years now, so you can, in principle, mix object files compiled with
different compilers. One would need to check the header files to
determine they are really compatible, but that appears to be the intent,
and Microsoft does not dare to change it (except perhaps for the _ctype
thing, which I don't fully understand).
What really hurts is that the CRT has a number of global variables: the
global FILE objects (FILE 0 to FILE 63, I believe), the global heap,
and the global atexit handlers. If you have multiple CRTs, you get
multiple copies of these globals, and the different routines in the
different CRTs each operate on their own copy of the global variable.
So it would seem that as far as the crt goes, we are at the mercy of the
micro soft ones.  They could introduce an incompatible crt at any time.
They could, but they won't. I believe they have long given up changing
or improving the CRT, since that would make things worse in most cases.
The only things they still do is to add new features; the existing ABI
apparently is never touched (again, perhaps except for a _ctype change
I don't understand).
By the way, I've googled around and found others outside the Python
community who have run into the same problem.  In some cases, they have
opted just to stay with VC 6.0.  One said, "At least the 6.0 compiler is 2.5
times as fast."  Groan.
This is what Python did for 2.3. Already at that time, user pressure
was quite high to move to a more recent compiler; with 2.4, it was
clear that we do need some of the new features (in particular,
ongoing commercial availability, and IPv6 support in winsock.h).
Regards,
Martin
--
http://mail.python.org/mailman/listinfo/python-list


Re: lies about OOP

2004-12-14 Thread Roy Smith
Terry Reedy <[EMAIL PROTECTED]> wrote:
> I did not really 'get' OOP until after learning Python.  The
> relatively simple but powerful user class model made more sense to
> me than C++.  So introducing someone to Python, where OOP is a
> choice, not a mandate, is how *I* would introduce a procedural
> programmer to the subject.  YMMV.

OOP is a choice in C++ too.  You can write procedural C++ code; no
need to use classes at all if you don't want to.  Something like Java
is a different story.  Java *forces* you to use classes.  Nothing
exists in Java that's not part of some class.

I think the real reason Python is a better teaching language for
teaching OO concepts is because it just gives you the real core of OO:
inheritence, encapsulation, and association of functions with the data
they act on.

C++ has so much stuff layed on top of that (type bondage, access
control, function polymorphism, templates) that it's hard to see the
forest for the trees.  You get C++ jocks who are convinced that that
stuff is part and parcel of OO, and if it doesn't have (for example),
private data, it can't be OO.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: lies about OOP

2004-12-14 Thread Martijn Faassen
[EMAIL PROTECTED] wrote:
A paper finding that OOP can lead to more buggy software is at
http://www.leshatton.org/IEEE_Soft_98a.html
[snip description of paper that compares C++ versus Pascal or C]
What papers have scientific evidence for OOP?
That's of course a good question. I'm sure also that comp.object has 
argued about this a thousand times. I'll just note that one paper is 
just a single data point with specific circumstances. The OO languages 
under investigation might have caused increased or lower failure rates 
for other reasons than their (lack of) object-orientedness, for 
instance. It is of course possible to come up with a lot of other 
explanations for a single data point besides a conclusion that OOP can 
lead to more buggy software. It for instance certainly not surprising to 
me that C++ can lead to more buggy software than some other languages. :)

[snip]
If OOP is so beneficial for large projects, why are the Linux kernel,
the interpreters for Perl and Python, and most compilers I know written
in C rather than C++?
Because C++ is not an ideal object oriented language? Because a Linux 
kernel has very stringent predictability requirements for what kind of 
machine code is generated that C meets and is much harder to do with 
C++? There are other reasons to choose C, such as portability, obiquity 
and performance.

Some of the same reasons probably apply to Perl and Python, though at a 
lesser degrees. I do not know a lot about Perl's implementation. I do 
know that Guido van Rossum has in fact considered rewriting Python in 
C++ in the past. And right now, there are various projects that are 
using object oriented languages to reimplement Python, including Python 
itself.

Finally, it is certainly possible to program in object oriented style in 
C. It is more cumbersome than in a language that supports it natively, 
but it is certainly possible. Such OO in C patterns occur throughout the 
Linux kernel, which needs a pluggability architecture for its various 
types of drivers. It can also be seen in many aspects of Python's 
implementation. Another example of a C-based system that uses object 
oriented technologies is the GTK+ widget set.

Anyway, this question is using a few data points to make an overly 
generic argument, and the data points themselves do not really support 
the argument so very well either.

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


Re: lies about OOP

2004-12-14 Thread Paul McGuire
"Roy Smith" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
> I think the real reason Python is a better teaching language for
> teaching OO concepts is because it just gives you the real core of OO:
> inheritence, encapsulation, and association of functions with the data
> they act on.
>
> C++ has so much stuff layed on top of that (type bondage, access
> control, function polymorphism, templates) that it's hard to see the
> forest for the trees.  You get C++ jocks who are convinced that that
> stuff is part and parcel of OO, and if it doesn't have (for example),
> private data, it can't be OO.

+1, QOTW!! :)  (esp. "type bondage"!)


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


Re: Automate Python-2.4 Installs on Windows

2004-12-14 Thread Fredrik Lundh
Martin v. Löwis wrote:

>> which might be great if you know how things work, but is bloody confusing
>> if you don't.  most importantly, how do you set properties?
>
> How do you know they are called properties?-) I would have thought that
> "Additional parameters can be passed at the end of this command line" is 
> precise enough

not when you call them "properties" in the rest of the document:

"The property TARGETDIR ...", "A number of properties", etc.

(and KEY=VALUE isn't exactly standard command-line syntax, even under
Windows).

 



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


Re: New versions breaking extensions, etc.

2004-12-14 Thread Jive

"Robin Becker" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
> Cameron Laird wrote:
> There was no rational reason
> for me to upgrade to VC 7.x, but now I'm forced to by my preferred
language.
> -- 
> Robin Becker

That's the way I feel about it too.  Actually, I'm getting pushed toward
Microsoft from other directions, also for no good reason -- and for a whole
lot of computers, not just for the one on my desk.

Open letter to Bill Gates:

Dear Bill,

Okay. You win again.  It was silly of me to think Python would help me
escape your clutches.  Look at how good I am being now.  I am typing this
into an Outlook Express window, using a Microsoft operating system that you
will no doubt find a way to make me replace very soon.  You beat me fair and
square.  Well, square, anyway.  Congratulations.  I give up.

Jive




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


effbot ElementTree question

2004-12-14 Thread dayzman
Hi,

Is anyone here familiar with ElementTree by effbot?

With hello how is "hello" stored in the
element tree? Which node is it under? Similarly, with:
foo  blah  bar, how is bar stored? Which node is
it in?

Cheers,
Ming

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


Re: Performance (pystone) of python 2.4 lower then python 2.3 ???

2004-12-14 Thread Dan
Lucas Hofman wrote:
A 7% speed DECREASE??? According to the documentation it should be a 5% increase?
I also see an 8-10% speed decrease in 2.4 (I built) from 2.3.3 (shipped 
w/Fedora2) in the program I'm writing (best of 3 trials each).  Memory 
use seems to be about the same.

2.4:   real2m44.131s
2.3.3: real2m29.865s
/Dan
--
dedded att verizon dott net
--
http://mail.python.org/mailman/listinfo/python-list


Re: lies about OOP

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

> Instead of copy and paste, I use functions for code reuse. I didn't see
> the light of OOP, yet. I use Python but never did anything with OOP. I
> just can't  see what can be done with OOP taht can't be done with
> standart procedural programing.

There are cases where functions just don't do the job.

I at one time needed to use the little-used (and probably little-know)
"account" featre of an ftp server to automate a regular file
transfer. Both Perl and Python come with ftp modules. Perl's was (is?)
procedural, Python's is OO. Neither supported the account feature.

Now, if I used perl to do this, I'd have to either modify the module
in place, meaning I'd have to remember to put the mods back every time
we updated perl if I couldn't get them to buy the patch, or I could
make a local copy of the module, meaning it wouldn't get any bug fixes
that might come with new versions of perl.

With the Python version, I created a subclass of the FTP connection
module, rewrote just the login method, and installed that locally. Now
I don't have to worry about installing new versions of Python, as my
code is outside the distribution. But I still get the benefit of any
bug fixes that show up outside the login method. I also submitted the
new login method, and it's now part of the standard module.

This kind of code reuse just isn't possible with procedural code.

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


logging in omniORB for python

2004-12-14 Thread Birgit Rahm
Hello newsgroup,

I work with omniORB for python and I what to log the calls, does anyone in
this group know how I can do this?
I use the command to initialize the ORB
ORB = CORBA.ORB_init(sys.argv + ["-ORBtraceLevel", "40"], CORBA.ORB_ID)
but I dont get a log file or a message in pythonwin output display about
anything.
Does anyone know, were the log data is? And how I can store it in a file?
By the way I ask also the omniORB mailing list, but here are the python
experts.

--

Mit freundlichen Grüßen / best regards
Birgit Rahm


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


Re: Regular Expression

2004-12-14 Thread Binu K S
You can do this without regular expressions if you like

>>> uptime='12:12:05  up 21 days, 16:31, 10 users,  load average:
0.01, 0.02, 0.04'
>>> load = uptime[uptime.find('load average:'):]
>>> load
'load average: 0.01, 0.02, 0.04'
>>> load = load.split(':')
>>> load
['load average', ' 0.01, 0.02, 0.04']
>>> load[1].split(',')
[' 0.01', ' 0.02', ' 0.04']

One liner:
>>> uptime[uptime.find('load average:'):].split(':')[1].split(',')[0]
' 0.01'

On Tue, 14 Dec 2004 23:16:43 -0700, Michael McGarry
<[EMAIL PROTECTED]> wrote:
> Hi,
> 
> I am horrible with Regular Expressions, can anyone recommend a book on it?
> 
> Also I am trying to parse the following string to extract the number
> after load average.
> 
> " load average: 0.04, 0.02, 0.01"
> 
> how can I extract this number with RE or otherwise?
> 
> Michael
> --
> http://mail.python.org/mailman/listinfo/python-list
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Regular Expression

2004-12-14 Thread Keith Dart
Michael McGarry wrote:
Hi,
I am horrible with Regular Expressions, can anyone recommend a book on it?
Also I am trying to parse the following string to extract the number 
after load average.

" load average: 0.04, 0.02, 0.01"
how can I extract this number with RE or otherwise?
This particular example might be parsed more quickly and easily just by 
chopping it up:

s = " load average: 0.04, 0.02, 0.01"
[left, right] = s.split(":")
[av1, av2, av3] = map(float, map(str.strip, right.split(",")))

--
   \/ \/
   (O O)
-- oOOo~(_)~oOOo
Keith Dart <[EMAIL PROTECTED]>
vcard: 
public key: ID: F3D288E4   URL: 

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


Re: Regular Expression

2004-12-14 Thread Michael McGarry
Binu K S wrote:
You can do this without regular expressions if you like

uptime='12:12:05  up 21 days, 16:31, 10 users,  load average:
0.01, 0.02, 0.04'
load = uptime[uptime.find('load average:'):]
load
'load average: 0.01, 0.02, 0.04'
load = load.split(':')
load
['load average', ' 0.01, 0.02, 0.04']
load[1].split(',')
[' 0.01', ' 0.02', ' 0.04']
One liner:
uptime[uptime.find('load average:'):].split(':')[1].split(',')[0]
' 0.01'
Thank you.
--
http://mail.python.org/mailman/listinfo/python-list


Regular Expression

2004-12-14 Thread Michael McGarry
Hi,
I am horrible with Regular Expressions, can anyone recommend a book on it?
Also I am trying to parse the following string to extract the number 
after load average.

" load average: 0.04, 0.02, 0.01"
how can I extract this number with RE or otherwise?
Michael
--
http://mail.python.org/mailman/listinfo/python-list


Re: Regular Expression

2004-12-14 Thread Steven Bethard
Michael McGarry wrote:
Also I am trying to parse the following string to extract the number 
after load average.

" load average: 0.04, 0.02, 0.01"
In Python 2.4:
>>> uptime='12:12:05  up 21 days, 16:31, 10 users,  load average: 0.01, 
0.02, 0.04'
>>> _, avg_str = uptime.rsplit(':', 1)
>>> avg_str
' 0.01, 0.02, 0.04'
>>> avgs = [float(s) for s in avg_str.split(',')]
>>> avgs
[0.01, 0.02, 0.040001]

I took advantage of the new str.rsplit function which splits from the 
right side instead of the left.

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


Re: effbot ElementTree question

2004-12-14 Thread Fredrik Lundh
<[EMAIL PROTECTED]> wrote:

> Is anyone here familiar with ElementTree by effbot?
>
> With hello how is "hello" stored in the
> element tree? Which node is it under? Similarly, with:
> foo  blah  bar, how is bar stored? Which node is
> it in?

reposting the reply I just posted to the discussion board where you
asked the same question:

in the body case, the "hello" text ends up in the 'text' attribute of the "body"
node (in HTML/CSS terminology, this is known as an "anonymous block").

in the other case, the trailing text is stored in the 'tail' attribute of the
preceeding element ("a" in this case); see:

http://effbot.org/zone/element-infoset.htm#mixed-content

for details on how ElementTree deals with mixed content.

 



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


Re: Regular Expression

2004-12-14 Thread Timothy Grant
On Tue, 14 Dec 2004 23:16:43 -0700, Michael McGarry
<[EMAIL PROTECTED]> wrote:
> Hi,
> 
> I am horrible with Regular Expressions, can anyone recommend a book on it?
> 
> Also I am trying to parse the following string to extract the number
> after load average.
> 
> " load average: 0.04, 0.02, 0.01"
> 
> how can I extract this number with RE or otherwise?

Lot's of good solutions for the problem.

However, you might want to check out Jeffrey Friedl's book Mastering
Regular Expressions, published by O'Reilly.


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


Re: Iteration within re.sub()?

2004-12-14 Thread Mark McEahern
Bryant Huang wrote:
Hi,
Is it possible to perform iteration within the re.sub() function call?
 

Sure.  As the docs note:
If repl is a function, it is called for every non-overlapping occurrence 
of pattern. The function takes a single match object argument, and 
returns the replacement string. For example:

#!/usr/bin/env python
import re
class Counter:
   def __init__(self):
   self.count = -1
   def increment(self, matchObject):
   self.count += 1
   return str(self.count)
text = "abbababbaabbaaa"
expected = "a01a2a34aa56aaa"
# Replace all b's with an integer that increments from 0.
c = Counter()
pat = re.compile("(b)")
actual = pat.sub(c.increment, text)
assert expected == actual
--
http://mail.python.org/mailman/listinfo/python-list


[OT] Re: [Boa Constr] new open source project developing with Boa Constructor

2004-12-14 Thread Stephen Waterbury
Stephen Waterbury wrote:
sosman wrote:
Just letting people know, I have launched a homebrew software package 
that is being developed with boa.

http://sourceforge.net/projects/brewsta/
So, give us a hint ... does it make beer or what?  :)
Oops!  Sorry gang.  Sent my wise-ass reply to the wrong list!
(The OP was on the boa-users list ... heh :)
--
http://mail.python.org/mailman/listinfo/python-list


Re: do you master list comprehensions?

2004-12-14 Thread Jeremy Bowers
On Tue, 14 Dec 2004 00:41:36 +0100, Max M wrote:

> Fredrik Lundh wrote:
>> Max M wrote:
>> 
>> 
I tried funnies like [[w for w in L] for L in data],
>>>
>>>That is absolutely correct. It's not a funnie at all.
>> 
>> well, syntactically correct or not, it doesn't do what he want...
> 
> Doh! *I* might not be used to list comprehensions then... You are right.
> 
> That example could have been expressed more clearly as:
> 
>  result = data

result = data[:]

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


Re: looking for blocking on read of a real file (not socket or pipe)

2004-12-14 Thread Peter Hansen
Steven wrote:
I'm seeking a read method that will block until new data is available. Is
there such a python function that does that?
It may be relevant which platform(s) are of interest.  Linux?
Mac?  Windows?  All?  The more cross-platform this needs to
be, the less likely it exists...
--
http://mail.python.org/mailman/listinfo/python-list


Re: lies about OOP

2004-12-14 Thread Timo Virkkala
projecktzero wrote:
A co-worker considers himself "old school" in that he hasn't seen the
light of OOP.(It might be because he's in love with Perl...but that's
another story.) He thinks that OOP has more overhead and is slower than
programs written the procedural way. I poked around google, but I don't
know the magic words to put in to prove or disprove his assertion. Can
anyone point me toward some resources?
Sounds like your co-worker has a major case of premature optimization. I don't 
know about speed issues with OO, but for large projects, using OOP makes data 
encapsulation so much easier. Writing correct code with minimum effort should be 
the first goal, speed issues (at that level) should be brought into the game 
later on.

You should ask your co-worker if he also puts all his data in global variables 
:)
*wink*
--
Timo Virkkala
--
http://mail.python.org/mailman/listinfo/python-list


Re: Iteration within re.sub()?

2004-12-14 Thread Bryant Huang
Ah beautiful, thank you both, Robert and Mark, for your instant and
helpful responses. I understand, so the basic idea is to keep a
variable that is globally accessible and call an external function to
increment that variable...

Thanks!
Bryant

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


Re: lies about OOP

2004-12-14 Thread Paul McGuire
"Jive" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
>

> But by '86, the Joy of OOP was widely known.
>

"Widely known"?  Errr?  In 1986, "object-oriented" programming was barely
marketing-speak.  Computing hardware in the mid-80's just wasn't up to the
task of dealing with OO memory and "messaging" overhead.  Apple Macs were
still coding in C and Forth.  Borland didn't ship Turbo-Pascal with
Object-Oriented programming until 1989, and Turbo-C++ shipped in 1991.
Smalltalk had been around for 10 years by 1986, but it was still a
curiosity, hardly "widely known."  It wasn't until the publication of David
Taylor's "Object Technology: A Manager's Guide" in 1990 that OOP began to be
legitimized to many management decision makers, that it was more than just
"fairy dust" (as Bill Gates had characterized it in an attempt to discredit
Borland's forays into the field).

I would pick the publication of "Design Patterns" in 1995 by the Gang of
Four (Gamma, Helm, Johnson, and Vlissides),  to be the herald of when "the
Joy of OOP" would be "widely known."  DP formalized a taxonomy for many of
the heuristics that had evolved only intuitively up until then.  Its
emergence reflects a general maturation of concept and practice, sufficient
to say that the Joy of OOP could be said to be "widely known."

-- Paul


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


Re: [dictionary] how to get key by item

2004-12-14 Thread Fredrik Lundh
Skip Montanaro wrote:

> That doubles your storage

careful: it creates another dictionary structure with the same size as the first
one, but it doesn't copy the objects in the dictionary.

so whether it doubles the actual memory usage depends on what data you
have in the dictionary (last time I checked, ints and dictionary slots were the
same size, but I cannot think of any other object that isn't larger...)

(but you knew that, of course)

 



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


Re: Iteration within re.sub()?

2004-12-14 Thread Fredrik Lundh
Bryant Huang wrote:

> Ah beautiful, thank you both, Robert and Mark, for your instant and
> helpful responses. I understand, so the basic idea is to keep a
> variable that is globally accessible and call an external function to
> increment that variable...

accessible for the callback function, that is.

see Mark's example for the right way to do it (using a object to hold
the state, and an object method as the callback -- the latter is known
as a "bound method", and holds a reference to both the data (self) and
the code).

 



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


Re: Performance (pystone) of python 2.4 lower then python 2.3 ???

2004-12-14 Thread Lucas Hofman
Istvan Albert  mailblocks.com> writes:

> 
> Lucas Hofman wrote:
> 
> > Anyone who understands what is going on?
> 
> It is difficult to measure a speedup that might be
> well within your measurement error.
> 
> Run the same pystone benchmark repeatedly and
> see what variation you get.
> 
> Istvan.

Very little variation actually. The system measured is only lightly loaded (and
it is a 2 processor box). I ran the benchmark > 4 times and got 3 results that
are within 1% of each other.

Lucas


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


Re: how do I "peek" into the next line?

2004-12-14 Thread Peter Hansen
[EMAIL PROTECTED] wrote:
suppose I am reading lines from a file or stdin.
I want to just "peek" in to the next line, and if it starts
with a special character I want to break out of a for loop,
other wise I want to do readline().
[snip example]
Neither your description above nor your example actually
requires looking ahead.  Are you sure you need to?
You would only need it if *after* breaking out of the
loop, you wanted to continue reading from the file
*and* wanted the line which triggered the loop termination
still to be available for reading.
-Peter
--
http://mail.python.org/mailman/listinfo/python-list


Re: PEP 338: Executing modules inside packages with '-m'

2004-12-14 Thread Just
In article <[EMAIL PROTECTED]>,
 "Fredrik Lundh" <[EMAIL PROTECTED]> wrote:

> Nick Coghlan wrote:
> 
> >> $ python -c "import foo.bar" arg
> >
> > This doesn't work. Any code protected by "if __name__ == '__main__':" won't 
> > run in this context 
> > (since 'foo.bar' is being imported as a module, not run as a script).
> 
> I appreciate that you're taking the time to teach me about Python, but I can
> assure you that it's not really needed.

Neither is the sarcasm.

> as for the rest of your arguments, I have to assume that you were joking.  
> (or
> that you have no experience whatsoever of distribution of Python programs in
> Unix and Windows environments).

Whatever. You suggestion does not work in many cases. How about a 
program that starts threads? Can't do that as a side effect of import.

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


Re: lies about OOP

2004-12-14 Thread Jive

"projecktzero" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
> I know this might not be the correct group to post this, but I thought
> I'd start here.
>
> A co-worker considers himself "old school" in that he hasn't seen the
> light of OOP.

Just how old *is* his school?  I saw the light in the 70's.  For those of
you too young to remember, those were menacing and sinister days, when pant
legs were too wide at the bottom, and the grotesque evil of "top down
programming" was on the land.  But by '86, the Joy of OOP was widely known.
Flowers bloomed and birds chirped.  Pant legs narrowed.  I believe that was
the year I attended the first C++ conference in Santa Fe.





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


Re: Python mascot proposal

2004-12-14 Thread Lenard Lindstrom
Steven Bethard <[EMAIL PROTECTED]> writes:

> Lenard Lindstrom wrote:
> > Steven Bethard <[EMAIL PROTECTED]> writes:
> >
> >>Brian Beck wrote:
> >>
> >>>http://exogen.cwru.edu/python2.png
> >>
> >>Oooh, I like this one.  Very cool!
> >>
> > Its visually stunning. But under Windows gears show up in the DLL
> > and batch file icons.
> 
> Is that a problem?  The fact that they show up in DLLs and batch files
> means they're not exclusive to a certain type of file...  And neither
> of these have pythons winding around them, I believe. ;)
> 
The only reason I bring it up is there are Python Windows icons for .py, .pyw,
and .pyc files, but not .pyd extension modules. I make do by setting
.pyd files to use the same icon as other DLLs. But if an icon with a
snake and gear is made into the new Windows icon for Python it would
make me think of the .pyd file icon that should have been.

Lenard Lindstrom
<[EMAIL PROTECTED]>

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


Re: [dictionary] how to get key by item

2004-12-14 Thread Roy Smith
In article <[EMAIL PROTECTED]>,
 Skip Montanaro <[EMAIL PROTECTED]> wrote:

> Egor> i know how to get item by key
> ...
> Egor> but i wonder how to get key by item
> 
> Assuming your dictionary defines a one-to-one mapping, just invert it:
> 
> >>> forward = {10 : 50, 2 : 12, 4 : 43}
> >>> reverse = dict([(v,k) for (k,v) in forward.iteritems()])
> >>> print forward
> {10: 50, 4: 43, 2: 12}
> >>> print reverse
> {50: 10, 43: 4, 12: 2}
> 
> That doubles your storage, so you'll have to trade that off against the
> speed gain of not having to loop over the entire dictionary.

Well, you *do* loop over the entire dictionary, but you only do it once, 
when you create the reverse dict.  If you are only going to do a single 
lookup, it's no gain, but if you amortize the cost over many lookups, 
it's almost certainly a big win.

This raises an interesting question.  Let's assume that you add all the 
entries to the dictionary before you do any lookups, and you then need 
to lookup things up in both directions.  Which is faster, to 
simultaneously build both the forward and reverse dicts, or to just 
build the forward one and when you're done doing that, build the reverse 
one in a single shot with the above list comprehension?

BTW, does Python really build the intermediate list and throw it away 
after using it to initialize the dictionary, or is it smart enough to 
know that it doesn't really need to build the whole list in memory?
-- 
http://mail.python.org/mailman/listinfo/python-list


how can I import a module without using pythonpath?

2004-12-14 Thread Phd
Hi,
I'm using python 2.2, I want to import a module by referring to its 
relative location. The reason for this is that there is another module 
with the same name that's already in pythonpath( not my decision, but I 
got to work around it, bummer). So is there any easy way to do it?

something like
import module "from this location"
Thanks!
--
http://mail.python.org/mailman/listinfo/python-list


Re: Redirecting ./configure --prefix

2004-12-14 Thread Mark Asbach
Hi Dan,

> > LD_LIBRARY_PATH=/some/private/dir/lib; export LD_LIBRARY_PATH
> 
> LD_LIBRARY_PATH does the trick, and sys.path seems okay by default.
> Thanks!

If you are the admin of the machine and python is not the only package
installed in a non-standard directory, then editing the /etc/ld.so.conf
file might be the better option.

Have look at 'man ldconfig' and 'man ld.so'.

Yours,

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


Re: lies about OOP

2004-12-14 Thread Alan Morgan
In article <[EMAIL PROTECTED]>,
projecktzero <[EMAIL PROTECTED]> wrote:
>I know this might not be the correct group to post this, but I thought
>I'd start here.
>
>A co-worker considers himself "old school" in that he hasn't seen the
>light of OOP.(It might be because he's in love with Perl...but that's
>another story.) He thinks that OOP has more overhead and is slower than
>programs written the procedural way.

In the world of computers, the statement "X is slower than Y" is true
for almost every value of X and Y under some circumstances.

IMHO, "loves perl" doesn't mesh with either "old school" or "cares
about overhead", but that's just me.

Alan
-- 
Defendit numerus
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: how can I import a module without using pythonpath?

2004-12-14 Thread Phd
Nice, thanks so much!

Doug Holton wrote:
Phd wrote:
Hi,
I'm using python 2.2, I want to import a module by referring to its 
relative location. The reason for this is that there is another module 
with the same name that's already in pythonpath( not my decision, but 
I got to work around it, bummer). So is there any easy way to do it?

import sys, os
sys.path.insert(0,os.path.abspath("relative path"))
import module
sys.path.remove(os.path.abspath("relative path"))
--
http://mail.python.org/mailman/listinfo/python-list


Re: [dictionary] how to get key by item

2004-12-14 Thread Roy Smith
"Delaney, Timothy C (Timothy)" <[EMAIL PROTECTED]> wrote:
> Python will do what you tell it.

Certainly it does.  The problem is that sometimes what I told it to do 
and what I think I told it to do are two different things :-)

> Using Python 2.4, the above can be rewritten as a generator expression:

Ah.  Very cool.  I really should take a look at 2.4.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Namespaces and the timeit module

2004-12-14 Thread David M. Cooke
Roy Smith <[EMAIL PROTECTED]> writes:

> I'm playing with the timeit module, and can't figure out how to time a 
> function call.  I tried:
>
> def foo ():
> x = 4
> return x
>
> t = timeit.Timer ("foo()")
> print t.timeit()
>
> and quickly figured out that the environment the timed code runs under 
> is not what I expected:
>
> Traceback (most recent call last):
>   File "./d.py", line 10, in ?
> print t.timeit()
>   File "/usr/local/lib/python2.3/timeit.py", line 158, in timeit
> return self.inner(it, self.timer)
>   File "", line 6, in inner
> NameError: global name 'foo' is not defined
>
> In fact, trying to time "print dir()" gets you:
>
> ['_i', '_it', '_t0', '_timer']
>
> It seems kind of surprising that I can't time functions.  Am I just not 
> seeing something obvious?

Like the documentation for Timer? :-)

class Timer([stmt='pass' [, setup='pass'  [, timer=]]])

You can't use statements defined elsewhere, you have to define them in
the setup arguments (as a string). Like this:


define_foo = '''
def foo():
x = 4
return x
'''

t = timeit.Timer("foo()" setup=define_foo)
print t.timeit()


One common idiom I've seen is to put your definition of foo() in a
module (say x.py), then, from the command line:

$ python -m timeit -s 'from x import foo' 'foo()'

(the -m is for python 2.4 to run the timeit module; use the full path
to timeit.py instead for earlier pythons)

Alternatively, the examples for the timeit module has another way to
time functions defined in a module.

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


Re: Performance (pystone) of python 2.4 lower then python 2.3 ???

2004-12-14 Thread Nick Craig-Wood
Peter Hansen <[EMAIL PROTECTED]> wrote:
>  For comparison, I do get a decent speedup.  Machine is an
>  AMD Athlon XP 2500+ (1.82GHz) running Win XP Pro SP2.
> 
>  Python 2.3.4: 36393 pystones.
>  Python 2.4:   39400 pystones.
> 
>  ...about an 8% speedup.

On my 2.6 GHz P4 running debian testing I got the following results :-

$ for p in 2.1 2.2 2.3 2.4; do echo $p; python$p pystone.py 100 ; done

2.1
Pystone(1.1) time for 100 passes = 40.67
This machine benchmarks at 24588.1 pystones/second
2.2
Pystone(1.1) time for 100 passes = 39.64
This machine benchmarks at 25227 pystones/second
2.3
Pystone(1.1) time for 100 passes = 32.49
This machine benchmarks at 30778.7 pystones/second
2.4
Pystone(1.1) time for 100 passes = 29.88
This machine benchmarks at 33467.2 pystones/second

Showing that 2.4 is the fastest so far!  (And is also a good advert
for AMD ;-)

-- 
Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-wood.com/nick
-- 
http://mail.python.org/mailman/listinfo/python-list


RE: [dictionary] how to get key by item

2004-12-14 Thread Skip Montanaro

Tim> Python will do what you tell it. In the above case, it will build a
Tim> list.

Whoops, yeah.  I called .iteritems() then forgot to use a generator
expression...

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


re: A problem with list

2004-12-14 Thread Tim Henderson
Hi
There are many different ways to solve the problem that you are having. 
The easiest if you are planning on only dealing with strings or a 
predictable data structure would be to do something like this:

Code:
~~
#Pre: Pass in a string and the character you want it tokenized by
#Post: Returns a list of all the tokens
def tokenizer(str, chr=' '): #heres a useful tool just like 
StringTokenizer feature in Java
   if chr != '': chr = chr[0]
   else: chr = ' '
   x = ""
   tokens = [""]
   z = 0
   for x in str:
   if x != chr:
   tokens[z] = tokens[z] + x
   else:
   z = z + 1
   tokens.append("")
   return tokens

list = ['abc', 'def', 'xyz']
str = ''
for x in list:
   str+=list+'.' #note this is a delimiter could be anything, if you 
wanted to you could re-implement the above function to work with 
delimiters of any length not just length 1

#save the str
#load str a loadedStr
loadedList = tokenizer(loadedStr, '.')
#loadedList = ['abc', 'def', 'xyz']
~~
that is one way too solve your problem
another is to use some sort of real database structure, for simplicity, 
you could use XML

example xml structure:
~~

   float
   3.14
   0


   int
   3
   1


   string
   Hi i am a string
   2

~~
The first way to solve your problem is quick dirty and efficient. The 
XML version is highly scalable but requires a lot more code to 
implement. As mentioned before there are a number of other solutions to 
the same problem

---
Cheers
Tim Henderson
original message:

The following code
##
import string
MyList=['abc','def']
for i in MyList:
print i
###
works as I expect that is I get
abc
def
but when I have Mylist in a file and I read it from the file it does
not work as I expect.
#
import string
ff=open('C:\\Robotp\\MyFile.txt','r') # read MyList from a file
MyList=ff.read()
for i in MyList:
print i
###
I will get
[
'
a
b
c
'
,
'
d
e
f
'
]
where my MyFile.txt looks like this:
['abc','def']
Where is a problem?
Thanks for help
Lad
--
http://mail.python.org/mailman/listinfo/python-list


Re: from string to raw string

2004-12-14 Thread Dan Perl
Yeah, you're right.  I got it all twisted in my mind.  It's late and I must 
be getting tired.

Thanks.

Dan

"Brian Beck" <[EMAIL PROTECTED]> wrote in message 
news:[EMAIL PROTECTED]
> Dan Perl wrote:
>> Is there a way to convert a regular string to a raw string so that one 
>> could get from '\bblah' to r'\bblah' other than parsing the string and 
>> modifying the escapes?
>
> There's no such thing as a raw string, only raw string literals. In other 
> words, it's a syntax to tell the Python interpreter which characters in 
> your string are 'special' and has no effect on strings not input as 
> literals directly within your code.  Strings from files or any input 
> besides the interactive Python shell will already be what you're looking 
> for.
>
> -- 
> Brian Beck
> Adventurer of the First Order 


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


Iteration within re.sub()?

2004-12-14 Thread Bryant Huang
Hi,

Is it possible to perform iteration within the re.sub() function call?

For example, if I have a string like:

str = "abbababbabbaaa"

and I want to replace all b's with an integer that increments from 0,
could I do that with re.sub()?

Replacing b's with 0's is trivial:

i = 0
pat = re.compile("b")
print pat.sub(`i`, str)

Now, how can I increment i in each replacement? Is this possible? Like,
using a lambda function, for example? Or do I use a different re
function altogether?

I use this trivial [ab]* language for simplicity, but I have a real
problem where I need to match a more complex regex and replace it with
an incrementing integer.

Thanks so much!
Bryant

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


Redirecting ./configure --prefix

2004-12-14 Thread Dan
I suspect this isn't specifically a Python question, but I
encountered it with Python so I thought I'd ask here.
I'm running Linux (Fedora 2), and just downloaded the Python 2.4
kit.  I did the following from my user account:
./configure --prefix=/some/private/dir --enable-shared
make
make test # all was okay
make install
Now, when I try to run this I get the following error:
python: error while loading shared libraries:
libpython2.4.so.1.0: cannot open shared object file: No such
file or directory
This library is in /some/private/dir/lib, but that directory is
not being searched.
So, I have these questions:
- Can I get Python to search /some/private/dir/lib for
  library files?
- Will sys.path be okay?  How can I make it okay?
- Is there anything else I need to worry about?
Any help would be appreciated.
Thanks,
Dan
--
dedded att verizon dott net
--
http://mail.python.org/mailman/listinfo/python-list


Re: looking for blocking on read of a real file (not socket or pipe)

2004-12-14 Thread Fredrik Lundh
<[EMAIL PROTECTED]> wrote:

> I doubt that the recipe you recomended will work at all in the case of
> different processes. To do this right file has to be open in shared
> mode (by both programs). Python does not support shared access.
> In the case of one program, but different threads probably this will
> work.

do you always assume that everyone uses the same operating system as
you do?  (even if the user agent they used to post the message doesn't run
on your operating system... ;-)

 



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


RE: xsdb does XML, SQL is dead as disco :) (oops)

2004-12-14 Thread aaronwmail-usenet
Some people pointed out that bighunks of my HUGE
ZIP file contained junk that could be regenerated.
Thanks!  It's now much smaller.  Sorry for the
screw up.  -- Aaron Watters

I wrote:
>  xsdb does XML, SQL is dead as disco :)
>
>The xsdbXML framework provides a
>flexible and well defined infrastructure to
>allow tabular data to be published, retrieved,
>and combined over the Internet.
>
>It's a little bit like the daughter of the
>Gadfly SQL engine in the buff,
>on steroids.  This is a major departure from
>the previous releases of xsdb.
>
>Please read about it and download it from
>http://xsdb.sourceforge.net
>
>Note that the download is over 90%
>documentation and example data files --
>the software itself is small.
>
>The xsdb framework makes all of
>the following assertions true.
>
>Database queries over web distributed data:
>  Databases may be broken up into multiple
>  files or servers on multiple machines
>  and queried as a single resource.
>Simple Publication:
>  Publishing a queriable collection of data
>  (a context) can be as simple as
>  placing an XML document on a web server.
>Sophisticated Publication:
>  Large and complex databases may
>  also be published using server software
>  which provides indexing and other optimizations.
>Heterogeneity:
>  Published data collections may be built
>  using parts of remotely defined data collections.
>External Data:
>  A data context may make reference
>  to another arbitrary web object.
>Open formats and definitions:
>  Databases may be constructed and
>  queried using standard formats and standard
>  web protocols using any programming language
>  in any computational environment.
>Simple formats
>  The content of a database or query may be
>  expressed in a manner which is easy
>  to parse and interpret (both for human readers
>  and for computer programs). Data,
>  queries and query responses are represented
>  using the same language of expressions.
>Clear definition
>  The meaning of database entries and queries
>  are defined using simple mathematical
>  definitions. 
 >
 > 
 > There ain't no sanity clause

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


RE: [dictionary] how to get key by item

2004-12-14 Thread Delaney, Timothy C (Timothy)
Roy Smith wrote:

>> >>> forward = {10 : 50, 2 : 12, 4 : 43}
>> >>> reverse = dict([(v,k) for (k,v) in forward.iteritems()])
>> >>> print forward {10: 50, 4: 43, 2: 12}
>> >>> print reverse
>> {50: 10, 43: 4, 12: 2}
> 
> BTW, does Python really build the intermediate list and throw it away
> after using it to initialize the dictionary, or is it smart enough to
> know that it doesn't really need to build the whole list in memory?

Python will do what you tell it. In the above case, it will build a
list.

Using Python 2.4, the above can be rewritten as a generator expression:

>>> forward = {10 : 50, 2 : 12, 4 : 43}
>>> reverse = dict((v,k) for (k,v) in forward.iteritems())
>>> print forward {10: 50, 4: 43, 2: 12}
>>> print reverse
{50: 10, 43: 4, 12: 2}

which does not build an intermediate list. Note that all I've done is
remove the [ and ] - that's because a genexp must be surrounded by
parentheses, but *any* parentheses will do - for example, the
parentheses surrounding the parameters in a function call.

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


Re: lies about OOP

2004-12-14 Thread Craig Ringer
On Tue, 2004-12-14 at 16:02, Mike Thompson wrote:

> > I would pick the publication of "Design Patterns" in 1995 by the Gang of
> > Four (Gamma, Helm, Johnson, and Vlissides),  to be the herald of when "the
> > Joy of OOP" would be "widely known."  DP formalized a taxonomy for many of
> > the heuristics that had evolved only intuitively up until then.  Its
> > emergence reflects a general maturation of concept and practice, sufficient
> > to say that the Joy of OOP could be said to be "widely known."

> In actual fact, virtually all the design patterns came from the 
> Interviews C++ GUI toolkit written in the early '90s. What an utterly 
> brilliant piece of work that was.

As somebody who has just been bowled over by how well Qt works, and how
it seems to make OOP in C++ work "right" (introspection, properties,
etc), I'd be interested in knowing what the similarities or lack thereof
between Qt and Interviews are.

I've been pleasantly astonished again and again by how I can write
something in C++ with Qt like I would write it in Python, and have it
just work. Alas, this doesn't extend as far as:

instance = Constructor(*args)

though if anybody knows how to do this in C++ I would be overjoyed to
hear from them. Qt _does_ provide a pleasant (if somewhat limited) of
the Python getattr() and setattr() calls.

--
Craig Ringer

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


Re: looking for blocking on read of a real file (not socket or pipe)

2004-12-14 Thread elbertlev
I doubt that the recipe you recomended will work at all in the case of
different processes. To do this right file has to be open in shared
mode (by both programs). Python does not support shared access.
In the case of one program, but different threads probably this will
work.

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


from string to raw string

2004-12-14 Thread Dan Perl
Is there a way to convert a regular string to a raw string so that one could 
get from '\bblah' to r'\bblah' other than parsing the string and modifying 
the escapes?

I am interested in this for the use of regular expressions.  I would like to 
be able to accept re patterns as inputs either from a file or from a GUI 
tool and I would like to allow those inputs as regular strings and not force 
users to write patterns with double escapes.

I naively thought there could be utilities for such a conversion either in 
the string module or the StringIO module but I don't see any utilities like 
that.

So, any suggestions?

Dan 


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


Re: Namespaces and the timeit module

2004-12-14 Thread Roy Smith
[EMAIL PROTECTED] (David M. Cooke) wrote:

> > It seems kind of surprising that I can't time functions.  Am I just not 
> > seeing something obvious?
> 
> Like the documentation for Timer? :-)
> 
> class Timer([stmt='pass' [, setup='pass'  [, timer=]]])
> 
> You can't use statements defined elsewhere, you have to define them in
> the setup arguments (as a string).

Doh!  Of course.  Now that you point it out, it makes perfect sense, but 
I didn't get that from reading the description.  Thanks.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: lies about OOP (somewhat OT because Perl)

2004-12-14 Thread Jeremy Bowers
On Mon, 13 Dec 2004 19:33:25 -0800, projecktzero wrote:
> We do web programming. I suspect that OO apps would behave as good as
> procedural apps, and you'd get the benefit of code reuse if you do it
> properly. Code reuse now consists of cutting and pasting followed by
> enough modification that I wonder if it was worth it to cut and paste
> in the first place.

OO is a huge, ginormous, amazingly large, unspeakably awesome,
can't-believe-anyone-ever-lived-without-it win... but not necessarily OO
as it is presented in Software Engineering class due to the unusual nature
of web programming.

Tell him to check out HTML::Mason, and be sure to work with it long enough
to actually use some of its features. Once he's hooked (and it really is
an awesome framework; Amazon is supposed to use it and while I'm sure it
is highly customized I can definitely see it), explain to him that the
various components are really objects, complete with quite a lot of the
object features like inheritance, even if it doesn't look it.

If he resists this and declares Mason to be "crap", then with all due
respect you've got a blowhard who refuses to learn on your hands, and in a
perfect world he'd be stripped of code responsibility and moved somewhere
where he can't hurt anything. (He may merely not like it; I reserve the
strong statements in the previous sentence for the case where he actually
dismisses it with prejudice.) In the meantime, I've had great luck in Perl
environments programming in OO anyhow, as long as you have reasonably
independent responsibilities, and eventually the advantages do not go
unnoticed. Perl gets bashed on around here (in a good natured way) but
there are certainly worse languages; generally when I want to do something
the Right Way it provides a way to avoid code duplication, though it is
usually more circuitous and complex than in Python.

Ultimately, of course, the true problem isn't that you aren't coding OO,
it is the use of Copy and Paste Programming. OO is one path out, but only
one. (Perl is strong enough that one can make a case for going functional,
though I strongly prefer a functional/OO hybrid that builds on OO but
freely borrows functional paradigms at will.) 

http://www.c2.com/cgi/wiki?CopyAndPasteProgramming

The problem with web programming is that you can *get away with*
"procedural" programming because the partitioning of the problem into web
pages provides a primitive, but marginally effective partitioning of the
problem into discrete components. Thus, unless you are running
*everything* through the exact same "web page" (CGI script probably in
this case), you aren't doing true procedural; the CGI scripts function as
primitive objects themselves, enough to let you get farther than you could
in a monolithic program and fool yourself into thinking you're safe, but
not strong enough to build a large-scale system with high-quality code
(i.e., low duplication).

But you still suffer.

ObPython (serious though): Which Python framework is the most Mason like?
(I'm more interested in the component infrastructure than the exact syntax
of the files; I'm not so worried about embedding Python into the HTML. I
think it might be Zope but I haven't tried enough of them to know.)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: from string to raw string

2004-12-14 Thread Phd
Hi,
I recently asked the same question, the response I got was that just use 
 the string. There is no raw string object so the conversion doesn't 
exist. As far as I know, I haven't run into any problem

Take a try. Please let me know if there is any problem with this approach.
Good luck

Dan Perl wrote:
Is there a way to convert a regular string to a raw string so that one could 
get from '\bblah' to r'\bblah' other than parsing the string and modifying 
the escapes?

I am interested in this for the use of regular expressions.  I would like to 
be able to accept re patterns as inputs either from a file or from a GUI 
tool and I would like to allow those inputs as regular strings and not force 
users to write patterns with double escapes.

I naively thought there could be utilities for such a conversion either in 
the string module or the StringIO module but I don't see any utilities like 
that.

So, any suggestions?
Dan 


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


Re: New versions breaking extensions, etc.

2004-12-14 Thread Jive

"Martin v. Löwis" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
> It's not hard-coded in the linker, but hard-coded in the import library.
> So if you link with msvcrt.lib (which might not be the precise name
> of the import library - I cannot look up the precise name right now),
> msvcrt.lib will in turn refer to msvcr71.dll.

But it makes no difference, no?  The problem is that both Python.exe and the
extensions are *compiled* to link with a *particular* crt.  (How "dyanamic"
is that?)  We could probably kluge around the problem if it were not for the
fact that one crt might perversely define some struct, (FILE, for example),
with difference layouts in different crt DLL's. Right?  The header files
contain the poison.

So it would seem that as far as the crt goes, we are at the mercy of the
micro soft ones.  They could introduce an incompatible crt at any time.

By the way, I've googled around and found others outside the Python
community who have run into the same problem.  In some cases, they have
opted just to stay with VC 6.0.  One said, "At least the 6.0 compiler is 2.5
times as fast."  Groan.




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


Re: Python vs. Perl

2004-12-14 Thread Keith Dart
Ian Bicking wrote:
Jon Perez wrote:
Michael McGarry wrote:
I intend to use a scripting language for GUI development and front 
end code for my simulations in C. I want a language that can support 
SQL, Sockets, File I/O, and shell interaction.

In my experience, Python is definitely much more suitable than Perl
for the first four areas mentioned in the last sentence.  For the
last area, I'm not sure, but Python's capabilities in this area are
also quite good.

Shell interaction (or rather, external process interaction) is a lot 
better with Python 2.4's subprocess module.  Better or worse than Perl? 
 I'm not sure; generally I'd guess better, as it avoids the shell with 
all the shell's issues, and provides a more controlled programmatic way 
of interacting with subprocesses.  OTOH, Perl might have perfectly good 
modules for doing the same thing.  I can only say it's been missing for 
a while in Python, and it's good to see this done right.

Yow, I must not get picked up in Google enough. ;-) The "proctools" 
module in the pyNMS package  has 
been around for years. I use it all the time for shell-like stuff. There 
is also an "expect" module, and the "termtools" module. If you need a 
more complete process spawning and controlling framework then use pyNMS. 
 It can "juggle" multiple processes, reaps child status (no 
zombies), operates asynchronously (The ProcManager object is a SIGCHLD 
handler), and works with pty's and pipes. It also offers a "thread-like" 
interface  for Python subprocesses (uses fork). Can leave some fd's open 
that you specify, can run the subprocess as a different user, and more...

Check it out.

--
   \/ \/
   (O O)
-- oOOo~(_)~oOOo
Keith Dart <[EMAIL PROTECTED]>
public key: ID: F3D288E4 

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


  1   2   >