Re: lies about OOP

2004-12-21 Thread Fredrik Lundh
Paul Foley wrote:
>
>> That's because their language is derived from Serbo-Croat.
>
> No it isn't.

time to tune your "absurd humour" sensor somewhat slightly?  I thought
the next sentence was a pretty obvious giveaway:

"But both the Finns and the Swedes will tell you it's the
Norwegians who are alcoholics."

 



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


Re: How about "pure virtual methods"?

2004-12-21 Thread Fredrik Lundh
Noam Raphael wrote:

> Oh, and another thing - maybe "abstract" is a better name than 
> "notimplemented"? notimplemented 
> might suggest a method which doesn't have to be implemented - and raises 
> NotImplementedError when 
> it is called. What do you think?

what's the difference?  no, really?

 



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


Re: how to start a new process while the other ist running on

2004-12-21 Thread Fredrik Lundh
Erik Geiger wrote:

> I have a running python script (capisuit incoming.py). This script shall
> start a linux shell script. If I start this script like os.system(/paht/to
> shellscipt.sh) the python scipt waits for the exit of the shell script and
> then goes on with the rest of the python script.
>
> How to start a shell script without waiting for the exit of that shell
> script? It shall start the shell script and immediately execute the next
> python command.

if you have Python 2.4, you can use the subprocess module:

http://docs.python.org/lib/module-subprocess.html

see the spawn(P_NOWAIT) example for how to use it in your
case:

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

as others have noted, os.spawn(P_NOWAIT) can be used directly, as
can os.system("command&") (where the trailing "&" tells the shell to run
the command in the background).

subprocess is available for Python 2.2 and 2.3 as well, by the way:

http://www.lysator.liu.se/~astrand/popen5/

 



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


Re: regular expression: perl ==> python

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

> i am so use to perl's regular expression that i find it hard
> to memorize the functions in python; so i would appreciate if
> people can tell me some equivalents.
>
> 1) In perl:
> $line = "The food is under the bar in the barn.";
> if ( $line =~ /foo(.*)bar/ ) { print "got <$1>\n"; }
>
> in python, I don't know how I can do this?
> How does one capture the $1? (I know it is \1 but it is still not clear
> how I can simply print it.

in Python, the RE machinery returns match objects, which has methods
that let you dig out more information about the match.  "captured groups"
are available via the "group" method:

m = re.search(..., line)
if m:
print "got", m.group(1)

see the regex howto (or the RE chapter in the library reference) for more
information:

http://www.amk.ca/python/howto/regex/

 



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


Re: BASIC vs Python

2004-12-21 Thread Jan Dries
Andrew Dalke wrote:
Jan Dries
If you just want to play notes, you could look at MIDI.

[snip]
It's hard to compare that to the current era.  Sound
clips are much more common, it's easy to record audio,
keyboards and other specialized devices are cheap, and
there's plenty of mixer and recording software.  Were
I to have started now I would have taken a different
course and perhaps one of these newer things would have
interested me more.
The funny thing is, for me, MIDI is dead old. One of my first computers, 
back in 1986, was an Atari ST. It came equiped with a MIDI port. And the 
MIDI file format was created in those days, on Atari. The Atari also had 
a Yamaha YM2149 sound chip on it that one could mess with in the way you 
describe, and I did play with that too. But the cool thing about MIDI 
was that it came with additional stuff, such as multiple voices, and 
different timbres for different instruments. And I didn't have to bother 
with the attack-decay-sustain-release envelope in order to make my notes 
sound like notes instead of beeps. Playing with the sound chip was like 
assembler, while playing with MIDI was more like a higher level 
language. At the time I was a teenager and couldn't afford my own 
keyboard though, and the Atari didn't have a sufficiently sophisticated 
audio system for playback of MIDI files.

Back in 1995 my then girlfriend wrote a thesis on AI where she did an 
analysis of Rachmaninov's Ampico rolls in an attemt to try to extract 
characteristics from that that could be applied to any piece of music to 
make it sound more "human" than when played by a computer.
I helped her out by writing a "notes to MIDI" converter, to make the 
results of her work audible.
I seem to remember that even then we still had to rely on a keyboard or 
so to do the playback.

But nowadays even the cheapest PC comes with "multi-media" sound 
hardware, and playback of MIDI files is easy. And the nice thing for me 
to find out is that the good old file format from back in the days on 
Atari is still out there, and well supported by programs like Windows 
Media Player.
Frankly I share your sentiment and "these newer things" like sound 
clips, mixers, recording software and so have never managed to 
interested me either. But MIDI is not among those, at least not for me. 
Because of my particular background, MIDI has for about 20 years now 
been the "serious" way to playing notes. And in fact, to the best of my 
knowledge it is still the easiest way to get decent notes out of my PC. 
A while ago I bought a few software packages that enable one to enter 
notes and play them back. After trying out half a dozen of these, I 
ended rolling my own solution in just 400 lines of Python, plus a Python 
module to read/write MIDI files.

Regards,
Jan

Andrew
[EMAIL PROTECTED]
--
http://mail.python.org/mailman/listinfo/python-list


Re: win32 process name

2004-12-21 Thread Fredrik Lundh
"phil" <[EMAIL PROTECTED]> wrote:

> from win32all
> EnumProcesses gives me the pids, then
> OpenProcess(pid) gives me a handle.
> Then what?
> GetModuleFileNameEX?  It requires two handles as args
> and I can't figure out which one is the handle from OpenProcess
> and what it wants for the other one and I can't find any
> Win32 SDK docs that help.

http://msdn.microsoft.com/library/en-us/perfmon/base/getmodulefilenameex.asp

describes a function with two [in] arguments, and one [out] argument.
the first argument is the process handle, the second a module handle;
the second argument can be NULL.

> This ought to be a nobrainer. But Nooo. Its Windows.

it can be pretty tricky on other platforms too; that's why Unix programs usually
solve this by writing their PID to a file in a known location, so that other 
programs
can find them without having to resort to more or less stupid tricks.

 



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


Re: error problems for import some copora with nltk

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

>I did install the python 2.4 and nltk.
> I am trying to follow the tutorial, but I kept getting error messages
> about importing corpus as follows
>
> ===
 from nltk.corpus import gutenberg
>
> Traceback (most recent call last):
> File "", line 1, in -toplevel-
> from nltk.corpus import gutenberg
> ImportError: cannot import name gutenberg
> ===
>
> I got the data files under c:\\python24\nltk\
> Do you know why I can't get the result?
> Any help?

what happens if you import "nltk" ?   if you still get an exception, you haven't
installed nltk in a proper way; double-checking the installation instructions 
might
help.

if importing nltk works, check if there's a "\python24\nltk\corpus\gutenberg.py"
or similar file.

if both the above are try, try doing this before importing the gutenberg module:

import sys
sys.path.insert(0, "c:/python24")

 



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


Re: input record sepArator (equivalent of "$|" of perl)

2004-12-21 Thread Steve Holden
John Machin wrote:
Steven Bethard wrote:
John Machin wrote:
Nick Coghlan wrote:
[snip]

delimeter.
Hey, Terry, another varmint over here!
No, no.  He's talking about a deli-meter.  It's the metric standard
for
measuring subs and sandwiches. ;)

Nobody mention the wurst! I did once, but I think I got away with it.
Subtle distinction: A metER is a measuring device. A MetRE is a unit of
distance.
So presumably a delimetre is the equivalent of just over three foot-long 
subs? And that Monty Python pun was the wurst I've seen this weak.

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


Re: word to digit module

2004-12-21 Thread Stephen Thorne
On Wed, 22 Dec 2004 10:27:16 +0530, Gurpreet Sachdeva
<[EMAIL PROTECTED]> wrote:
> Is there any module available that converts word like 'one', 'two',
> 'three' to corresponding digits 1, 2, 3??

This seemed like an interesting problem! So I decided to solve it.

I started with 
http://www.python.org/pycon/dc2004/papers/42/ex1-C/ which allowed me
to create a nice test suite.
import num2eng
for i in range(4):
e = num2eng.num2eng(i)
if toNumber(e) != i:
print e, i, toNumber(e)

once this all important test suite was created I was able to knock up
the following script. This is tested up to 'ninty nine thousand nine
hundred and ninty nine'. It won't do 'one hundred thousand', and isn't
exceptionally agile. If I were to go any higher than 'one hundred
thousand' I would probably pull out http://dparser.sf.net/ and write a
parser.

translation = {
'and':0,
'zero':0,
'one':1,
'two':2,
'three':3,
'four':4,
'five':5,
'six':6,
'seven':7,
'eight':8,
'nine':9,
'ten':10,
'eleven':11,
'twelve':12,
'thirteen':13,
'fourteen':14,
'fifteen':15,
'sixteen':16,
'seventeen':17,
'eighteen':18,
'nineteen':19,
'twenty':20,
'thirty':30,
'forty':40,
'fifty':50,
'sixty':60,
'seventy':70,
'eighty':80,
'ninety':90,
'hundred':100,
'thousand':1000,
}

def toNumber(s):
items = s.replace(',', '').split()
numbers = [translation.get(item.strip(), -1) for item in items if
item.strip()]
if -1 in numbers:
raise ValueError("Invalid string '%s'" % (s,))

if 1000 in numbers:
idx = numbers.index(1000)
hundreds = numbers[:idx]
numbers = numbers[idx+1:] + [1000*x for x in hundreds]

if 100 in numbers:
idx = numbers.index(100)
hundreds = numbers[:idx]
numbers = numbers[idx+1:] + [100*x for x in hundreds]

return sum(numbers)

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


Re: regular expression: perl ==> python

2004-12-21 Thread Steven Bethard
[EMAIL PROTECTED] wrote:
1) In perl:
$line = "The food is under the bar in the barn.";
if ( $line =~ /foo(.*)bar/ ) { print "got <$1>\n"; }
in python, I don't know how I can do this?
I don't know Perl very well, but I believe this is more or less the 
equivalent:

>>> import re
>>> line = "The food is under the bar in the barn."
>>> matcher = re.compile(r'foo(.*)bar')
>>> match = matcher.search(line)
>>> print 'got <%s>' % match.group(1)
got 
Of course, you can do this in fewer lines if you like:
>>> print 'got <%s>' % re.search(r'foo(.*bar)', line).group(1)
got 
Steve
--
http://mail.python.org/mailman/listinfo/python-list


Re: Python To Send Emails Via Outlook Express

2004-12-21 Thread Lenard Lindstrom
[EMAIL PROTECTED] writes:

> That sound really promising. Is there any chance you could forward me a
> copy of the script. I'm still very new to Python and it would help me a
> lot.
> Thanks again
> 
> Ian

This is a simple example I have put together:

=== SimpleMAPI.py ==
# module SimpleMAPI

from ctypes import *

FLAGS = c_ulong
LHANDLE = c_ulong
LPLHANDLE = POINTER(LHANDLE)

# Return codes
SUCCESS_SUCCESS = 0
# Recipient class
MAPI_ORIG = 0
MAPI_TO = 1

NULL = c_void_p(None)

class MapiRecipDesc(Structure):
_fields_ = [('ulReserved', c_ulong),
('ulRecipClass', c_ulong),
('lpszName', c_char_p),
('lpszAddress', c_char_p),
('ulEIDSize', c_ulong),
('lpEntryID', c_void_p),
   ]
lpMapiRecipDesc = POINTER(MapiRecipDesc)

class MapiFileDesc(Structure):
_fields_ = [('ulReserved', c_ulong),
('flFlags', c_ulong),
('nPosition', c_ulong),
('lpszPathName', c_char_p),
('lpszFileName', c_char_p),
('lpFileType', c_void_p),
   ]
lpMapiFileDesc = POINTER(MapiFileDesc)

class MapiMessage(Structure):
_fields_ = [('ulReserved', c_ulong),
('lpszSubject', c_char_p),
('lpszNoteText', c_char_p),
('lpszMessageType', c_char_p),
('lpszDateReceived', c_char_p),
('lpszConversationID', c_char_p),
('flFlags', FLAGS),
('lpOriginator', lpMapiRecipDesc), # ignored?
('nRecipCount', c_ulong),
('lpRecips', lpMapiRecipDesc),
('nFileCount', c_ulong),
('lpFiles', lpMapiFileDesc),
   ]
lpMapiMessage = POINTER(MapiMessage)

MAPI = windll.mapi32

MAPISendMail=MAPI.MAPISendMail
MAPISendMail.restype = c_ulong  # Error code
MAPISendMail.argtypes = (LHANDLE,   # lhSession
 c_ulong,   # ulUIParam
 lpMapiMessage, # lpMessage
 FLAGS, # lpFlags
 c_ulong,   # ulReserved
 )

def SendMail(recipient, subject, body):
"""Post an e-mail message using Simple MAPI

recipient - string: address to send to
subject - string: subject header
body - string: message text
"""

recip = MapiRecipDesc(0, MAPI_TO, None, recipient, 0, None)
msg = MapiMessage(0, subject, body, None, None, None, 0,
  cast(NULL, lpMapiRecipDesc), 1, pointer(recip),
  0, cast(NULL, lpMapiFileDesc))
