Re: [perl-python] sending email

2005-01-30 Thread Jürgen Exner
Xah Lee wrote:
[...]
> Here's how the situation stands as of 2001 March:
^^

Well, at least now we know why Mr. Lee is a little bit behind 

jue 


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


Re: Coding style article with interesting section on white space

2005-01-30 Thread Fredrik Lundh
[EMAIL PROTECTED] wrote:

> The recent "Pystone Benchmark" message says that Python is only 75% as
> fast on Linux as on Windows.

no, it really only says that the Pystone benchmark is 75% as fast as Linux as on
Windows, on the poster's hardware, using his configuration, and using different
compilers.

 



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


Re: limited python virtual machine

2005-01-30 Thread Alex Martelli
Nick Coghlan <[EMAIL PROTECTED]> wrote:
   ...
> > If you _can_ execute (whatever) in a separate process, then an approach
> > based on BSD's "jail" or equivalent features of other OS's may be able
> > to give you all you need, without needing other restrictions to be coded
> > in the interpreter (or whatever else you run in that process).
> 
> I think that's where these discussion have historically ended. . . making a
> Python-specific sandbox gets complicated enough that it ends up making more
> sense to just use an OS-based sandbox that lets you execute arbitrary binaries
> relatively safely.
> 
> The last suggestion I recall along these lines was chroot() plus a monitoring
> daemon that killed the relevant subprocess if it started consuming too much
> memory or looked like it had got stuck in an infinite loop.

"Yes, but" -- that ``if'' at the start of this quote paragraph of mine
is, I believe, a meaningful qualification.  It is not obvious to me that
all applications and platforms can usefully execute untrusted Python
code in a separate jail'd process; so, I think there would still be use
cases for an in-process sandbox, although it's surely true that making
one would not be trivial.


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


Test of comp.lang.python to python-list to gmane pathway.

2005-01-30 Thread Terry Reedy
Feel free to ignore this.  Some system falsely labeled this post (sent via 
gmane) as possible spam.  I am sending it back in the opposite direction to 
see what transpires that way.  Sorry for the disturbance.  tjr

"Terry Reedy" <[EMAIL PROTECTED]> wrote in message 
news:[EMAIL PROTECTED]
>
> "Michael Tobis" <[EMAIL PROTECTED]> wrote in message 
> news:[EMAIL PROTECTED]
>
>> I'd like to dynamically add a method to an instance at
>> instantiation time.
>
> No can do.  A method is function that is an attribute of a class, even if 
> accessed via an instance.  A function added to an instance as an 
> attribute of the instance remains a function.  It is instance-specific 
> data that methods and other code can use, just like other instance data, 
> for instance-specific effects.  Two common examples:
>
> class composer:
>  # skip obvious init
>  def __call__(self, x): return self.outer(self.inner(x))
>
> sincos = composer(math.sin, math.cos)
> # yes, this can also be done with composer function with nested scope
>
> class memoizer: # posted several times
>  # skip init again
>  def __call__(self,x):
> # return previously computed self.memodict[x] if it exists
> # or calculate, store, and return self.func(x)
>
> \> PS - any idea how to get past google's stupid formatting these days? I
>> thought they were supposed to like python, but they just ignore leading
>> blanks.
>
> Don't use google to post on clp.  Go to news.gmane.org instead.
>
> Terry J. Reedy
>
>
>
> -- 
> http://mail.python.org/mailman/listinfo/python-list
> 


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


Re: What's so funny? WAS Re: rotor replacement

2005-01-30 Thread "Martin v. Löwis"
Paul Rubin wrote:
Oh, ok.  Earlier you said you wanted user feedback before you could
conclude that there was reason to want an AES module at all.
I believe I never said that. I said that I wanted user feedback to
determine whether *this* AES module (where this is either your
from-scratch implementation, or any other specific implementation
contributed) is desirable.
Hmm, this is very very interesting.  I am highly confident that all
the purely technical questions (i.e. everything about the API and the
code quality, etc.) can converge to a consensus-acceptable solution
without much hassle.  I had thought there were insurmountable
obstacles of a nontechnical nature, mainly caused by legal issues, and
that these are beyond any influence that I might have by writing or
releasing anything.
These obstacles are indeed real. But I believe they are not
unsurmountable. For example, there is the valid complaint that,
in order to export the code from SF, we need to follow U.S.
export laws. 10 years ago, these would have been unsurmountable.
Today, it is still somewhat painful to comply with these laws,
but this is what the PSF is for, which can fill out the forms
necessary to allow exporting this code from the U.S.A.
Regards,
Martin
--
http://mail.python.org/mailman/listinfo/python-list


Re: Need programming tip

2005-01-30 Thread Alex Martelli
<[EMAIL PROTECTED]> wrote:
   ...
> 1511156   As Requested 2000 adv server -2000AdvSrv.vol001+02.PAR2 (1/4) -
> 21/27
> 1511157   As Requested 2000 adv server -2000AdvSrv.vol001+02.PAR2 (2/4) -
> 21/27
   ...
> would be to look for (1/ in the subject string then find the
> denominator and loop thru as many times as the denominator to create
> the  part of the nzb file. Is this the best way or is there an
> easier method? Also what would be the best way to search for the (1/
> using string searches or RegExp? If REgExp could someone provide me
> with the RegExp for searching for this string?

If the only thing that identifies these posts as part of one logical
post is that (n/m) in the subject then I guess there's nothing for it
but analysis of the subject, and a re seems appropriate.

import re
re_n_of_m = re.compile(r'(.*)\s*\((\d+)/(\d+)\)')

might be one approach.   Then, somewhere in your loop,

mo = re_n_of_m.search(subject)

sets mo to None if it doesn't match the pattern; if it does match, then
mo is a match object with three groups.  mo.group(1) is the part of the
subject before the (n/m) marker; mo.group(2) is n as a string;
mo.group(3) is n as a string.  You can use mo.group(1) as the key into a
dictionary where you collect (n,m) pairs as values, so that once you've
collected all posts you can tell which one are multipart and also check
for inconsistency (different m values), duplicates, missing parts.  What
you need to do in each case, I don't know...


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


Re: Coding style article with interesting section on white space

2005-01-30 Thread Alex Martelli
<[EMAIL PROTECTED]> wrote:

> Michael Tobis wrote:
> > (unwisely taking the bait...)
> >
> > If you like your language to look like this
> > http://www.cs.rpi.edu/~szymansk/OOF90/bugs.html
> > then more power to you.
> 
> Thanks for pointing out that interesting article on Fortran 90 bugs.
> How long would a comparable C++ list be? Even Python has gotchas, for
> example the difference between deep and shallow copies.

C++ "gotchas" spawn whole books.  So, once, did C ones -- Koenig's "C
Traps and Pitfalls" is a wonderful book; to be honest, that was only
partly about the _language_... Koenig's advocacy of half-open loops and
intervals is just as valid in any language, but it was still a point
WELL worth making.

The referenced page, in part, is simply pointing out places where
Fortran might prove surprising to a programmer just because it works
differently from some other language the programmer might be used to.
For example, the very first entry just says that '.and.' does not
short-circuit, so when you need guard behavior you should rather use
nested IF statements.  This is no bug, just a reasonable language design
choice; anybody coming from (standard) Pascal would not be surprised;
Ada even has two different forms ('and' doesn't short-circuit, if you
want short-circuit you use 'and then').
In some sense it can be a gotcha for some programmers, but it would be
silly to count it as a "fortran bug"!  Or even "wart" for that matter.

So, I would try to classify things in three classes:

a. some things are important techniques which one may choose to
   highlight in the context of a given language, yet it would simply
   be silly to classify as gotchas, warts, or bugs _of that language_;

b. some aspects of a language's behavior are surprising to people
   familiar w/other languages which behave differently, and thus are
   worth pointing out as "gotchas" though they're surely not bugs (and
   may or may not be warts);

c. lastly, some things are irregularities within the language, or
   truly unexpected interactions among language features, or vary
   between implementations in ways most programmers won't expect;
   these can be described as warts (and maybe even bugs, meaning
   things that may well be fixed in the next version of a language).

The advantages of half-open intervals (per Koenig's book), the fact that
copies exist in both shallow and deep senses, or the fact that with
pointers to pointers you need to allocate the parent pointers first (the
last entry in the referenced page) are really about [a] -- of course if
a language doesn't have pointers, or doesn't offer a standardized way to
make copies, you won't notice those aspects in that language (the issue
of half-open loops and intervals is wider...), but really these kinds of
observations apply across broad varieties of languages.

Point (b) will always be with us unless all languages work in exactly
the same way;-).  'and' will either short-circuit or not (or the
language will be more complicated to let you specify), array indices
will start from 0 or from 1 (or the language will be more complicated to
let you specify, etc etc), default values for arguments will be computed
at some specified time -- compile-time, call-time, whatever -- or the
language will be poorer (no default values, or only constant ones) or
more complicated (to let you specify when the default gets computed).
Etc, etc.

Point (c) is really the crux of the matter.  Generally, simple languages
such as C or Python will have relatively few (c)-warts; very big and
rich ones such as C++ or Perl will have many; and ones in the middle, as
it appears to me that Fortran 90 is, will have middling amounts.  I'm
not saying that lanugage size/complexity is the only determinant --
there are other aspects which contribute, e.g., the need for backwards
compatibility often mandates the presence of legacy features whose
interaction with other features may cause (c) moments, so, a language
which is older, has evolved a lot, and is careful to keep compatibility,
will be more at risk of (c)-level issues.  Still, size matters.  It's
just like saying that a big program is likely to have more bugs than a
small one... even though many other factors contribute (backwards
compatible evolution from previous versions matters here, too).


> > I prefer my languages to be portable, terse and expressive.
> 
> Fortran programmers are generally happy with the portability of the
> language. A difficulty with Python portability and maintainability is
> that some needed functionality is not in the core language but in C
> extensions. For scientific computation, consider the case of Numeric
> and Numarray. I don't think Numeric binaries are available for Python
> 2.4, 

 ?  Just
googled and visited the first hit -- I don't currently use Windows so I
don't know if it's still there, works well, etc.

> The recent "Pystone Benchmark" message says that 

Re: PythonWin (build 203) for Python 2.3 causes Windows 2000 to grind to a halt?

2005-01-30 Thread Martin Bless
[EMAIL PROTECTED] (Chris P.)]

>The bug you suggested is exactly the problem that I was having... I
>had looked through the bugs being tracked, but the title of that one
>didn't jump out at me as something that would help.  Thanks!

Yes, using Python24 and the latest win32 build on my machine the bug
still exists. PythonWin works fine if you don't use the debugger.

But since the debugger is the most valuable feature for me I sadly had
to stop using PythonWin. For a while I found some help by running the
script below every now and then. It deletes the erroneous registry
entries. But currently the bugs are stronger.

Here's my solution: I spent some money and switched to "WingIde" from
wingware.com. Wow, it's breathtaking and worth each penny. Don't
compare WingIde with other editors. WingIde really plays in the IDE
(integrated development environment) league. And it's very Python
aware and knowledgable ...

mb - Martin Bless


Here's my script to delete the erroneous debugger entries:

Script "delete-debugger-entries,pywin,python24.py"

#!/usr/bin/env python
# -*- coding: iso-8859-1 -*-

"""Delete problematic registry entries in 'Python for Win32'.

Martin Bless, mb, 2004-09-24, 2005-01-05
No warrenties whatsoever. Use at your own risk.
"""

import win32api
import win32con

subKey = r'Software\Python 2.4\Python for Win32'
subKey = r'Software\Python 2.4\Python for Win32'

if 1:
#HKEY_CURRENT_USER\Software\Python 2.4\Python for
Win32\ToolbarDebugging-Bar0
k =
win32api.RegOpenKeyEx(win32con.HKEY_CURRENT_USER,subKey,0,win32con.KEY_ALL_ACCESS)
nsubkeys,nvalues,timeval = win32api.RegQueryInfoKey(k)
keys = []
for i in range(nsubkeys):
s = win32api.RegEnumKey(k,i)
if (s.startswith('ToolbarDefault-Bar') or
s.startswith('ToolbarDebugging-Bar')):
keys.append(s)
for i,key in enumerate(keys):
subKey2 = subKey + '\\' + key
print i,':', subKey2
win32api.RegDeleteKey(win32con.HKEY_CURRENT_USER,subKey2)
if i>9:
break
k.Close()
print len(keys),"deleted."

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


Re: naive doc question

2005-01-30 Thread Duncan Booth
Gabriel B. wrote:

> Is it just me that can't find a full reference in the docs?
> 
> I wanted a list of all the methods of dict for example... where can i
> find it? 
> 
> Thanks, and sorry if this question is just dumb, i really can't find
> it 

If you want to find out about all the methods of dict then try:

  lib\pydoc.py dict

from a shell prompt, or

>>> help(dict)

from the interactive interpreter.

The catch is that many of the methods that will be shown aren't really 
relevant to dictionaries, so you will need to ignore the irrelevant ones.

Run pydoc interactively ('lib\pydoc.py -g') or as a web-server if you want 
to get the output as strangely coloured html. e.g. 'lib\pydoc.py -p 8081' 
then point your browser at 'http://localhost:8081/dict' for help on the 
dict type. (Pick a different port number if 8081 is used on your machine.)

http://localhost:8081/__builtin__ is a good starting point to browse the 
builtin types, and http://localhost:8081/ will give you an index of all the 
modules installed on your system.

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


Re: What's so funny? WAS Re: rotor replacement

2005-01-30 Thread Nick Craig-Wood
Skip Montanaro <[EMAIL PROTECTED]> wrote:

>  Fine.  Go build a sumo distribution and track the normal CPython.
>  The problem isn't all that new.  (Take a look at scipy.org for one
>  take on that theme.  Of course Linux distros have been doing their
>  take on this forever.)

If I'm writing code just for fun. I'll be doing on Debian Linux, then
I can do

  apt-get install python-crypto

and I'm away. 