rc = MAPISendMail(0, 0, byref(msg), 0, 0)
if rc != SUCCESS_SUCCESS:
raise WindowsError, "MAPI error %i" % rc
= Example usage =
import SimpleMAPI
SimpleMAPI.SendMail("[EMAIL PROTECTED]",
"The subject line"
"This is the message content.\n")


Lenard Lindstrom
<[EMAIL PROTECTED]>

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


Re: word to digit module

2004-12-21 Thread M.E.Farmer

Gurpreet Sachdeva wrote:
> Is there any module available that converts word like 'one', 'two',
> 'three' to corresponding digits 1, 2, 3??
>
> Thanks and Regards,
> GSS


Hello,
This is not a module but is a way to do it
Hope this helps you.

# lookup example
numbers = {'zero':0,
'one':1,
'two':2,
'three':3,
'four':4,
'five':5,
'six':6,
'seven':7,
'eight':8,
'nine':9}

def getNumber(numname, numbers):
return numbers.get(numname.lower(), 'error')

print getNumber('OnE' , numbers)
print getNumber('siX' , numbers)
print getNumber('fOur' , numbers)
print getNumber('nine' , numbers)
print getNumber('SEven' , numbers)
#

M.E.Farmer

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


Re: word to digit module

2004-12-21 Thread Binu K S
Oops! That just does the opposite of what you want.
I guess you can tinker it a bit to do the reverse conversion unless
someone suggests a better module.

On Wed, 22 Dec 2004 10:41:46 +0530, Binu K S <[EMAIL PROTECTED]> wrote:
> You'll find a script here:
> http://www.python.org/pycon/dc2004/papers/42/ex1-C/
> Found it in the miscellany section at http://www.vex.net/parnassus/ (num2eng)
> 
> On Wed, 22 Dec 2004 10:27:16 +0530, Gurpreet Sachdeva
> <[EMAIL PROTECTED]> wrote:
> > Is there any module available that converts word like 'one', 'two',
> > 'three' to corresponding digits 1, 2, 3??
> >
> > Thanks and Regards,
> > GSS
> > --
> > http://mail.python.org/mailman/listinfo/python-list
> >
>
-- 
http://mail.python.org/mailman/listinfo/python-list


regular expression: perl ==> python

2004-12-21 Thread les_ander
Hi,
i am so use to perl's regular expression that i find it hard
to memorize the functions in python; so i would appreciate if
people can tell me some equivalents.

1) In perl:
$line = "The food is under the bar in the barn.";
if ( $line =~ /foo(.*)bar/ ) { print "got <$1>\n"; }

in python, I don't know how I can do this?
How does one capture the $1? (I know it is \1 but it is still not clear
how I can simply print it.
thanks

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


Re: word to digit module

2004-12-21 Thread Binu K S
You'll find a script here:
http://www.python.org/pycon/dc2004/papers/42/ex1-C/
Found it in the miscellany section at http://www.vex.net/parnassus/ (num2eng)

On Wed, 22 Dec 2004 10:27:16 +0530, Gurpreet Sachdeva
<[EMAIL PROTECTED]> wrote:
> Is there any module available that converts word like 'one', 'two',
> 'three' to corresponding digits 1, 2, 3??
> 
> Thanks and Regards,
> GSS
> --
> http://mail.python.org/mailman/listinfo/python-list
>
-- 
http://mail.python.org/mailman/listinfo/python-list


word to digit module

2004-12-21 Thread Gurpreet Sachdeva
Is there any module available that converts word like 'one', 'two',
'three' to corresponding digits 1, 2, 3??

Thanks and Regards,
GSS
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Is this a good use for lambda

2004-12-21 Thread Terry Reedy

"Alan G Isaac" <[EMAIL PROTECTED]> wrote in message 
news:[EMAIL PROTECTED]
>I need a clarification of the argument.
> Are the opponents saying that I should not be able to:

If you define 'opponent to lambda' as one who thinks such, then sure ;-).

> def compose(list_of_functions): return reduce(lambda f, g: lambda x:
> f(g(x)), list_of_functions)
>
> In a nutshell: why?
> And may I see the proposed "better" replacement for function composition.