However if I'm writing code for work, it has to work on windows as
well, which introduces a whole extra barrier to using 3rd party
modules.  Something else to compile.  Something else to stick in the
installer.  Basically a whole heap of extra work.

I think one of the special things about Python is its batteries
included approach, and a crypto library would seem to be an obvious
battery to install since it doesn't (or needn't) depend on any other
library or application.

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


Re: What's so funny? WAS Re: rotor replacement

2005-01-30 Thread Nick Craig-Wood
Paul Rubin  wrote:
>  "Martin v. Löwis" <[EMAIL PROTECTED]> writes:
> > Apparently, people disagree on what precisely the API should be. E.g.
> > cryptkit has
> > 
> > obj = aes(key)
> > obj.encrypt(data)
> 
>  I don't disagree about the API.  The cryptkit way is better than ECB
>  example I gave, but the ECB example shows it's possible to do it in
>  one call.

There is a PEP about this...

  API for Block Encryption Algorithms v1.0
  http://www.python.org/peps/pep-0272.html

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


Re: What's so funny? WAS Re: rotor replacement

2005-01-30 Thread Paul Rubin
Nick Craig-Wood <[EMAIL PROTECTED]> writes:
> There is a PEP about this...
> 
>   API for Block Encryption Algorithms v1.0
>   http://www.python.org/peps/pep-0272.html

Yes, I know about that and have been in contact with its author.  He
and I are in agreement (or at least were in agreement some time ago)
that the proposed API of the new module is an improvement, at least
for a generic module.  PEP 272 seems to document the interface of
something that had been implemented for some particular application.

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


Re: Python 2.1 - 2.4 differences

2005-01-30 Thread RPM1

"BOOGIEMAN" <[EMAIL PROTECTED]> wrote ...
> I found some e-book about Python 2.1, I want to print it but just to check
> first if sintax of Python 2.1 is same as 2.4 ? Also does anybody know
where
> can I download any newer Python related e-book, because there isn't any
> published yet in my country.

Take a look at:
http://diveintopython.org



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


Re: The next Xah-lee post contest

2005-01-30 Thread Arthur
On Sat, 29 Jan 2005 15:41:00 +0100, PA <[EMAIL PROTECTED]>
wrote:

>
>On Jan 29, 2005, at 15:32, rbt wrote:
>
>> Unix donkey! You not elegant. You have poor design.
>> Sloppy Perl monkey! You be lazy! You code very very bad.
>>
>> Xah know all!
>
>Follow The True Path, follow The Xah Way To Enlightenment:
>
>"The Unix Pestilence"
>http://www.xahlee.org/UnixResource_dir/freebooks.html
>
>Cheers

Not sure how Xah got himself into all this.  When I actually read the
substance of Xah's articles like the one referenced above, and ignore
the stuff in Red, I don't find it all that bizarre - or uninformative.
He links to substantive resources.  He has postive things to say about
lots of things, including Python.

Guess I am prejudiced by the fact that I have always enjoyed his plane
curve pages, and after David Eppsteins Geometry Junkyard and a few
others, consider it one of the more interesting web resources in
respect to geometry.  I knew of him for this, well before I knew of
him as the Usenet character he is.

Wish he would do himself the favor of better separating he various
"interests".  One can google on "plane curves", and the first hit will
be Xah's site. I certainly find it interesting and well done.

On the other hand, if one goes by way of his home page, one is greeted
first with a vitriolic message expressing a sentiment not all that
uncommon but not very relevant to the substance of much of what is to
be found at the site.

Oh well.

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


Re: [perl-python] sending email

2005-01-30 Thread Tad McClellan
Jürgen Exner <[EMAIL PROTECTED]> wrote:
> Xah Lee wrote:
> [...]
>> Here's how the situation stands as of 2001 March:
> ^^
> 
> Well, at least now we know why Mr. Lee is a little bit behind 


Mr. Lee is a *big* behind!


-- 
Tad McClellan  SGML consulting
[EMAIL PROTECTED]   Perl programming
Fort Worth, Texas
-- 
http://mail.python.org/mailman/listinfo/python-list


test_socket.py failure

2005-01-30 Thread x2164

 hi all,

 Linux 2.4.28
 Glibc 2.2.5
 gcc   2.95.3


 I'm new to Python.

 I've compiled Python 2.4 from tar file.

 When running 'make test' i'm getting a failure
 in test_socket.

 Running './python Lib/test/test_socket.py' yields:


==
ERROR: testGetServBy (__main__.GeneralModuleTests)
--
Traceback (most recent call last):
  File "Lib/test/test_socket.py", line 330, in testGetServBy
port2 = socket.getservbyname(service)
error: service/proto not found

--
Ran 58 tests in 3.826s



 The value of 'service' was "daytime".

 After much hand wringing, editing, and use of 'print'
 statements i commented out line 330,
 '# port2 = socket.getservbyname(service)' and replaced it
 with the line 'port2 = port'.

 Running './python Lib/test/test_socket.py' now yields:


testGetServBy (__main__.GeneralModuleTests) ... ok
   .
   .
   .
--
Ran 58 tests in 5.181s

OK

 
 Located the code for 'socket_getservbyname' in 
 'Modules/socketmodule.c' where the call to the glibc
 function 'getservbyname' is made: 

 Py_BEGIN_ALLOW_THREADS
 sp = getservbyname(name, proto);
 Py_END_ALLOW_THREADS
 if (sp == NULL) {
 PyErr_SetString(socket_error, "service/proto not found");
 return NULL;
 }

 
 The only call of socket.getservbyname that failed was when
 it was passed the single argument.  Since the error message
 "service/proto not found" seems to only be generated upon
 failure of gibc's 'getservbyname' could it be that 
 'PyArg_ParseTuple(args, "s|s:getservbyname", &name, &proto)'
 generates values for 'name' and/or 'proto' that cause the
 failure?

 My search for prior reports of failure at line 330 found
 a mention of problems at line 331.

 Well, at any rate, if someone could point me down the 
 correct path on this i would appreciate it.


 pete jordan
 x2164 -> mailcity.com
 -> equals at symbol




-- 


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


Re: what's OOP's jargons and complexities?

2005-01-30 Thread Pascal Bourguignon
"Larry" <[EMAIL PROTECTED]> writes:

> Xah Lee wrote:
> > in computer languages, often a function definition looks like this:
> 
> >  [EMAIL PROTECTED]
> >  http://xahlee.org/PageTwo_dir/more.html
> 
> Your ideas are original, insightful and simply reflect incredibly deep
> creative genius.  I have read your work and I want to hire you for
> highly classified work in software design and philosophical writing.
> Would you possibly be available to meet with me in my secret mountain
> compound to discuss terms?
> 
> Larry

You forgot to mention the coordinates of your secret mountain compound: 

   28 deg 5 min N, 86 deg 58 min E


-- 
__Pascal Bourguignon__ http://www.informatimago.com/

Nobody can fix the economy.  Nobody can be trusted with their finger
on the button.  Nobody's perfect.  VOTE FOR NOBODY.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: limited python virtual machine

2005-01-30 Thread Jack Diederich
On Sun, Jan 30, 2005 at 11:59:39AM +1000, Nick Coghlan wrote:
> Alex Martelli wrote:
> >It didn't seem to me that Steven's question was so restricted; and since
> >he thanked me for my answer (which of course is probably inapplicable to
> >some custom interpreter that's not written yet) it appears to me that my
> >interpretation of his question was correct, and my answer useful to him.
> 
> Yes, I'd stopped following the thread for a bit, and the discussion had 
> moved further afield than I realised :)
> 
> >If you _can_ execute (whatever) in a separate process, then an approach
> >based on BSD's "jail" or equivalent features of other OS's may be able
> >to give you all you need, without needing other restrictions to be coded
> >in the interpreter (or whatever else you run in that process).
> 
> I think that's where these discussion have historically ended. . . making a 
> Python-specific sandbox gets complicated enough that it ends up making more 
> sense to just use an OS-based sandbox that lets you execute arbitrary 
> binaries relatively safely.
> 
> The last suggestion I recall along these lines was chroot() plus a 
> monitoring daemon that killed the relevant subprocess if it started 
> consuming too much memory or looked like it had got stuck in an infinite 
> loop.
> 

The Xen virtual server[1] was recently metnioned on slashdot[2].
It is more lightweight and faster than full scale machine emulators because
it uses a modified system kernel (so it only works on *nixes it has been
ported to).  You can set the virtual memory of each instance to keep
programs from eating the world.  I don't know about CPU, you might still
have to monitor & kill instances that peg the CPU.

If anyone does this, a HOWTO would be appreciated!

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


ANN: Frog 1.3 released (python 'blog' application)

2005-01-30 Thread Irmen de Jong
I've just uploaded the Frog 1.3 release.
Frog is a blog (web log) system written in 100% Python.
It is a web application written for Snakelets.
It outputs XHTML, is fully unicode compatible, small,
and doesn't require a database.
You can read about it and download it here:
   http://snakelets.sourceforge.net/frog/
It's 60Kb if you already have Snakelets, otherwise 122Kb.
Frog 1.3 uses the same storage format as 1.2 so no conversion
is required. If you encounter bugs or problems, or want to give
some feedback, please let me know.
Enjoy,
--Irmen de Jong.
PS I'm running Frog for my personal blog, so if you want
to see it in action, please visit:
  http://www.razorvine.net/snake/frog/user/irmen/
(still somewhat experimental and most is in Dutch)
--
http://mail.python.org/mailman/listinfo/python-list


Re: [perl-python] sending email

2005-01-30 Thread YYusenet
Xah Lee wrote:
 [snip]
The first two has glaring problems. I'm sorry i forgot what they
^   ^^
are.
  
 [snip]
How can you complain about *Mail::Mailer* and *Mail::Send* when you 
don't even know what they are?

--
k g a b e r t (at) x m i s s i o n (dot) c o m
--
http://mail.python.org/mailman/listinfo/python-list


Re: [perl-python] sending email

2005-01-30 Thread Chris Mattern
YYusenet wrote:

> Xah Lee wrote:
>   [snip]
>> 
>> The first two has glaring problems. I'm sorry i forgot what they
>^   ^^
>> are.
>  
>   [snip]
> 
> How can you complain about *Mail::Mailer* and *Mail::Send* when you
> don't even know what they are?
> 
You know, I started to make fun of that, but then decided there was
nothing I could say that it doesn't say for itself.

-- 
 Christopher Mattern

"Which one you figure tracked us?"
"The ugly one, sir."
"...Could you be more specific?"
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: naive doc question

2005-01-30 Thread Philippe C. Martin
Gabriel B. wrote:

> Is it just me that can't find a full reference in the docs?
> 
> I wanted a list of all the methods of dict for example... where can i
> find it? 
> 
> Thanks, and sorry if this question is just dumb, i really can't find
> it 

Also if you are using mozilla or firefox, I suggest you try this
documentation sidebar: http://projects.edgewall.com/python-sidebar/

Regards,

Philippe



-- 
***
Philippe C. Martin
SnakeCard LLC
www.snakecard.com
***

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


Re: Coding style article with interesting section on white space

2005-01-30 Thread beliavsky

Alex Martelli wrote:



> > For scientific computation, consider the case of Numeric
> > and Numarray. I don't think Numeric binaries are available for
Python
> > 2.4,
>
>  ?  Just
> googled and visited the first hit -- I don't currently use Windows so
I
> don't know if it's still there, works well, etc.

I should have Googled. I will investigate that link. At SourceForge,
http://sourceforge.net/project/showfiles.php?group_id=1369 I see a
Numarray but not a Numeric Windows binary for Python 2.4. The latest
Numeric Windows binary there is for Python 2.3.

>
> > The recent "Pystone Benchmark" message says that Python is only 75%
as
> > fast on Linux as on Windows. Fortran programs do not suffer this
> > performance hit and are in this respect more portable. In theory,
as
>
> You're saying that using a different and better compiler cannot speed
> the execution of your Fortran program by 25% when you move it from
one
> platform to another...?!  This seems totally absurd to me, and yet I
see
> no other way to interpret this assertion about "Fortran programs not
> suffering" -- you're looking at it as a performance _hit_ but of
course
> it might just as well be construed as a performance _boost_ depending
on
> the direction you're moving your programs.

I had in mind the Polyhedron Fortran 90 benchmarks for Windows and
Linux on Intel x86 at
http://www.polyhedron.co.uk/compare/linux/f90bench_p4.html and
http://www.polyhedron.co.uk/compare/win32/f90bench_p4.html . The speed
differences of Absoft, Intel, and Lahey between Linux and Windows for
individual programs, not to mention the average differential across all
programs, is much less than 25%. The differences on a single OS between
compilers can be much larger, but that has less bearing on portability
across OS's.

Thanks for your earlier informative comments on languages. Sparring
with Alex Martelli is like boxing Mike Tyson, except that one
experiences brain enhancement rather than brain damage :).

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


Re: Coding style article with interesting section on white space

2005-01-30 Thread Andrew McLean
In article <[EMAIL PROTECTED]>, Alex Martelli 
<[EMAIL PROTECTED]> writes
You're saying that using a different and better compiler cannot speed
the execution of your Fortran program by 25% when you move it from one
platform to another...?!  This seems totally absurd to me, and yet I see
no other way to interpret this assertion about "Fortran programs not
suffering" -- you're looking at it as a performance _hit_ but of course
it might just as well be construed as a performance _boost_ depending on
the direction you're moving your programs.
I think that upon mature consideration you will want to retract this
assertion, and admit that it IS perfectly possible for the same Fortran
program on the same hardware to have performance that differs by 25% or
more depending on how good the optimizers of different compilers happen
to be for that particular code, and therefore that, whatever point you
thought you were making here, it's in fact totally worthless.
Look at the Fortran compiler benchmarks here:
http://www.polyhedron.co.uk/compare/win32/f77bench_p4.html
for some concrete evidence to support Alex's point.
You will see that the average performance across different benchmarks of 
different Fortran compilers on the same platform can be as much a factor 
of two. Variation of individual benchmarks as much as a factor of three.