The issue with respect to lambda is not whether composition should be 
explicit, by building on a compose2 function, or implict, by induction, but 
whether, in this case, the function that composes two functions should get 
a name like 'compose2' or be anonymous (and generically referred to by 
CPython as ''.  To me, the following is clearer to read and hardly 
takes more keystrokes:

def compose2(f, g): return lambda x: f(g(x))
def compose(*callables):return reduce(compose2, callables)

This allows independent use of compose2 and may give a better error message 
should callables include a non-callable.

But understanding either version requires knowing that composition is 
associative, so that reducing left to right with reduce() has the same 
effect as reducing right to left as did with a for loop.  Also, as written, 
both reduce versions fall into the reduce trap and fail with an empty list. 
To avoid this, add the identity function either always:

def compose(*callables): return reduce(compose2, callables, lambda x: x)

or, more efficiently, just when needed:

def compose(*callables):
if callables: return reduce(compose2, callables)
else: return lambda x: x

Terry J. Reedy



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


Re: Printing

2004-12-21 Thread Craig Ringer
On Wed, 2004-12-22 at 10:58, Jim & Joanne Collins wrote:

> I'm not using any widget or any graphics.  I've done programs in Basic for
> years and  they have all been strict data handling.  I want to convert some
> to Python
> as Windows XP doesn't like 16 bit Basic.

Ah, I see. I thought you were using something like VB, because now when
many people say BASIC without further qualification they seem to mean
VB.

> If I have a line in basic that says "print "This is a test print"" how do I
> direct that line to the printer instead of the console?  And to send an escape
> sequence with it for printer control in PCL what is the syntax/format 
> required?

I don't have a windows box to test with - well, our NT4 server, but it
doesn't have anything on the serial ports. I would think that one just:

printerport = open("lpt1","w")

but on my NT box that results in a file not found exception. lpt0 opens,
but I have no idea if it works. I did a quick google search and turned
up little, but I'm sure this has been asked before so you might want to
try a google groups search, etc.

As for PCL commands - they're just part of the text stream, nothing
interesting or special about them at all. You just need to know how to
express them as Python string literals.

Untested: The sequence &d0D (begin underline) from my HP4MV manual
might be expressed as:

'\x1b&d0D'

or

'\x1b&d%iD' % 0

The %i substitutes in the argument specified after the string. Good for
escapes that can take many values. The \x1b is the escape sequence for
the 'escape' character, same as the ^[ code some MS-DOS editors use. In
most UNIX-like string escapes \e works too, but Python doesn't appear to
accept that.

IMO if you're doing much more than trivial formatting its much easier to
use PDF. I was lucky enough never to have to fight printers that viewed
output in terms of lines and columns, and I don't plan to start now ;-)

> How does one use the operating system after importing it?  Syntax and
> commands?

help(os)

and see the Python documentation. Also note that 'import os' doesn't
import the operating system - it imports a Python module that provides
you with access to some operating system functionality.

>  What is the syntax for using COM?

I'm afraid I have no idea - I don't use windows. The names win32all and
ctypes come up a lot here. You might want to check out the archives,
ctypes docs, ActivePython docs on win32all if any, etc.

Someone who uses COM on windows might want to give him a quick summary.

> In basic I write "shell"dir c:\temp\*.*>files.tem" and it does the same as
> a dir command
> at a DOS prompt and stores it in "files.tem" for me to access later.

You don't generally need to use temporary files like that in Python.
help(os.listdir) . 

I strongly recommend you read the Python tutorial if you haven't
already, and have a browse over the documentation for some of the key
modules like os and sys. Google and Google Groups are also often very
helpful - you can use Google Groups to search comp.lang.python (this
list/newsgroup).

--
Craig Ringer

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


Re: BASIC vs Python

2004-12-21 Thread Andrew Dalke
Jan Dries
> If you just want to play notes, you could look at MIDI.

I've been thinking about how to answer this and came
to the conclusion I can't.

I was talking about my early experiences in learning
to program as a teenager in the early 1980s.  I had
fun messing around with sound, both to play songs I
had the music for and to make up sounds.

It's hard to compare that to the current era.  Sound
clips are much more common, it's easy to record audio,
keyboards and other specialized devices are cheap, and
there's plenty of mixer and recording software.  Were
I to have started now I would have taken a different
course and perhaps one of these newer things would have
interested me more.

Andrew
[EMAIL PROTECTED]

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


Re: How about "pure virtual methods"?

2004-12-21 Thread Mike Meyer
Noam Raphael <[EMAIL PROTECTED]> writes:

> The answer is that a subclass is guaranteed to have the same
> *interface* as the base class. And that's what matters.

This is false. For instance:

class A(object):
 def method(self, a):
print a

class B(A):
 def method(self, a, b):
   print a, b

B implements a different interface than A. Statically typed OO
languages either use multi-methods or disallow changing the signature
of an overridden method.

A tool to detect such cases would probably be almost as useful as the
tool you've proposed.

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


win32 process name

2004-12-21 Thread phil
I need to know if a process is running.
not just python.exe
but python.exe myapp
from win32all
EnumProcesses gives me the pids, then
OpenProcess(pid) gives me a handle.
Then what?
GetModuleFileNameEX?  It requires two handles as args
and I can't figure out which one is the handle from OpenProcess
and what it wants for the other one and I can't find any
Win32 SDK docs that help.
Or if I could figure out this function, would it even give me
the answer.
I discovered wmi.
Win32_Process returns a list of processes.
then process.Name just gives me python.exe.
But I could have python.exe running several times.
I need to know is python.exe myapp running.
In other words, the command line.
This ought to be a nobrainer. But Nooo. Its Windows.
Any help or ideas appreciated.  Thanks.
--
http://mail.python.org/mailman/listinfo/python-list


Re: embedding: forcing an interpreter to end

2004-12-21 Thread pdectm
> Is there any signal handler you can use in your C program? Maybe
signling
> yourself will get the control back to the C program and then you can
kill
> the interpreter.

Well, the app is multi-threaded, so I do have a big issue getting
control back to my C program.  I just can not seem to cleanly stop the
interpreter.  The best I could do is:

void terminateInterpreter( PyInterpreterState *interp )
{
PyGILState_STATE gilstate;
PyObject *exc;
PyThreadState *tstate;

gilstate = PyGILState_Ensure();
tstate = PyThreadState_Swap(interp->tstate);

exc = PyString_FromString("Die");
PyThreadState_SetAsyncExc(interp->tstate->thread_id, exc);
Py_DECREF(exc);

PyThreadState_Swap(tstate);
PyGILState_Release(gilstate);
}

> You have a Python port to uClinux?

Nope, not yet.  That would have been my next post :-)  I thought there
would have been much more work on cross-compiling and porting Python.
I may need to reconsider if Python is appropriate; the other
possibiities are javascript or lua.

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


Re: How about "pure virtual methods"?

2004-12-21 Thread Jp Calderone
On Wed, 22 Dec 2004 02:27:35 +0200, Noam Raphael <[EMAIL PROTECTED]> wrote:
>Jeff Shannon wrote:
> > In the context of changing an existing interface, a unit-testing 
> > scenario would mean that, instead of installing a "pure virtual" method 
> > on a base class, you'd change the unit-tests to follow the new 
> > specification, and then write code that would pass the unit tests.  If 
> > you are subclassing from a common base, then you'd only need to change 
> > the unit test for that common base class (presuming that all derived 
> > classes would run those unit tests as well).
> > 
> The problem is that I couldn't write a general unit test, since the base 
> class wasn't instantiable - there wasn't even any point in making it 
> instantiable, since every subclass was constructed with different 
> argument definition. They were just required to provide some methods 
> (check whether they contain an object, for example) - I don't know how 
> to write a unit test for such a base class, or what does it mean. (Well, 
> it may mean: check whether all the required methods exist, but come on - 
> that's exactly the idea of my suggestion. There's no point in having to 
> write the list of required methods another time).

  from harness import TestCase

  class FoobarTestCase(TestCase):
  def instanceFactory(self):
  raise NotImplementedError()

  def testBazMethod(self):
  inst = self.instanceFactory()
  self.assertEquals(inst.baz(), 'baz')
  ...

  class QuuxTestCase(FoobarTestCase):
  def instanceFactory(self):
  return Quux(x=y, a=b)

  class WibbleTestCase(FoobarTestCase):
  def instanceFactory(self):
  return Wibble(1, 2, 3)

  This lets you avoid duplicate test code as well as easily test
new concrete implementations.  It's an ideal approach for frameworks
which mandate application-level implementations of a particular 
interface and want to ease the application developer's task.

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


Fw: Printing

2004-12-21 Thread Jim & Joanne Collins


 Craig,

 Thank you very much for your response.  I've interspersed my questions in
 your reply.

 If you have answers to my question I would be extremely gratefull for your
 assistance!

 Thanks.

 Jim Collins

 - Original Message - 
> From: "Craig Ringer" <[EMAIL PROTECTED]>
> To: "Jim & Joanne Collins" <[EMAIL PROTECTED]>
> Cc: <[EMAIL PROTECTED]>
> Sent: Monday, December 20, 2004 11:34 PM
> Subject: Re: Printing
>
>
> > On Tue, 2004-12-21 at 06:45, Jim & Joanne Collins wrote:
 > > I've completed a semester of computer programming in Python and one
 > > thing we didn't learn was how to send data to a windows printer
 > > instead of the screen.
 >
 > It would be helpful to know what graphical toolkit and canvas widget you
 > are using, as this may well be significant.

I'm not using any widget or any graphics.  I've done programs in Basic for
years and  they have all been strict data handling.  I want to convert some
to Python
as Windows XP doesn't like 16 bit Basic.

 If I have a line in basic that says "print "This is a test print"" how do I
direct that line to the printer
instead of the console?  And to send an escape sequence with it for printer
control in PCL
what is the syntax/format required?

 > > Any help would be greatly appreciated!
> >
> > My usual approach is actually to generate a PDF document using ReportLab
> > and send that to the printer. Under *nix this is easy - if available,
> > CUPS can handle PDF directly, or you use acroread -toPostScript to
> > generate postscript and send that. Under Windows, I expect you can use
> > COM to call acrobat if there isn't a simpler method.
> >
> > If you're using an existing canvas widget for your drawing, it depends
> > on the canvas widget. Some can be saved to a bitmap, some can save
> > vector data, etc.
> >
> > If you could explain how you're doing your screen drawing, that would
> > help a lot.

No screen drawing - no graphics - just data and printer controls.

> > Also, is there any way to send a shell command to access some function
> > of the basic windows operating system such as sort?
> >
> > import os

How does one use the operating system after importing it?  Syntax and
commands?

> > help(os.system)
> > help(os.popen)
> >
> > for more advanced use, COM is an option.

 What is the syntax for using COM?

> > > Or to do a DOS directory and send it directly to a file to be accessed
> > > as needed?
> >
> > I'm afraid I just don't understand that. "Do" a DOS directory?  If you
> > want to list the contents of a directory, see help(os.listdir) .

 In basic I write "shell"dir c:\temp\*.*>files.tem" and it does the same as
a dir command
at a DOS prompt and stores it in "files.tem" for me to access later.
 --
> > Craig Ringer
> >
>

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


RE: error problems for import some copora with nltk

2004-12-21 Thread Tony Meyer
> I am trying to follow the tutorial, but I kept getting error messages
> about importing corpus as follows
> 
> ===
> >>> from nltk.corpus import gutenberg
> 
> Traceback (most recent call last):
> File "", line 1, in -toplevel-
> from nltk.corpus import gutenberg
> ImportError: cannot import name gutenberg
> ===
> 
> I got the data files under c:\\python24\nltk\

Have you imported nltk before that line?  Try this:

Python 2.3.4 (#53, May 25 2004, 21:17:02) [MSC v.1200 32 bit (Intel)] on
win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import nltk
>>> from nltk.corpus import gutenberg

I suspect you may be doing this:

Python 2.3.4 (#53, May 25 2004, 21:17:02) [MSC v.1200 32 bit (Intel)] on
win32
Type "help", "copyright", "credits" or "license" for more information.
>>> from nltk.corpus import gutenburg
Traceback (most recent call last):
  File "", line 1, in ?
ImportError: cannot import name gutenburg

Note that if the corpus can't be found, you can still do the import (just
not use the corpus).

=Tony.Meyer

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


Re: Best GUI for small-scale accounting app?

2004-12-21 Thread Ed Leafe
On Dec 21, 2004, at 7:42 PM, Bulba! wrote:
This advice of yours (thanks) may have "slashdotted" your site by
flood of requests from Python programmers all looking at your
website. ;-)
"Proxy Error
The proxy server received an invalid response from an upstream server.
The proxy server could not handle the request GET /."
	Nah, it was my own doing. I was changing some things on the server, 
and you must have hit the site just when I was restarting Zope. Try it 
again.

 ___/
/
   __/
  /
 /
 Ed Leafe
 http://leafe.com/
 http://dabodev.com/
--
http://mail.python.org/mailman/listinfo/python-list


Re: Tabnanny really useful?

2004-12-21 Thread Mike Meyer
"Yet Another Mike" <[EMAIL PROTECTED]> writes:

> I'm told Tabnanny was inspired by lint, the Unix utiltity to check C sources 
> (and probably others).  Lint was primarily useful in days long ago when CPUs 
> were slow and a compile used a significant amount of resources. In a 
> multiuser environment (we ran an Intel 286 in multiuser mode!!), the 
> compiles could bring everyone else to a crawl. Lint was used because it was 
> a less-CPU intensive way to catch bonehead errors and fix them before using 
> precious compile time.

Originally, lint caught errors the C compiler didn't flag as
errors. For example:

int *main = { . } ;

The C compiler would build and link that just fine on v7. lint would
complain about it. Of course, if you used the right ints to fill the
array, it would produce a valid executable.

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


Re: expression form of one-to-many dict?

2004-12-21 Thread Mike Meyer
[EMAIL PROTECTED] (Alex Martelli) writes:

> Mike Meyer <[EMAIL PROTECTED]> wrote:
>
>> [EMAIL PROTECTED] (Bengt Richter) writes:
>> 
>> > On Sun, 19 Dec 2004 21:29:27 +0100, "Fredrik Lundh"
> <[EMAIL PROTECTED]> wrote:
>> > (or maybe a restricted unquote_arg function for better safety).
>> > E.g., double back-tick is a syntax error now, so you could write
>> >
>> > def ternary(c, ``t, ``f):
>> > if c: return eval(t)
>> > else: return eval(f)
>> 
>> Actually, I think it would be more pythonic if the indication of
>> non-evaluation happened at the function invocation instead of the
>> function definition. Having it at the function definition makes it
>
> As in, say, calling
> x = ternary(c, lambda:t, lambda:f)
> ?  The 'lambda:' is a (not nice-looking, but...) "indication of
> non-evaluation"... or am I misundertanding what you're saying?

No, you're saying it exactly right. And that does, indeed, do the
trick. Just a bit ugly is all.

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


Re: BASIC vs Python

2004-12-21 Thread Mike Meyer
Leif K-Brooks <[EMAIL PROTECTED]> writes:

> Mike Meyer wrote:
>> They do have a first-class function-like object called an agent. But
>> to use a standard method as an agent, you have to wrap it.
>
> Just curious, but how does a method get wrapped in an agent if methods
> aren't first-class objects? Subclassing the agent base class with a
> new run method or something?

No, an  agent deals with the method. All you can do with methods are
invoke them, are wrap them as agents. No assignment or creation of
subobjects of the function or anything like that.

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


error problems for import some copora with nltk

2004-12-21 Thread [EMAIL PROTECTED]
I did install the python 2.4 and nltk.
I am trying to follow the tutorial, but I kept getting error messages
about importing corpus as follows

===
>>> from nltk.corpus import gutenberg

Traceback (most recent call last):
File "", line 1, in -toplevel-
from nltk.corpus import gutenberg
ImportError: cannot import name gutenberg
===

I got the data files under c:\\python24\nltk\
Do you know why I can't get the result?
Any help?

Thanks in advance,

Kyung in Texas

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


Re: input record sepArator (not sepErator)

2004-12-21 Thread Terry Reedy

"Fredrik Lundh" <[EMAIL PROTECTED]> wrote in message 
news:[EMAIL PROTECTED]
> Terry Reedy wrote:
>
>> My gripe for the day, just to let non-native writers know what not to 
>> imitate.
>
> are there any non-native languages where separate are spelled seperate?

If you are asking whether there is any European language where the cognate 
is spelled with root 'per' instead of 'par', the answer is that I don't 
know.  What is not to imitate is the frequent misspelling on this and, 
according to Peter, other programming language groups and lists.  The 
frequency of misspelling is so high for this particular word that several 
years ago *I* consulted a dictionary to be sure of its correct spelling, so 
I can imagine others being fooled also.

Terry J. Reedy



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


Re: Boo who? (was Re: newbie question)

2004-12-21 Thread Terry Reedy

"Luis M. Gonzalez" <[EMAIL PROTECTED]> wrote in message 
news:[EMAIL PROTECTED]

> Terry Reedy wrote:

In response to a claim (I presume by LG and snipped by LG) that Boo is as 
related to Python as PyPy or Stackless, I wrote.

>> but I think this is silly.

The 'this' that I referred to as silly was the equality part of the claim, 
not that that Boo has *some* relation to Python.  I tried to explain by 
continuing ...

>>  PyPy is an alternate implementation of Python,
>> not a different language.  Stackless is a compiled extension, like many
>> others, that works with the standard implementation or maybe still a
>> minor modification thereof.

> you're right, but what when I say "python related", I mean that it has
> something or a lot in common with python,

I did not and do not dispute that Boo has some (lesser) degree of 
relatedness.  I continued by suggesting that it was about the same as for 
Prothon.  That there are differences in degree of relatedness was my point.

Nor did I or would I claim that the lesser degree of either is so low that 
neither should ever mentioned here.

Terry J. Reedy



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


Re: how to start a new process while the other ist running on

2004-12-21 Thread Jean Brouwers


See the os. spawn* functions.  For example

  os.spawnv(os.P_NOWAIT, /path/to/script, args)

/Jean Brouwers



In article <[EMAIL PROTECTED]>, Erik Geiger <[EMAIL PROTECTED]>
wrote:

> Hi,
> 
> sorry, my english ist not that got but I'll try.
> 
> I have a running python script (capisuit incoming.py). This script shall
> start a linux shell script. If I start this script like os.system(/paht/to
> shellscipt.sh) the python scipt waits for the exit of the shell script and
> then goes on with the rest of the python script.
> 
> How to start a shell script without waiting for the exit of that shell
> script? It shall start the shell script and immediately execute the next
> python command.
> 
> Thanks for any hints
> 
> Erik
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: how to start a new process while the other ist running on

2004-12-21 Thread Harlin Seritt
Quickie:

os.system("/path/to/script.sh &")

More elegant, have a look at threads


Harlin Seritt

Erik Geiger wrote:

> Hi,
> 
> sorry, my english ist not that got but I'll try.
> 
> I have a running python script (capisuit incoming.py). This script shall
> start a linux shell script. If I start this script like os.system(/paht/to
> shellscipt.sh) the python scipt waits for the exit of the shell script and
> then goes on with the rest of the python script.
> 
> How to start a shell script without waiting for the exit of that shell
> script? It shall start the shell script and immediately execute the next
> python command.
> 
> Thanks for any hints
> 
> Erik


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


Re: How about "pure virtual methods"?

2004-12-21 Thread Noam Raphael
Scott David Daniels wrote:
class Abstract(object):
'''A class to stick anywhere in an inheritance chain'''
__metaclass__ = MustImplement
def notimplemented(method):
'''A decorator for those who prefer the parameters declared.'''
return NotImplemented
I just wanted to say that I thought of notimplemented as a class, that 
would save a reference to the functions it got in the constructor. In 
that way pydoc and his friends would be able to find the arguments the 
method was expected to get, and its documentation string.

But it's a great implementation.
Noam
Oh, and another thing - maybe "abstract" is a better name than 
"notimplemented"? notimplemented might suggest a method which doesn't 
have to be implemented - and raises NotImplementedError when it is 
called. What do you think?
--
http://mail.python.org/mailman/listinfo/python-list


Re: sql server support from linux

2004-12-21 Thread Simon Wittber
> If you can get the DB-API wrappers running on Win2k, how about doing that 
> locally and then
> writing a quickie socket server which your linux client can connect to?

That is, essentially, exactly what I have done.

I've exposed the DB API using Pyro. I had to turn multithreading off,
as the server leaked memory on every query. (The MSSQL module claims a
threadsafety of 3 so I guess something in my code, or Pyro, is
leaking).

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


RE: sql server support from linux

2004-12-21 Thread Robert Brewer
Simon Wittber wrote:
> I am currently tasked with connecting Python CGI programs, under
> Apache2 / Linux, to SQL Server on Windows 2000.
> ...
> Does anyone in this list ever connect to SQL Server from Linux, using
> Python? If so, what is your solution?

If you can get the DB-API wrappers running on Win2k, how about doing that 
locally and then writing a quickie socket server which your linux client can 
connect to?


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


how to start a new process while the other ist running on

2004-12-21 Thread Erik Geiger
Hi,

sorry, my english ist not that got but I'll try.

I have a running python script (capisuit incoming.py). This script shall
start a linux shell script. If I start this script like os.system(/paht/to
shellscipt.sh) the python scipt waits for the exit of the shell script and
then goes on with the rest of the python script.

How to start a shell script without waiting for the exit of that shell
script? It shall start the shell script and immediately execute the next
python command.

Thanks for any hints

Erik
-- 
Jemanden wie ein rohes Ei zu behandeln kann auch bedeuten, ihn in die Pfanne
zu hauen.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Best GUI for small-scale accounting app?

2004-12-21 Thread Bulba!
On Tue, 21 Dec 2004 16:20:48 -0500, Ed Leafe <[EMAIL PROTECTED]> wrote:


>   You might want to check out Dabo, an application framework of which I 
>am one of the authors. We use wxPython as our UI toolkit, but have 
>streamlined the programming of the UI. We've also added data binding, 
>making developing apps that need to work with a database much, much 
>simpler.

This advice of yours (thanks) may have "slashdotted" your site by
flood of requests from Python programmers all looking at your 
website. ;-)

"Proxy Error

The proxy server received an invalid response from an upstream server.
The proxy server could not handle the request GET /."





--
It's a man's life in a Python Programming Association.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: What is on-topic for the python list [was "Re: BASIC vs Python"]

2004-12-21 Thread Aahz
In article <[EMAIL PROTECTED]>,
Erik Max Francis  <[EMAIL PROTECTED]> wrote:
>Doug Holton wrote:
>>
>> I'm not going to dignify that or the rest of your note with a response.
>
>Please stop dignifying the whole group, then.

Seconded.  This is an extremely undignified newsgroup.
-- 
Aahz ([EMAIL PROTECTED])   <*> http://www.pythoncraft.com/

"19. A language that doesn't affect the way you think about programming,
is not worth knowing."  --Alan Perlis
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How about "pure virtual methods"?

2004-12-21 Thread Noam Raphael
Jeff Shannon wrote:
Except that unit tests should be written to the *specification*, not the 
implementation.  In other words, forgetting a complete method would 
require that you forget to write the method, *and* that you failed to 
translate the specification into unit tests *for that same method*.
You are absolutely right - but when you are not that tidy, and don't 
have a written specification apart from the code, it would be natural to 
go over each method in the class definition, and write a test to check 
if it does what it should. I'm not saying that it's the ideal way, but 
it is not that bad, usually.

In the context of changing an existing interface, a unit-testing 
scenario would mean that, instead of installing a "pure virtual" method 
on a base class, you'd change the unit-tests to follow the new 
specification, and then write code that would pass the unit tests.  If 
you are subclassing from a common base, then you'd only need to change 
the unit test for that common base class (presuming that all derived 
classes would run those unit tests as well).

The problem is that I couldn't write a general unit test, since the base 
class wasn't instantiable - there wasn't even any point in making it 
instantiable, since every subclass was constructed with different 
argument definition. They were just required to provide some methods 
(check whether they contain an object, for example) - I don't know how 
to write a unit test for such a base class, or what does it mean. (Well, 
it may mean: check whether all the required methods exist, but come on - 
that's exactly the idea of my suggestion. There's no point in having to 
write the list of required methods another time).

Jeff Shannon
Technician/Programmer
Credit International
Thanks for your comment. You're welcomed to reply if you don't agree.
Noam
--
http://mail.python.org/mailman/listinfo/python-list


Re: File locking is impossible in Windows?

2004-12-21 Thread Roger Upole
I get

The process cannot access the file because another process has locked a
portion of the file.
0 file(s) copied.

on both Win2k and WinXP.  (Python 2.4, Pywin32 build 203)
Are you sure the log.txt you're copying to is actually the right one ?  You
should at least get a
prompt to confirm overwrite on the command line.

  Roger



"Pekka Niiranen" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
> Hi,
>
> I have used the following example from win32 extensions:
>
> -SCRIPT STARTS
>
> import win32file
> import win32con
> import win32security
> import pywintypes
>
> class Flock:
>  def __init__(self,file):
> self.file=file
> secur_att = win32security.SECURITY_ATTRIBUTES()
> secur_att.Initialize()
> self.highbits=-0x7fff
> self.hfile=win32file.CreateFile( self.file,\
> win32con.GENERIC_READ|win32con.GENERIC_WRITE,\
> win32con.FILE_SHARE_READ|win32con.FILE_SHARE_WRITE,\
> secur_att, win32con.OPEN_ALWAYS,\
> win32con.FILE_ATTRIBUTE_NORMAL , 0 )
> def lock(self):
> lock_flags=win32con.LOCKFILE_EXCLUSIVE_LOCK|\
> win32con.LOCKFILE_FAIL_IMMEDIATELY
> self.ov=pywintypes.OVERLAPPED()
> win32file.LockFileEx(self.hfile,lock_flags,0,\
> self.highbits,self.ov)
> def unlock(self):
> win32file.UnlockFileEx(self.hfile,0,\
> self.highbits,self.ov)
> self.hfile.Close()
>
> if __name__ == '__main__':
> from time import time, strftime, localtime
> import sys
>
> l=Flock("e:log.txt")
> print 'calling lock'
> l.lock()
> print "Now locked.  Hit enter to release lock."
> dummy = sys.stdin.readline()
>
> l.unlock()
> print 'now unlocked'
>
> -SCRIPT ENDS
>
> If I start one python process from dos window I get message:
>
> E:\>python lockker.py
> calling lock
> Now locked.  Hit enter to release lock.
>
> All well, now if
>
> 1) I start another Dos -shell and run the same command I get:
>
> E:\>python lockker.py
> calling lock
> Traceback (most recent call last):
>   File "lockker.py", line 35, in ?
> l.lock()
>   File "lockker.py", line 23, in lock
>win32file.LockFileEx(self.hfile,lock_flags,0,\
>self.highbits,self.ov)
> pywintypes.error: (33, 'LockFileEx',\
> 'The process cannot access the file because\
> another process has locked a portion of  the file.')
>
> Which is correct.
>
> 2) I try to read the contents of the file from Dos -shell, I get:
> E:\>type log.txt
> The process cannot access the file because another\
> process has locked a portion of the file.
>
> This is correct.
>
> 3) When I open the file into notepad.exe I can edit the screen
> but not write changes to disk. Correct again!
>
> 4) I cannot delete the file from Dos shell or from W2K explorer
> which is correct.
>
> 5) However, I can overwrite the file over with:
> E:\>copy d:\log.txt log.txt
>  1 file(s) copied.
>
> Which is WRONG as is me being able to copy another file over it
> with W2K explorer too.
>
>
> Is there a way around this? How can I stop file being COPIED OVER while
> it is being open? Is this window's feature? Is readlines() operation
> "atomic" enough for me not to worry about these issues?
>
> My python script modifies set of files from a directory one by one.
> I try to lock them all exclusively for the script
> until all are modified. If one of the files gets overwritten
> by another version (by another process) the script may fail.
>
> -pekka-
>
>
>
>
>
>
>




---== Posted via Newsfeed.Com - Uncensored Usenet News ==--
   http://www.newsfeed.com   The #1 Newsgroup Service in the World!
-= Over 100,000 Newsgroups - Unlimited Fast Downloads - 19 Servers =-
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How about "pure virtual methods"?

2004-12-21 Thread Noam Raphael
My long post gives all the philosophy, but I'll give here the short answers.
Mike Meyer wrote:
+0
Python doesn't use classes for typing. As Alex Martelli puts it,
Python uses protocols. So the client expecting a concrete subclass of
your abstract class may get an instantiation of a class that doesn't
inherit from the abstract class at all.
That's right - this mechanism is useful mostly for he who implements 
that class, to make sure that he implemented all that is needed to be 
assigned the title "a subclass of that class".

Or maybe the subclass is only going to use a subset of the features of
the abstract class, and the author knows that sum deferred methods
won't be invoked. The correct behavior in this case would be to allow
the subclass to be instantiated, and then get a runtime error if one
of the features the author thought he could skip was actually called.
I disagree - my reasoning is that a subclass must implement the complete 
interface of its base class (see my long post). The author may implement 
a class which defines only a part of the interface, and give it to the 
function, and it may work and be great. But it must not be called "an 
instance of the abstract class".

Finally, in a sufficiently complex class hierarchy, this still leaves
you wondering through the hierarchy trying to find the appropriate
parent class that tagged this method as unimplemented, and then
figuring out which class should have implemented it - as possibly a
parent of the class whose instantiation failed is the subclass that
should have made this method concrete.
You are right - but I needed this for a class hierarchy of only two 
levels (the base abstract class and the concrete subclasses), so there 
were not many classes to blame for a missing method.
   I hope this seems reasonable,
Noam
--
http://mail.python.org/mailman/listinfo/python-list


Re: input record sepArator (equivalent of "$|" of perl)

2004-12-21 Thread Brian van den Broek
John Machin said unto the world upon 2004-12-21 18:20:
Subtle distinction: A metER is a measuring device. A MetRE is a unit of
distance.
Not everyone agrees . I do, 
but then I think it ought be spelled 'colour', too.

Best,
Brian vdB
--
http://mail.python.org/mailman/listinfo/python-list


Re: How about "pure virtual methods"?

2004-12-21 Thread Jeff Shannon
Noam Raphael wrote:
But what about the unit tests? They would have still reported a 
success - where of course they shouldn't have; my classes, in this 
stage, didn't do what they were expected to do. This problem might 
arise even when not changing the interface at all - it's quite easy to 
write a class which, by mistake, doesn't implement all the interface. 
Its successful unit tests may check every single line of code of that 
class, but a complete method was simply forgotten, and you wouldn't 
notice it until you try the class in the larger framework (and, as I 
understand, the point of unit testing is to test the class on its own, 
before integrating it).

Except that unit tests should be written to the *specification*, not the 
implementation.  In other words, forgetting a complete method would 
require that you forget to write the method, *and* that you failed to 
translate the specification into unit tests *for that same method*. 

In the context of changing an existing interface, a unit-testing 
scenario would mean that, instead of installing a "pure virtual" method 
on a base class, you'd change the unit-tests to follow the new 
specification, and then write code that would pass the unit tests.  If 
you are subclassing from a common base, then you'd only need to change 
the unit test for that common base class (presuming that all derived 
classes would run those unit tests as well).

Jeff Shannon
Technician/Programmer
Credit International


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


Re: How about "pure virtual methods"?

2004-12-21 Thread Noam Raphael
Steve Holden wrote:
Even if you can do it, how would you then implement a class hierarchy 
where the ultimate base class had virtual methods, and you wanted to 
derive from that class another class, to be used as a base class for 
usable classes, which implemented only a subset of the virtual methods, 
leaving the others to be implemented by the ultimate subclasses?

What I suggest is that only *instantiation* would be forbidden. You are 
free to make a subclass which defines only some of the abstract methods, 
and to subclass the subclass and define the rest. You would only be able 
to make instances of the subclass of the subclass, but that's ok.

See Scott's implementation - the test at the end does exactly this.
I hope this helped,
Noam
--
http://mail.python.org/mailman/listinfo/python-list


Re: input record sepArator (equivalent of "$|" of perl)

2004-12-21 Thread Jeff Shannon
John Machin wrote:
Subtle distinction: A metER is a measuring device. A MetRE is a unit of
distance.
 

... except in the US, where we stubbornly apply the same spelling to 
both of those.  (It figures that we Americans just ignore subtle 
distinctions)

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


Re: How about "pure virtual methods"?

2004-12-21 Thread Noam Raphael
Thank you all, especially Alex for your enlightening discussion, and 
Scott for your implementation. I'm sorry that I can't be involved in a 
daily manner - but I did read all of the posts in this thread. They 
helped me understand the situation better, and convinced me that indeed 
this feature is needed. Let's see if I can convince you too.

First, the actual situation in which I stood, which made me think, "I 
would like to declare a method as not implemented, so that subclasses 
would have to implement it."

I wrote a system in which objects had to interact between themselves. In 
my design, all those objects had to implement a few methods for the 
interaction to work. So I wrote a base class for all those objects, with 
a few methods which the subclasses had to implement. I think it's good, 
for *me*, to have an explicit list of what should be implemented, so 
that when (in a function) I expect to get an object of this kind I know 
what I may and may not do with it.