Some of you might be surprised at how many different Fortran compilers 
are available!

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


Re: Coding style article with interesting section on white space

2005-01-30 Thread Alex Martelli
<[EMAIL PROTECTED]> wrote:

> I had in mind the Polyhedron Fortran 90 benchmarks for Windows and
> Linux on Intel x86 at
> http://www.polyhedron.co.uk/compare/linux/f90bench_p4.html and
> http://www.polyhedron.co.uk/compare/win32/f90bench_p4.html . The speed
> differences of Absoft, Intel, and Lahey between Linux and Windows for
> individual programs, not to mention the average differential across all
> programs, is much less than 25%. The differences on a single OS between
> compilers can be much larger, but that has less bearing on portability
> across OS's.

So, you think that comparing a single commercial compiler for code
generation on Windows vs Linux (which _should_ pretty obviously be
pretty much identical) is the same thing as comparing the code
generation of two DIFFERENT compilers, a commercial one on Windows vs a
free one on Linux?!  This stance sounds singularly weird to me.

If on one platform you use a compiler that's only available for that
platform (such as Microsoft's), then "portability across OS's" (in terms
of performance, at least) can of course easily be affected.  If you care
so much, splurge for (say) the commercial compilers that Intel will be
quite happy to sell you for both platforms -- the one for Windows is a
plug-in replacement for Microsoft's, inside MS Visual Studio (at least,
it used to be that way, with VS 6.0; I don't know if that's still the
case), the one for Linux is usable in lieu of the free gcc.  So, each
should compile Python without any problem.  Presumably, the optimizer
and code generator will be essentially unchanged across platforms, as
they are in the offerings of other vendors of commercial compilers -- it
would seem silly for any vendor to do otherwise!

If one has no funding to purchase commercial compilers for several
platforms, or one doesn't care particularly about the differences in
speed resulting from different compilers' optimizers, then, surprise
surprise, one's programs are quite liable to have different performance
on different platforms.  Trying to imply that this has ANYTHING to do
with the LANGUAGE the programs are coded in, as opposed to the compilers
and expenses one is willing to incur for them, is either an extremely
serious error of logic, if incurred in good faith, or else is an attempt
to "score points" in a discussion, and then good faith is absent.


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


Re: Coding style article with interesting section on white space

2005-01-30 Thread Michael Tobis
[EMAIL PROTECTED] wrote:
> Michael Tobis wrote:
> > (unwisely taking the bait...)
> >
> > If you like your language to look like this
> > http://www.cs.rpi.edu/~szymansk/OOF90/bugs.html
> > then more power to you.
>
> Thanks for pointing out that interesting article on Fortran 90 bugs.
> How long would a comparable C++ list be? Even Python has gotchas, for
> example the difference between deep and shallow copies.

The reply "C++ is even worse", while debatable either way, seems to be
a common response from Fortran defenders. It misses the point.

What the scientific community needs, whether they know it or not, is
high-performance Python if that's possible, or something as close to it
as possible. Specifically, something with serious introspective power
and economy of expression.

> > I prefer my languages to be portable, terse and expressive.
>
> Fortran programmers are generally happy with the portability of the
> language.

Until they try to port something...? Honestly, I can't imagine where
anyone would get this impression.

Now, about the terseness and expressiveness?

> For scientific computation, consider the case of Numeric
> and Numarray.

I'm not happy with these, because they either make temporary arrays
with wild abandon, or enforce an unnatural style of expression. I could
see how they would be useful to others but they are awkward in
long-time spatially coarse finite difference/finite volume/spectral
calculations, which is the problem space I care about.

As for non-coarse (finite element) integrations (where rectangular
decompositions do not suffice) it seems to me that using Fortran is
sheer madness, even though there are real pointers now.

I do not suggest that Python is currently competitive with C++ or
Fortran. I simply agree with
http://www.fortranstatement.com that something new ought to be
designed, that a backward compatible Fortran2003 cannot possibly be it,
and that attention to fortran diverts resources from teh osrt of
genuine progress that ought to be possible.

> The recent "Pystone Benchmark" message says that Python is only 75%
as
> fast on Linux as on Windows. Fortran programs do not suffer this
> performance hit and are in this respect more portable. In theory, as
> has been mentioned, one could use a faster compiler to compile
CPython
> on Linux, but AFAIK this has not yet been done.

Without disagreeing with Alex Martelli's response to this, I find it
nonsensical on other grounds.

Performance portability has nothing to do with what I'm talking about.

The answer belies the attitude that programmers are there to put in
time and expend effort, because the only resource worth considering is
production cycles on a big machine. This attitude explains why working
with Fortran is so unpleasant an experience for anyone who has been
exposed to other languages.

An alternative attitude is that the amount of human effort put into
solving a problem is a relevant factor.

In this view, "portability" is actually about build effort, not runtime
performance. Perhaps the Fortran community finds this idea surprising?

Getting a python package working usually amounts to an install command
to the OS and an import command to the interpreter. Then you can get
down to work. Getting a Fortran package working involves not only an
endless dance with obscure compiler flags and library links, but then a
set of workarounds for codes that produce expected results on one
compiler and compile failures or even different results on another.

The day when project cost was dominated by machine time as opposed to
programmer time is coming to a close. Fortran is a meaningful solution
only to the extent that programmer time is not just secondary but
actually negligible as a cost.

The assumption that portability is somehow about performance belies
total lack of concern for the programmer as a resource, and therefore
to the time-to-solution of any new class of scientific problem. The
result of this habit of thought (entirely appropriate to 1955) is that
in an environment where fortran is expected, new problems are
interpreted as changes to old problems, and the packages become vast
and bloated.

Since most of these legacy codes in practice predate any concept of
design-for-test, they are also almost certainly wrong, in the sense
that they are unlikely to implement the mathematics they purport to
implement. Usually they are "close enough" for some purposes, but it's
impossible to delimit what purposes are inside or outside the range of
application.

> Nobody is stopping Python developers from working on projects like
> Psyco.

They aren't helping either, for the most part.

Psyco aside, institutions that ought to be supporting development of
high-performance high-expressiveness scientific languages are not doing
so.

Institutions with a Fortran legacy base are confused between
maintaining the existing investment and expanding it. The former is
frequently a mistake already, but the latter is a mistake almost
al

Re: what's OOP's jargons and complexities?

2005-01-30 Thread Cesar Rabak
Pascal Bourguignon escreveu:
"Larry" <[EMAIL PROTECTED]> writes:

Xah Lee wrote:
in computer languages, often a function definition looks like this:

[EMAIL PROTECTED]
http://xahlee.org/PageTwo_dir/more.html
Your ideas are original, insightful and simply reflect incredibly deep
creative genius.  I have read your work and I want to hire you for
highly classified work in software design and philosophical writing.
Would you possibly be available to meet with me in my secret mountain
compound to discuss terms?
Larry

You forgot to mention the coordinates of your secret mountain compound: 

   28 deg 5 min N, 86 deg 58 min E
Pascal!!
You spoiled a carefully kept Larry's secret. . . now it will have to 
change his compound. . .



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


Disassembling strings and turning them into function parameters

2005-01-30 Thread mercuryprey
Hi,
I'm pretty new to Python, to programming overall...so how would I make
something where the user inputs multiple words in a string - like
"connect 123.123.123.123 21 user password" or similar, and then I can
split this string up to pass these arguments to a function like
ftp_connect(ip, port, user, pw) etc...? I have no idea how to "break"
the string up so I can get these out of it..


thanks for answers,
munin

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


Re: Disassembling strings and turning them into function parameters

2005-01-30 Thread Peter Hansen
[EMAIL PROTECTED] wrote:
Hi,
I'm pretty new to Python, to programming overall...so how would I make
something where the user inputs multiple words in a string - like
"connect 123.123.123.123 21 user password" or similar, and then I can
split this string up to pass these arguments to a function like
ftp_connect(ip, port, user, pw) etc...? I have no idea how to "break"
the string up so I can get these out of it..
The .split() method of strings should work for you.
If you need more, provide more background...  and maybe
let us know that this isn't homework. ;-)
-Peter
--
http://mail.python.org/mailman/listinfo/python-list


Re: Disassembling strings and turning them into function parameters

2005-01-30 Thread Fredrik Lundh
<[EMAIL PROTECTED]> wrote:

> I'm pretty new to Python, to programming overall...so how would I make
> something where the user inputs multiple words in a string - like
> "connect 123.123.123.123 21 user password" or similar, and then I can
> split this string up to pass these arguments to a function like
> ftp_connect(ip, port, user, pw) etc...? I have no idea how to "break"
> the string up so I can get these out of it..

you can use the split() method to split on whitespace:

>>> s = "connect 123.123.123.123 21 user password"
>>> s.split()
['connect', '123.123.123.123', '21', 'user', 'password']

btw, the cmd module might be useful for your project:

http://effbot.org/librarybook/cmd.htm
http://docs.python.org/lib/module-cmd.html

 



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


Re: Disassembling strings and turning them into function parameters

2005-01-30 Thread M.E.Farmer
[EMAIL PROTECTED] wrote:
> Hi,
> I'm pretty new to Python, to programming overall...so how would I
make
> something where the user inputs multiple words in a string - like
> "connect 123.123.123.123 21 user password" or similar, and then I can
> split this string up to pass these arguments to a function like
> ftp_connect(ip, port, user, pw) etc...? I have no idea how to "break"
> the string up so I can get these out of it..
>
>
> thanks for answers,
> munin

Ok well this is pretty basic but it sounds wrong on some level.
Maybe you should post some code, you will get better responses.
You could try something like:
Py>stuff = "connect 123.123.123.123 21 user password"
Py>parts_list = stuff.split()# can handle other seperators
Py>print parts_list
['connect', '123.123.123.123', '21', 'user', 'password']
Py>def StrFtp(userinfo):
...parts = userinfo.slpit()
...funktion, ip, port, usedr, pw = parts
...funktion = funktion.lower()
...if funktion == 'connect'
...return ftp_connect(ip, port, user, pw)
...elif funktion == 'other_function_name_here':
...return 'your other action here'
...else:
...return None

Py>ftpconnect = StrFtp("connect 123.123.123.123 21 user password")

Also add asserts and error checking all through the code for malformed
input.
hth, 
M.E.Farmer

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


Re: installing tkiner

2005-01-30 Thread rccharles

Robert wrote:
> I am trying to use tkinter on macos 10.2.6.

There is a documented restriction that you cannot run gui programs from
the ide.

re-installed TclTkAquaBI-8.4.6.1-Jaguar.dmg
used the pythonw command.

Robert

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


Re: Disassembling strings and turning them into function parameters

2005-01-30 Thread mercuryprey
Hey,
that's exactly what I need! Thanks for your help, the others too of
course :) Didn't expect to get answers so quickly..

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


Exception from bsddb module

2005-01-30 Thread jalil
I am using Python 2.4 and get this exception when running my mod_python
application. This used to work in my older environment.

Any ideas on how I can debug this issue?

-Jalil


Mod_python error: "PythonHandler mod_python.psp"

Traceback (most recent call last):

File "/usr/local/lib/python2.4/site-packages/mod_python/apache.py",
line 299, in HandlerDispatch
result = object(req)

File "/usr/local/lib/python2.4/site-packages/mod_python/psp.py", line
297, in handler
p.run()

File "/usr/local/lib/python2.4/site-packages/mod_python/psp.py", line
191, in run
session = Session.Session(req)

File "/usr/local/lib/python2.4/site-packages/mod_python/Session.py",
line 389, in Session
timeout=timeout, lock=lock)

File "/usr/local/lib/python2.4/site-packages/mod_python/Session.py",
line 294, in __init__
timeout=timeout, lock=lock)

File "/usr/local/lib/python2.4/site-packages/mod_python/Session.py",
line 124, in __init__
if self.load():

File "/usr/local/lib/python2.4/site-packages/mod_python/Session.py",
line 185, in load
dict = self.do_load()

File "/usr/local/lib/python2.4/site-packages/mod_python/Session.py",
line 315, in do_load
dbm = self._get_dbm()

File "/usr/local/lib/python2.4/site-packages/mod_python/Session.py",
line 302, in _get_dbm
result = self._dbmtype.open(self._dbmfile, 'c')

File "/usr/local/lib/python2.4/anydbm.py", line 83, in open
return mod.open(file, flag, mode)

File "/usr/local/lib/python2.4/dbhash.py", line 16, in open
return bsddb.hashopen(file, flag, mode)

File "/usr/local/lib/python2.4/bsddb/__init__.py", line 285, in
hashopen
e = _openDBEnv()

File "/usr/local/lib/python2.4/bsddb/__init__.py", line 339, in
_openDBEnv
e.open('.', db.DB_PRIVATE | db.DB_CREATE | db.DB_THREAD |
db.DB_INIT_LOCK | db.DB_INIT_MPOOL)
DBError: (15344, 'Unknown error 15344')

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


search engine

2005-01-30 Thread jlrodilla
hi all, i´m doing a search engine using python for the spider and php
to make a web for the search. The Database i have choosen is
postgreSQL. Do you think it is a good choosen? Any suggestion?

if anybody in interested in colaborate please send an e-mail to
[EMAIL PROTECTED]

In a few weeks i will upload all the code to one domain and so i can be
able to send you information about this project.

The idea is to build a search engine like "google", but my/our search
engine only look for tech pages, i also wants that users can select if
they want to search a web, faqs/howto, manuals/tutorials...

Thanks.

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


Re: Coding style article with interesting section on white space

2005-01-30 Thread Michael Sparks
On 30 Jan 2005 [EMAIL PROTECTED] wrote:

> Sparring
> with Alex Martelli is like boxing Mike Tyson, except that one
> experiences brain enhancement rather than brain damage :).

+1 QOTW

:-)

Michael.

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


Re: search engine

2005-01-30 Thread Premshree Pillai
On 30 Jan 2005 11:19:30 -0800, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote:
> hi all, i´m doing a search engine using python for the spider and php
> to make a web for the search. The Database i have choosen is