Then, I wrote the classes themselves. And I wrote unit tests for them. 
(Ok, I lie. I didn't. But I should have!) Afterwards, I decided that I 
needed all my objects of that kind to supply another method. So I added 
another "raise NotImplementedError" method to the base class. But what 
about the unit tests? They would have still reported a success - where 
of course they shouldn't have; my classes, in this stage, didn't do what 
they were expected to do. This problem might arise even when not 
changing the interface at all - it's quite easy to write a class which, 
by mistake, doesn't implement all the interface. Its successful unit 
tests may check every single line of code of that class, but a complete 
method was simply forgotten, and you wouldn't notice it until you try 
the class in the larger framework (and, as I understand, the point of 
unit testing is to test the class on its own, before integrating it).

Ok. This was the practical reason why this is needed. Please note that I 
didn't use "isinstance" even once - all my functions used the 
*interface* of the objects they got. I needed the extra checking for 
myself - if someone wanted to implement a class that wouldn't inherit 
from my base class, but would nevertheless implement the required 
interface, he was free to do it, and it would have worked fine with the 
framework I wrote.

Now for the "theoretical" reason why this is needed. My reasoning is 
based on the existence of "isinstance" in Python. Well, what is the 
purpose of isinstance? I claim that it doesn't test if an object *is* of 
a given type. If that would have been its purpose, it would have checked 
whether type(obj) == something. Rather, it checks whether an object is a 
subclass of a given type. Why should we want such a function? A subclass 
may do a completely different thing from what the original class did! 
The answer is that a subclass is guaranteed to have the same *interface* 
as the base class. And that's what matters.

So I conclude that a subclass, in Python, must implement the interface 
of its parent class. Usually, this is obvious - there's no way for a 
subclass not to implement the interface of its parent class, simply 
because it can only override methods, but can't remove methods. But what 
shall we do if the some methods in the base class consist *only* of an 
interface? Can we implement only a part of the interface, and claim that 
instances of that class are instances of the original class, in the 
"isinstance" fashion? My answer is no. The whole point of "isinstance" 
is to check whether an instance implements an interface. If it doesn't - 
what is the meaning of the True that isinstance returns? So we should 
simply not allow instances of such classes.

You might say that abstract classes at the base of the hierarchy are 
"not Pythonic". But they are in Python already - the class basestring is 
exactly that. It is an uninstantiable class, which is there only so that 
you would be able to do isinstance(x, basestring). Classes with 
"notimplemented" methods would behave in exactly the same way - you 
wouldn't be able to instantiate them, just to subclass them (and to 
check, using isinstance, whether they implement the required protocol, 
which I agree that wouldn't be Pythonic, probably).

Ok. This is why I think this feature fits Python like a glove to a hand. 
Please post your comments on this! I apologize now - I may not be able 
to reply in the next few days. But I will read them at the end, and I 
will try to answer.

Have a good day,
Noam
--
http://mail.python.org/mailman/listinfo/python-list


Re: What is on-topic for the python list [was "Re: BASIC vs Python"]

2004-12-21 Thread Doug Holton
Reinhold Birkenfeld wrote:
Non sequitur. The phrase's interpretation depends on the posting(s) it
refers to.
Exactly.  He was saying boo (and/or I) am offensive, but logo is not. 
And then he apologized for misleading me to believe he was censuring me 
instead of flaming me.
--
http://mail.python.org/mailman/listinfo/python-list


Re: What is on-topic for the python list [was "Re: BASIC vs Python"]

2004-12-21 Thread Doug Holton
Hans Nowak wrote:
 > The discussion with Logo and other languages in it was off-topic too,
 > but it wasn't offensive to anyone.
I'm not going to dignify that or the rest of your note with a response.

No, by all means, let's ignore any pieces of a post that might lead to 
constructive discussion.

Well, it's been fun, but I really don't have time for this.  If we 
cannot end this thread with some kind of mutual understanding, then I 
will end it unilaterally.  You have the dubious honor of being the first 
person in my killfile since 1997.

You've yet again confirmed that your only point in this whole thread was 
to be disrepectful and complain about what offends you.  And you end it 
with yet more parting insults.  If you had better articulated what you 
really meant at the beginning, I never would have responded to you.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Python To Send Emails Via Outlook Express

2004-12-21 Thread ian
That sound really promising. Is there any chance you could forward me a
copy of the script. I'm still very new to Python and it would help me a
lot.
Thanks again

Ian

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


Re: What is on-topic for the python list [was "Re: BASIC vs Python"]

2004-12-21 Thread Hans Nowak
Doug Holton wrote:
Hans Nowak wrote:
Quote:
"this is comp.lang.python, not comp.lang.boo."

Which is obviously not the same as "Boo should not be mentioned on 
this newsgroup".  
I used the exact same phrase in another note except using the term 
"logo" instead of "boo", and that is the exact interpretation I 
immediately received from others - they felt I was censuring the 
discussion here, as I felt you were.
Maybe they felt that way because, in your case, it was followed by the 
innocent little sentence "Please refrain from discussing topics not 
related to CPython."?

 > The discussion with Logo and other languages in it was off-topic too,
 > but it wasn't offensive to anyone.
I'm not going to dignify that or the rest of your note with a response.
No, by all means, let's ignore any pieces of a post that might lead to 
constructive discussion.

Well, it's been fun, but I really don't have time for this.  If we 
cannot end this thread with some kind of mutual understanding, then I 
will end it unilaterally.  You have the dubious honor of being the first 
person in my killfile since 1997.

--
Hans Nowak
http://zephyrfalcon.org/
--
http://mail.python.org/mailman/listinfo/python-list


Re: BASIC vs Python

2004-12-21 Thread Alan Gauld
On Tue, 21 Dec 2004 16:26:57 GMT, Scott Robinson
<[EMAIL PROTECTED]> wrote:
Speaking of Forth...
> was making the point it would be good for general purpose.  I suspect
> that it would quickly run up against memory limitations and would go
> no faster than the machine driving the memory market (with a possible
> last gasp when Rambus came online).

I dunno. Here in the UK there was a small home computer called (I
think) the Oric(*) which had a membrane keyboard, 4K or RAM and
ran Forth.It had a small cult following before dying out. It
looked a bit like the early Sinclair/Timex ZX81 and I think the
developers came from that stable.

(*)I suspect the name was a dedication to a populat SciFi series
of the time, Blake's 7, which had a computer called Orac...

Alan G.
Author of the Learn to Program website
http://www.freenetpages.co.uk/hp/alan.gauld
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: BASIC vs Python

2004-12-21 Thread Mike Meyer
Doug Holton <[EMAIL PROTECTED]> writes:
> This is comp.lang.python, not comp.lang.logo.  Please refrain from
> discussing topics not related to CPython.

Doug, please quit trolling this newsgroup.

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


Installing new version, erasing previous versions of Python

2004-12-21 Thread David Smith
I currently have Python 2.2 and 2.3.4 installed.  I want to install Python 2.4,
and erase 2.3.4, but retain 2.2, for I need it for my connectivity program.

According to the the documentation:

If you have a previous installation of Python that you don't want to replace
yet, use

make altinstall

the same set of files as "make install" except it doesn't create the hard link
to "python" named "python" and it doesn't install the manual page at
all."

And prior to this, it says:

All subdirectories created will have Python's version number in their
name, e.g. the library modules are installed in
"/usr/local/lib/python/" by default, where  is the
. release number (e.g. "2.1").  The Python binary is
installed as "python" and a hard link named "python" is
created.  The only file not installed with a version number in its
name is the manual page, installed as "/usr/local/man/man1/python.1"
by default.


If I understand the above correctly, 1) "make install" and "make altinstall" use
the same process, the only difference being the man page update, and the hard
link, and 2) that previous versions of python are not deleted.  Therefore I
should be able to install 2.4 without deleting 2.2.2.  If I wish to delete
2.3.4, I have to rm -r the appropriate directories.  Any caveats?  Is there any
crosstalk between 2.2.2 and 2.4 modules?  Thank you.
-- 
David Smith
1845 Purdue Ave #3
Los Angeles Calif 90025-5592
(310) 478-8050
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Installing new version, erasing previous versions of Python

2004-12-21 Thread Fredrik Lundh
David Smith wrote:

> If I understand the above correctly, 1) "make install" and "make altinstall" 
> use
> the same process, the only difference being the man page update, and the hard
> link

correct.

> 2) that previous versions of python are not deleted.  Therefore I should be 
> able
> to install 2.4 without deleting 2.2.2.

correct.

> If I wish to delete 2.3.4, I have to rm -r the appropriate directories.  Any 
> caveats?
> Is there any crosstalk between 2.2.2 and 2.4 modules?

nope (unless you've moved things around, or tinkered with the python paths)

 



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


When was extended call syntax introduced?

2004-12-21 Thread Edward K. Ream
Various documentation pages, e.g.
http://www.python.org/doc/2.3.3/lib/non-essential-built-in-funcs.html
state that the apply function has been deprecated since 2.3.

Can anyone tell me when extended call syntax was actually introduced? 
Neither googling nor brief checks of the 'What's new in Python' or the pep's 
has turned up this information.  Thanks.

Edward

Edward K. Ream   email:  [EMAIL PROTECTED]
Leo: Literate Editor with Outlines
Leo: http://webpages.charter.net/edreamleo/front.html



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


Re: input record sepArator (equivalent of "$|" of perl)

2004-12-21 Thread John Machin

Steven Bethard wrote:
> John Machin wrote:
> > Nick Coghlan wrote:
> > [snip]
> >
> >>delimeter.
> >
> > Hey, Terry, another varmint over here!
>
> No, no.  He's talking about a deli-meter.  It's the metric standard
for
> measuring subs and sandwiches. ;)
>

Nobody mention the wurst! I did once, but I think I got away with it.

Subtle distinction: A metER is a measuring device. A MetRE is a unit of
distance.

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


Re: Best GUI for small-scale accounting app?

2004-12-21 Thread Paul Rubin
Dave Cook <[EMAIL PROTECTED]> writes:
> Web browser "widgets" seem pretty limited to me, though. 

You might not care.

> You don't even have something as simple as a combo box (i.e. an
> editable entry with a drop down),

Just put an input field and a dropdown on the page.

> let alone the rich set of widgets something like wxwidgets offers.

The rich set of widgets is sort of like a rich set of fonts in a word
processor.  Most of the time, your document can function perfectly
well with just one font.

> Also web development doesn't seem as coherent to me as development
> with a good GUI framework.

I'm not sure what that means.  But yeah, any gui (web or client side)
tends to need a lot of tweaking.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: A rational proposal

2004-12-21 Thread Mike Meyer
Nick Coghlan <[EMAIL PROTECTED]> writes:

> Mike Meyer wrote:
>>  I'm willing to do the work to get
>> decimals working properly with it.
>
> Facundo's post reminded me of some of the discussion about the
> interaction between floats and Decimal that went on when he was
> developing the module that eventually made it into the standard
> library.
>
> Perhaps Rational should have the same "arm's length" interaction with
> floats that Decimal does - require the user to set the precision they
> want by turning the float into a string that is then fed to the
> Rational constructor. My argument is that the following behaviour
> might be a little disconcerting:
>
> Py> x = 1.1
> Py> Rational(x)
> Rational("11001 / 1")

Yeah. That's why the spec specified integers for the argumetns.

> as opposed to:
> Py> x = 1.1
> Py> Rational("%.2f" % x)
> Rational("11 / 10")
>
> (A direct Decimal->Rational conversion should be OK, however, since it
> should match standard expections regarding the behaviour of the
> fractional portion)

Yeah. I've already added that to my copy of the PEP. That makes
rationals like (1/"1E1000") much easier to represent properly.

> The other point is that, since converting a Rational to float() or
> Decimal() may lose information, this is something that Python
> shouldn't really do automatically. As Facundo suggested, a string
> representation is a suitable intermediate format that makes explicit
> the degree of precision used in the conversion.

Well, you want to be able to add floats to rationals. The results
shouldn't be rational, for much the same reason as you don't want to
convert floats to rationals directly. I figure the only choice that
leaves is that the result be a float. That and float(rational) should
be the only times that a rational gets turned into a float.

Are you suggestiong that float(rational) should be a string, with the
number of degrees of precesion set by something like the Context type
in Decimal?

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


Re: How do I cut parts from a text file

2004-12-21 Thread Fredrik Lundh
"Rigga" <[EMAIL PROTECTED]> wrote:

> I am new to Python and need to parse a text file and cut parts out i.e. say
> the text file contained 5 rows of text:
>
> line 1 of the text file
> line 2 of the text file
> line 3 of the text file
> line 4 of the text file
> line 5 of the text file
>
> And the text I want starts at line 2 and goes through to line 4, what is the
> best way to cut this text out?

the same way as you'd do it in any other programming language...

you can add stuff to the end of a file, but you cannot insert or remove stuff
inside the file, without rewriting the rest of the file.  unless your files are 
really
huge, the easiest way to do this is to

1) load the entire file into memory

text = open(filename).readlines()

2) manipulate the data structure in memory

# remove first and last line
del text[0], text[-1]

3) write it back

f = open(outfilename, "w")
f.writelines(text)
f.close()






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


Re: When was extended call syntax introduced?

2004-12-21 Thread Fredrik Lundh
Edward K. Ream wrote:

> Various documentation pages, e.g.
> http://www.python.org/doc/2.3.3/lib/non-essential-built-in-funcs.html
> state that the apply function has been deprecated since 2.3.
>
> Can anyone tell me when extended call syntax was actually introduced? Neither 
> googling nor brief 
> checks of the 'What's new in Python' or the pep's has turned up this 
> information.

$ python1.5 -c "print max(*(1, 2))"
  File "", line 1
print max(*(1, 2))
  ^
SyntaxError: invalid syntax
$ python2.0 -c "print max(*(1, 2))"
2
$ python2.1 -c "print max(*(1, 2))"
2
$ python2.2 -c "print max(*(1, 2))"
2
$ python2.3 -c "print max(*(1, 2))"
2
$ python2.4 -c "print max(*(1, 2))"
2

 



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


Re: When was extended call syntax introduced?

2004-12-21 Thread Jim Sizelove
Edward K. Ream wrote:
Various documentation pages, e.g.
http://www.python.org/doc/2.3.3/lib/non-essential-built-in-funcs.html
state that the apply function has been deprecated since 2.3.
Can anyone tell me when extended call syntax was actually introduced? 
Neither googling nor brief checks of the 'What's new in Python' or the pep's 
has turned up this information.  Thanks.

Edward

Edward K. Ream   email:  [EMAIL PROTECTED]
Leo: Literate Editor with Outlines
Leo: http://webpages.charter.net/edreamleo/front.html


It looks like the extended call syntax was added in Python 2.0.  See 
"What's New in Python 2.0, 9.1 Minor Langage Changes" at 
http://www.amk.ca/python/2.0/new-python.html

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


Re: When was extended call syntax introduced?