Just curious: is there any particular reason you want to use PHP for
building the web interface?

> postgreSQL. Do you think it is a good choosen? Any suggestion?
> 
> if anybody in interested in colaborate please send an e-mail to
> [EMAIL PROTECTED]
> 
> In a few weeks i will upload all the code to one domain and so i can be
> able to send you information about this project.
> 
> The idea is to build a search engine like "google", but my/our search
> engine only look for tech pages, i also wants that users can select if
> they want to search a web, faqs/howto, manuals/tutorials...
> 
> Thanks.
> 
> --
> http://mail.python.org/mailman/listinfo/python-list
> 


-- 
Premshree Pillai
http://www.livejournal.com/~premshree
--
http://mail.python.org/mailman/listinfo/python-list


Re: An mysql-python tutorial?

2005-01-30 Thread Andy Dustman
It definitely looks like an access control problem; recheck your grants.

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


Re: The next Xah-lee post contest

2005-01-30 Thread Eric Pederson
> From: Arthur <[EMAIL PROTECTED]>

> Not sure how Xah got himself into all this.  


One can easily see that Java programmers are geeks who secretly wanted to make 
the football team and are now trying to conform, ignoring their language's 
critical lack of Prolog syntax.  Python coders, similarly, do not recognize 
that they may be violating several open source patents each time they write: 
"class(Object):", and both languages may become unusable when the Government 
changes the inheritance tax.

Rather than throw stones or make fun, all but the closet Republicans should 
examine how poor Xah came to such a state of misunderstanding IPv8, and try to 
help him.

>From Aahz tag line we have a clue:

"19. A language that doesn't affect the way you think about programming,is 
not worth knowing." Â--Alan Perlis

Further understanding will require research.  Was it Perl that did this to Mr. 
Lee's brain, or perhaps it was trying to ascertain the web services "standard"? 
 Was it a massive PHP program that simply grew beyond comprehendability and 
blew all normal circuits?  Or perhaps an attempt to jump straight from Fortran 
77 into Ruby?

Perhaps we will never know the cause, but surely when the ill come to us we 
must prescribe something.

Ah, perhaps if he will join us in a song we will all be OK:

Python Choir:
Lee's a lumberjack, and he's OK,
He codes all night and he posts all day.

XL:
I cut down trees, I eat my lunch,
I go to the lavatory.
On Wednesdays I go shopping,
And have buttered scones for tea.

Python Choir:
Lee cuts down trees, He eats his lunch,
He goes to the lavatory.
On Wednesdays he goes shopping,
And have buttered scones for tea.

Lees a lumberjack, and he's OK,
He codes all night and he posts all day.

XL:
I cut down trees, I skip and jump,
I like to press wild flowers.
I put on women's clothing,
And hang around in bars.

Python Choir:
Lee cuts down trees, he skips and jumps,
He likes to press wild flowers.
He puts on women's clothing
And hangs around In bars???


Well.  At least I feel better.  For now.



/Eric - sentenced to re-learn and write an application in Perl 5.0
What will that do to my mind?


http://www.songzilla.blogspot.com
:::
domainNot="@something.com"
domainIs=domainNot.replace("s","z")
ePrefix="".join([chr(ord(x)+1) for x in "do"])
mailMeAt=ePrefix+domainIs
:::

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


Regarding exception handling

2005-01-30 Thread Aggelos I. Orfanakos
Hello.

In a program, I want to ensure that a socket closes (so I use try ...
finally), but I also want to catch/handle a socket exception. This is
what I have done:

try:
try:
s = ... # socket opens

# various code ...
except socket.error, x:
# exception handling
finally:
s.close() # socket closes

Is there a more "elegant" or "proper" way to do this? Or the above code
is OK?

Thanks in advance.

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


Re: The next Xah-lee post contest

2005-01-30 Thread Bryan
Eric Pederson wrote:
From: Arthur <[EMAIL PROTECTED]>

Not sure how Xah got himself into all this.  

One can easily see that Java programmers are geeks who secretly wanted to make the 
football team and are now trying to conform, ignoring their language's critical lack of 
Prolog syntax.  Python coders, similarly, do not recognize that they may be violating 
several open source patents each time they write: "class(Object):", and both 
languages may become unusable when the Government changes the inheritance tax.
Rather than throw stones or make fun, all but the closet Republicans should 
examine how poor Xah came to such a state of misunderstanding IPv8, and try to 
help him.
From Aahz tag line we have a clue:
"19. A language that doesn't affect the way you think about programming,is 
not worth knowing."  --Alan Perlis
Further understanding will require research.  Was it Perl that did this to Mr. Lee's 
brain, or perhaps it was trying to ascertain the web services "standard"?  Was 
it a massive PHP program that simply grew beyond comprehendability and blew all normal 
circuits?  Or perhaps an attempt to jump straight from Fortran 77 into Ruby?
Perhaps we will never know the cause, but surely when the ill come to us we 
must prescribe something.
Ah, perhaps if he will join us in a song we will all be OK:
Python Choir:
Lee's a lumberjack, and he's OK,
He codes all night and he posts all day.
XL:
I cut down trees, I eat my lunch,
I go to the lavatory.
On Wednesdays I go shopping,
And have buttered scones for tea.
Python Choir:
Lee cuts down trees, He eats his lunch,
He goes to the lavatory.
On Wednesdays he goes shopping,
And have buttered scones for tea.
Lees a lumberjack, and he's OK,
He codes all night and he posts all day.
XL:
I cut down trees, I skip and jump,
I like to press wild flowers.
I put on women's clothing,
And hang around in bars.
Python Choir:
Lee cuts down trees, he skips and jumps,
He likes to press wild flowers.
He puts on women's clothing
And hangs around In bars???
Well.  At least I feel better.  For now.

/Eric - sentenced to re-learn and write an application in Perl 5.0
What will that do to my mind?
http://www.songzilla.blogspot.com
:::
domainNot="@something.com"
domainIs=domainNot.replace("s","z")
ePrefix="".join([chr(ord(x)+1) for x in "do"])
mailMeAt=ePrefix+domainIs
:::
oh great... now you just legend-ized him on this group forever :(
--
http://mail.python.org/mailman/listinfo/python-list


Re: Regarding exception handling

2005-01-30 Thread Aggelos I. Orfanakos
(I don't know why, but indentation was not preserved once I posted.)

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


type() takes one or *three* arguments!?

2005-01-30 Thread jamesthiele . usenet
I was looking at Simon Burton's Povray.py code (part of pypov) and saw
this line:
globals()[name] = type( name, (KWItem,), {} ) # nifty :)

where 'KWItem' was a class. It did seem nifty, but it was unclear to me
what was happening.

I went to python.org's online documentation which said that type()
takes one argument. So I fired up python:
>>> type(42)

>>> type("x", (type(42),), {})


OK, It appears that type() with 3 arguments constructs a class. Is this
documented somewhere? If not can someone explain what is going on?
james

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


Re: Need programming tip

2005-01-30 Thread ssaeed1973
Alex,
Thanks, I will try this.
Salman

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


Re: type() takes one or *three* arguments!?

2005-01-30 Thread Pedro Werneck
Hi,

Up to Python 2.2, type() was just a function to return an object type.
>From 2.2 on, type have this behavior when called with only one argument
and is used to create a new type when called with 3 arguments.


>From http://www.python.org/2.2/descrintro.html :

"The signature of type() requires an explanation: traditionally, type(x)
returns the type of object x, and this usage is still supported.
However, type(name, bases, methods) is a new usage that creates a brand
new type object. (This gets into metaclass programming, and I won't go
into this further here except to note that this signature is the same as
that used by the Don Beaudry hook of metaclass fame.)"



So, an example:

Foo = type('Foo', (object,), {})

and...

class Foo(object):
   pass

Are the same thing... 




On 30 Jan 2005 11:57:23 -0800
[EMAIL PROTECTED] wrote:

> I was looking at Simon Burton's Povray.py code (part of pypov) and saw
> this line:
> globals()[name] = type( name, (KWItem,), {} ) # nifty :)
> 
> where 'KWItem' was a class. It did seem nifty, but it was unclear to
> me what was happening.
> 
> I went to python.org's online documentation which said that type()
> takes one argument. So I fired up python:
> >>> type(42)
> 
> >>> type("x", (type(42),), {})
> 
> 
> OK, It appears that type() with 3 arguments constructs a class. Is
> this documented somewhere? If not can someone explain what is going
> on? james
> 
> -- 
> http://mail.python.org/mailman/listinfo/python-list
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: limited python virtual machine

2005-01-30 Thread Nick Craig-Wood
Jack Diederich <[EMAIL PROTECTED]> wrote:
>  The Xen virtual server[1] was recently metnioned on slashdot[2].
>  It is more lightweight and faster than full scale machine emulators because
>  it uses a modified system kernel (so it only works on *nixes it has been
>  ported to).

...it also uses python for its control programs.

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


Re: Need programming tip

2005-01-30 Thread beliavsky
A Usenet tip is that one should never use such a generic subject as
"need programming tip" or the ever-popular "newbie question". In this
case, "create a database of posts made to binary groups" could have
been a better title, so that people unable to answer to the question
and not interested in the topic can skip it.

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


Re: Regarding exception handling

2005-01-30 Thread beliavsky
Aggelos I. Orfanakos wrote:
> (I don't know why, but indentation was not preserved once I posted.)

This problem and its possible solutions was discussed here in the
thread "OT: spacing of code in Google Groups".

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


Re: test_socket.py failure

2005-01-30 Thread Steve Holden
[EMAIL PROTECTED] wrote:
 hi all,
 Linux 2.4.28
 Glibc 2.2.5
 gcc   2.95.3
 I'm new to Python.
 I've compiled Python 2.4 from tar file.
 When running 'make test' i'm getting a failure
 in test_socket.
 Running './python Lib/test/test_socket.py' yields:
==
ERROR: testGetServBy (__main__.GeneralModuleTests)
--
Traceback (most recent call last):
  File "Lib/test/test_socket.py", line 330, in testGetServBy
port2 = socket.getservbyname(service)
error: service/proto not found
--
Ran 58 tests in 3.826s

 The value of 'service' was "daytime".
 After much hand wringing, editing, and use of 'print'
 statements i commented out line 330,
 '# port2 = socket.getservbyname(service)' and replaced it
 with the line 'port2 = port'.
 Running './python Lib/test/test_socket.py' now yields:
testGetServBy (__main__.GeneralModuleTests) ... ok
   .
   .
   .
--
Ran 58 tests in 5.181s
OK
 
 Located the code for 'socket_getservbyname' in 
 'Modules/socketmodule.c' where the call to the glibc
 function 'getservbyname' is made: 

 Py_BEGIN_ALLOW_THREADS
 sp = getservbyname(name, proto);
 Py_END_ALLOW_THREADS
 if (sp == NULL) {
 PyErr_SetString(socket_error, "service/proto not found");
 return NULL;
 }
 
 The only call of socket.getservbyname that failed was when
 it was passed the single argument.  Since the error message
 "service/proto not found" seems to only be generated upon
 failure of gibc's 'getservbyname' could it be that 
 'PyArg_ParseTuple(args, "s|s:getservbyname", &name, &proto)'
 generates values for 'name' and/or 'proto' that cause the
 failure?

 My search for prior reports of failure at line 330 found
 a mention of problems at line 331.
 Well, at any rate, if someone could point me down the 
 correct path on this i would appreciate it.

Compiling from source requires you to indicate the features that you 
want compiled in. Without thread support, sockets din't work, so it 
looks like you need to configure threads in. IIRC you do this by editing 
the Modules.? file.

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


how do i create such a thing?

2005-01-30 Thread Lowell Kirsh
I want to create a class called DefaultAttr which returns a default 
value for all attributes which haven't been given values yet. It will 
work like this:

>> x = DefaultAttr(99)
>> print x.foo
99
>> print x.bar
99
>> x.foo = 7
>> print x.foo
7
I already have a similar class called DefaultDict which works similarly 
which I assume would be a good thing to use.

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


Re: is this sort method the same as the one in python 2.4

2005-01-30 Thread Lowell Kirsh
How come you reverse the list twice? And why does this preserve stability?
Raymond Hettinger wrote:
"Lowell Kirsh"
I'm trying to emulate the sorted() method introduced in python 2.4. The
only difference is that it takes a sequence as one of its arguments
rather than being a method of the sequence class. Does my method do the
same as the sorted()?

Almost.  This is closer to the mark:
def sorted(iterable, cmp=None, key=None, reverse=False):
"return a sorted copy of its input"
if sys.version_info >= (2,4):
return sorted(iterable, cmp, key, reverse)
seq = list(iterable)
if reverse:
seq.reverse()# preserve stability
if key is not None:
seq = [(key(elem), i, elem) for i, elem in enumerate(seq)]
seq.sort(cmp)
if key is not None:
seq = [elem for (key, i, elem) in seq]
if reverse:
seq.reverse()
return seq
Try it against the tests in Lib/test/test_builtin.py.
The differences from your version:
* >= 2.4 rather than just > 2.4
* renamed the parameter to iterable
* handle the case where both cmp and key are defined
* add an enumerated tie breaker to prevent full key comparisons
* preserve by using reverse twice
The real sorted() does the same thing but is implemented a bit differently.  A
custom key wrapper is applied to each object so that only the key value gets
compared (no need for a full tuple with a tie breaker value).
Raymond Hettinger

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


Re: Help! Host is reluctant to install Python

2005-01-30 Thread Ian
On Wed, 26 Jan 2005 01:40:39 GMT, [EMAIL PROTECTED] wrote:


...
>I think you should look into some type of virtual hosting that gives
>you more ability to install your own software.  Typing "uml hosting"
>(UML is user-mode Linux) into Google finds a lot of such services.  If
>you find one that you like, post it here, I'm interested in this myself.

I'm very happy with uml from tummy.com for 25 USD/month, with good
support by email for configuring mod_python in my case.  They are also
a Pycon sponsor.

Ian

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


RFC 2965 cookies, cookielib, and mailman.

2005-01-30 Thread John J Lee
Just noticed your c.l.py post quoted below.  Nobody but me knows or cares
about this obscure stuff ;-) so I'm not surprised you got no answer...

C. Titus Brown   Dec 27 2004, 12:41 pm wrote:
[...]
> The issue turned out to be that mailman sends out RFC 2965 [1] cookies,
> which are by default rejected by cookielib.  I don't remotely pretend to
> understand the issues involved; hence my post ;).
> 
> A few questions for those more clued in than me:
> 
> * what is the difference between RFC 2965 cookies and others?

See "Where can I find out more about the HTTP cookie protocol?" here:

http://wwwsearch.sourceforge.net/ClientCookie/

For both very short, slightly longer (first link in that section, to a
section of the ClientCookie docs on the cookie standards), and
insanely detailed (Kristol's paper) explanations.


> * why would mailman implement RFC 2965 cookies over the old format?
> (I'm guessing simply because it's the latest/best/format?)

Because Barry didn't realise that almost no browsers implement it (and
never will), I guess.


> * why would cookielib NOT accept RFC 2965 cookies by default?

See above: browsers don't implement it.  It's essentially dead as an
internet standard.  The only real standard is "what IE and Mozilla
do", plus some wisdom from RFCs 2109, 2965 and (more readably!) 2964.

[...]
> In any case, the way to make the cookielib example work for mailman is
> like so:
> 
>  policy = cookielib.DefaultCookiePolicy(rfc2965=True)
>  cj = cookielib.LWPCookieJar('cookies.lwp', policy=policy)

Hmm, cookielib should work if IE and Mozilla do, so that's a bug :(
You shouldn't need to turn on 2965 handling.

Do you have a script that demonstrates the problem, so I can fix it?

Thanks


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


Re: how do i create such a thing?

2005-01-30 Thread Pedro Werneck
Hi,

If you need direct access to some atribute, use object.__getattribute__.


>>> class DefaultAttr(object):
... def __init__(self,  default):
... self.default = default
... def __getattribute__(self, name):
... try:
... value = object.__getattribute__(self, name)
... except AttributeError:
... value = self.default
... return value
... 
>>> x = DefaultAttr(99)
>>> 
>>> print x.a
99
>>> x.a = 10
>>> print x.a
10
>>> 



On Sun, 30 Jan 2005 13:54:38 -0800
Lowell Kirsh <[EMAIL PROTECTED]> wrote:

> I want to create a class called DefaultAttr which returns a default 
> value for all attributes which haven't been given values yet. It will 
> work like this:
> 
>  >> x = DefaultAttr(99)
>  >> print x.foo
> 99
>  >> print x.bar
> 99
>  >> x.foo = 7
>  >> print x.foo
> 7
> 
> I already have a similar class called DefaultDict which works
> similarly  which I assume would be a good thing to use.
> 
> Lowell
> -- 
> http://mail.python.org/mailman/listinfo/python-list
-- 
http://mail.python.org/mailman/listinfo/python-list


pickle, cPickle, & HIGHEST_PROTOCOL

2005-01-30 Thread A.B., Khalid
I wonder if someone can explain what is wrong here. I am pickling a
list of dictionaries (see code attached) and unpickling it back using
the HIGHEST_PROTOCOL of pickle and cPickle. I am getting an error
message and trace backs if the list exceeds eight items. Whether I use
pickle or cPickle does not matter, i.e., the eight number causes a
problem in both modules, although the trace backs are of course
dissimilar.

This pickling and unpickling of the list of dictionaries worked when I
stopped using the HIGHEST_PROTOCOL in both modules (pickle and
cPickle), which got Python to use the ASCII format (I suppose) as I can
read the pickled data.

This behavior was observed in Python 2.3.4 (final), and 2.4 (final) on
Win98.

Any comments?


Regards,
Khalid



# Sample program tester.py begin
!
! import pickle as pkl
! import os
! #-
! def test_pickle():
!fn = 'rkeys.txt'
!f = file(fn, 'r')
!lines = f.readlines()
!f.close()
!_test_list = []
!for line in lines:
!sline = line.split(',')
!#print sline
!key, value = sline[0], sline[1].strip()
!_test_dict = {}
!_test_dict[key] = value
!_test_list.append(_test_dict)
!
!# Let's see the contents of our object
!print _test_list
!
!# Then pickle it
!f = file('pkl_' + fn, 'w')
!pkl.dump(_test_list, f, pkl.HIGHEST_PROTOCOL)
!f.close()
!
!# Empty it
!_test_list = []
!print _test_list
!
!# Unpickling object here:
!f = file('pkl_' + fn, 'r')
!_test_list = pkl.load(f)
!f.close()
!
!# See contents after loading
!print _test_list
!#-
!if __name__ == '__main__':
!   test_pickle()
!
!# Sample program end


# Contents of file rkeys.txt (without the triple quotes):
"""
'1','v1'
'2','v2'
'3','v3'
'4','v4'
'5','v5'
'6','v6'
'7','v7'
'8','v8'
'9','v9'
"""


# Output (without the triple quotes)
# Using "import pickle as pkl":
"""
[{"'1'": "'v1'"}, {"'2'": "'v2'"}, {"'3'": "'v3'"}, {"'4'": "'v4'"},
{"'5'": "'v5'"}, {"'6'": "'v6'"}, {"'7'": "'v7'"}, {"'8'": "'v8'"},
{"'9'": "'v9'"}]
[]
!Traceback (most recent call last):
!  File "tester.py", line 41, in ?
!test_pickle()
!  File "tester.py", line 34, in test_pickle
!_test_list = pkl.load(f)
!  File "D:\PY23\PYTHON\DIST\SRC\lib\pickle.py", line 1390, in load
!return Unpickler(file).load()
!  File "D:\PY23\PYTHON\DIST\SRC\lib\pickle.py", line 872, in load
!dispatch[key](self)
!  File "D:\PY23\PYTHON\DIST\SRC\lib\pickle.py", line 1189, in
load_binput
!i = ord(self.read(1))
!TypeError: ord() expected a character, but string of length 0 found
"""


# Output (without the triple quotes)
# Using "import cPickle as pkl":
"""
[{"'1'": "'v1'"}, {"'2'": "'v2'"}, {"'3'": "'v3'"}, {"'4'": "'v4'"},
{"'5'": "'v5'"}, {"'6'": "'v6'"}, {"'7'": "'v7'"}, {"'8'": "'v8'"},
{"'9'": "'v9'"}]
[]
!Traceback (most recent call last):
!  File "tester.py", line 41, in ?
!test_pickle()
!  File "tester.py", line 34, in test_pickle
!_test_list = pkl.load(f)
!EOFError
"""


# Output (without the triple quotes)
# Using "import cPickle as pkl", or "import pickle as pkl"
# but _not_ using the HIGHEST_PROTOCOL:
"""
[{"'1'": "'v1'"}, {"'2'": "'v2'"}, {"'3'": "'v3'"}, {"'4'": "'v4'"},
{"'5'": "'v5'"}, {"'6'": "'v6'"}, {"'7'": "'v7'"}, {"'8'": "'v8'"},
{"'9'": "'v9'"}]
[]
[{"'1'": "'v1'"}, {"'2'": "'v2'"}, {"'3'": "'v3'"}, {"'4'": "'v4'"},
{"'5'": "'v5'"}, {"'6'": "'v6'"}, {"'7'": "'v7'"}, {"'8'": "'v8'"},
{"'9'": "'v9'"}]
"""

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


Re: search engine

2005-01-30 Thread BJörn Lindqvist
> hi all, i´m doing a search engine using python for the spider and php
> to make a web for the search. The Database i have choosen is
> postgreSQL. Do you think it is a good choosen? Any suggestion?

"Databases are implementation details! Considering the database should
be deferred as long as possible. Far too many applications are
inextricably tied to their databases because they were designed with
the database in mind from the beginning. Remember the definition of
abstraction: the amplification of the essential and the elimination of
the irrelevant. The database is irrelevant at this stage of the
project; it is merely a technique used for storing and accessing data,
nothing more." (Robert C. Martin, Agile Software Development, p. 194)

-- 
mvh Björn
--
http://mail.python.org/mailman/listinfo/python-list


gmail access with python!

2005-01-30 Thread int
hi,
i want to write a python program which will grab all my gmail msgs and
store them on my hard drive. i've done an extensive google search and
tried _every_ possible gmail python script i could find (including of
course libgmail) and none of them seem to work, even on trivial example
code.
(perhaps all these scripts are out of date due to recent changes in
gmail itself?)

my question is: does anyone have a working script which can grab msgs
from a gmail inbox ?

Thanks!

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


ANNOUNCE: KirbyBase 1.7

2005-01-30 Thread Jamey Cribbs
KirbyBase is a simple, plain-text, database management system written in 
Python.  It can be used either embedded in a python script or in a 
client/server, multi-user mode.  You use python code to express your 
queries instead of having to use another language such as SQL.  
KirbyBase is disk-based, not memory-based.  Database changes are 
immediately written to disk.

You can find more information on KirbyBase at:
http://www.netpromi.com/kirbybase.html
You can download KirbyBase for Python at:
http://www.netpromi.com/files/KirbyBase_Python_1.7.zip
Wow!  It's been almost two years since the initial release of 
KirbyBase.  Time sure does fly!  Version 1.7 includes most of the bug 
fixes that have accumulated over the months and a few enhancements that 
I hope you will enjoy.

I would like to thank everyone who has emailed me with comments, bug 
reports, and enhancement requests/ideas.  Hearing from people who 
actually use KirbyBase is what makes working on it worthwhile.  Please 
keep the emails coming!

I would particularly like to thank Pierre Quentel, the author of 
Karrigell (http://karrigell.sourceforge.net), for his contribution of 
ideas and code for many of the enhancements in version 1.7 of KirbyBase.

For those of you who requested better documentation, the manual has been 
completely re-written.  I'm not saying it's any better, but at least 
it's different.  :)

Changes in Version 1.7:
  ***IMPORTANT - IF YOU ARE UPGRADING THIS COULD BITE YOU!!!***
*  Changed the default value for the keyword argument 'useRegExp' to
   be false instead of true.  This means that, when doing a update,
   delete, or select, records being selected on string fields will
   be matched using exact matching instead of regular expression
   matching.  If you want to do regular expression matching, pass
   'useRegExp = True' to the method.
  ***IMPORTANT***
* Added a keyword argument to select() called returnType.  If set to
  'object', the result list returned will contain Record objects
  where each field name is an attribute of the object, so you could
  refer to a record's field as plane.speed instead of plane[4].  If
  set to 'dict', the result list returned will contain dictionaries
  where each key is a field name and each value is a field value. 
  If set to 'list', the default, the result is a list of lists.

* Added a new method, insertBatch.  It allows you to insert multiple
  records at one time into a table.  This greatly improves the speed
  of batch inserts.
* Added a new public method called validate.  Calling this method
  with a table name will check each record of that table and
  validate that all of the fields have values of the correct type.
  This can be used to validate data you have put into the table by
   means other than through KirbyBase, perhaps by opening the table
   in a text editor and typing in information.
* Fixed a bug in _closeTable where if an exception occurred it was
  blowing up because the variable 'name' did not exist.
* Fixed a bug in _writeRecord where if an exception occured it was
  blowing up because the variable 'name' did not exist.
* Fixed a bug in _getMatches where I was referencing
  self.field_names as a method instead of as a dictionary.
* Added a new private method, _strToBool, that converts string
  values like 'True' to boolean values.
* Added a new private method, _convertInput, and moved to it the
  code that ensures that the data on an insert is in proper list
  format.  I did this so that I did not have duplicate code in both
  the insert and insertBatch methods.
* To accomodate the fact that users can now send a large batch of
  records to be inserted, I changed _sendSocket so that it first
  sends the length of the database command to the server, then it
  actually sends the command itself, which can now be any length.
* Changed the code in _getMatches to precompile the regular
  expression pattern instead of dynamically compiling every time the
  pattern is compared to a table record.  This should speed up
  queries a little bit.
* Changed the code in select that converts table fields back to
  their native types to be more efficient.
* Changed _sendSocket to use StringIO (actually cStringIO) to hold
  the result set of a client/server-based query instead of just
  capturing the result by concatenating records to one big string.
  In informal testing on large result sets, it shaves a few tenths
  of a second off the query time.
Jamey Cribbs
[EMAIL PROTECTED]
--
http://mail.python.org/mailman/listinfo/python-list


RE: gmail access with python!

2005-01-30 Thread Tony Meyer
> i want to write a python program which will grab all my gmail 
> msgs and store them on my hard drive.
[...]
> my question is: does anyone have a working script which can 
> grab msgs from a gmail inbox ?

Possibly not of use, but if you're not using POP3 access to your gmail
account for anything else, then you could simply enable POP3 access and use
poplib.

=Tony.Meyer

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


Fortran pros and cons (was Re: Coding style article with interesting section on white space)

2005-01-30 Thread beliavsky
Michael Tobis wrote:

> > Fortran programmers are generally happy with the portability of the
> > language.
>
> Until they try to port something...? Honestly, I can't imagine where
> anyone would get this impression.

>From the fact that Fortran has been used on hundreds of platforms and
that many portable libraries like LAPACK exist. Fortran 90+ allows one
to write even more portable code using the KIND mechanism and the
selected_int_kind and selected_real_kind functions, which let you
specify the ranges of basic data types.

> Now, about the terseness and expressiveness?

Fortran 90/95 is more expressive than Fortran 77 in many ways, as
described in (for example) pages 7-8 of the essay "Numerical Recipes:
Does This Paradigm Have a Future?", available at
http://www.nr.com/CiP97.pdf . Quoting that paper:

"This, for us, was the revelation of parallel programming in Fortran
90.
The use of parallel and higher-level constructions -- wholly
independently of whether they are executed on tomorrow's parallel
machines or today's ordinary workstations -- expresses more science per
line of code and per programming workday. Based on our own experience,
we think that productivity, or achievable complexity of project, is
increased a factor of 2 or 3 in going from Fortran 77 to Fortran 90 --
if one makes the investment of mastering Fortran 90's higher level
constructs."

> > For scientific computation, consider the case of Numeric
> > and Numarray.
>
> I'm not happy with these, because they either make temporary arrays
> with wild abandon

Some early Fortran 90 compilers did this but have improved
significantly in this respect.

> or enforce an unnatural style of expression.

I wonder what this means.



> I do not suggest that Python is currently competitive with C++ or
> Fortran. I simply agree with
> http://www.fortranstatement.com that something new ought to be
> designed, that a backward compatible Fortran2003 cannot possibly be
it,
> and that attention to fortran diverts resources from [the sort] of
> genuine progress that ought to be possible.

You have not given specifics about what "genuine progress" in a
scientific programming language would be.



> Performance portability has nothing to do with what I'm talking
about.
>
> The answer belies the attitude that programmers are there to put in
> time and expend effort, because the only resource worth considering
is
> production cycles on a big machine.

Nonsense. Fortran was originally created to make PROGRAMMERS more
efficient by letting them code algebraic expressions instead of machine
code.

> This attitude explains why working with Fortran is so unpleasant an
> experience for anyone who has been exposed to other languages.

"Anyone"? Since I have been exposed to Python and C++ and still find
Fortran 90+ enjoyable, your statement is demonstrably false. Have you
ever used a version of Fortran past F77? The free Fortran 95 compiler
called g95 http://www.g95.org is available.



> Getting a python package working usually amounts to an install
command
> to the OS and an import command to the interpreter. Then you can get
> down to work. Getting a Fortran package working involves not only an
> endless dance with obscure compiler flags and library links, but then
a
> set of workarounds for codes that produce expected results on one
> compiler and compile failures or even different results on another.

If one writes standard-conforming code it does not. At least with
Fortran one has multiple independent implementations of an ISO
standardized language, about 10 each on Intel Windows or Linux, and 4
for Mac OS X. Links are at
http://dmoz.org/Computers/Programming/Languages/Fortran/Compilers/ . If
one Fortran compiler leaks memory when multiplying matrices, one can
use another. If Python Numarray does, the only alternative I know of is
Numeric, which is no longer supported according to
http://www.pfdubois.com/numpy/ . I have found it extremely useful to
work with multiple compilers and compiler options. A good compiler such
as Lahey/Fujitsu has debugging options that aid programmer productivity
by finding bugs, both at compile and run time, at some cost in speed. I
gave a few examples in a previous thread. The existence of such
compilers refutes your assertion that Fortran programmers think only
machine time is important.

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


Re: is this sort method the same as the one in python 2.4

2005-01-30 Thread Pedro Werneck

What about this ?


#
if sys.version_info >= (2,4):
def sorted(iterable, *args, **kwds):
seq = list(iterable)
seq.sort(*args, **kwds)
return seq
#

It worked against the TestSorted in lib/test/test_builtins.py





On Sun, 30 Jan 2005 08:30:17 +0100
"Fredrik Lundh" <[EMAIL PROTECTED]> wrote:

> Raymond Hettinger wrote:
> 
> >> I'm trying to emulate the sorted() method introduced in python 2.4. The
> >> only difference is that it takes a sequence as one of its arguments
> >> rather than being a method of the sequence class. Does my method do the
> >> same as the sorted()?
> >
> > Almost.  This is closer to the mark:
> >
> > def sorted(iterable, cmp=None, key=None, reverse=False):
> >"return a sorted copy of its input"
> >if sys.version_info >= (2,4):
> >return sorted(iterable, cmp, key, reverse)
> 
> with your code
> 
> print sorted([1, 2, 3])
> 
> gives me a traceback that ends with
> 
>   File "test.py", line 6, in sorted
> return sorted(iterable, cmp, key, reverse)
>   File "test.py", line 6, in sorted
> return sorted(iterable, cmp, key, reverse)
>   File "test.py", line 6, in sorted
> return sorted(iterable, cmp, key, reverse)
>   File "test.py", line 5, in sorted
> if sys.version_info >= (2,4):
> RuntimeError: maximum recursion depth exceeded in cmp
> 
> the recursion isn't really that hard to explain, but the runtime error doesn't
> really seem right...
> 
> :::
> 
> to fix the recursion, move the if-statement so you only define the function
> if needed:
> 
>  if sys.version_info < (2,4):
> def sorted(...):
> 
> 
>  
> 
> 
> 
> -- 
> http://mail.python.org/mailman/listinfo/python-list
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: ANNOUNCE: KirbyBase 1.7

2005-01-30 Thread Paul Rubin
Jamey Cribbs <[EMAIL PROTECTED]> writes:
> KirbyBase is a simple, plain-text, database management system written
> in Python.  It can be used either embedded in a python script or in a
> client/server, multi-user mode.  You use python code to express your
> queries instead of having to use another language such as SQL.
> KirbyBase is disk-based, not memory-based.  Database changes are
> immediately written to disk.

That's cute, especially the part about using Python expressions
instead of SQL to express queries.  I don't see anything in the info
page about what happens when you have multiple clients updating the db
concurrently.  Do you make any attempt to handle that?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: how do i create such a thing?

2005-01-30 Thread Steven Bethard
Pedro Werneck wrote:
If you need direct access to some atribute, use object.__getattribute__.
class DefaultAttr(object):
... def __init__(self,  default):
... self.default = default
... def __getattribute__(self, name):
... try:
... value = object.__getattribute__(self, name)
... except AttributeError:
... value = self.default
... return value
... 

x = DefaultAttr(99)
print x.a
99
x.a = 10
print x.a
10
Of if you only want to deal with the case where the attribute doesn't 
exist, you can use getattr, which gets called when the attribute can't 
be found anywhere else:

py> class DefaultAttr(object):
... def __init__(self, default):
... self.default = default
... def __getattr__(self, name):
... return self.default
... 
py> x = DefaultAttr(99)
py> x.a
99
py> x.a = 10
py> x.a
10
Steve
--
http://mail.python.org/mailman/listinfo/python-list


Re: pickle, cPickle, & HIGHEST_PROTOCOL

2005-01-30 Thread Tim Peters
[A.B., Khalid]
> I wonder if someone can explain what is wrong here. I am pickling a
> list of dictionaries (see code attached) and unpickling it back using
> the HIGHEST_PROTOCOL of pickle and cPickle.
...
> ... on Win98.

Pickles are binary data.  Therefore you should open pickle files in
binary mode on all platforms, and must open them in binary mode on
Windows.  That is, replace your lines:

   f = file('pkl_' + fn, 'w')
   f = file('pkl_' + fn, 'r')

with:

   f = file('pkl_' + fn, 'wb')
   f = file('pkl_' + fn, 'rb')

It's true that you can get away with opening pickle files in text mode
on Windows if you stick to the default pickle protocol (0), although
in that case your pickle files won't be portable across platforms. 
For that reason, don't try to be clever:  always use binary-mode files
to store pickles, regardless of pickle protocol in use.
-- 
http://mail.python.org/mailman/listinfo/python-list


RE: Pystone benchmark: Win vs. Linux (again)

2005-01-30 Thread Delaney, Timothy C (Timothy)
Franco Fiorese wrote:

>   * Windows XP Pro:  16566.7 pystones/second
>   * Linux (kernel 2.6.9 NPTL): 12346.2 pystones/second

First of all, realise that pystone is not meant to be a general-purpose
benchmarking program. It test a specific, *small* subset of the
functionality available in Python. It's also not meant to be able to
compare across machines, etc. It's highly susceptible to cache effects
and various other things.

If you include parrotbench you will get a better view of things, but
it's also not designed for comparisons across machines.

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


Re: is this sort method the same as the one in python 2.4

2005-01-30 Thread Raymond Hettinger
"Lowell Kirsh"
> How come you reverse the list twice? And why does this preserve stability?

It's easy to see if you trace through the steps:

Given sample the following dataset and a desire to sort on the first field:
>>> data = [('a', 1), ('a', 2), ('b', 3)]

Here are the step:
>>> data.reverse()
>>> data
[('b', 3), ('a', 2), ('a', 1)]
>>> data.sort(key=lambda record: record[0])
>>> data
[('a', 2), ('a', 1), ('b', 3)]
>>> data.reverse()
>>> data
[('b', 3), ('a', 1), ('a', 2)]

Note, in the final result, the two equal records (the ones with 'a') appear in
the same order as the original dataset (that is what stability means).

Now, try it without the initial reversal and note that stability is not
preserved:
>>> data = [('a', 1), ('a', 2), ('b', 3)]
>>> data.sort(key=lambda record: record[0])
>>> data.reverse()
>>> data
[('b', 3), ('a', 2), ('a', 1)]

Here's another way of accomplishing the original sort and preserving stability:
>>> data = [('a', 1), ('a', 2), ('b', 3)]
>>> sorted(data, cmp = lambda x,y:  cmp(y[0], x[0]))
[('b', 3), ('a', 1), ('a', 2)]



Raymond Hettinger




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


Re: ANNOUNCE: KirbyBase 1.7

2005-01-30 Thread Jamey Cribbs
Paul Rubin wrote:
That's cute, especially the part about using Python expressions
instead of SQL to express queries.  I don't see anything in the info
page about what happens when you have multiple clients updating the db
concurrently.  Do you make any attempt to handle that?
Yep.  There are two server scripts included with the distribution.  One 
(kbsimpleserver.py) does serial, blocking requests, so there are no 
concurrent-access issues.  The second server script 
(kbthreadedserver.py) is threaded and non-blocking.  I have code in the 
script that manages read and write locks for each table.  I'm no rocket 
scientist, but I have been using kbthreadedserver.py at work for several 
months with no issues so far, so I am beginning to trust the code.  :)

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


Microsoft Visual C++ and pyton

2005-01-30 Thread mike
Hi,
I am new with python.  Is it possible to have an MFC application and
develop some module using python? what are the steps in doing this? can
anybody give me a url or some documentation for this.. thanks..

mike

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


Re: is this sort method the same as the one in python 2.4

2005-01-30 Thread Raymond Hettinger
"Pedro Werneck"
>
> What about this ?
>
>
> #
> if sys.version_info >= (2,4):
> def sorted(iterable, *args, **kwds):
> seq = list(iterable)
> seq.sort(*args, **kwds)
> return seq
> #
>
> It worked against the TestSorted in lib/test/test_builtins.py

The key= and reverse= parameters were introduced to list.sort() in Py2.4.
Consequently, the above code won't provide the desired functionality in Py2.3
and prior.


Raymond Hettinger


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


Re: Regarding exception handling

2005-01-30 Thread Aggelos I. Orfanakos
Thanks. This should now be OK:

#try:
#try:
#s = ... # socket opens
#
## various code ...
#except socket.error, x:
## exception handling
#finally:
#s.close() # socket closes

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


PyGame not working(?) (was: trouble installing numeric)

2005-01-30 Thread Chris Weisiger
On 1/29/05 11:38 PM, Robert Kern  wrote:

> Chris Weisiger wrote:
>>  I'm trying to install numeric on my MacOS X box using Darwin, with 
>> the  eventual goal of satisfying all of PyGame's dependencies so I 
>> can  finally start working on my semester project. I would be using 
>> MacPython,  except that I can't seem to get its Package Manager to 
>> work.

> 
> This is fixed in CVS.
> 

Thanks; I've now successfully installed Numeric, as well as all of the 
other dependencies listed for PyGame. However, PyGame appears to still 
not be working. When I try to run the program at the top of this page: 
http://www.pygame.org/docs/tut/tom/games2.html
I get the following error: 

% python main.py
Fatal Python error: Interpreter not initialized (version mismatch?)
Abort

Is this a problem with PyGame or with something else? I can run a simple 
Hello World program, so I'm assuming that Python itself is fine. Any 
ideas?

-- 
"Don't take life so serious, son - it ain't nohow permanent." - 
Porkypine
http://www.cs.hmc.edu/~cweisige
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: type() takes one or *three* arguments!?

2005-01-30 Thread jamesthiele . usenet
Thank you - that explains everything quite nicely.

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


Re: Regarding exception handling

2005-01-30 Thread Dan Perl

"Aggelos I. Orfanakos" <[EMAIL PROTECTED]> wrote in message 
news:[EMAIL PROTECTED]
> Thanks. This should now be OK:
>
> #try:
> #try:
> #s = ... # socket opens
> #
> ## various code ...
> #except socket.error, x:
> ## exception handling
> #finally:
> #s.close() # socket closes
>

Why the nested try's?  If I understand your intention correctly this should 
do the same thing:

try:
 s = ... # socket opens
 # various code ...
except socket.error, x:
 # exception handling
s.close() # socket closes

You would need the try-finally statement only if you expect it to handle 
other exceptions than socket.error or if the socket.error is re-raised in 
the "except" clause.  Otherwise, the try-finally statement is redundant 
because no socket.error are getting out of the try-except statement.

Dan 


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


Problem with loading textfiles into dictionaries.

2005-01-30 Thread mercuryprey
Hello,
I want to do the following:

def do_load(self, arg):
sitefile = file('sitelist', 'r+', 1)
while True:
siteline = sitefile.readline()
site_rawlist = siteline.split()
sitelist[site_rawlist[0]] = site_rawlist[1:]
if len(siteline) == 0:
break

I want to load a textfile into a dictionaries and use the first word on
a line as the key for the list, then take the remaining words of the
line and make them values of the key. This doesn't work:

File "ftp.py", line 57, in do_load
sitelist[site_rawlist[0]] = site_rawlist[1:]
IndexError: list index out of range

However, it works flawlessy in another function, where I have:

def do_add(self, arg):
sitefile = file('sitelist', 'r+', 1)
act_addlist = arg.split()
sitelist[act_addlist[0]] = act_addlist[1:]
sitefile.seek(0,2)
sitefile.write(arg + "\n")
print "Written to database."

Anyone knows why it doesn't work in the first function? Help very much
appreciated.

munin

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


Re: Problem with loading textfiles into dictionaries.

2005-01-30 Thread Stephen Thorne
On 30 Jan 2005 16:43:26 -0800, [EMAIL PROTECTED]
<[EMAIL PROTECTED]> wrote:
> Hello,
> I want to do the following:
> 
> def do_load(self, arg):
> sitefile = file('sitelist', 'r+', 1)
> while True:
> siteline = sitefile.readline()
> site_rawlist = siteline.split()
> sitelist[site_rawlist[0]] = site_rawlist[1:]
> if len(siteline) == 0:
> break

maybe you would be better off doing something slightly simpler, and in
such a way that you see the input which is causing problems.

sitelist = {}
for line in file('sitelist'):
  elems = line.split()
  if len(elems) == 1:
 raise ValueError, "Invalid line in file %r" % line
  sitelist[elem[0]] = elem[1:]

:)

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