2004-12-21 Thread "Martin v. Löwis"
Edward K. Ream wrote:
Various documentation pages, e.g.
http://www.python.org/doc/2.3.3/lib/non-essential-built-in-funcs.html
state that the apply function has been deprecated since 2.3.
Can anyone tell me when extended call syntax was actually introduced? 
That was in Python 2.0, see
http://www.python.org/2.0/new-python.html#SECTION000101
Regards,
Martin
--
http://mail.python.org/mailman/listinfo/python-list


Re: convert \uXXXX to native character set?

2004-12-21 Thread Bengt Richter
On Mon, 20 Dec 2004 12:49:39 +0200, Miki Tebeka <[EMAIL PROTECTED]> wrote:

>Hello Joe,
>
>> Is there any library to convert HTML page with \u encoded text to
>>native character set, e.g. BIG5.
>Try: help("".decode)
>
But the OP wants to en-code, I think. E.g. (I don't know what Chinese for ichi 
is ;-)

 >>> ichi = u'\u4e00'
 >>> ichi
 u'\u4e00'
 >>> ichi.encode('big5')
 '\xa4@'

UIAM that created two str bytes constituting big5 code for
the single horizontal stroke glyph whose unicode code is u'\u4e00'

 >>> list(ichi.encode('big5'))
 ['\xa4', '@']

going from big5-encoded str back to unicode then takes de-coding:

 >>> '\xa4@'.decode('big5')
 u'\u4e00'

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


Re: memory leak

2004-12-21 Thread Stephen Kellett
In message <[EMAIL PROTECTED]>, Daniel 
Wheeler <[EMAIL PROTECTED]> writes
I'm on a linux platform and looking in proc/pid/status. Using top shows 
the same problem.
OK, If you were on Windows I could give you some detailed advice - but 
for Linux, better that somebody else does it. Linux is not my main thing 
these days (it was in '94 :-).

Stephen
--
Stephen Kellett
Object Media Limitedhttp://www.objmedia.demon.co.uk
RSI Information:http://www.objmedia.demon.co.uk/rsi.html
--
http://mail.python.org/mailman/listinfo/python-list


Re: input record sepArator (not sepErator)

2004-12-21 Thread Reinhold Birkenfeld
Reinhold Birkenfeld wrote:
> Peter Otten wrote:
>> Reinhold Birkenfeld wrote:
>> 
 the web: 4%
 python: 9%
 slashdot: 26%
 perl: 29% *
>>> 
>>> How did you get these data points?
>> 
>> I copied the numbers from these pages:
>> 
>> http://www.google.com/search?q=separate
>> http://groups-beta.google.com/group/comp.lang.python/search?group=comp.lang.python&q=separate
>> http://www.google.com/search?q=site%3Aslashdot.org+separate
>> http://groups-beta.google.com/group/comp.lang.perl.misc/search?group=comp.lang.perl.misc&q=separate
>> 
>> Same thing for the "alternative" spelling.
> 
> Thanks. A pity that there is no de.comp.lang.python, as for German posts
> the "Standard/Standart" relation could be more accurate...
> 
> or-just-count-the-misplaces-apostrophs-ly yours, Reinhold

s/misplaces/misplaced/

just-don't-try-to-write-a-perfect-posting-ly yours!

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


Re: File locking is impossible in Windows?

2004-12-21 Thread Fredrik Lundh
Pekka Niiranen wrote:

> Is there a way around this? How can I stop file being COPIED OVER while
> it is being open?

you could rename the file before you start updating it, and rename it back when
done.

 



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


How do I cut parts from a text file

2004-12-21 Thread Rigga
Hi,

I am new to Python and need to parse a text file and cut parts out i.e. say
the text file contained 5 rows of text:

line 1 of the text file
line 2 of the text file
line 3 of the text file
line 4 of the text file
line 5 of the text file

And the text I want starts at line 2 and goes through to line 4, what is the
best way to cut this text out? I guess I need to mark the start and end of
the text and then pass these values to a command which will chop the file
at that location however I am at a loss.

Any advice or pointers of where to find more info would be greatly
appreciated.

Thanks

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


Re: input record sepArator (not sepErator)

2004-12-21 Thread Peter Otten
Reinhold Birkenfeld wrote:

>> the web: 4%
>> python: 9%
>> slashdot: 26%
>> perl: 29% *
> 
> How did you get these data points?

I copied the numbers from these pages:

http://www.google.com/search?q=separate
http://groups-beta.google.com/group/comp.lang.python/search?group=comp.lang.python&q=separate
http://www.google.com/search?q=site%3Aslashdot.org+separate
http://groups-beta.google.com/group/comp.lang.perl.misc/search?group=comp.lang.perl.misc&q=separate

Same thing for the "alternative" spelling.

Peter

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


Re: What is on-topic for the python list [was "Re: BASIC vs Python"]

2004-12-21 Thread Erik Max Francis
Doug Holton wrote:
I'm not going to dignify that or the rest of your note with a response.
Please stop dignifying the whole group, then.
--
Erik Max Francis && [EMAIL PROTECTED] && http://www.alcyone.com/max/
San Jose, CA, USA && 37 20 N 121 53 W && AIM erikmaxfrancis
  There was one thing I didn't show / I love him and he doesn't know
  -- Zhane
--
http://mail.python.org/mailman/listinfo/python-list


Re: What is on-topic for the python list [was "Re: BASIC vs Python"]

2004-12-21 Thread Reinhold Birkenfeld
Doug Holton wrote:
> Hans Nowak wrote:
>>> Quote:
>>> "this is comp.lang.python, not comp.lang.boo."
>> 
>> 
>> Which is obviously not the same as "Boo should not be mentioned on this 
>> newsgroup".  
> 
> I used the exact same phrase in another note except using the term 
> "logo" instead of "boo", and that is the exact interpretation I 
> immediately received from others - they felt I was censuring the 
> discussion here, as I felt you were.

Non sequitur. The phrase's interpretation depends on the posting(s) it
refers to.

Reinhold

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


Re: input record sepArator (not sepErator)

2004-12-21 Thread Reinhold Birkenfeld
Peter Otten wrote:
> Reinhold Birkenfeld wrote:
> 
>>> the web: 4%
>>> python: 9%
>>> slashdot: 26%
>>> perl: 29% *
>> 
>> How did you get these data points?
> 
> I copied the numbers from these pages:
> 
> http://www.google.com/search?q=separate
> http://groups-beta.google.com/group/comp.lang.python/search?group=comp.lang.python&q=separate
> http://www.google.com/search?q=site%3Aslashdot.org+separate
> http://groups-beta.google.com/group/comp.lang.perl.misc/search?group=comp.lang.perl.misc&q=separate
> 
> Same thing for the "alternative" spelling.

Thanks. A pity that there is no de.comp.lang.python, as for German posts
the "Standard/Standart" relation could be more accurate...

or-just-count-the-misplaces-apostrophs-ly yours, Reinhold

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


Re: What is on-topic for the python list [was "Re: BASIC vs Python"]

2004-12-21 Thread Doug Holton
Hans Nowak wrote:
Quote:
"this is comp.lang.python, not comp.lang.boo."

Which is obviously not the same as "Boo should not be mentioned on this 
newsgroup".  
I used the exact same phrase in another note except using the term 
"logo" instead of "boo", and that is the exact interpretation I 
immediately received from others - they felt I was censuring the 
discussion here, as I felt you were.

> The discussion with Logo and other languages in it was off-topic too,
> but it wasn't offensive to anyone.
I'm not going to dignify that or the rest of your note with a response.
--
http://mail.python.org/mailman/listinfo/python-list


how to force HTTP 1.1 when using urllib2?

2004-12-21 Thread jacob c.
When I request a URL using urllib2, it appears that urllib2 always
makes the request using HTTP 1.0, and not HTTP 1.1.  I'm trying to use
the "If-None-Match"/"ETag" HTTP headers to conserve bandwidth, but if
I'm not mistaken, these are HTTP 1.1 headers, so I can't reasonably
expect a web server to respond correctly to my requests.  (In my
limited testing, it looks like some servers respond correctly with an
HTTP 304 status, while some respond with an HTTP 200 and a full
response body.)

My specific issue notwithstanding, is there any way to force HTTP 1.1
to be used?  Or am I doing something wrong?

I've condensed my code into the following example, which produces
similar results on two different setups, Python 2.3.2 on Windows and
Python 2.2.1 on Debian Linux.  With this particular URL, the server
responds to my HTTP 1.0 request with an HTTP 1.1 response and an HTTP
304 status code, which suits my purposes, but I'd feel more comfortable
if my outgoing response also declared itself to be an HTTP 1.1 request.


Example code:

import httplib
httplib.HTTPConnection.debuglevel = 1
import urllib2

url = 'http://www.mozilla.org/images/firefox-oneoh-top.png'
etag = '"788054-2d18-3b21a80"'

request = urllib2.Request(url)
request.add_header('If-None-Match', etag)
opener = urllib2.build_opener()
response = opener.open(request)


Example output:

connect: (www.mozilla.org, 80)
send: 'GET /images/firefox-oneoh-top.png HTTP/1.0\r\nHost:
www.mozilla.org\r\nUser-agent: Python-urllib/2.0a1\r\nIf-none-match:
"788054-2d18-3b21a80"\r\n\r\n'
reply: 'HTTP/1.1 304 Not Modified\r\n'
header: Date: Tue, 21 Dec 2004 21:56:27 GMT
header: Server: Apache/2.0.46 (Red Hat)
header: Connection: close
header: ETag: "788054-2d18-3b21a80"
Traceback (most recent call last):
File "urllib2-test.py", line 11, in ?
response = opener.open(request)
File "D:\Python\lib\urllib2.py", line 333, in open
'_open', req)
File "D:\Python\lib\urllib2.py", line 313, in _call_chain
result = func(*args)
File "D:\Python\lib\urllib2.py", line 849, in http_open
return self.do_open(httplib.HTTP, req)
File "D:\Python\lib\urllib2.py", line 843, in do_open
return self.parent.error('http', req, fp, code, msg, hdrs)
File "D:\Python\lib\urllib2.py", line 359, in error
return self._call_chain(*args)
File "D:\Python\lib\urllib2.py", line 313, in _call_chain
result = func(*args)
File "D:\Python\lib\urllib2.py", line 419, in http_error_default
raise HTTPError(req.get_full_url(), code, msg, hdrs, fp)
urllib2.HTTPError: HTTP Error 304: Not Modified

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


File locking is impossible in Windows?

2004-12-21 Thread Pekka Niiranen
Hi,
I have used the following example from win32 extensions:
-SCRIPT STARTS
import win32file
import win32con
import win32security
import pywintypes
class Flock:
def __init__(self,file):
self.file=file
secur_att = win32security.SECURITY_ATTRIBUTES()
secur_att.Initialize()
self.highbits=-0x7fff
self.hfile=win32file.CreateFile( self.file,\
win32con.GENERIC_READ|win32con.GENERIC_WRITE,\
win32con.FILE_SHARE_READ|win32con.FILE_SHARE_WRITE,\
secur_att, win32con.OPEN_ALWAYS,\
win32con.FILE_ATTRIBUTE_NORMAL , 0 )
def lock(self):
lock_flags=win32con.LOCKFILE_EXCLUSIVE_LOCK|\
win32con.LOCKFILE_FAIL_IMMEDIATELY
self.ov=pywintypes.OVERLAPPED()
win32file.LockFileEx(self.hfile,lock_flags,0,\
self.highbits,self.ov)
def unlock(self):
win32file.UnlockFileEx(self.hfile,0,\
self.highbits,self.ov)
self.hfile.Close()
if __name__ == '__main__':
from time import time, strftime, localtime
import sys

l=Flock("e:log.txt")
print 'calling lock'
l.lock()
print "Now locked.  Hit enter to release lock."
dummy = sys.stdin.readline()
l.unlock()
print 'now unlocked'
-SCRIPT ENDS
If I start one python process from dos window I get message:
E:\>python lockker.py
calling lock
Now locked.  Hit enter to release lock.
All well, now if
1)  I start another Dos -shell and run the same command I get:
E:\>python lockker.py
calling lock
Traceback (most recent call last):
  File "lockker.py", line 35, in ?
l.lock()
  File "lockker.py", line 23, in lock
   win32file.LockFileEx(self.hfile,lock_flags,0,\
   self.highbits,self.ov)
pywintypes.error: (33, 'LockFileEx',\
'The process cannot access the file because\
 another process has locked a portion of  the file.')
Which is correct.
2)  I try to read the contents of the file from Dos -shell, I get:
E:\>type log.txt
The process cannot access the file because another\
process has locked a portion of the file.

This is correct.
3)  When I open the file into notepad.exe I can edit the screen
but not write changes to disk. Correct again!
4)  I cannot delete the file from Dos shell or from W2K explorer
which is correct.
5)  However, I can overwrite the file over with:
E:\>copy d:\log.txt log.txt
1 file(s) copied.
Which is WRONG as is me being able to copy another file over it
with W2K explorer too.
Is there a way around this? How can I stop file being COPIED OVER while
it is being open? Is this window's feature? Is readlines() operation
"atomic" enough for me not to worry about these issues?
My python script modifies set of files from a directory one by one.
I try to lock them all exclusively for the script
until all are modified. If one of the files gets overwritten
by another version (by another process) the script may fail.
-pekka-



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


Re: Best GUI for small-scale accounting app?