Re: Problem with loading textfiles into dictionaries.

2005-01-30 Thread M.E.Farmer
[EMAIL PROTECTED] wrote:
> Hello,
> I want to do the following:
>
> def do_load(self, arg):
> sitefile = file('sitelist', 'r+', 1)
> while True:
> siteline = sitefile.readline()
> site_rawlist = siteline.split()
> sitelist[site_rawlist[0]] = site_rawlist[1:]
> if len(siteline) == 0:
> break
>
> I want to load a textfile into a dictionaries and use the first word
on
> a line as the key for the list, then take the remaining words of the
> line and make them values of the key. This doesn't work:
>
> File "ftp.py", line 57, in do_load
> sitelist[site_rawlist[0]] = site_rawlist[1:]
> IndexError: list index out of range

Hello again Munin,
First i'll start with a spanking!
Post your code like this:(or pick your favorite starter)
Py> def do_load(self, arg):
...sitefile = file('sitelist', 'r+', 1)
...while True:
...siteline = sitefile.readline()
...site_rawlist = siteline.split()
...sitelist[site_rawlist[0]] = site_rawlist[1:]
...if len(siteline) == 0:
...break
See how much nicer that is even if the newsfeed gets mangled it comes
out ok(mostly).
If I guess right it looks like you are trying disect a line that was
empty or only had one element.
If you check for line length first you might do better.
Py> def do_load(self, arg):
...sitefile = file('sitelist', 'r+', 1)
...while True:
...if len(siteline) == 0:
...break
...siteline = sitefile.readline()
...site_rawlist = siteline.split()
...sitelist[site_rawlist[0]] = site_rawlist[1:]