2004-12-21 Thread Jarek Zgoda
Bulba! wrote:
- QT seems to be industrial-strength, but.. it's probably
more complex/difficult to use.
- wxPython/PythonCard is probably simple to use, but.. 
are there not some pitfalls that development will fall 
into once the app starts growing (they all do)?
From my point of view, PyQt is easier to use (and is simpler, runs 
faster, looks better on Linux etc), while wxPython is much cheaper (and 
runs faster on Windows). As I am guerilla Python programmer (and try to 
drive as much Python into company as I can), I use wxPython on Windows 
platform as it doesn't trigger unnecessary questions on licensing, 
pricing et caetera.

wxPython has very nice GUI builder (wxGlade), it is not about as 
complete as Qt Designer, but speeds-up development significantly.

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


Re: break/continue - newbe

2004-12-21 Thread John Machin

Ann wrote:
> I have trouble sometimes figuring out where
> break and continue go to. Is there some easy
> way to figure it out, or a tool?
> TIA
> Ann

You need a tool called py2ftn. It would convert a sequence of
statements like:

while 1:
blah1
if cond1: break
blah2
if cond2: continue
blah3

to:

1 IF(1)10001,10003,10001
10001 CONTINUE
BLAH1
IF(COND1)GOTO10003
BLAH2
IF(COND2)GOTO10002
BLAH3
10002 CONTINUE
  GOTO1
10003 CONTINUE

HTH,
John

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


Re: What is on-topic for the python list [was "Re: BASIC vs Python"]

2004-12-21 Thread Hans Nowak
Doug Holton wrote:
Hans Nowak wrote:
You said that boo should not be mentioned on this newsgroup.  

Please point me to the post where I said that.  Since everything is 
stored in Google Groups, it should be easy for you to come up with an 
URL... if such a post existed.

Quote:
"this is comp.lang.python, not comp.lang.boo."
Which is obviously not the same as "Boo should not be mentioned on this 
newsgroup".  I suppose you can interpret this any way you want.  One 
can take it as an attempt at censorship.  But it was actually meant as 
part of an explanation why people were giving you a hard time.

The discussion with Logo and other languages in it was off-topic too, 
but it wasn't offensive to anyone.  In fact, it actually adds to the 
richness of this newsgroup.

Look, let's get this thing out of the way.  It has already taken up too 
much energy from everyone involved.  I apologize if you were under the 
impression that I tried to tell you what to say and what not to say in 
this newsgroup.  I intended to do no such thing.  Now maybe we should 
let it rest and go write some nice code.

--
Hans Nowak
http://zephyrfalcon.org/
--
http://mail.python.org/mailman/listinfo/python-list


Re: break/continue - newbe

2004-12-21 Thread John Machin

Ann wrote:
> I have trouble sometimes figuring out where
> break and continue go to. Is there some easy
> way to figure it out, or a tool?
> TIA
> Ann

You need a tool called py2ftn. It would convert statements like "if a >
b: break" to e.g. "IF(A.GT.B)GOTO12345".

A longer example; this:

while 1:
blah1
if cond1: break
blah2
if cond2: continue
blah3

becomes:

1 IF(1)10001,10003,10001
10001 CONTINUE
BLAH1
IF(COND1)GOTO10003
BLAH2
IF(COND2)GOTO10002
BLAH3
10002 CONTINUE
  GOTO1
10003 CONTINUE

HTH,
John

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


[ANN] rpncalc-1.1 RPN Calculator For Python

2004-12-21 Thread Raymond L. Buvel
The rpncalc package adds an interactive Reverse Polish Notation (RPN)
interpreter to Python.  This interpreter allows the use of Python as
an RPN calculator.  You can easily switch between the RPN interpreter
and the standard Python interpreter.
Home page:  http://calcrpnpy.sourceforge.net/
Changes in 1.1
* Stack checking gives an appropriate error message instead of aborting 
to the Python interpreter.

* Exceptions are handled within the RPN interpreter instead of aborting 
to the Python interpreter.  This makes recovery much simpler since there 
are very few situations that actually require the Python interpreter for 
recovery.

* Vocabularies are now ordered by priority.  A complete list of all the 
currently defined vocabularies is available from within the interpreter.

* User can select degrees or radians mode for trig functions.
* Added extended precision floating point using the gmpy module.
* Added a const module that provides some physical constants in SI (MKS) 
units.

* Converted to a Python package to simplify future expansion.
--
http://mail.python.org/mailman/listinfo/python-list


Re: What is on-topic for the python list [was "Re: BASIC vs Python"]

2004-12-21 Thread Doug Holton
Hans Nowak wrote:
You said that boo should not be mentioned on this newsgroup.  

Please point me to the post where I said that.  Since everything is 
stored in Google Groups, it should be easy for you to come up with an 
URL... if such a post existed.
Quote:
"this is comp.lang.python, not comp.lang.boo."
This is not comp.lang.logo, either, but discussing it from the point of 
view of a python user is perfectly acceptable.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Best GUI for small-scale accounting app?

2004-12-21 Thread Ed Leafe
On Dec 20, 2004, at 7:25 AM, Bulba! wrote:
The long lists of invoices, subcontractors and tasks (possibly
hundreds or thousands) will have to be displayed - which toolkit
is better for that in your experience?
I would appreciate anybody sharing their experiences with
relevant toolkits in development of this type of software
or similar.
	You might want to check out Dabo, an application framework of which I 
am one of the authors. We use wxPython as our UI toolkit, but have 
streamlined the programming of the UI. We've also added data binding, 
making developing apps that need to work with a database much, much 
simpler.

	Even though Dabo is still in development, I've used it to create an 
app that helps me manage the archives of the technical email lists I 
host (currently holding over a quarter-million rows).

 ___/
/
   __/
  /
 /
 Ed Leafe
 http://leafe.com/
 http://dabodev.com/
--
http://mail.python.org/mailman/listinfo/python-list


Re: temp file name

2004-12-21 Thread Artur M. Piwko
In the darkest hour on Fri, 17 Dec 2004 17:21:53 +0530,
km <[EMAIL PROTECTED]> screamed:
> Is there a way to  create  a unique file name; safely
> i have used os.tmpnam() with python2.4, i warns that the usage is a potential 
> security risk.
>

Security risk comes from posix tmpnam itself.
>From tmpnam manual:

BUGS
   The precise meaning of `appropriate' is undefined;  it  is  unspecified
   how  accessibility  of a directory is determined.  Never use this func-
   tion. Use mkstemp(3) instead.

Use tempfile.mkstemp() instead.

-- 
[ Artur M. Piwko : Pipen : AMP29-RIPE : RLU:100918 : From == Trap! : SIG:214B ]
[ 22:11:02 user up 10467 days, 10:06,  1 user, load average: 0.06, 0.06, 0.06 ]

  Another megabytes the dust.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python To Send Emails Via Outlook Express

2004-12-21 Thread Lenard Lindstrom
Steve Holden <[EMAIL PROTECTED]> writes:

> [EMAIL PROTECTED] wrote:
> 
> > Hi Fredrik,
> > Thank you for the suggestion.
> > I tried different from/to settings and guess what? The mail came
> > thru.
> > The script is now..
> > import win32com.client
> > s = win32com.client.Dispatch('CDO.Message')
> > s.From = "[EMAIL PROTECTED]"(was
> > "[EMAIL PROTECTED]")
> > s.To = "[EMAIL PROTECTED]"  (was
> > "[EMAIL PROTECTED]")
> > s.Subject = "The subject"
> > s.Send()
> > My problem is thought, the message is still not being sent via
> > Outlook
> > Express.
> > What am I missing?
> > Thanks again for your help so far!!
> > Kind regards
> > Ian
> >
> Unfortunately Outlook Express isn't programmable in the same way as
> Outlook. I used to use it because this property gave it a certain
> degree of immunity from macro viruses (back in the days when Outlook
> came configured to open any Office document it came across).
> 
Outlook Express can be accessed through the Simple Mapi interface -
at least the version on Win98 can. I have a program that reads
and deletes messages from the new mail folder. So I would imaging
mail can be also sent through Outlook Express using Simple Mapi,
but I have not tried it. I have also not tried using Simple Mapi
under Python, only VC++. But a quick test shows I can access
MAPI32.DLL use the ctypes package:

import ctypes
mapi = ctypes.windll.mapi32
MAPILogon = mapi.MAPILogon
...

It is messy though.

Lenard Lindstrom
<[EMAIL PROTECTED]>

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


Re: memory leak

2004-12-21 Thread Jean Brouwers

Since you are on Linux, one thing which could be helpful is to lower
the virtual memory limit.  Before running your program, use the Csh
limit command to set the upper limit for vmemory.

If there is a leak in your program or in any of the extensions, it will
run out of memory earlier.  But setting the limit does not help finding
the root cause of a leak.  That requires additional effort and/or
dignostic tools.

/Jean Brouwers


In article <[EMAIL PROTECTED]>,
Daniel Wheeler <[EMAIL PROTECTED]> wrote:

> I'm on a linux platform and looking in proc/pid/status. Using top shows 
> the same problem.
> 
> I've actually just found the c routine where the memory is leaking by 
> the painstaking process of
> taking the difference between memory consumption before and after each 
> python routine. I guess
> that memory leaks that are not associated with python dangling 
> references are nearly always in the
> underlying c code.
> 
> Also, does anyone know of some good memory diagnostic tools for python, 
> maybe even a GUI.
> I am currently using some pulled from various webpages:
> 
>  http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/286222
>  http://www.nightmare.com/medusa/memory-leaks.html
> 
> 
> On Dec 21, 2004, at 12:18 PM, Stephen Kellett wrote:
> 
> > In message <[EMAIL PROTECTED]>, 
> > Daniel Wheeler <[EMAIL PROTECTED]> writes
> >> However, I would like to understand first if pure python can leak 
> >> without the reference count increasing?
> >
> > How are you determining that used memory is increasing?
> >
> > Stephen
> > -- 
> > Stephen Kellett
> > Object Media Limitedhttp://www.objmedia.demon.co.uk
> > RSI Information:http://www.objmedia.demon.co.uk/rsi.html
> > -- 
> > http://mail.python.org/mailman/listinfo/python-list
> >
> >
> >
> -
> Daniel Wheeler
> Telephone: (301) 975-8358
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: input record sepArator (equivalent of "$|" of perl)

2004-12-21 Thread Steven Bethard
John Machin wrote:
Nick Coghlan wrote:
[snip]
delimeter.
Hey, Terry, another varmint over here!
No, no.  He's talking about a deli-meter.  It's the metric standard for 
measuring subs and sandwiches. ;)

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


Re: Boo who? (was Re: newbie question)

2004-12-21 Thread Jarek Zgoda
Fredrik Lundh wrote:
(and by the way, comp.lang.python isn't "the community".  most python pro-
grammers are elsewhere, and will only read what we post when googling for
the answer to some specific problem...)
They are busy writing programs in Python, some of them even do it for 
the money, 9 AM - 5 PM. And specific problems they encounter are driving 
Python development (in most cases).

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


Re: Writev

2004-12-21 Thread Adam DePrince
On Sun, 2004-12-19 at 23:43, Jp Calderone wrote:
> On Sun, 19 Dec 2004 23:12:27 -0500, Adam DePrince <[EMAIL PROTECTED]> wrote:
> > [snip]
> > 
> > Of course, to take advantage of this requires that writev be exposed.  I
> > have an implementation of writev.  This implementation is reasonably
> > smart, it "unrolls" only so as many iteration.next calls as necessary to
> > fill the pointer list for the next invocation of writev.   Of course, on
> > many systems (Linux, BSD) writev's limit is 1024 items, so to
> > accommodate users who don't want to peel off and hold in memory 1024
> > iteration.next()'s, you can set an optional parameter to a smaller
> > value. 
> > 
> > I'm not sure where to take this as a "next step."  It seems too small a
> > change for a PEP.  Any ideas?
> > 
> > You can download the patch from
> > http://deprince.net/software/writev/index.html
> > 
> 
>   writev() in the standard library would be nice.  I have an 
> implementation too ;)  I wonder how many other people do as 
> well.
> 
>   Regarding the implementation, just one part confuses me.  
> What's the idea behind this check at the beginning of the 
> iterator unrolling loop?
> 
> +if ( !PyObject_CheckReadBuffer( buf ) )
> +  continue;
> 
>   Is it me, or is that silently ignoring bad input?
> 
>   Other miscellaneous feedback:
> 
> The use of alloca() isn't common in CPython.  PyMem_Malloc 
> is probably what you want to be calling.  At the very least, 
> alloca()'s return value should be checked to be sure it is 
> non-NULL.  If you switch to PyMem_Malloc, you'll have to be 
> sure to free the memory, of course.
> 
> The support of iterators is a cool idea, but I'm not sure
> it is actually useful.  Consider the case where not all bytes 
> are written.  How is an application supposed to handle writing 
> the rest of the bytes, if they have been consumed from an 
> iterator?  Hopefully I'm missing the obvious answer, because
> supporting arbitrary iterators would be cool, but it seems like
> only sequences can really be usefully supported.
> 

Fixed this.  The return value is a tuple of bytes written and a tuple of
stuff that didn't get shipped.  And yes, the first element is replaced
with a string that represents the fraction of that element that didn't
get sent.   Here is simple sample code that illustrates how this works.

data = [  lots of little strings in this list ... ]
data = iter( data )
import itertools
import writev

while 1:
  (count, leftovers ) = writev.writev( fd, data )
  if leftovers == None: break
  data = itertools.chain( iter( leftovers ), data )
  ... Of course, our loop would in a real example be controlled by a
select.  In this naive example we would want to sleep ... 

Adam DePrince 

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


Re: Lazy argument evaluation (was Re: expression form of one-to-many dict?)

2004-12-21 Thread Steven Bethard
Nick Coghlan wrote:
def lazy(x, *args, **kwds):
  """Executes x(*args, **kwds) when called"""
  if args or kwds:
return lambda : x(*args, **kwds)
  else:
return x # No arguments, so x must be callable by itself
[snip]
Huh. I think I like the idea of lazy() much better than I like the 
current PEP 312.
Well, 'lazy' is definitely much easier to read, reference in the 
documentation, etc. than ':' would be.

There must be something wrong with this idea that I'm 
missing. . .
Well, it does cost you some conciceness, as your examples show[1]:
lazy(mul, x, y) v.s.   :x * y
lazy(itemgetter(i), x)  v.s.   :x[i]
lazy(attrgetter("a"), x)v.s.   :x.a
lazycall(lazy(attrgetter("a"), x))  v.s.   :x.a()
Not sure how I feel about this yet.  I don't personally need lazy 
argument evaluation often enough to be able to decide which syntax would 
really be clearer...

Steve
[1] To try to make things as fair as possible, I'm assuming that you've done
from operator import mul, itemgetter, attrgetter
at the top of the module.
--
http://mail.python.org/mailman/listinfo/python-list


Re: [Mingw-users] Problem with msvcrt60 vs. msvcr71 vs. strdup/free

2004-12-21 Thread Danny Smith
From: "Gerhard Haering"
>Is there any way I can force mingw to not link in msvcr for things
>like strdup?

mdkdir /mingw/lib/msvcr71
cp -f libmsvcr71.a  /mingw/lib/msvcr71/libmsvcrt.a
gcc ${OBJECTS} -L /mingw/lib/msvcr71

Or you could hand edit gcc's specs file, replacing -lmsvcrt with -lwhatever..

Patches to facilitate switching to an alternative msvcr*.dll could be submitted
to gcc.

Danny

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


Re: break/continue - newbe

2004-12-21 Thread Fredrik Lundh
"Ann" <[EMAIL PROTECTED]> wrote:

> Thanks Jeff, that solves my problem. BTW: is there an easy way to
> break/continue out more than one level?

not really; to continue more than one level, you have to break out of the
inner loop, and make sure the logic in that loop body brings you back to
the top.

to break more than one level, you can:

1) use an exception

class LeaveLoop(Exception): pass

def myfunction():
try:
for a in ...:
for b in ...:
if c:
raise LeaveLoop # break out of both loops
do something
except LeaveLoop:
pass

2) organize your code so you can use return rather than "multi-break"

def myfunction():
calculate()

def calculate():
for a in ...:
for b in ...:
if c:
return
do something

3) use flags

def myfunction():
run = 1
for a in ...:
for b in ...:
if c:
run = 0
if not run:
break
if not run:
break

Solution 2 is almost always the best way to do this; solution 3 is often the 
worst.

 



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


Re: A reception desk in a sort of office building

2004-12-21 Thread Fredrik Lundh
/.../

Hans: [Boo] may *look* like Python, but its inner workings are nothing
 like Python /.../ Pointing out the difference is not trolling.

Doug: Hans Nowak and others were the ones unsuccessfully trying to
control what people could talk about here.

Hans: I never said that.

Doug: You said that boo should not be mentioned on this newsgroup.
That is a fact.

Mr Vibrating: (pressing the bell on his desk) Thank you, good morning.

Doug: What?

Mr Vibrating: That's it. Good morning.

Doug: That was never five minutes just now!

Mr Vibrating: I'm afraid it was.

Doug: No it wasn't.

Mr Vibrating: I'm sorry, I'm not allowed to argue any more.

Doug: What!?

Mr Vibrating: If you want me to go on arguing, you'll have to pay for another
five minutes. 



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


Re: break/continue - newbe

2004-12-21 Thread Ann

"Jeff Shannon" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
> Ann wrote:
>
> >I have trouble sometimes figuring out where
> >break and continue go to. Is there some easy
> >way to figure it out, or a tool?
> >
> >
>
> Break and continue always operate on the most-nested loop that's
> currently executing.  To show an example, let's add some line numbers to
> some code...
>
> 1) while spam:
> 2) if foo(spam):
> 3) continue
> 4) for n in range(spam):
> 5) if bar(n):
> 6) break
> 7) results.append(baz(spam, n))
> 8) spam = spam - 1
>
> Now, when this loop runs, when foo(spam) evaluates as True we execute
> the continue at line 3.  At this time, we're running code that's at the
> loop-nesting level just inside 'while spam' (line 1), so line 1 is the
> loop statement that's affected by the continue on line 3.  If line 3 is
> triggered, then we skip lines 4-8 and go back to line 1.
>
> If line 3 is *not* triggered, then we enter a for loop at line 4.
> There's a break at line 6; if this gets triggered, then we look
> backwards to find the most-current (i.e. most nested) loop, which is now
> that for loop on line 4.  So we break out of that for loop (which
> comprises lines 4-7), and drop down to line 8.
>
> So, in general, the way to determine how break and continue will affect
> program flow is to look backwards (up) for the most recent loop
> statement; the break/continue will be inside that statement's dependent
> body.  Break will drop you down to the next line after the loop body,
> and continue will bring you back up to the top of the loop body and the
> start of the next loop iteration.
>
> Jeff Shannon
> Technician/Programmer
> Credit International
>
Thanks Jeff, that solves my problem. BTW: is there an easy way to
break/continue out more than one level?


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


Re: break/continue - newbe

2004-12-21 Thread Jeff Shannon
Ann wrote:
I have trouble sometimes figuring out where
break and continue go to. Is there some easy
way to figure it out, or a tool?
 

Break and continue always operate on the most-nested loop that's 
currently executing.  To show an example, let's add some line numbers to 
some code...

1) while spam:
2) if foo(spam):
3) continue
4) for n in range(spam):
5) if bar(n):
6) break
7) results.append(baz(spam, n))
8) spam = spam - 1
Now, when this loop runs, when foo(spam) evaluates as True we execute 
the continue at line 3.  At this time, we're running code that's at the 
loop-nesting level just inside 'while spam' (line 1), so line 1 is the 
loop statement that's affected by the continue on line 3.  If line 3 is 
triggered, then we skip lines 4-8 and go back to line 1.

If line 3 is *not* triggered, then we enter a for loop at line 4.  
There's a break at line 6; if this gets triggered, then we look 
backwards to find the most-current (i.e. most nested) loop, which is now 
that for loop on line 4.  So we break out of that for loop (which 
comprises lines 4-7), and drop down to line 8.

So, in general, the way to determine how break and continue will affect 
program flow is to look backwards (up) for the most recent loop 
statement; the break/continue will be inside that statement's dependent 
body.  Break will drop you down to the next line after the loop body, 
and continue will bring you back up to the top of the loop body and the 
start of the next loop iteration.

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


Re: What is on-topic for the python list [was "Re: BASIC vs Python"]

2004-12-21 Thread Hans Nowak
Doug Holton wrote:
Hans Nowak wrote:
Now you're trying to make it seem like I am against free speech on 
this list, and against people's rights to discuss whatever they want.  
I never said that, and I in fact enjoy the fact that c.l.py posters 
are an eclectic bunch who have knowledge of, and like to talk about, a 
great number of topics.

You said that boo should not be mentioned on this newsgroup.  
Please point me to the post where I said that.  Since everything is 
stored in Google Groups, it should be easy for you to come up with an 
URL... if such a post existed.

--
Hans Nowak
http://zephyrfalcon.org/
--
http://mail.python.org/mailman/listinfo/python-list


Re: Best GUI for small-scale accounting app?

2004-12-21 Thread Dave Cook
On 2004-12-20, Paul Rubin  wrote:

> I think I can put together a useable (but not visually stunning) web
> interface faster than I can put together any pure client-side
> interface.  

Web browser "widgets" seem pretty limited to me, though.  You don't even
have something as simple as a combo box (i.e. an editable entry with a drop
down), let alone the rich set of widgets something like wxwidgets offers.
Also web development doesn't seem as coherent to me as development with a
good GUI framework.

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


Re: What is on-topic for the python list [was "Re: BASIC vs Python"]

2004-12-21 Thread Doug Holton
Hans Nowak wrote:
Now you're trying to make it seem like I am against free speech on this 
list, and against people's rights to discuss whatever they want.  I 
never said that, and I in fact enjoy the fact that c.l.py posters are an 
eclectic bunch who have knowledge of, and like to talk about, a great 
number of topics.
You said that boo should not be mentioned on this newsgroup.  That is a 
fact.  You cannot and should not try to dictate any standard for what 
can and cannot be said in this forum, other than what I already 
suggested in the quote below:

>> Anything related to python or from the perspective of a current or
>> potential python user is on-topic for this list.  We can talk about
>> logo, jython, java or other topics whenever and whereever we want. If
>> you can't accept free speech and different perspectives, you're going
>> to be disappointed.
Sorry to disappoint.
--
http://mail.python.org/mailman/listinfo/python-list


[ANNOUNCE] Twentieth release of PythonCAD now available

2004-12-21 Thread Art Haas
Hi.

I'm pleased to announce the twentieth development release of PythonCAD,
a CAD package for open-source software users. As the name implies,
PythonCAD is written entirely in Python. The goal of this project is
to create a fully scriptable drafting program that will match and eventually
exceed features found in commercial CAD software. PythonCAD is released
under the GNU Public License (GPL).

PythonCAD requires Python 2.2 or Python 2.3. The interface is GTK 2.0
based, and uses the PyGTK module for interfacing to GTK. The design of
PythonCAD is built around the idea of separating the interface
from the back end as much as possible. By doing this, it is hoped
that both GNOME and KDE interfaces can be added to PythonCAD through
usage of the appropriate Python module. Addition of other PythonCAD 
interfaces will depend on the availability of a Python module for that
particular interface and developer interest and action.

The twentieth release of PythonCAD improves the undo/redo abilities
of the program by making layer creation and deletion actions that
can be undone or redone. Also, the addition and removal of chamfers
and fillets is now an undoable and redoable action. The code for
managing undo/redo operations has been improved, and various bug
fixes for these actions have been applied. Another improvement in
this release is a reworked set of file saving operations. The code
for saving a file onto disk has been made more robust by adding
additional error checks and by ensuring the new version of a file
is stored successfully prior to replacing the existing copy. A
good number of bug fixes and code improvements are included in
this release as well.

PythonCAD is now two years old! The first public release was on December
21, 2002. Celebrate PythonCAD's second birthday by downloading and
installing the twentieth release!

The mailing list for the development and use of PythonCAD is available.
Visit the following page for information about subscribing and viewing
the mailing list archive:

http://mail.python.org/mailman/listinfo/pythoncad

Visit the PythonCAD web site for more information about what PythonCAD
does and aims to be:

http://www.pythoncad.org/

Come and join me in developing PythonCAD into a world class drafting
program!

Art Haas
-- 
Man once surrendering his reason, has no remaining guard against absurdities
the most monstrous, and like a ship without rudder, is the sport of every wind.

-Thomas Jefferson to James Smith, 1822
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: extending python with a C-written dll

2004-12-21 Thread Scott David Daniels
Jean-Baptiste PERIN wrote:
I can already conclude that either I don't know how to use lcc
or it doesn't suit my needs ..
I plan to first test the cygwin's gcc compiler before goign to MinGW32
MinGW32 is "Minimalist Gnu for Windows -- 32-bit," and _works_ at
being ABI compatible with Microsoft's ABI and its C runtime.  Cygwin
is a way of building a *nix-compatible toolset _on_ Windows, not _in_
windows.  What that means (as far as I understand the issues) is that
you'll need to build a Cygwin python in order to use Cygwin modules.
I put in a bit of effort to make sure Python could build for that
compiler (not by MinGW-specific code, but by cleaning up an issue in
the CPython header file for non-MS compilers).  There are toolchain
issues to consider (not just the compiler itself, , but function call
conventions, global access, linker/loader, and debugger symbols and
access are involved).
Python 2.4's jump to a new C compiler on windows is a well-justified
decision (Windows C/C++ 6.0's stuff is getting long in the tooth), but
short-term disruptive to small-time Python C module development.  The
change does not portend a continuous series of compiler-jumps, but
rather a hope to not become hopelessly mired in ancient history.  It
is getting hard (or is impossible, I don't know which) to purchase
Windows C/C++ 6.0 for money these days, and this will only get harder.
In short, I urge you to go with MinGW if you are hoping to write for
windows with a GNU compiler; you'll be swimming upstream a bit less.
--Scott David Daniels
[EMAIL PROTECTED]
--
http://mail.python.org/mailman/listinfo/python-list


  1   2   3   >