Ok next thing is this smells like you really are trying to reinvent a
sort of pickle.
If you don't know search for 'python pickle module'.
examples abound but here it is anyway:
Py> import pickle
Py> # Pickle a dictionary
Py> f = open('/tmp/mydata', 'wb')
Py> f.write(pickle.dumps(yourdict)
Py> f.close()
Py> # and it is easy to get back as well
Py> f = open('tmp/mydata', rb')
Py> pdata = f.read()
Py> f.close()
Py> yourdict = pickle.load(pdata)
hth,
M.E.Farmer

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


Re: a sequence question

2005-01-30 Thread gene . tani
cookbook's not an easy grep but:

http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/303060

http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/303279
http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/347689

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


Re: Problem with loading textfiles into dictionaries.

2005-01-30 Thread Kartic
[EMAIL PROTECTED] said the following on 1/30/2005 7:43 PM:
Hello,
I want to do the following:
def do_load(self, arg):
sitefile = file('sitelist', 'r+', 1)
while True:
siteline = sitefile.readline()
site_rawlist = siteline.split()
sitelist[site_rawlist[0]] = site_rawlist[1:]
if len(siteline) == 0:
break
I want to load a textfile into a dictionaries and use the first word on
a line as the key for the list, then take the remaining words of the
line and make them values of the key. This doesn't work:
File "ftp.py", line 57, in do_load
sitelist[site_rawlist[0]] = site_rawlist[1:]
IndexError: list index out of range
Hi - It looks like your code encountered a blank line when you got this 
error.

You should move "if len(siteline) == 0" part right after your readline. 
The way you have done it really does not help.

def do_load(self, arg):
sitefile = file('sitelist', 'r+', 1)
while True:
  siteline = sitefile.readline()
  if len(siteline) == 0:
 break
  site_rawlist = siteline.split()
  sitelist[site_rawlist[0]] = site_rawlist[1:]
Thanks,
--Kartic
--
http://mail.python.org/mailman/listinfo/python-list


Re: Problem with loading textfiles into dictionaries.

2005-01-30 Thread Kartic
Kartic said the following on 1/30/2005 8:21 PM:
[EMAIL PROTECTED] said the following on 1/30/2005 7:43 PM:

Hi - It looks like your code encountered a blank line when you got this 
error.

You should move "if len(siteline) == 0" part right after your readline. 
The way you have done it really does not help.

def do_load(self, arg):
sitefile = file('sitelist', 'r+', 1)
while True:
  siteline = sitefile.readline()
  if len(siteline) == 0:
 break
  site_rawlist = siteline.split()
  sitelist[site_rawlist[0]] = site_rawlist[1:]

Sorry...siteline = sitefile.readline().strip()
--
http://mail.python.org/mailman/listinfo/python-list


Re: Help! Host is reluctant to install Python

2005-01-30 Thread gene . tani
Based on discusses with these guys, who know LAMP, python, ruby inside
and out, and support it well:

http://textdrive.com/

I'm guessing you'd have a hard time finding mod_python / apache hosting
unless you get a dedicated server.  It's pretty labor-intensive setup
and admin-wise.   linux shell / python / SSH shdn't be a big deal, tho.

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


Re: What's so funny? WAS Re: rotor replacement

2005-01-30 Thread Paul Rubin
"Martin v. Löwis" <[EMAIL PROTECTED]> writes:
> > Oh, ok.  Earlier you said you wanted user feedback before you could
> > conclude that there was reason to want an AES module at all.
> 
> I believe I never said that. I said that I wanted user feedback to
> determine whether *this* AES module (where this is either your
> from-scratch implementation, or any other specific implementation
> contributed) is desirable.

If that's what you're saying now, I'll accept it and not bother
looking for your other posts that came across much differently.

> > I had thought there were insurmountable
> > obstacles of a nontechnical nature, mainly caused by legal issues,..
> 
> These obstacles are indeed real. But I believe they are not
> unsurmountable. For example, there is the valid complaint that,
> in order to export the code from SF, we need to follow U.S.
> export laws. 10 years ago, these would have been unsurmountable.

Well, yes, 10 years ago, SF didn't exist .  But there was an ftp
site run by Michael Johnson that had some special server side checks
that made sure the client was in the USA.  That was considered good
enough to comply with the export regs, and another guy and I
distributed crypto code (a program that let you use your PC as an
encrypted voice phone) through that site in 1995.

Of course, every time my co-author and I released a new version
through the controlled ftp site, within a day or so the code somehow
managed to show up on another ftp site in Italy with worldwide access.
We (the authors) always managed to be shocked when that happened.  But
we had nothing to do with it, so it wasn't our problem.

> Today, it is still somewhat painful to comply with these laws,
> but this is what the PSF is for, which can fill out the forms
> necessary to allow exporting this code from the U.S.A.

Well, complying is painful in the sense of being morally repugnant
(people shouldn't have to notify the government in order to exercise
their free speech rights), but the actual process is pretty easy in
terms of the work required.  Python should qualify for the TSU
exception which means you just need to send an email to the BXA,
without needing to fill out any forms.  I thought that's what you had
done for the rotor module.
-- 
http://mail.python.org/mailman/listinfo/python-list


[Python-Announce] cfgparse v01_00 released

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

cfgparse can optionally cooperate with the optparse module to provide
coordination between command line and configuration file options. In
addition, the cooperation can be used to allow the user to control
features of the parser from the command line.

URLs
-
Docs/home page: http://cfgparse.sourceforge.net/
Download: http://sourceforge.net/projects/cfgparse/

Feature Summary
-
+ Simple ini style configuration syntax
+ Type checking with error handling and help messages
+ Help summary modelled after that in optparse
+ Round trip - read, modify, write configuration files with comment retention
+ Cooperates with optparse for configuration file options that should be 
overridden by command line options
+ Supports heirarchically organized option settings
* User may store multiple option settings in a arbitrarily deep
keyed dictionary.
* Application uses a key list to walk into the dictionary to
obtain a setting.
* User controls key list with setting in configuration file.
* Supports adding keys to the list through a command line option or from 
environment variables.
+ Supports allowing user control of configuration files used.
* Environment variables may be used to allow user to specify a default 
configuration file.
* Command line options to specify configuration file supported.
* Configuration files may include other configuration files where where 
sections are read in parallel.
* Configuration files may be nested heirarchically by including
configuration
files from within a section or subsection.
+ Configuration files may alternatively be written in Python.
* full power and flexibility of Python available for creation of
option settings
* allows options settings to be real Python objects
* this feature is NOT enabled by default
+ May be extended to support syntax such as XML.

Enjoy,
Dan Gass
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: The next Xah-lee post contest

2005-01-30 Thread gene . tani
Tragi-comic.  really.  BTW you forgot cross-post to c.l.scheme, C,
smalltalk and C++

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


Re: Regarding exception handling

2005-01-30 Thread Bryan
Dan Perl wrote:
"Aggelos I. Orfanakos" <[EMAIL PROTECTED]> wrote in message 
news:[EMAIL PROTECTED]

Thanks. This should now be OK:
#try:
#try:
#s = ... # socket opens
#
## various code ...
#except socket.error, x:
## exception handling
#finally:
#s.close() # socket closes

Why the nested try's?  If I understand your intention correctly this should 
do the same thing:

try:
 s = ... # socket opens
 # various code ...
except socket.error, x:
 # exception handling
s.close() # socket closes
You would need the try-finally statement only if you expect it to handle 
other exceptions than socket.error or if the socket.error is re-raised in 
the "except" clause.  Otherwise, the try-finally statement is redundant 
because no socket.error are getting out of the try-except statement.

Dan 


i always use the try/finally statement with resources, but in a slightly 
different way than the above two examples:

s = ... # socket opens
try:
# various code ...
finally:
s.close()
or, if i want to handle the socket.error if s gets successfully bound,
s = ... # socket opens
try:
try:
# various code
except socket.error e:
# exception handling
finally:
s.close()
i disagree with the statement:
"You would need the try-finally statement only if you expect it to handle other 
exceptions than socket.error or if the socket.error is re-raised in the "except" 
clause.  Otherwise, the try-finally statement is redundant because no 
socket.error are getting out of the try-except statement."

IMO, that is not the reason for the try/finally statement and it is not 
redundant.  the try/finally statement guarantees the resource is closed and the 
try/finally statement only gets executed if and only if the opening of the 
resource doesn't raise an exception.  it has nothing to do with exception handling.

in the previous 2 examples s = ... was placed inside the try/finally, but if an 
exception occures and s doesn't get bound to an object, then s.close() in both 
examples will raise a NameError on s.

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


tkSnack pitch() for frequency estimation

2005-01-30 Thread Justin Shaw
I am using the tkSnack library to estimate the frequency from a sound file.
The pitch seems to drop down an octave at 400 Hertz.  For example A~440
Hertz comes out at 220 Hertz.  When I use the maxpitch and minpitch options
to limit the response to say 380 - 460 the result is all zeros.

Any ideas on how I can estimate the pitch of a sound up to 880 Hertz (with
tkSnack or not)?

Thanks
Justin Shaw


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


Re: gmail access with python!

2005-01-30 Thread Daniel Bickett
Indeed, here is a detailed help document on GMail POP3 access:

http://gmail.google.com/support/bin/answer.py?answer=12103

huh...look at that, they're using python :) Never noticed that before.

Anyway, after that you can simply use a standard POP3 module. There's
no need to get fancy and use gmail-specific libraries, really.

-- 
Daniel Bickett
dbickett at gmail.com
http://heureusement.org/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Regarding exception handling

2005-01-30 Thread Aggelos I. Orfanakos
I need it because the "various code" may raise other exceptions (not
related to sockets). In such case, the "except socket.error, x:" won't
catch it, but thanks to the "finally:", it is sure that the socket will
close.

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


Re: Regarding exception handling

2005-01-30 Thread Aggelos I. Orfanakos
Good point, but with your way, if "s = ... # socket opens" fails, then
nothing will catch it. What I usually do is what I wrote above (place
it below the 2nd try), and when attempting to close it, first use an if
like: "if locals().has_key('s'):".

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


Re: {Spam?} Re: naive doc question

2005-01-30 Thread Skip Montanaro

>> I wanted a list of all the methods of dict for example... where can i
>> find it?

Terry> Lib Ref 2.3.8 Mapping Types.  Do browse chapter 2 so you know
Terry> what is there.

I think the best doc page to bookmark is the global module index:

http://docs.python.org/lib/modindex.html

Not only does it give you a quick index to the modules, but if you click
__builtin__ it will refer you to section 2.1.  In the dev docs (2.5a0) it
refers you to chapter 2, even better as far as I'm concerned.

With the above bookmark I don't really have to remember where much else in
the docs live.

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


Re: What's so funny? WAS Re: rotor replacement

2005-01-30 Thread Skip Montanaro

Nick> I think one of the special things about Python is its batteries
Nick> included approach, and a crypto library would seem to be an
Nick> obvious battery to install since it doesn't (or needn't) depend on
Nick> any other library or application.

Obvious for some I suppose (I've never used any).  While it might be
convenient to not have to distribute some third party library in addition to
Python, there is a fundamental problem implementing a crypto algorithm from
scratch for inclusion into Python.  There is always the problem that the new
code has to be more rigorously tested than typical code and new bugs means a
new distribution of Python, not just a replacement library.  A bug in code
that is not security-related generally means something doesn't work and only
rarely means a security hole has been opened on the computer.  A bug in
security-related code more often means the latter as well.  I'd much rather
trust a widely-disseminated piece of crypto code that is simply wrapped by
Python than one that was written expressly written for Python (and that will
likely not be exercised much outside the Python community).

I realize the sha module is incorporated this way.  It has this comment:

 * This code for the SHA algorithm was noted as public domain. The original
 * headers are pasted below.
 *
 * Several changes have been made to make it more compatible with the
 * Python environment and desired interface.

While I imagine the changes were fairly small, the guys involved are all
very smart, and the code is fairly straightforward (little, if any, memory
allocation going on), there is still the possibility that a bug lurks in
either the incorporated code or in the changes to it.  How quickly could the
Python community respond if a bug was found and fixed in the public domain
SHA code?  How much harder would it be for people to adapt if they had to
reinstall Python instead of just an external library?

Skip

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


Re: gmail access with python!

2005-01-30 Thread Mr Follower
Did you try the CVS version of libgmail? While none of the "release
versions" (i.e. up 0.0.8) currently work, as of a week ago the CVS
version handled the two recent modifications to Gmail.
--Phil. (Author libgmail)

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


next line, new line

2005-01-30 Thread rasdj
I have a lot of SQL to convert to postgres from oracle. I have most of
the problems worked out except for this last bit. Many of my tables
need the last comma replaced with a close parenthesis - they look like
this:

create table schema.table (
FLD000 NUMERIC(10,0) NOT NULL,
FLD001 CHAR(3) NOT NULL,
FLD002 DATE NOT NULL,
;

when the syntax requires:

FLD002 DATE NOT NULL)
;

I output the text in reverse thinking I could find the semicolon, go to
the next line and replace the 'comma newline' with 'closeparen newline'
and then go on to find the next semicolon.

;
FLD002 DATE NOT NULL,
FLD001 CHAR(3) NOT NULL,
FLD000 NUMERIC(10,0) NOT NULL,
create table schema.table (
;
FLD002 DATE NOT NULL,
FLD001 CHAR(3) NOT NULL,
FLD000 NUMERIC(10,0) NOT NULL,
create table schema.table2 (

I don't seem to be making any progress altho I have had some
interesting output. 

Throw me a bone?

Thank you,

RasDJ

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


Re: What's so funny? WAS Re: rotor replacement

2005-01-30 Thread Paul Rubin
Skip Montanaro <[EMAIL PROTECTED]> writes:
> While it might be convenient to not have to distribute some third
> party library in addition to Python, there is a fundamental problem
> implementing a crypto algorithm from scratch for inclusion into
> Python.  There is always the problem that the new code has to be
> more rigorously tested than typical code 

Actually and surprisingly, that's not really true.  Crypto algorithms
are pretty straightforward, so if you examine the code and check that
it passes a bunch of test vectors, you can be pretty sure it's
correct.  It's much harder to check something like a compiler, which
has a much bigger state space, far more decision points, etc.  The
usual bugs in crypto apps (and there are lots of such bugs) are in how
the primitives are used, not in the primitives themselves.  

> and new bugs means a new distribution of Python, not just a
> replacement library.

Why would that be true of a crypto module and not true of, say, the socket
module?  If the socket module has a bug that allows a remote takeover of
the application, that's as bad as a crypto bug.

> A bug in code that is not security-related generally means something
> doesn't work and only rarely means a security hole has been opened
> on the computer.  A bug in security-related code more often means
> the latter as well. 

People often don't understand that that almost all code is
security-related.  Any code that touches data that came from the
internet is security related.  If the math library arctangent function
has a buffer overflow bug triggered by a certain input number, and
someone uses math.arctan in an image viewing program, then maybe a
specially concocted image designed to set off the bug can take over
the user's computer.  So even something like math.arctan is security
related.

> While I imagine the changes were fairly small, the guys involved are
> all very smart, and the code is fairly straightforward (little, if
> any, memory allocation going on), there is still the possibility
> that a bug lurks in either the incorporated code or in the changes
> to it.  How quickly could the Python community respond if a bug was
> found and fixed in the public domain SHA code?  How much harder
> would it be for people to adapt if they had to reinstall Python
> instead of just an external library?

If they're able to install external libraries, what stops them from
reinstalling a patched sha module?

The hazards of using a crypto module are sort of like the hazards of
using the threading module.  Unless you know what you're doing and are
very careful, it's easy to make an error.  But the resulting bugs
happen because the module did exactly what you asked for, not because
it did something different from what you asked for.

If you ever write code that uses the Internet, I highly recommend the
book "Security Engineering", by Ross Anderson.  It will give you some
idea of what you are up against.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: gmail access with python!

2005-01-30 Thread Jeremy Bowers
On Sun, 30 Jan 2005 21:54:46 -0500, Daniel Bickett wrote:

> Indeed, here is a detailed help document on GMail POP3 access:
> 
> http://gmail.google.com/support/bin/answer.py?answer=12103
> 
> huh...look at that, they're using python :) Never noticed that before.

Can you expand on that for us non-GMail users? A login is required to view
that page.

(I don't care to use GMail; having your own domain still ought to out-geek
it :-).)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: next line, new line

2005-01-30 Thread Jeremy Bowers
On Sun, 30 Jan 2005 19:42:22 -0800, rasdj wrote:

> I have a lot of SQL to convert to postgres from oracle. I have most of the
> problems worked out except for this last bit. Many of my tables need the
> last comma replaced with a close parenthesis - they look like this:
> 
> create table schema.table (
> FLD000 NUMERIC(10,0) NOT NULL,
> FLD001 CHAR(3) NOT NULL,
> FLD002 DATE NOT NULL,
> ;
> 
> when the syntax requires:
> 
> FLD002 DATE NOT NULL)
> ;
> 
> I output the text in reverse thinking I could find the semicolon, go to
> the next line and replace the 'comma newline' with 'closeparen newline'
> and then go on to find the next semicolon.

You don't give a heck of a lot of details here, but the first thing that
leaps to mind is,

* Suck it all into a string, let's call it "s".
* s = s.replace(",\n;", ")\n;")
* Dump out s.

Failing that, regex can be used to allow for any whitespace, but worry
about that if this isn't enough. We can also discuss trying to stream this
operation if your SQL won't fit into memory all at once, but on modern
machines that would be a breathtaking number of table definitions that
would make me think you have other, larger problems :-)

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


Re: Fortran pros and cons (was Re: Coding style article with interesting section on white space)

2005-01-30 Thread Michael Tobis
[EMAIL PROTECTED] wrote:
> Michael Tobis wrote:

> Fortran 90/95 is more expressive than Fortran 77 in many ways, as
> described in ...
> http://www.nr.com/CiP97.pdf .
>

> ... expresses more science per
> line of code and per programming workday.

The example shown on p 10 illustrates a shorter piece of code in f90
than in f77, but it is not obviously more expressive or less complex.
Arguably the f77 code is easier to write and maintain, even though it
has more linefeeds in it, so I find the example far from compelling.

In fact, I find the f90 example impenetrable. Specifically, what does
array_copy(source,dest,n,nn) do? I note that n and nn are uninitialized
at call time. Are these outputs from array_copy(), appearing, in that
inimitable Fortran way, in the call signature?

Here it is in Python with NumArray:

b = sort(compress(less(v,200.) * greater(v,100.),m ))
result = b[(len(b)+3)//4]

I certainly think this example is competitive for whatever that's
worth. It has the added benefit of handling the case of an empty list
with a nice catchable IndexError exception.

However, if this were intended to be maintainable code I would find it
most effectively expressed something like this:

... def magthresh(vel,mag,vmin=100.,vmax=200.):
...selector = less(vel,vmax) * greater(vel,vmin)
...sortedmags = sort(compress(selector,mag))
...if len(sortedmags):
...   index = (len(sortedmags) + 3) // 4
...   return sortedmags[index]
...else:
...   raise IndexError,"No velocities in range."

mt

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


Re: test_socket.py failure

2005-01-30 Thread x2164
Steve Holden <[EMAIL PROTECTED]> wrote:
> [EMAIL PROTECTED] wrote:
> >  hi all,
> > 
> >  Linux 2.4.28
> >  Glibc 2.2.5
> >  gcc   2.95.3
> > 
> > 
> >  I'm new to Python.
> > 
> >  I've compiled Python 2.4 from tar file.
> > 
> >  When running 'make test' i'm getting a failure
> >  in test_socket.
> > 
> >  Running './python Lib/test/test_socket.py' yields:
> > 
> > 
> > ==
> > ERROR: testGetServBy (__main__.GeneralModuleTests)
> > --
> > Traceback (most recent call last):
> >   File "Lib/test/test_socket.py", line 330, in testGetServBy
> > port2 = socket.getservbyname(service)
> > error: service/proto not found
> > 
> > --
> > Ran 58 tests in 3.826s
> > 
> > 
> > 
> >  The value of 'service' was "daytime".
> > 
> >  After much hand wringing, editing, and use of 'print'
> >  statements i commented out line 330,
> >  '# port2 = socket.getservbyname(service)' and replaced it
> >  with the line 'port2 = port'.
> > 
> >  Running './python Lib/test/test_socket.py' now yields:
> > 
> > 
> > testGetServBy (__main__.GeneralModuleTests) ... ok
> >.
> >.
> >.
> > --
> > Ran 58 tests in 5.181s
> > 
> > OK
> > 
> >  
> >  Located the code for 'socket_getservbyname' in 
> >  'Modules/socketmodule.c' where the call to the glibc
> >  function 'getservbyname' is made: 
> > 
> >  Py_BEGIN_ALLOW_THREADS
> >  sp = getservbyname(name, proto);
> >  Py_END_ALLOW_THREADS
> >  if (sp == NULL) {
> >PyErr_SetString(socket_error, "service/proto not found");
> >return NULL;
> >  }
> > 
> >  
> >  The only call of socket.getservbyname that failed was when
> >  it was passed the single argument.  Since the error message
> >  "service/proto not found" seems to only be generated upon
> >  failure of gibc's 'getservbyname' could it be that 
> >  'PyArg_ParseTuple(args, "s|s:getservbyname", &name, &proto)'
> >  generates values for 'name' and/or 'proto' that cause the
> >  failure?
> > 
> >  My search for prior reports of failure at line 330 found
> >  a mention of problems at line 331.
> > 
> >  Well, at any rate, if someone could point me down the 
> >  correct path on this i would appreciate it.
> > 
> Compiling from source requires you to indicate the features that you 
> want compiled in. Without thread support, sockets din't work, so it 
> looks like you need to configure threads in. IIRC you do this by editing 
> the Modules.? file.

> regards
>   Steve

hi Steve,

Here's a cut down version of the compilation line for
socketmodule.c which contains the 'socket_getservbyname'
code:

 gcc -pthread -DNDEBUG ... 
 -c /usr/src/Python-2.4/Modules/socketmodule.c
 -o build/temp.linux-i686-2.4/socketmodule.o

Is '-pthread' the type of thread i need?

I'm still curious why only the call with one argument to
'socket.getservbyname' fails while the two other calls
which pass two arguments don't fail.

Any ideas?


pete jordan
x2164 at
mailcity com



-- 


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


Re: gmail access with python!

2005-01-30 Thread Daniel Bickett
On Jeremy Bowers wrote:
> Can you expand on that for us non-GMail users? A login is required to view
> that page.

I apologize, I wasn't aware :)

It simply outlines all of the credentials to use gmail with pop3, I'll
list it all here:

Incoming server: pop.gmail.com
Outgoing server: smtp.gmail.com

Be sure to include @gmail.com for your username.

For the incoming server (the topic at hand, if I'm not mistaken,) It
instructs you to use an SSL connection and port 995, so that is sure
to change some things.

I believe that's all.

-- 
Daniel Bickett
dbickett at gmail.com
http://heureusement.org/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: next line, new line

2005-01-30 Thread rasdj
Thanks Jeremy, something like this would work:

try:
lines = [ line.replace(",\n;", ")\n;") for line in input  ]

If I could figgure out how to:

IF ':' in line
READ next line in
lines = [ line.replace(",\n;", ")\n;") for line in input  ]
output.write(str.join('', lines))

because there are lots of "comma newline" but the only ones I want are
the ones that follow the semicolon.

RasDJ

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


python and gpl

2005-01-30 Thread John Hunter

I have a question about what it takes to trigger GPL restrictions in
python code which conditionally uses a GPL library.

Here is the context of my question.  matplotlib, which I develop, is a
plotting module which is distributed under a PSF compatible license,
and hence we avoid using GPLd code so as to not trigger the GPL
requirements.  matplotlib has rigid segregation between the front end
(plotting commands, figure objects, etc) and backends (gtk, wx, ps,
svg, etc).  The backend is chosen dynamically at runtime -- eg the
same python script could trigger the import gtk, wx, or ps, depending
an some rc settings or command line opts.

The question is: does shipping a backend which imports a module that
links with GPL code make some or all of the library GPL.  This
question is complicated, in my mind at least, by several factors.

Here are some sub-questions:

  * If a backend module somebackend does

 import somelib

where somelib is a python wrapper of GPL code, is somebackend
GPLd?

  * Assuming the answer to the above question is yes, is matplotlib
GPLd if it distributes somebackend?  I think this is a nuanced
situation because matplotlib would work just fine w/o somemodule,
and only uses somemodule's code if it is selected at runtime by
the user.  Ie, no other part of the code depends on it since it is
one of many interchangeable backends.

  * To further complicate the question, the backend in question is qt,
which is dual licensed, commercial and GPL.  The qt backend code
just needs to 'import qt', and neither the backend writer nor the
matplotlib frontend knows whether the deployed qt on the system is
commercial or GPLd.  To date, the only GPL-like backend is GTK,
which is LGPL.  Since we're only linking and not using the src,
we're protected from the GPL requirements.  With QT, which has a
pure (non L) GPL variant, the situation is less clear to me.

Thoughts, links, etc, appreciated...


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


  1   2   >