Re: How to send E-mail without an external SMTP server ?

2006-10-15 Thread Rob Wolfe

[EMAIL PROTECTED] wrote:
> Hi,
>
> I just want to send a very simple email from within python.
>
> I think the standard module of smtpd in python can do this, but I
> haven't found documents about how to use it after googleing. Are there
> any examples of using smtpd ? I'm not an expert,so I need some examples
> to learn how to use it.

See standard documentation:

http://docs.python.org/lib/SMTP-example.html

HTH,
Rob

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


Re: OT: What's up with the starship?

2006-10-15 Thread Thomas Heller
T. Bryan schrieb:
> Thomas Heller wrote:
> 
>> I cannot connect to starship.python.net: neither http, nor can I login
>> interactively with ssl (and the host key seems to have changed as well).
>> 
>> Does anyone know more?
> 
> starship.python.net was compromised.  It looked like a rootkit may have been
> installed.  The volunteer admins are in the process of reinstalling the OS
> and rebuilding the system.  That process will probably take a few days at
> least.  

Thanks for the info.  I appreciate the work that the admins are doing.

Thanks,
Thomas

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


Re: python's OOP question

2006-10-15 Thread neoedmund
Oh, How great is the solution!  ( though i don't know how it works. )
Thank you George.

George Sakkis wrote:
> neoedmund wrote:
>
> > python use multiple inheritance.
> > but "inheritance" means you must inherite all methods from super type.
> > now i just need "some" methods from one type and "some" methods from
> > other types,
> > to build the new type.
> > Do you think this way is more flexible than tranditional inheritance?
>
> The following does the trick:
>
> from types import MethodType
>
> def addMethod(meth, obj):
> f = meth.im_func
> setattr(obj, f.__name__, MethodType(f,obj))
>
> def test1():
> addMethod(C2.m, C3)
> addMethod(C1.v, C3)
> o = C3()
> o.m()
>
> The same works as is on modifying individual instances, rather than
> their class:
>
> def test2():
> o = C3()
> addMethod(C2.m, o)
> addMethod(C1.v, o)
> o.m()
> # raises AttributeError
> # C3().m()
> 
>  
> George

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


Re: python's OOP question

2006-10-15 Thread neoedmund
I found a dynamic way to inherite classes:

def MixIn(pyClass, mixInClass):
if mixInClass not in pyClass.__bases__:
pyClass.__bases__ += (mixInClass,)

def test1():
o = C3()
MixIn(C3,C1)
MixIn(C3,C2)
o.m()

"expected aaa"

neoedmund wrote:
> thank you, Kay.
>
> But i need a "dynamic" way. Say i have a existing class, and add some
> method from other class into it.
>
>
> Kay Schluehr wrote:
> > neoedmund wrote:
> > > There's a program, it's result is "unexpected aaa", i want it to be
> > > "expected aaa". how to make it work?
> > >
> > > [code]
> > >
> > > class C1(object):
> > >   def v(self, o):
> > >   return "expected "+o
> > >
> > > class C2(object):
> > >   def v(self, o):
> > >   return "unexpected "+o
> > >   def m(self):
> > >   print self.v("aaa")
> > >
> > > class C3(object):
> > >   def nothing(self):
> > >   pass
> > >
> > > def test1():
> > >   o = C3()
> > >   setattr(o,"m",C2().m)
> > >   setattr(o,"v",C1().v)
> > >   o.m()
> > >
> > > test1()
> > >
> > > [/code]
> >
> > class C3(C1, C2):pass
> >
> > >>> C3.mro()  # shows method resolution order
> > [, , ,
> > ]
> > 
> > >>> o = C3()
> > >>> o.m()
> > expected aaa

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


Re: python's OOP question

2006-10-15 Thread George Sakkis
neoedmund wrote:

> python use multiple inheritance.
> but "inheritance" means you must inherite all methods from super type.
> now i just need "some" methods from one type and "some" methods from
> other types,
> to build the new type.
> Do you think this way is more flexible than tranditional inheritance?

The following does the trick:

from types import MethodType

def addMethod(meth, obj):
f = meth.im_func
setattr(obj, f.__name__, MethodType(f,obj))

def test1():
addMethod(C2.m, C3)
addMethod(C1.v, C3)
o = C3()
o.m()

The same works as is on modifying individual instances, rather than
their class:

def test2():
o = C3()
addMethod(C2.m, o)
addMethod(C1.v, o)
o.m()
# raises AttributeError
# C3().m()

 
George

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


How to send E-mail without an external SMTP server ?

2006-10-15 Thread [EMAIL PROTECTED]
Hi,

I just want to send a very simple email from within python.

I think the standard module of smtpd in python can do this, but I 
haven't found documents about how to use it after googleing. Are there 
any examples of using smtpd ? I'm not an expert,so I need some examples 
to learn how to use it.

Or maybe there is a better way to to this?

Thanks.

xiaojf



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


Re: python's OOP question

2006-10-15 Thread Gregor Horvath
neoedmund schrieb:
> python use multiple inheritance.
> but "inheritance" means you must inherite all methods from super type.
> now i just need "some" methods from one type and "some" methods from
> other types,
> to build the new type.
> Do you think this way is more flexible than tranditional inheritance?
> 

Probably your problem is better solved with delegation instead of
inheritance.

-- 
  Servus, Gregor
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: OT: What's up with the starship?

2006-10-15 Thread George Sakkis
[EMAIL PROTECTED] wrote:
> Robert Hicks wrote:
> > [EMAIL PROTECTED] wrote:
> > > T. Bryan wrote:
> > > > Thomas Heller wrote:
> > > >
> > > > > I cannot connect to starship.python.net: neither http, nor can I login
> > > > > interactively with ssl (and the host key seems to have changed as 
> > > > > well).
> > > > >
> > > > > Does anyone know more?
> > > >
> > > > starship.python.net was compromised.  It looked like a rootkit may have 
> > > > been
> > > > installed.  The volunteer admins are in the process of reinstalling the 
> > > > OS
> > > > and rebuilding the system.  That process will probably take a few days 
> > > > at
> > > > least.
> > >
> > > Does anyone know more?
> > >
> > > What about the integrity of the python packages hosted there?
> > > When was the site compromised?
> > > I just installed the python 2.5 pywin module last week.
> > > Should I be concerned?
> > >
> > > Is this related to the Python security problem recently announced?
> >
> > Did you even read about the vulnerability?
>
> Yes.  Do you have any answers, or do you just enjoy posting irrevelant
> responses?

I guess his response implied that what's irrelevant here is the
vulnerability, and accordingly your worries about it.

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


Re: wx.grid question (trying to use code from Grid_Example.py)

2006-10-15 Thread [EMAIL PROTECTED]
To extend and revise my remarks my error is

 File "C:\Python24\Lib\site-packages\boa-constructor\test of
snake\csoundgrid.py", line 8, in create_grid
win = Grid_MegaExample.MegaTable(self, data, colnames, pugins)
NameError: global name 'self' is not defined
Script terminated.

http://www.dexrow.com
[EMAIL PROTECTED] wrote:
> I am having trouble trying to reuse the code that was provided in the
> wxdemo package of wxpython.  The program I am trying to use parts of is
> Grid_MegaExample.py thier code is
>
> class MegaTable(Grid.PyGridTableBase):
> """
> A custom wx.Grid Table using user supplied data
> """
> def __init__(self, data, colnames, plugins):
> """data is a list of the form
> [(rowname, dictionary),
> dictionary.get(colname, None) returns the data for column
> colname
> """
> # The base class must be initialized *first*
> Grid.PyGridTableBase.__init__(self)
> self.data = data
> self.colnames = colnames
> self.plugins = plugins or {}
> # XXX
> # we need to store the row length and column length to
> # see if the table has changed size
> self._rows = self.GetNumberRows()
> self._cols = self.GetNumberCols()
>
> My code is
>
> import wx.grid
> import os
> import sys
> import string
> import Grid_MegaExample
>
> def create_grid():
> win = Grid_MegaExample.MegaTable(self, data, colnames, pugins)
> win.Show(True)
>
> def create_colums(line):
> "creates colums based on what is passed to subroutine"
> for word in line:
> colnames = word
>
> def create_sco_grid(from_file):
> "reads .sco file and inputs it into a wx.grid"
> data = []
> infile = open(from_file, 'r')
> testline = 'false'
> for line in infile:
> if """;""" in line:
> create_colums(line)
> testline = 'true'
> if testline == 'true':
> for word in line:
> data.append(word)
> create_grid()
> create_sco_grid("""test.sco""")
> 
> 
> 
> 
> http://www.dexrow.com

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


wx.grid question (trying to use code from Grid_Example.py)

2006-10-15 Thread [EMAIL PROTECTED]
I am having trouble trying to reuse the code that was provided in the
wxdemo package of wxpython.  The program I am trying to use parts of is
Grid_MegaExample.py thier code is

class MegaTable(Grid.PyGridTableBase):
"""
A custom wx.Grid Table using user supplied data
"""
def __init__(self, data, colnames, plugins):
"""data is a list of the form
[(rowname, dictionary),
dictionary.get(colname, None) returns the data for column
colname
"""
# The base class must be initialized *first*
Grid.PyGridTableBase.__init__(self)
self.data = data
self.colnames = colnames
self.plugins = plugins or {}
# XXX
# we need to store the row length and column length to
# see if the table has changed size
self._rows = self.GetNumberRows()
self._cols = self.GetNumberCols()

My code is

import wx.grid
import os
import sys
import string
import Grid_MegaExample

def create_grid():
win = Grid_MegaExample.MegaTable(self, data, colnames, pugins)
win.Show(True)

def create_colums(line):
"creates colums based on what is passed to subroutine"
for word in line:
colnames = word

def create_sco_grid(from_file):
"reads .sco file and inputs it into a wx.grid"
data = []
infile = open(from_file, 'r')
testline = 'false'
for line in infile:
if """;""" in line:
create_colums(line)
testline = 'true'
if testline == 'true':
for word in line:
data.append(word)
create_grid()
create_sco_grid("""test.sco""")




http://www.dexrow.com

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


Re: python's OOP question

2006-10-15 Thread neoedmund
python use multiple inheritance.
but "inheritance" means you must inherite all methods from super type.
now i just need "some" methods from one type and "some" methods from
other types,
to build the new type.
Do you think this way is more flexible than tranditional inheritance?


Ben Finney wrote:
> [Please don't top-post above the text to which you're replying.]
>
> "neoedmund" <[EMAIL PROTECTED]> writes:
>
> > I'm trying to achieve a higher level of "reusability". Maybe it
> > cannot be done in python? Can anybody help me?
>
> What, specifically, are you trying to achieve? What problem needs
> solving?
>
> --
>  \ "If you're a horse, and someone gets on you, and falls off, and |
>   `\  then gets right back on you, I think you should buck him off |
> _o__) right away."  -- Jack Handey |
> Ben Finney

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

Re: python's OOP question

2006-10-15 Thread Ben Finney
[Please don't top-post above the text to which you're replying.]

"neoedmund" <[EMAIL PROTECTED]> writes:

> I'm trying to achieve a higher level of "reusability". Maybe it
> cannot be done in python? Can anybody help me?

What, specifically, are you trying to achieve? What problem needs
solving?

-- 
 \ "If you're a horse, and someone gets on you, and falls off, and |
  `\  then gets right back on you, I think you should buck him off |
_o__) right away."  -- Jack Handey |
Ben Finney

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

Re: python's OOP question

2006-10-15 Thread neoedmund
I'm trying to achieve a higher level of "reusability". Maybe it cannot
be done in python? Can anybody help me?


Ben Finney wrote:
> "neoedmund" <[EMAIL PROTECTED]> writes:
>
> > There's a program, it's result is "unexpected aaa", i want it to be
> > "expected aaa". how to make it work?
> >
> > [code]
> >
> > class C1(object):
> > def v(self, o):
> > return "expected "+o
> >
> > class C2(object):
> > def v(self, o):
> > return "unexpected "+o
> > def m(self):
> > print self.v("aaa")
> >
> > class C3(object):
> > def nothing(self):
> > pass
> >
> > def test1():
> > o = C3()
> > setattr(o,"m",C2().m)
> > setattr(o,"v",C1().v)
> > o.m()
>
> Setting attributes on an object externally isn't the same thing as
> making bound methods of that object.
>
> In this case, 'o.m' is a bound method of a C2 instance, and has no
> knowledge of C1. 'o.v' is a bound method of a C1 instance, and has no
> knowledge of C2. Neither of them has any knowledge of C3.
>
> What is it you're trying to achieve?
>
> --
>  \ "Unix is an operating system, OS/2 is half an operating system, |
>   `\   Windows is a shell, and DOS is a boot partition virus."  -- |
> _o__)  Peter H. Coffin |
> Ben Finney

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

Re: python's OOP question

2006-10-15 Thread neoedmund
thank you, Kay.

But i need a "dynamic" way. Say i have a existing class, and add some
method from other class into it.


Kay Schluehr wrote:
> neoedmund wrote:
> > There's a program, it's result is "unexpected aaa", i want it to be
> > "expected aaa". how to make it work?
> >
> > [code]
> >
> > class C1(object):
> > def v(self, o):
> > return "expected "+o
> >
> > class C2(object):
> > def v(self, o):
> > return "unexpected "+o
> > def m(self):
> > print self.v("aaa")
> >
> > class C3(object):
> > def nothing(self):
> > pass
> >
> > def test1():
> > o = C3()
> > setattr(o,"m",C2().m)
> > setattr(o,"v",C1().v)
> > o.m()
> >
> > test1()
> >
> > [/code]
>
> class C3(C1, C2):pass
>
> >>> C3.mro()  # shows method resolution order
> [, , ,
> ]
> 
> >>> o = C3()
> >>> o.m()
> expected aaa

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


Re: python's OOP question

2006-10-15 Thread Kay Schluehr
neoedmund wrote:
> There's a program, it's result is "unexpected aaa", i want it to be
> "expected aaa". how to make it work?
>
> [code]
>
> class C1(object):
>   def v(self, o):
>   return "expected "+o
>
> class C2(object):
>   def v(self, o):
>   return "unexpected "+o
>   def m(self):
>   print self.v("aaa")
>
> class C3(object):
>   def nothing(self):
>   pass
>
> def test1():
>   o = C3()
>   setattr(o,"m",C2().m)
>   setattr(o,"v",C1().v)
>   o.m()
>
> test1()
>
> [/code]

class C3(C1, C2):pass

>>> C3.mro()  # shows method resolution order
[, , ,
]

>>> o = C3()
>>> o.m()
expected aaa

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


Re: python's OOP question

2006-10-15 Thread Ben Finney
"neoedmund" <[EMAIL PROTECTED]> writes:

> There's a program, it's result is "unexpected aaa", i want it to be
> "expected aaa". how to make it work?
>
> [code]
>
> class C1(object):
>   def v(self, o):
>   return "expected "+o
>
> class C2(object):
>   def v(self, o):
>   return "unexpected "+o
>   def m(self):
>   print self.v("aaa")
>
> class C3(object):
>   def nothing(self):
>   pass
>
> def test1():
>   o = C3()
>   setattr(o,"m",C2().m)
>   setattr(o,"v",C1().v)
>   o.m()

Setting attributes on an object externally isn't the same thing as
making bound methods of that object.

In this case, 'o.m' is a bound method of a C2 instance, and has no
knowledge of C1. 'o.v' is a bound method of a C1 instance, and has no
knowledge of C2. Neither of them has any knowledge of C3.

What is it you're trying to achieve?

-- 
 \ "Unix is an operating system, OS/2 is half an operating system, |
  `\   Windows is a shell, and DOS is a boot partition virus."  -- |
_o__)  Peter H. Coffin |
Ben Finney

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


Weekly Python Patch/Bug Summary

2006-10-15 Thread Kurt B. Kaiser
Patch / Bug Summary
___

Patches :  431 open ( +3) /  3425 closed ( +8) /  3856 total (+11)
Bugs:  916 open (-23) /  6273 closed (+44) /  7189 total (+21)
RFE :  244 open ( +4) /   240 closed ( +1) /   484 total ( +5)

New / Reopened Patches
__

typo in PC/_msi.c  (2006-10-07)
CLOSED http://python.org/sf/1572724  opened by  jose nazario

Fix for segfault in ISO 2022 codecs  (2006-10-07)
CLOSED http://python.org/sf/1572832  opened by  Ray Chason

let quit and exit really exit  (2006-10-09)
CLOSED http://python.org/sf/1573835  opened by  Gerrit Holl

urllib2 - Fix line breaks in authorization headers  (2006-10-09)
   http://python.org/sf/1574068  opened by  Scott Dial

Add %var% support to ntpath.expandvars  (2006-10-09)
   http://python.org/sf/1574252  opened by  Chip Norkus

Mailbox will lock properly after flush()  (2006-10-11)
   http://python.org/sf/1575506  opened by  Philippe Gauthier

Support spawnvp[e] + use native execvp[e] on win32  (2006-10-12)
   http://python.org/sf/1576120  opened by  Snaury

os.utime acess denied with directories on win32  (2006-10-12)
CLOSED http://python.org/sf/1576166  opened by  Snaury

os.execvp[e] on win32 fails for current directory  (2006-10-13)
   http://python.org/sf/1576313  opened by  Snaury

Fix VC6 build, remove redundant files for VC7 build  (2006-10-14)
CLOSED http://python.org/sf/1576954  opened by  Larry Hastings

Fix VC6 build, remove redundant files for VC7 build  (2006-10-14)
CLOSED http://python.org/sf/1577078  opened by  Larry Hastings

Add _ctypes, _ctypes_test, and _elementtree to VC6 build  (2006-10-15)
CLOSED http://python.org/sf/1577551  opened by  Larry Hastings

newline in -DSVNVERSION=\"`LANG=C svnversion .`\"  (2006-10-15)
CLOSED http://python.org/sf/1577756  opened by  Daniel Stränger

Patches Closed
__

typo in PC/_msi.c  (2006-10-07)
   http://python.org/sf/1572724  closed by  gbrandl

Fix for segfault in ISO 2022 codecs  (2006-10-08)
   http://python.org/sf/1572832  closed by  perky

fix crash with continue in nested try/finally  (2006-08-18)
   http://python.org/sf/1542451  closed by  gbrandl

let quit and exit really exit  (2006-10-09)
   http://python.org/sf/1573835  closed by  mwh

Fix for Lib/test/crashers/gc_inspection.py  (2006-07-04)
   http://python.org/sf/1517042  closed by  gbrandl

os.utime acess denied with directories on win32  (2006-10-12)
   http://python.org/sf/1576166  closed by  loewis

Fix VC6 build, remove redundant files for VC7 build  (2006-10-14)
   http://python.org/sf/1576954  closed by  loewis

Fix VC6 build, remove redundant files for VC7 build  (2006-10-14)
   http://python.org/sf/1577078  deleted by  lhastings

Add _ctypes, _ctypes_test, and _elementtree to VC6 build  (2006-10-15)
   http://python.org/sf/1577551  closed by  loewis

newline in -DSVNVERSION=\"`LANG=C svnversion .`\"  (2006-10-15)
   http://python.org/sf/1577756  deleted by  schmaller

New / Reopened Bugs
___

cElementTree.SubElement doesn't recognize keyword "attrib"  (2006-10-07)
CLOSED http://python.org/sf/1572710  opened by  Mark Stephens

import org.python.core imports local org.py  (2006-10-08)
CLOSED http://python.org/sf/1573180  opened by  E.-O. Le Bigot

ctypes unit test fails (test_macholib.py) under MacOS 10.4.7  (2006-08-21)
CLOSED http://python.org/sf/1544102  reopened by  ronaldoussoren

struct module doesn't use weakref for cache  (2006-10-08)
CLOSED http://python.org/sf/1573394  opened by  Mark Flacy

sqlite3 documentation on rowcount is contradictory  (2006-10-10)
   http://python.org/sf/1573854  opened by  Seo Sanghyeon

if(status = ERROR_MORE_DATA)  (2006-10-09)
CLOSED http://python.org/sf/1573928  opened by  Helmut Grohne

WSGI, cgi.FieldStorage incompatibility  (2006-10-09)
   http://python.org/sf/1573931  opened by  Michael Kerrin

isinstance swallows exceptions  (2006-10-09)
   http://python.org/sf/1574217  opened by  Brian Harring

os.popen with os.close gives error message  (2006-10-10)
   http://python.org/sf/1574310  opened by  dtrosset

Error with callback function and as_parameter with NumPy ndp  (2006-10-10)
   http://python.org/sf/1574584  opened by  Albert Strasheim

ctypes: Pointer-to-pointer unchanged in callback  (2006-10-10)
   http://python.org/sf/1574588  opened by  Albert Strasheim

ctypes: Returning c_void_p from callback doesn't work  (2006-10-10)
   http://python.org/sf/1574593  opened by  Albert Strasheim

Request wave support > 16 bit samples  (2006-10-11)
   http://python.org/sf/1575020  opened by  Murray Lang

isSequenceType returns True for dict subclasses (<> 2.3)  (2006-10-11)
   http://python.org/sf/1575169  opened by  Martin Gfeller

typo: section 2.1 -> property  (2006-10-12)
CLOSED http://python.org/sf/1575746  opened by  Antoine De Groote

Missing notice on environment setting LD_LIBRARY_PATH  (2006-10-12)
CLOSED http://python.or

Re: IDE that uses an external editor?

2006-10-15 Thread Dan Sommers
On Sun, 15 Oct 2006 23:34:14 +0200,
"Ramon Diaz-Uriarte" <[EMAIL PROTECTED]> wrote:

> ... I guess, though, that this is very personal ...

Absolutely.

> ... and that I might be missing the point of Eclipse (and I don't do
> any Java programming).

The point of Eclipse is to lessen the burden imposed by Java.  :-/

(I can say that now that they've been making me write Java at work for a
few months.  Without starting a language flamewar, I can definitely
understand why the Java folks are so into their IDEs while us Python
folks can get along as well or better with grep and a decent REPL.)

Regards,
Dan

-- 
Dan Sommers

"I wish people would die in alphabetical order." -- My wife, the genealogist
-- 
http://mail.python.org/mailman/listinfo/python-list


python's OOP question

2006-10-15 Thread neoedmund
There's a program, it's result is "unexpected aaa", i want it to be
"expected aaa". how to make it work?

[code]

class C1(object):
def v(self, o):
return "expected "+o

class C2(object):
def v(self, o):
return "unexpected "+o
def m(self):
print self.v("aaa")

class C3(object):
def nothing(self):
pass

def test1():
o = C3()
setattr(o,"m",C2().m)
setattr(o,"v",C1().v)
o.m()

test1() 

[/code]

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


Re: problem with the 'math' module in 2.5?

2006-10-15 Thread Steven D'Aprano
On Sun, 15 Oct 2006 20:03:18 +1000, Ben Finney wrote:

> "Paddy" <[EMAIL PROTECTED]> writes:
> 
>> Ben Finney wrote:
>> > Your calculator is probably doing rounding without you asking for
>> > it.
>> >
>> > Python refuses to guess what you want, and gives you the
>> > information available.
>>
>> I don't think Python should take too much credit here.
> 
> I don't understand what you could mean by this. Credit for "giv[ing]
> you the information available"? That's exactly what it's doing.
> 
>> Floating point calcuations are subject to rounding. Sometimes it
>> shows.
> 
> And Python is showing it, rather than hiding it. It certainly isn't
> doing any rounding unless asked to do so.

Python simply exposes whatever the C maths library does. The C maths
library is almost certainly doing some rounding: floats have only a finite
precision, which generally means the designer of the math library has two
choices: just truncate (chop) the calculation, or carry extra guard digits
(or bits) and round down. Most systems these days use guard digits, as
that is more accurate than truncating to a fixed precision.

If you mean that Python isn't doing *extra* rounding, above and beyond
what the C library is doing, you're correct. But rounding is happening.

This is a useful resource:

"What every computer scientist should know about floating-point
arithmetic"
http://docs.sun.com/source/806-3568/ncg_goldberg.html

To go back to the Original Poster's problem, he pointed out that his "16
bit calculator" gave a more accurate (but less precise) answer for
sin(pi), namely 0, instead of the more precise (but less accurate)
1.2246063538223773e-016 that Python reported. That just goes to show that,
sometimes, extra precision in floating point maths is a bad thing -- a
less precise library would actually have given a more correct answer.

This isn't strictly a Python question, but if there is anybody out there
who knows what the C library is doing, I'd appreciate an answer: since
sine is periodic, doesn't it make sense to reduce the argument modulo pi
before calculating the sine? Something like this:

def _sin(x):
x = x % math.pi
return math.sin(x)

Yes, you lose precision for large values of x because of the modulo, and
because math.pi isn't precisely pi, but that's got to be better than
losing precision for moderate values of x, surely? Have I missed something?


-- 
Steve.

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


Re: classroom constraint satisfaction problem

2006-10-15 Thread Carl Banks
Steven Bethard wrote:
> I'm trying to solve a constraint-satisfaction problem, and I'm having
> some troubles framing my problem in such a way that it can be
> efficiently solved.
>
> Basically, I want to build groups of two teachers and four students such
> that [1]:
>
> * Students are assigned to exactly one group
> * Teachers are assigned to approximately the same number of groups
> * Students are not in groups with their homeroom teachers
> * Students in each group are from four different homerooms
>
> So given teachers A, B, C, D, E and F and their corresponding students
> A1, A2, ... F3, F4, here's a good grouping:
>
> A, B:   C1, D1, E1, F1
> B, C:   A1, D2, E2, F2
> C, D:   A2, B1, E3, F3
> D, E:   A3, B2, C2, F4
> E, F:   A4, B3, C3, D3
> F, A:   B4, C4, D4, E4

[snip]

> [1] There are actually two other constraints that I omitted:
>
> * Some teachers cannot be placed in the same group, e.g. I might know
> that A cannot work with B or that E cannot work with F.
>
> * If you create a graph out of the teacher pairs from all the groups,
> the graph should not be disconnected.  That is, the following grouping
> is bad because the teachers are disconnected:

I would do it in two steps.

Step 1: Generate a graph of all teachers, such that there is one
connection for every four students, and each teacher has approximately
equal number of connections.  A simple, approximate way to do this
would be to generate random subsets of two teachers until you have
enough connections (though that won't work well if you have a lot of
teachers that can't work together, which wouldn't be surprising).  I'm
sure graph theory has some algorithms to do this if you need more
exactitude.

Step 2: Assign students from appropriate homerooms to each connection.
The following simple algorithm is probably satisfactory: for each
connection between teachers, choose a random subset of four homerooms
not governed by those teachers to form a group.  Assign a random
student from each homeroom.  Once every student from a homeroom has
been been assigned, remove that homeroom from the set of available
homerooms.  With this method, you might have some connections at the
end without enough remaining homerooms; just go fishing for a suitable
switch among students already assigned.  Or, work out a way to make
sure you don't exhaust too many homerooms.  Perhaps there is a known
algorithm for doing this.

Carl Banks

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


Re: SOAPpy and callback

2006-10-15 Thread fabien . benard
Ok guys, thanks for the lesson! I'm probably not going to try to
implement this solution. However, I've learned a lot!

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


Re: A friendlier, sugarier lambda -- a proposal for Ruby-like blocks in python

2006-10-15 Thread Steven D'Aprano
On Sat, 14 Oct 2006 09:00:53 +, James Stroud wrote:

> > Compared to the Python I know and love, Ruby isn't quite the same.
> > However, it has at least one terrific feature: "blocks".

[snip 220-odd quoted lines]

> http://mail.python.org/pipermail/python-list/2004-April/215805.html


Hi James,

You seem to have mislaid your snipper. It is very useful for when you're
replying to a very large post, and all you want to do is add a single line
at the end. It reduces frustration in readers who find themselves
scrolling, and scrolling, and scrolling, and scrolling through quoted text
they've already read, wondering why you've quoted all this stuff if you
aren't actually commenting on it, and prevents readers from unfairly
dismissing you as just another "metoobie".



-- 
Steven.

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


Re: Book about database application development?

2006-10-15 Thread Peter Decker
On 10/15/06, Wolfgang Keller <[EMAIL PROTECTED]> wrote:

> What I'm interested in is rather how to connect a GUI to a database, with
> quite a bit of application logic in between. And how to do it well.

You've described Dabo perfectly. Have you looked into it yet? It's
written by a couple of database application developers.

-- 

# p.d.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: IDE that uses an external editor?

2006-10-15 Thread Jorge Godoy
[EMAIL PROTECTED] writes:

> >> #> I realize I can do a lot within Emacs/XEmacs, but I suspect with a
> >> #> tool like Eclipse I could do more. However, I don't want to give
> >> #> up the text editing power of Emacs to get it.
> ...
> Ramon> I've tried using Eclipse several times, because several good
> Ramon> meaning people told me things like "you coud do more". 
>
> My observation about Eclipse comes simply from watching one of the other
> developers at work use it.  I'd like to give it a try, but not at the
> expense of giving up Emacs.

Eclipse: just a GUI over a subset of Emacs today.

One day, when it evolves, it will be something interesting...  I won't give up
on Emacs loading fast and allowing me to work remotely for something that
makes the machine crawl and requires almost all of the RAM I have.

-- 
Jorge Godoy  <[EMAIL PROTECTED]>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: SPE for 2.5?

2006-10-15 Thread Fuzzyman

SPE - Stani's Python Editor wrote:
> John Salerno schreef:
>
> > Does anyone know if SPE is compatible with Python 2.5? I don't see a
> > Windows exe file for 2.5, so I wasn't sure if I should use the 2.4 version.
> >
> > Thanks.
>
> It should be. Contact me and I'll help you to make a 2.5 installer,
> which I'll gladly provide for download. I use SPE on daily basis
> myself.

Hello Stani,

Work on it does seem to have slowed down.

When do you expect your new project to start bearing fruit ?

Fuzzyman
http://www.voidspace.org.uk


> 
> Stani

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


Re: SPE for 2.5?

2006-10-15 Thread SPE - Stani's Python Editor
John Salerno schreef:

> Does anyone know if SPE is compatible with Python 2.5? I don't see a
> Windows exe file for 2.5, so I wasn't sure if I should use the 2.4 version.
>
> Thanks.

It should be. Contact me and I'll help you to make a 2.5 installer,
which I'll gladly provide for download. I use SPE on daily basis
myself.

Stani

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


[ANN] rest2web 0.5.0 Final

2006-10-15 Thread Fuzzyman
At last `rest2web 0.5.0 Final
`_ is released.

Quick download links:

* `rest2web-0.5.0.zip
`_
* `rest2web-0.5.0.tar.gz
`_

This release has several bugfixes, as well as some interesting new
features, over previous releases.

Release Summary
=

Important changes since the last release (0.5.0 Beta 1) include:

* All the standard `macros
`_ are now
built-in. There is no need for a separate macro file if you are only
using the standard ones.
* A new 'skiperrors' config file / command line option. Errors in
processing a file can now be ignored and rest2web will attempt to
continue processing.
* A config file is no longer required in force mode. (The current
directory is used as the source directory and html output is put into a
subdirectory called 'html'.)
* The restindex and uservalues block may now be in a ReST comment. This
means that rest2web source documents with a restindex can still be
valid ReStructured Text documents.


What is rest2web
=

**rest2web** is a tool for creating websites, parts of websites, and
project documentation.

It allows you to keep your site contents in `ReStructured Text
`_ or {acro;HTML;HyperText Markup
Language}.

Using a flexible templating system, using embedded Python code for
unlimited flexibility and no new templating language to learn, it can
then output the HTML for your site.

**rest2web** is extremely flexible, with many optional features, making
it suitable for building all kinds of websites.

See the `main page `_ for
links to some of the sites built with rest2web.


What's New ?
==

You can find the full changelog: `here
`_.

Paths in the ``file`` keyword and in the config file now have '~'
expanded. This
means they can use paths relative to the user directory. (Plus the
'colorize' and
'include' macros.)

Added 'skiperrors' config file / command line option. Errors in
processing a file can now be
ignored and rest2web will attempt to continue processing.

Fixed bug where non-ascii uservalues would blow up.

There was a bug in handling tabs in embedded code. This has been fixed.

The macro system has been revamped. All the standard macros are now
built in
as default macros. The modules needed by the default macros are also
now built
into rest2web. You can still add your own macros, or override the
default ones,
by supplying an additional macros file.

``Macro Paths`` section added to the config file for configuring the
default
macros ``smiley`` and ``emoticon``.

The initial message printed by rest2web has been changed to ``INFO``
level, so
that it is not displayed by the ``-a`` and ``-w`` verbosity levels.

The namespace and uservalues for each page are now available to the
macros,
using global variables ``uservalues`` and ``namespace`` (dictionaries).
This
means you can write macros that are customised for individual pages.

A config file is no longer required in force mode. (The current
directory is
used as the source directory and html output is put into a subdirectory
called
'html'.)

The restindex and uservalues block may now be in a ReST comment. This
means
that rest2web source documents with a restindex can still be valid
ReStructured
Text documents.

Fixed imports in the gallery plugin. (Thanks to Steve Bethard.)

Changed over to use the latest version of
`StandOut `_.

rest2web now exits with an error code corresponding to the number of
warnings and errors generated.

Errors and warnings are now output on ``sys.stderr``.

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


classroom constraint satisfaction problem

2006-10-15 Thread Steven Bethard
I'm trying to solve a constraint-satisfaction problem, and I'm having 
some troubles framing my problem in such a way that it can be 
efficiently solved.

Basically, I want to build groups of two teachers and four students such 
that [1]:

* Students are assigned to exactly one group
* Teachers are assigned to approximately the same number of groups
* Students are not in groups with their homeroom teachers
* Students in each group are from four different homerooms

So given teachers A, B, C, D, E and F and their corresponding students 
A1, A2, ... F3, F4, here's a good grouping:

A, B:   C1, D1, E1, F1
B, C:   A1, D2, E2, F2
C, D:   A2, B1, E3, F3
D, E:   A3, B2, C2, F4
E, F:   A4, B3, C3, D3
F, A:   B4, C4, D4, E4


My current solution is to create a constraint satisfaction problem using 
python-constraint (http://labix.org/python-constraint) where there are 
variables for:

* each student  domain: group names
* each group name   domain: all pairs of teachers

This works for simple problems, but because most of my constraints have 
to iterate over all students and/or all groups, this takes way too long 
on my real dataset (which has 300+ students).  I thought about trying to 
reframe the problem so that there are variables for:

* each group name   domain: pairs of teachers X 4-tuples of students

but that seems like it would be generating something like 15^2*300^4 
items for the domain, which is clearly also going to be way too big.


Any suggestions on how to speed things up?  I've posted my current code_ 
and the tests_ in case anyone has the time to look at them.

.. _code: http://ucsu.colorado.edu/~bethard/py/constraint/student_groups.py
.. _tests:
http://ucsu.colorado.edu/~bethard/py/constraint/test_student_groups.py


Thanks!

Steve


[1] There are actually two other constraints that I omitted:

* Some teachers cannot be placed in the same group, e.g. I might know 
that A cannot work with B or that E cannot work with F.

* If you create a graph out of the teacher pairs from all the groups, 
the graph should not be disconnected.  That is, the following grouping 
is bad because the teachers are disconnected:

A, B: ...
C, D: ...
A, B: ...

while this grouping would be okay:

A, B: ...
B, C: ...
C, D: ...
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: IDE that uses an external editor?

2006-10-15 Thread skip

>> #> I realize I can do a lot within Emacs/XEmacs, but I suspect with a
>> #> tool like Eclipse I could do more. However, I don't want to give
>> #> up the text editing power of Emacs to get it.
...
Ramon> I've tried using Eclipse several times, because several good
Ramon> meaning people told me things like "you coud do more". 

My observation about Eclipse comes simply from watching one of the other
developers at work use it.  I'd like to give it a try, but not at the
expense of giving up Emacs.

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


Re: OT: What's up with the starship?

2006-10-15 Thread rurpy

Robert Hicks wrote:
> [EMAIL PROTECTED] wrote:
> > T. Bryan wrote:
> > > Thomas Heller wrote:
> > >
> > > > I cannot connect to starship.python.net: neither http, nor can I login
> > > > interactively with ssl (and the host key seems to have changed as well).
> > > >
> > > > Does anyone know more?
> > >
> > > starship.python.net was compromised.  It looked like a rootkit may have 
> > > been
> > > installed.  The volunteer admins are in the process of reinstalling the OS
> > > and rebuilding the system.  That process will probably take a few days at
> > > least.
> >
> > Does anyone know more?
> >
> > What about the integrity of the python packages hosted there?
> > When was the site compromised?
> > I just installed the python 2.5 pywin module last week.
> > Should I be concerned?
> >
> > Is this related to the Python security problem recently announced?
>
> Did you even read about the vulnerability?

Yes.  Do you have any answers, or do you just enjoy posting irrevelant
responses?

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


Re: IDE that uses an external editor?

2006-10-15 Thread Ramon Diaz-Uriarte
On 10/14/06, Slawomir Nowaczyk <[EMAIL PROTECTED]> wrote:
> On Sat, 14 Oct 2006 13:01:17 -0500
> [EMAIL PROTECTED] wrote:

(...)
> #> I realize I can do a lot within Emacs/XEmacs, but I suspect with a
> #> tool like Eclipse I could do more. However, I don't want to give up
> #> the text editing power of Emacs to get it.
>
> I don't know... I have never, personally, used Eclipse, so I cannot
> comment on that. It is highly dependent on what you are working on, I
> presume.
>


I've tried using Eclipse several times, because several good meaning
people told me things like "you coud do more". But I've always: a)
felt overwhelmed and lost (like in "this is way too complex"); b) felt
deprived of valuable screen real-state (it might be personal thing,
because on my .emacs I turn off the toolbar and menu bar); c)
eventually felt that time reading the Eclipse tutorial and docs would
be better spent reading more of the Emacs manual. I guess, though,
that this is very personal, and that I might be missing the point of
Eclipse (and I don't do any Java programming).


-- 
Ramon Diaz-Uriarte
Statistical Computing Team
Structural Biology and Biocomputing Programme
Spanish National Cancer Centre (CNIO)
http://ligarto.org/rdiaz
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: problem with the 'math' module in 2.5?

2006-10-15 Thread andy2O
Chris wrote:
> sin(pi*0.5) is what I expected, but I expected to get 0 for sin(pi).

Computers in general, and Python too, usually use floating point
arithmetic in which all numbers are approximated by rational numbers of
a particular form (see http://en.wikipedia.org/wiki/Floating_point for
details).

1) pi is an irrational number, so it *cannot* be represented exactly in
floating point. Therefore the value of pi in your call to the sin
function is definitely, proveably, *not* exactly equal to the true
value of pi.

2) So, even if the function "sin" could be evaluated exactly, the fact
that you are not evaluating it exactly at the true value of pi, but
instead at a good but imperfect approximation to this value, means that
the sine function *should not* give the result = 0 for your request!

3) The function sin is also evaluated to only a finite degree of
precision - just like everything else in floating point arithmetic.
Therefore you should not expect absolutely precise results. Instead,
you need to understand the limitations of floating point arithmetic,
understand the precision you *can* expect, and work within these
bounds. It's a good system, but you do need to understand its
limitations. The links other people have posted are good resources for
this.

Best wishes,
andy

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


Re: Tkinter: populating Mac Help menu?

2006-10-15 Thread Edward K. Ream
> hm = Menu(mb, name='help')

Yes, that worked.  Many thanks for your help with Help.

Edward

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



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


Re: Reverse string-formatting (maybe?)

2006-10-15 Thread Dustan

> Only you know what anomalies will be found in your data-sets.  If
> you know/assert that
>
> -the only stuff in the formatting string is one set of characters
>
> -that stuff in the replacement-values can never include any of
> your format-string characters
>
> -that you're not using funky characters/formatting in your format
> string (such as "%%" possibly followed by an "s" to get the
> resulting text of "%s" after formatting, or trying to use other
> formatters such as the aforementioned "%f" or possibly "%i")
>
> then you should be safe.  It could also be possible (with my
> original replacement of "(.*)") if your values will never include
> any substring of your format string.  If you can't guarantee
> these conditions, you're trying to make a cow out of hamburger.
> Or a pig out of sausage.  Or a whatever out of a hotdog. :)
>
> Conventional wisdom would tell you to create a test-suite of
> format-strings and sample values (preferably worst-case funkiness
> in your expected format-strings/values), and then have a test
> function that will assert that the unformatting of every
> formatted string in the set returns the same set of values that
> went in.  Something like
>
> tests = {
>   'I was %s but now I am %s' : [
>   ('hot', 'cold'),
>   ('young', 'old'),
>   ],
>   'He has 3 %s and 2 %s' : [
>   ('brothers', 'sisters'),
>   ('cats', 'dogs')
>   ]
>   }
>
> for format_string, values in tests:
>   unformatter = format.replace('%s', '(.*)')
>   for value_tuple in values:
>   formatted = format_string % value_tuple
>   unformatted = unformatter.search(formatted).groups()
>   if unformatted <> value_tuple:
>   print "%s doesn't match %s when unformatting %s" % (
>   unformatted,
>   value_tuple
>   format_string)
> 
> -tkc

Thanks for all your help. I've gotten the idea.

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


Re: OT: What's up with the starship?

2006-10-15 Thread Robert Hicks

[EMAIL PROTECTED] wrote:
> T. Bryan wrote:
> > Thomas Heller wrote:
> >
> > > I cannot connect to starship.python.net: neither http, nor can I login
> > > interactively with ssl (and the host key seems to have changed as well).
> > >
> > > Does anyone know more?
> >
> > starship.python.net was compromised.  It looked like a rootkit may have been
> > installed.  The volunteer admins are in the process of reinstalling the OS
> > and rebuilding the system.  That process will probably take a few days at
> > least.
>
> Does anyone know more?
>
> What about the integrity of the python packages hosted there?
> When was the site compromised?
> I just installed the python 2.5 pywin module last week.
> Should I be concerned?
>
> Is this related to the Python security problem recently announced?

Did you even read about the vulnerability?

Robert

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


Re: Book about database application development?

2006-10-15 Thread Wolfgang Keller
Hello,

and thanks for your reply, but...

> Here's a start:
> 
> http://philip.greenspun.com/sql/

...small misunderstanding: I already know a bit of SQL, and I intend to avoid 
its use as far as possible (and use e.g. Modeling or SQLAlchemy).  

What I'm interested in is rather how to connect a GUI to a database, with 
quite a bit of application logic in between. And how to do it well.

Sincerely,

Wolfgang Keller

-- 
My email-address is correct.
Do NOT remove ".nospam" to reply.

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


Re: paseline(my favorite simple script): does something similar exist?

2006-10-15 Thread RickMuller
Amazing! There were lots of great suggestions to my original post, but
I this is my favorite.

Rick

Fredrik Lundh wrote:
> RickMuller wrote:
>
> > I'm posting this here because (1) I'm feeling smug at what a bright
> > little coder I am
>
> if you want to show off, and use a more pythonic interface, you can do
> it with a lot fewer lines.  here's one example:
>
> def parseline(line, *types):
>  result = [c(x) for (x, c) in zip(line.split(), types) if c] or [None]
>  return len(result) != 1 and result or result[0]
>
> text = "H0.000   0.000   0.000"
>
> print parseline(text, str, float, float, float)
> print parseline(text, None, float, float, float)
> print parseline(text, None, float)
>
> etc.  and since you know how many items you'll get back from the
> function, you might as well go for the one-liner version, and do
> the unpacking on the way out:
>
> def parseline(line, *types):
>  return [c(x) for (x, c) in zip(line.split(), types) if c] or [None]
>
> text = "H0.000   0.000   0.000"
>
> [tag, value] = parseline(text, str, float)
> [value] = parseline(text, None, float)
> 
> 

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


run subprocess in separate window

2006-10-15 Thread Radek
Hi,

I am trying to create GUI launcher of several applications using Python
and Tkinter.

Currently when using subprocess.Popen("mycommand") all output goes to
the stdout of my launcher.

For some command line applications I need to launch them so that their
output goes into the separate "terminal" window.

How can I make it?

Thanks,

Radek

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


Re: Where can I find good python code?

2006-10-15 Thread vasudevram

Chris Lambacher wrote:
> On Sat, Oct 14, 2006 at 01:08:37AM +0900, js  wrote:
> >  Hi,
> >
> > I've learned basics of Python and want to go to the next step.
> > So I'm looking for good python examples
> > I steal good techniques from.
> >
> > I found Python distribution itself contains some examples in Demo directory.
> > I spent some time to read them and
> > I think they're good but seemed not so practical to me.
> >
> > Any recommendations?
> A large portion of the standard library is pure python and of high
> quality(thats how it made it there in the first place).  The newer a module is
> to the library, the better it will conform to current best practices.
>
> On Unix environments you can find the standard library in
> $PREFIX/lib/python$VERSION/ where $PREFIX is often /usr but sometimes
> /usr/local and version is the version you have installed (maybe 2.4 or 2.5?)
>
> On Windows you can find the standard library in c:\Python%VERSION%\Lib where
> %VERSION% is the version you installed (maybe 24 or 25?)
>
> -Chris

Try reading the code in this package:
http://sourceforge.net/projects/xtopdf
Not very idiomatic or Pythonic code (done when I was still fairly new
to Python), but clear, well-commented - IMO, of course.
Also it is a real-world, though small, app, with both end-user tools
and a developer API.
So you can play around with using and extending it, etc. - and its easy
to understand too.
Might help motivate the learning if you try to build something useful
with it :-)

HTH
Vasudev Ram
~~
Software training and consulting
Dancing Bison Enterprises
http://www.dancingbison.com
~~

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


Re: Cannot import a module from a variable

2006-10-15 Thread Colin J. Williams
Christian Joergensen wrote:
> "Jia Lu" <[EMAIL PROTECTED]> writes:
> 
>> Hi all:
>>
>> I try to do things below:
> import sys
> for i in sys.modules.keys():
>>  import i
>> Traceback (most recent call last):
>>   File "", line 2, in 
>> import i
>> ImportError: No module named i
>>
>> But it seems that import donot know what is i ? why?
> 
> Try using __import__(i) instead.
> 
(a) you need something like exec('import ' + i) for most cases
but (b) "encodings" is a package i.e. it points to a directory which has 
an __init__.py file.

Colin W.

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


Re: Output from subprocess.Popen()

2006-10-15 Thread Clodoaldo Pinto Neto

Fredrik Lundh wrote:
> this works for me:
>
>  >>> f = subprocess.Popen("set | grep IFS", shell=True,
> stdout=subprocess.PIPE)
>  >>> f.stdout.readlines()
> ["IFS=$' \\t\\n'\n"]
>
> what does the above return on your machine?

>>> f = subprocess.Popen("set | grep IFS", shell=True, stdout=subprocess.PIPE)
>>> f.stdout.readlines()
["BASH_EXECUTION_STRING='set | grep IFS'\n", "IFS=' \t\n"]

I'm on FC5

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


Re: A friendlier, sugarier lambda -- a proposal for Ruby-like blocks in python

2006-10-15 Thread [EMAIL PROTECTED]
Alexey Borzenkov wrote:
> [EMAIL PROTECTED] wrote:
> > but maybe it reduces code readabilty a bit for people
> > that have just started to program:
> >
> > mul2 = def(a, b):
> > return a * b
> >
> > Instead of:
> >
> > def mul2(a, b):
> > return a * b
>
> For such simple cases, yes. What about:
>
>   button.click += def(obj):
> # do stuff
>
> You obviously can't:
>
>   def button.click(obj):
> # do stuff
>
> :-) And if you make intermediate function and then assign it somewhere,
> it "pollutes namespace": it's still left there, unneeded.

If you're really uptight about it you can
def temp_function(...):
  
button.click = temp_function
del(temp_function)

But for something like the example I'd probably just use a local name
wherever the definition is needed; there's no namespace pollution in
any meaningful sense then.

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


Re: Cannot import a module from a variable

2006-10-15 Thread Christian Joergensen
"Jia Lu" <[EMAIL PROTECTED]> writes:

> Hi all:
>
> I try to do things below:
import sys
 for i in sys.modules.keys():
>   import i
> Traceback (most recent call last):
>   File "", line 2, in 
> import i
> ImportError: No module named i
>
> But it seems that import donot know what is i ? why?

Try using __import__(i) instead.

-- 
Christian Joergensen | Linux, programming or web consultancy
http://www.razor.dk  | Visit us at: http://www.gmta.info
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: OT: What's up with the starship?

2006-10-15 Thread rurpy

T. Bryan wrote:
> Thomas Heller wrote:
>
> > I cannot connect to starship.python.net: neither http, nor can I login
> > interactively with ssl (and the host key seems to have changed as well).
> >
> > Does anyone know more?
>
> starship.python.net was compromised.  It looked like a rootkit may have been
> installed.  The volunteer admins are in the process of reinstalling the OS
> and rebuilding the system.  That process will probably take a few days at
> least.

Does anyone know more?

What about the integrity of the python packages hosted there?
When was the site compromised?
I just installed the python 2.5 pywin module last week.
Should I be concerned?

Is this related to the Python security problem recently announced?

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


Re: Where I can find

2006-10-15 Thread Grant Edwards
On 2006-10-15, Lawrence Oluyede <[EMAIL PROTECTED]> wrote:
><[EMAIL PROTECTED]> wrote:

>> Where I can find this files(modules):
>> 
>> fcntl,FCNTL,tty,termios, TERMIOS
>
> import fcntl
> import tty
> import termios
>
> for start :-)

But you just might want to take a look at pyserial instead...

-- 
Grant Edwards   grante Yow!  Is this my STOP??
  at   
   visi.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Cannot force configure/setup.py to pick up location of readline (SFWrline) on Solaris 10

2006-10-15 Thread Chris Miles
Martin v. Löwis wrote:
> You need to use GNU make for that to work. The build regenerates the
> makefile, but Sun make doesn't recognize the change. There was a message
> telling you so.

Thanks Martin, you are totally correct.  Using gmake avoids the problem.

> Also, your original complaint wasn't that readline isn't considered,
> but that setup.py didn't find it even though configure did. A patch
> fixing that has a higher chance of being accepted than a patch adding
> /opt/sfw to the standard search path (which is really a decision
> Sun should take, not the Python maintainers - in absence of a Sun
> change, it's then the local administrator who decides).

Fair point.  If time permits I'll look into constructing such a patch.

Cheers,
Chris

-- 
http://chrismiles.info/

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


Re: Output from subprocess.Popen()

2006-10-15 Thread Fredrik Lundh
Clodoaldo Pinto Neto wrote:

> Output from the shell:
> 
> [EMAIL PROTECTED] teste]$ set | grep IFS
> IFS=$' \t\n'
> 
> Output from subprocess.Popen():
> 
 import subprocess as sub
 p = sub.Popen('set | grep IFS', shell=True, stdout=sub.PIPE)
 p.stdout.readlines()[1]
> "IFS=' \t\n"
> 
> Both outputs for comparison:stdout=subprocess.PIPE)
> IFS=$' \t\n'
> "IFS=' \t\n"
> 
> The subprocess.Popen() output is missing the $ and the last '

if you expect one line of output, why are you doing readlines()[1] ?

 >>> f = subprocess.Popen("set | grep IFS", shell=True,
 >>> f.stdout.readlines()[1]
Traceback (most recent call last):
Traceback (most recent call last):
   File "", line 1, in 
IndexError: list index out of range

this works for me:

 >>> f = subprocess.Popen("set | grep IFS", shell=True, 
stdout=subprocess.PIPE)
 >>> f.stdout.readlines()
["IFS=$' \\t\\n'\n"]

what does the above return on your machine?



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


Re: Where I can find

2006-10-15 Thread Lawrence Oluyede
<[EMAIL PROTECTED]> wrote:
> Where I can find this files(modules):
> 
> fcntl,FCNTL,tty,termios, TERMIOS

import fcntl
import tty
import termios

for start :-)

-- 
Lawrence - http://www.oluyede.org/blog
http://www.neropercaso.it
"Nothing is more dangerous than an idea
if it's the only one you have" - E. A. Chartier
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Problem with importing a package

2006-10-15 Thread Fredrik Lundh
[EMAIL PROTECTED] wrote:

> I have to work with matrices on python and for that i need a package
> NUMPY. I downloaded it and saved it in the same folder as the program
> which imports it. But on running the program it gives an error
> "ImportError: No module named numpy". Do we need to save the file
> required to be imported in a specific folder?

did you follow the installation instructions supplied with that library?



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


Output from subprocess.Popen()

2006-10-15 Thread Clodoaldo Pinto Neto
Output from the shell:

[EMAIL PROTECTED] teste]$ set | grep IFS
IFS=$' \t\n'

Output from subprocess.Popen():

>>> import subprocess as sub
>>> p = sub.Popen('set | grep IFS', shell=True, stdout=sub.PIPE)
>>> p.stdout.readlines()[1]
"IFS=' \t\n"

Both outputs for comparison:
IFS=$' \t\n'
"IFS=' \t\n"

The subprocess.Popen() output is missing the $ and the last '

How to get the raw shell output from subprocess.Popen()?

Regards, Clodoaldo Pinto Neto

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


Re: Where I can find

2006-10-15 Thread Martin v. Löwis
[EMAIL PROTECTED] schrieb:
> Where I can find this files(modules):
> 
> fcntl,FCNTL,tty,termios, TERMIOS

They are included in the standard installation of Python.
Notice that some of them work only on Unix.
Also notice that FCNTL no longer exist; I'm not sure
whether TERMIOS ever existed.

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


Re: Cannot force configure/setup.py to pick up location of readline (SFWrline) on Solaris 10

2006-10-15 Thread Martin v. Löwis
Chris Miles schrieb:
> I hope this process can be improved, and if I have time I'll look at why
> make fails half way but works fine when kicked off a second time.

You need to use GNU make for that to work. The build regenerates the
makefile, but Sun make doesn't recognize the change. There was a message
telling you so.

GNU make will see that the makefile was rebuilt, and re-read it before
proceeding.

> I'd like to get /opt/sfw/ added to the standard lib/include path for
> Solaris (10 at least) as this is where Sun's open-source packages get
> installed.  Is this just a matter of raising a ticket?

Not easily - resolving this might take months or years. If you provide
a well-engineered patch, chances that Python changes are much higher.

Also, your original complaint wasn't that readline isn't considered,
but that setup.py didn't find it even though configure did. A patch
fixing that has a higher chance of being accepted than a patch adding
/opt/sfw to the standard search path (which is really a decision
Sun should take, not the Python maintainers - in absence of a Sun
change, it's then the local administrator who decides).

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


Re: Cannot force configure/setup.py to pick up location of readline (SFWrline) on Solaris 10

2006-10-15 Thread Chris Miles
Thanks to those who offered suggestions for this.

It appears that building Python 2.4.3 on Solaris 10 with readline 
(SFWrline package) support is a little long-winded but possible, using 
the following steps:

$ ./configure --prefix=/opt/python-2.4.3 --enable-shared
$ vi Modules/Setup.local
--- add one line: ---
readline readline.c -I/opt/sfw/include -L/opt/sfw/lib -lreadline -ltermcap
-
$ make
### will fail with ld error: ###
Undefined   first referenced
symbol in file
initreadline./libpython2.4.so
ld: fatal: Symbol referencing errors. No output written to python
collect2: ld returned 1 exit status
*** Error code 1
make: Fatal error: Command failed for target `python'

### however, just running make again ends up building fine ... ###
$ make
$ make install  # might need root access (sudo/su)

I hope this process can be improved, and if I have time I'll look at why 
make fails half way but works fine when kicked off a second time.

I'd like to get /opt/sfw/ added to the standard lib/include path for 
Solaris (10 at least) as this is where Sun's open-source packages get 
installed.  Is this just a matter of raising a ticket?

Cheers,
Chris


Chris Miles wrote:
> On a standard Solaris 10 installation with Sun-supplied open-source 
> packages installed (like SFWrline for readline libs) I cannot seem to 
> force Python configure/setup.py to build with readline support.

-- 
http://chrismiles.info/

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


Re: A friendlier, sugarier lambda -- a proposal for Ruby-like blocks in python

2006-10-15 Thread Kay Schluehr
[EMAIL PROTECTED] wrote:
> Kay Schluehr wrote:
> > The with statement is already implemented in Python 2.5.
> >
> > http://docs.python.org/whatsnew/pep-343.html
> >
> > The main difference between the with statement and Ruby blocks is that
> > the with-statement does not support loops. Yielding a value of a
> > function decorated with a contextmanager and passing it to the BLOCK of
> > the with statement is essentially a one-shot. Therefore you can't use
> > the with statement to define iterators. It is not a lightweight visitor
> > pattern replacement as it is in Ruby. Hence the with- and the
> > for-statement are orthogonal to each other in Python.
>
> Thanks or the What's-New link, it clarified things for me.  So there
> are several ways to do things with code blocks now in python..
>  * for/while define loops around their blocks
>  * if defines contional control into its block
>  * with defines startup/cleanup context surrounding its block
>
> Twisted addCallback() is a different pattern than either of these.  The
> code is deferred to execute at some later time.  If there are many more
> patterns of things you could want to do with a block, it might be nice
> to have a blocks-are-closures mechanism.

That's true. As I mentioned in my response to Paul Boddie I do think it
is a poor solution even in Ruby(!) but I agree that given the situation
we just have with poorly designed application frameworks ( no illusion:
they won't ever go away and I do not pretend to be smarter and doing it
better in any case ) blocks are a quite nice feature for providing ad
hoc solutions. I consider them as somewhat aligned with a
worse-is-better philosophy.



I recently created an extended lambda as an example for my EasyExtend
language extension framework for Python. These kind of showcases are,
at least for me, important for getting programming practice within the
system and explore and extend the framework. The two things I cared
about when altering the semantics of lambda were:
1) Enabling multiple expressions separated by ';'
2) Enabling so called "simple statements"

Python does not only distinguish between expressions and statements but
also between simple and compound statements within its grammar
description. A compound statement is typically multiline and contains a
block. A simple statement is something like print, exec, raise or
assert containing no block. So I actually extended lambda to the limit
of an anonymous closure containing no block.

One might take this into consideration and alter the premises. But this
would be up to you, breno. At the moment I do not recommend using EE
because it is under heavy reconstruction but for the not so distant
future ( end of november is my personal deadline for the next release )
I recommend taking a look on it by anyone who aims to walk the RoR path
of a customized domain specific language for Python. For those who are
dilligent there are will be quite a lot of examples. For some it might
be even fun.

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


Cannot import a module from a variable

2006-10-15 Thread Jia Lu
Hi all:

I try to do things below:
>>>import sys
>>> for i in sys.modules.keys():
import i
Traceback (most recent call last):
  File "", line 2, in 
import i
ImportError: No module named i

But it seems that import donot know what is i ? why?

Thanks/

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


Where I can find

2006-10-15 Thread vedran_dekovic
Hello,
Where I can find this files(modules):

fcntl,FCNTL,tty,termios, TERMIOS













 THANKS!!!

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


Re: Reverse string-formatting (maybe?)

2006-10-15 Thread Tim Chase
>>>  >>> template = '%s, %s, %s'
>>>  >>> values = ('Tom', 'Dick', 'Harry')
>>>  >>> formatted = template % values
>>>  >>> import re
>>>  >>> unformat_string = template.replace('%s', '([^, ]+)')
>>>  >>> unformatter = re.compile(unformat_string)
>>>  >>> extracted_values = unformatter.search(formatted).groups()
>>>
>>> using '[^, ]+' to mean "one or more characters that aren't a
>>> comma or a space".
>>
>> One more thing (I forgot to mention this other situation earlier)
>> The %s characters are ints, and outside can be anything except int
>> characters. I do have one situation of '%s%s%s', but I can change it to
>> '%s', and change the output into the needed output, so that's not
>> important. Think something along the lines of "abckdaldj iweo%s
>> qwierxcnv !%sjd".
> 
> That was written in haste. All the information is true. The question:
> I've already created a function to do this, using your original
> deformat function. Is there any way in which it might go wrong?

Only you know what anomalies will be found in your data-sets.  If 
you know/assert that

-the only stuff in the formatting string is one set of characters

-that stuff in the replacement-values can never include any of 
your format-string characters

-that you're not using funky characters/formatting in your format 
string (such as "%%" possibly followed by an "s" to get the 
resulting text of "%s" after formatting, or trying to use other 
formatters such as the aforementioned "%f" or possibly "%i")

then you should be safe.  It could also be possible (with my 
original replacement of "(.*)") if your values will never include 
any substring of your format string.  If you can't guarantee 
these conditions, you're trying to make a cow out of hamburger. 
Or a pig out of sausage.  Or a whatever out of a hotdog. :)

Conventional wisdom would tell you to create a test-suite of 
format-strings and sample values (preferably worst-case funkiness 
in your expected format-strings/values), and then have a test 
function that will assert that the unformatting of every 
formatted string in the set returns the same set of values that 
went in.  Something like

tests = {
'I was %s but now I am %s' : [
('hot', 'cold'),
('young', 'old'),
],
'He has 3 %s and 2 %s' : [
('brothers', 'sisters'),
('cats', 'dogs')
]
}

for format_string, values in tests:
unformatter = format.replace('%s', '(.*)')
for value_tuple in values:
formatted = format_string % value_tuple
unformatted = unformatter.search(formatted).groups()
if unformatted <> value_tuple:
print "%s doesn't match %s when unformatting %s" % (
unformatted,
value_tuple
format_string)

-tkc








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


Re: Reverse string-formatting (maybe?)

2006-10-15 Thread Dan Sommers
On 14 Oct 2006 05:35:02 -0700,
"Dustan" <[EMAIL PROTECTED]> wrote:

> Is there any builtin function or module with a function similar to my
> made-up, not-written deformat function as follows? I can't imagine it
> would be too easy to write, but possible...

[ snip ]

> Any input? I've looked through the documentation of the string module
> and re module, did a search of the documentation and a search of this
> group, and come up empty-handed.

Track down pyscanf.  (Google is your friend, but I can't find any sort
of licensing/copyright information, and the web addresses in the source
code aren't available, so I hesitate to post my ancient copy.)

HTH,
Dan

-- 
Dan Sommers

"I wish people would die in alphabetical order." -- My wife, the genealogist
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Reverse string-formatting (maybe?)

2006-10-15 Thread Dustan

Dustan wrote:
> Dustan wrote:
> > Tim Chase wrote:
> > > > My template outside of the '%s' characters contains only commas and
> > > > spaces, and within, neither commas nor spaces. Given that information,
> > > > is there any reason it might not work properly?
> > >
> > > Given this new (key) information along with the assumption that
> > > you're doing straight string replacement (not dictionary
> > > replacement of the form "%(key)s" or other non-string types such
> > > as "%05.2f"), then yes, a reversal is possible.  To make it more
> > > explicit, one would do something like
> > >
> > >  >>> template = '%s, %s, %s'
> > >  >>> values = ('Tom', 'Dick', 'Harry')
> > >  >>> formatted = template % values
> > >  >>> import re
> > >  >>> unformat_string = template.replace('%s', '([^, ]+)')
> > >  >>> unformatter = re.compile(unformat_string)
> > >  >>> extracted_values = unformatter.search(formatted).groups()
> > >
> > > using '[^, ]+' to mean "one or more characters that aren't a
> > > comma or a space".
> > >
> > > -tkc
> >
> > Thanks.
> >
> > One more thing (I forgot to mention this other situation earlier)
> > The %s characters are ints, and outside can be anything except int
> > characters. I do have one situation of '%s%s%s', but I can change it to
> > '%s', and change the output into the needed output, so that's not
> > important. Think something along the lines of "abckdaldj iweo%s
> > qwierxcnv !%sjd".
>
> That was written in haste. All the information is true. The question:
> I've already created a function to do this, using your original
> deformat function. Is there any way in which it might go wrong?

Again, haste. I used Peter's deformat function.

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


Re: Reverse string-formatting (maybe?)

2006-10-15 Thread Dustan

Dustan wrote:
> Tim Chase wrote:
> > > My template outside of the '%s' characters contains only commas and
> > > spaces, and within, neither commas nor spaces. Given that information,
> > > is there any reason it might not work properly?
> >
> > Given this new (key) information along with the assumption that
> > you're doing straight string replacement (not dictionary
> > replacement of the form "%(key)s" or other non-string types such
> > as "%05.2f"), then yes, a reversal is possible.  To make it more
> > explicit, one would do something like
> >
> >  >>> template = '%s, %s, %s'
> >  >>> values = ('Tom', 'Dick', 'Harry')
> >  >>> formatted = template % values
> >  >>> import re
> >  >>> unformat_string = template.replace('%s', '([^, ]+)')
> >  >>> unformatter = re.compile(unformat_string)
> >  >>> extracted_values = unformatter.search(formatted).groups()
> >
> > using '[^, ]+' to mean "one or more characters that aren't a
> > comma or a space".
> >
> > -tkc
>
> Thanks.
>
> One more thing (I forgot to mention this other situation earlier)
> The %s characters are ints, and outside can be anything except int
> characters. I do have one situation of '%s%s%s', but I can change it to
> '%s', and change the output into the needed output, so that's not
> important. Think something along the lines of "abckdaldj iweo%s
> qwierxcnv !%sjd".

That was written in haste. All the information is true. The question:
I've already created a function to do this, using your original
deformat function. Is there any way in which it might go wrong?

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


Re: Reverse string-formatting (maybe?)

2006-10-15 Thread Dustan

Tim Chase wrote:
> > My template outside of the '%s' characters contains only commas and
> > spaces, and within, neither commas nor spaces. Given that information,
> > is there any reason it might not work properly?
>
> Given this new (key) information along with the assumption that
> you're doing straight string replacement (not dictionary
> replacement of the form "%(key)s" or other non-string types such
> as "%05.2f"), then yes, a reversal is possible.  To make it more
> explicit, one would do something like
>
>  >>> template = '%s, %s, %s'
>  >>> values = ('Tom', 'Dick', 'Harry')
>  >>> formatted = template % values
>  >>> import re
>  >>> unformat_string = template.replace('%s', '([^, ]+)')
>  >>> unformatter = re.compile(unformat_string)
>  >>> extracted_values = unformatter.search(formatted).groups()
>
> using '[^, ]+' to mean "one or more characters that aren't a
> comma or a space".
>
> -tkc

Thanks.

One more thing (I forgot to mention this other situation earlier)
The %s characters are ints, and outside can be anything except int
characters. I do have one situation of '%s%s%s', but I can change it to
'%s', and change the output into the needed output, so that's not
important. Think something along the lines of "abckdaldj iweo%s
qwierxcnv !%sjd".

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


Re: Reverse string-formatting (maybe?)

2006-10-15 Thread Tim Chase
> My template outside of the '%s' characters contains only commas and
> spaces, and within, neither commas nor spaces. Given that information,
> is there any reason it might not work properly?

Given this new (key) information along with the assumption that 
you're doing straight string replacement (not dictionary 
replacement of the form "%(key)s" or other non-string types such 
as "%05.2f"), then yes, a reversal is possible.  To make it more 
explicit, one would do something like

 >>> template = '%s, %s, %s'
 >>> values = ('Tom', 'Dick', 'Harry')
 >>> formatted = template % values
 >>> import re
 >>> unformat_string = template.replace('%s', '([^, ]+)')
 >>> unformatter = re.compile(unformat_string)
 >>> extracted_values = unformatter.search(formatted).groups()

using '[^, ]+' to mean "one or more characters that aren't a 
comma or a space".

-tkc




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


Re: Book about database application development?

2006-10-15 Thread Paul Rubin
Wolfgang Keller <[EMAIL PROTECTED]> writes:
> I'm especially interested in such practical topics as e.g. how to implement 
> things such that the resulting application doesn't show the hourglass for 
> minutes on every mouseclick.
> 
> And, btw; "W** applications" are totally irrelevant for me.

Here's a start:

http://philip.greenspun.com/sql/
-- 
http://mail.python.org/mailman/listinfo/python-list


Book about database application development?

2006-10-15 Thread Wolfgang Keller
Hello,

does anyone know of a good book that about development of database 
applications?

Preferrably language independent, if that's not available something 
"readable" as the example language would be nice (Delphi is ok for me, not 
any kind of C-dialect including Java and C#). Unfortunately there seems to be 
nothing dedicated to database applications with Python.

I'm especially interested in such practical topics as e.g. how to implement 
things such that the resulting application doesn't show the hourglass for 
minutes on every mouseclick.

And, btw; "W** applications" are totally irrelevant for me.

TIA,

Sincerely,

Wolfgang Keller

-- 
My email-address is correct.
Do NOT remove ".nospam" to reply.

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


Re: Reverse string-formatting (maybe?)

2006-10-15 Thread Dustan

Peter Otten wrote:
> Dustan wrote:
>
> > Is there any builtin function or module with a function similar to my
> > made-up, not-written deformat function as follows? I can't imagine it
> > would be too easy to write, but possible...
> >
>  template = 'I am %s, and he %s last %s.'
>  values = ('coding', "coded', 'week')
>  formatted = template % values
>  formatted
> > 'I am coding, and he coded last week.'
>  deformat(formatted, template)
> > ('coding', 'coded', 'week')
> >
> > expanded (for better visual):
>  deformat('I am coding, and he coded last week.', 'I am %s, and he %s
>  last %s.')
> > ('coding', 'coded', 'week')
> >
> > It would return a tuple of strings, since it has no way of telling what
> > the original type of each item was.
> >
> >
> > Any input? I've looked through the documentation of the string module
> > and re module, did a search of the documentation and a search of this
> > group, and come up empty-handed.
>
> Simple, but unreliable:
>
> >>> import re
> >>> template = "I am %s, and he %s last %s."
> >>> values = ("coding", "coded", "week")
> >>> formatted = template % values
> >>> def deformat(formatted, template):
> ... r = re.compile("(.*)".join(template.split("%s")))
> ... return r.match(formatted).groups()
> ...
> >>> deformat(formatted, template)
> ('coding', 'coded', 'week')
>
> Peter

Trying to figure out the 'unreliable' part of your statement...

I'm sure 2 '%s' characters in a row would be a bad idea, and if you
have similar expressions for the '%s' characters within as well as in
the neighborhood of the '%s', that would cause difficulty. Is there any
other reason it might not work properly?

My template outside of the '%s' characters contains only commas and
spaces, and within, neither commas nor spaces. Given that information,
is there any reason it might not work properly?

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


Re: Can I set up a timed callback without Tkinter or twisted orsomething?

2006-10-15 Thread skip

Hendrik> is there not something based on signals?  - I seem to recall
Hendrik> some such thing here in another thread.. ( I am running Linux)

Have you tried:

import signal
help(signal)

at the interpreter prompt?

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


Re: where is Python tutorial?

2006-10-15 Thread Tshepang Lekhonkhobe
On 15 Oct 2006 04:03:33 -0700, Paul Rubin
<"http://phr.cx"@nospam.invalid> wrote:
> "Tshepang Lekhonkhobe" <[EMAIL PROTECTED]> writes:
> > I looked in the packages list and couldn't find the tutorial and was
> > wondering if it was removed from the archive. Was it?
>
> http://www.google.com/search?q=%22python+tutorial%22
>
> finds it pretty fast

Sorry for this since I thought I was sending to Debian-Python, and was
looking for a Debian package.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Standard Forth versus Python: a case study

2006-10-15 Thread [EMAIL PROTECTED]
John you nailed it. I was a big forth fan in the mid-80s but it was
very clear that you either had to spend a lot of money on proprietary
systems or do it ALL yourself. Not having any money I was pleased to be
able to do it all but today, in the age of instant communication and
collaboration, its not a competitive option in any language. Had forth
kicked off the open source community about a decade earlier than the
UNIX folk (in useful terms) I think we'd be living in a much different
world from a computing perspective. Forth is still cool - but only when
its for something I wanna do all by myself... :)

  -- Ben

John Doty wrote:
> I realized that I have a little job on the table that is a fine test of
> the Python versus Standard Forth code availability and reusability issue.
>
> Note that I have little experience with either Python or Standard Forth
> (but I have much experience with a very nonstandard Forth). I've noodled
> around a bit with both gforth and Python, but I've never done a serious
> application in either. In my heart, I'm more of a Forth fan: Python is a
> bit too much of a black box for my taste. But in the end, I have work to
> get done.
>
> The problem:
>
> I have a bunch of image files in FITS format. For each raster row in
> each file, I need to determine the median pixel value and subtract it
> from all of the pixels in that row, and then write out the results as
> new FITS files.
>
> This is a real problem I need to solve, not a made-up toy problem. I was
> originally thinking of solving it in C (I know where to get the pieces
> in that language), but it seemed like a good test problem for the Python
> versus Forth issue.
>
> I looked to import FITS reading/writing, array manipulation, and median
> determination. From there, the solution should be pretty easy.
>
> So, first look for a median function in Python. A little googling finds:
>
> http://www.astro.cornell.edu/staff/loredo/statpy/
>
> Wow! This is good stuff! An embarrassment of riches here! There are even
> several FITS modules, and I wasn't even looking for those yet. And just
> for further gratification, the page's author is an old student of mine
> (but I'll try not to let this influence my attitude). So, I followed the
> link to:
>
> http://www.nmr.mgh.harvard.edu/Neural_Systems_Group/gary/python.html
>
>  From there, I downloaded stats.py, and the two other modules the page
> says it requires, and installed them in my site-packages directory. Then
> "from stats import median" got me a function to approximately determine
> the median of a list. It just worked. The approximation is good enough
> for my purposes here.
>
> Pyfits required a little more resourcefulness, in part because STSCI's
> ftp server was down yesterday, but I got it installed too. It helps that
> when something is missing, the error message gives you a module name. It
> needs the numarray module, so I got array manipulation as a side effect.
>
> I haven't finished the program, but I've tried out the pieces and all
> looks well here.
>
> OK, now for Forth. Googling for "forth dup swap median" easily found:
>
> http://www.taygeta.com/fsl/library/find.seq
>
> At first blush, this looked really good for Forth. The search zeroed in
> on just what I wanted, no extras. The algorithm is better than the one
> in the Python stats module: it gives exact results, so there's no need
> to check that an approximation is good enough. But then, the
> disappointment came.
>
> What do you do with this file? It documents the words it depends on, but
> not where to get them. I'm looking at a significant effort to assemble
> the pieces here, an effort I didn't suffer through with Python. So, my
> first question was: "Is it worth it?".
>
> The answer came from searching for FITS support in Forth. If it exists
> in public, it must be really well hidden. That's a "show stopper", so
> there was no point in pursuing the Forth approach further.
>
> In the end, it was like comparing a muzzle-loading sharpshooter's rifle
> with a machine gun: Forth got off one really good shot, but Python just
> mowed the problems down.
>
> The advocates of the idea that Standard Forth has been a boon to code
> reusability seem mostly to be people with large private libraries of
> Forth legacy code. No doubt to them it really has been a boon. But I
> think this little experiment shows that for the rest of us, Python has a
> published base of reusable code that puts Forth to shame.
>
> --
> John Doty, Noqsi Aerospace, Ltd.
> --
> Specialization is for robots.

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


Re: where is Python tutorial?

2006-10-15 Thread Paul Rubin
"Tshepang Lekhonkhobe" <[EMAIL PROTECTED]> writes:
> I looked in the packages list and couldn't find the tutorial and was
> wondering if it was removed from the archive. Was it?

http://www.google.com/search?q=%22python+tutorial%22

finds it pretty fast
-- 
http://mail.python.org/mailman/listinfo/python-list


where is Python tutorial?

2006-10-15 Thread Tshepang Lekhonkhobe
Hi,
I looked in the packages list and couldn't find the tutorial and was
wondering if it was removed from the archive. Was it?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: problem with the 'math' module in 2.5?

2006-10-15 Thread Ben Finney
"Paddy" <[EMAIL PROTECTED]> writes:

> Ben Finney wrote:
> > Your calculator is probably doing rounding without you asking for
> > it.
> >
> > Python refuses to guess what you want, and gives you the
> > information available.
>
> I don't think Python should take too much credit here.

I don't understand what you could mean by this. Credit for "giv[ing]
you the information available"? That's exactly what it's doing.

> Floating point calcuations are subject to rounding. Sometimes it
> shows.

And Python is showing it, rather than hiding it. It certainly isn't
doing any rounding unless asked to do so.

-- 
 \ Legionnaire: "We have their leader captive!"  C泡r: "Is he |
  `\bound?"  Legionnaire: "Of his health I know not, sir."  -- The |
_o__)Goon Show, _The Histories Of Pliny The Elder_ |
Ben Finney

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

Problem with importing a package

2006-10-15 Thread [EMAIL PROTECTED]
I have to work with matrices on python and for that i need a package
NUMPY. I downloaded it and saved it in the same folder as the program
which imports it. But on running the program it gives an error
"ImportError: No module named numpy". Do we need to save the file
required to be imported in a specific folder?

Plz help me out with this.

Thanks

Amit

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


Re: problem with the 'math' module in 2.5?

2006-10-15 Thread Jorgen Grahn
On Sun, 15 Oct 2006 00:18:29 -0400, Carsten Haese <[EMAIL PROTECTED]> wrote:
...
> You're not getting *exactly* zero because you're not passing in *exactly* pi
> but a close approximation of pi.

That, plus the fact that floating-point math never is (in some sense)
precise. I am surprised noone brought up this one:

>>> .2
0.20001

The original poster should read more on the subject. The Wikipedia article
seems like a good place to start:

 http://en.wikipedia.org/wiki/Floating-point

/Jorgen

-- 
  // Jorgen Grahn   R'lyeh wgah'nagl fhtagn!
-- 
http://mail.python.org/mailman/listinfo/python-list


Which class?

2006-10-15 Thread Fulvio
***
Your mail has been scanned by InterScan MSS.
***


Hello,

Sorry, I very new in programming and the use of the classes still unknown.
I'm really interested to apply the right one as far as the results aren't as 
expected.

Here's the example:

from poplib import POP3
ProtocolError = 'Error in Protocol'  # handler for IMAP4 and POP3 errors

try:
_pop = POP3(args[0])
_pop.user(args[1])
except:
raise ProtocolError
a.append( 'STAT = POP Server %s reply\n %s\n' %(args[0], _pop.pass_(args[2])))
(numMsgs, totalSize) = _pop.stat()
for cnt in range(1, numMsgs +1):
#Need a cleanup for the envelope header  'Unix-From'

try:
msgs =_pop.top(cnt,0)[1]
except:
raise ProtocolError

# Here I'd like to have some part removed and I known that some class in email 
# will do the neat job without missing any of the needed detail

hdrs = [k for itms in ('from', 'to', 'cc',
'date', 'subject', 'reply-to', 'message-')
for k in msgs if k.startswith(itms.capitalize())]

# This isn't the right risult. Some time missing one of the wanted item.

_pop.quit()

I've put my opinions as comments, in order to copy and try. The args contains 
(pop address, user, and password) respectively.
The list comprehension fails for some comparison, might be more accurate a 
regex, I just fill too complicated  for a simple scan and I know that there 
are already good classes that will do the right way. I just miss the learning 
how to use them.

This a part of a small program, which will attempt to organize all the emails, 
locals and remote in order to do spam removal and/or backup the good ones.
I'd like somebody to join, not for a speedy result but for a joy of exchanging 
technics and tricks.

F

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


Re: problem with the 'math' module in 2.5?

2006-10-15 Thread Paddy

Ben Finney wrote:
> "Chris" <[EMAIL PROTECTED]> writes:
>
> > Oh, ok that explains it. Is that why my 16-bit calculator gives me
> > 0?
>
> Your calculator is probably doing rounding without you asking for it.
>
> Python refuses to guess what you want, and gives you the information
> available.
>
Hi Ben,
I don't think Python should take too much credit here. Floating point
calcuations are subject to rounding. Sometimes it shows.

- Pad.

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


Re: Need a function. Any built-in function or module for this?

2006-10-15 Thread wcc
Thanks you very much Paul.  I think I have a little more homework to
do.
1. The upper case letter may not be the first letter in each word.
2. There may be more than one (continous) upper case letters in one
word.
I just wanted to find out if there is something already there in python
built-in functions, modules.  Thanks again.

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


Re: A friendlier, sugarier lambda -- a proposal for Ruby-like blocks in python

2006-10-15 Thread Kay Schluehr
Paul Boddie wrote:
> Kay Schluehr wrote:
> >
> > Spreading tiny function definitions all over the code
> > may be finally not such a good idea compared with a few generic methods
> > that get just called? OO might run out of fashion these days but Python
> > is not Java and Pythons OO is pretty lightweight.
>
> I think you've successfully identified a recent trend in Python
> development: the abandonment of fairly transparent object-oriented
> techniques in favour of more opaque but supposedly more convenient
> hybrid techniques. Unlike Java, Python's first class functions and
> methods are already highly useful for callback-based systems - such
> systems in Java suffer from interface proliferation and needless
> one-off class definitions - but it seems to me that the subsequent
> language evolution in favour of anonymous blocks brings fewer benefits
> and can, as you say, diminish readability.

I was actually more concerned about extensibility than readability.
Talking about classes being lightweight I mentioned classes to be
"first-class" objects and intended constructions like this:

class fetchPage_event(fetchPage('http://python.org')):
def _showResponse(self, response)
print "fancy formatting: %s" % response.text

where all the registration and framework magics happens when the
fetchPage_event class is created. Adding "callbacks" just happen when
you add a method to the class. Here you have your "block" with no
additional syntax. You can pass the fetchPage_event class around and
add and overwrite methods in subclasses in the same fashion. A subclass
can be created within any statement on the fly etc. Here you have an OO
solution that is both short and has a clean design.

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


Re: Can I set up a timed callback without Tkinter or twisted orsomething?

2006-10-15 Thread Hendrik van Rooyen

"hg" <[EMAIL PROTECTED]> wrote:


> Hendrik van Rooyen wrote:
> > Hi,
> >
> > I want to do the equivalent of the after thingy in tkinter - setting up in
> > effect a timed call back.
> >
> > My use case is as a "supervisory" timer - I want to set up an alarm, which I
> > want to cancel if the expected occurrence occurs - but its not a GUI app.
> >
> > My googling gets a lot of stuff pointing to optparse...
> >
> > Does the standard lib have anything like this?
> >
> > - Hendrik
> >
>
> http://python.active-venture.com/lib/timer-objects.html
>
 Thanks - will check it out - Hendrik

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


Re: Can I set up a timed callback without Tkinter or twisted orsomething?

2006-10-15 Thread Hendrik van Rooyen
"Scott David Daniels" <[EMAIL PROTECTED]> wrote:


> Hendrik van Rooyen wrote:
> > I want to do the equivalent of the after thingy in tkinter - setting up in
> > effect a timed call back.
> >
> > My use case is as a "supervisory" timer - I want to set up an alarm, which I
> > want to cancel if the expected occurrence occurs - but its not a GUI app.
>
> Use a thread that uses something like:
>def action():
>sleep(50)
>if not canceled:
>callback(foo)
> as its action.
>
> The callback ill be in another thread, but   Look up threading for
> more details.

Thanks - I was hoping that I did not have to do it myself - the Tkinter thingy
works nicely - I was hoping that the interpreter could handle something like
this... What I don't like too much about the sleep based solution is that yer
blind and deaf while sleeping - at least in that thread - and I am trying for
fairly fine grained timing resolution...

is there not something based on signals?  - I seem to recall some such thing
here in another thread.. ( I am running Linux)

-Hendrik

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


Re: Web Hosting

2006-10-15 Thread Gregor Horvath
Sir Psycho schrieb:
> 
> Im looking at making a site in Python, however, Im lost as to what ISPs
> actually support. Some ISPs say they support Python so does that mean
> if I wanted to use TurboGears It would just work anyway?

http://docs.turbogears.org/1.0/Hosting?highlight=%28hosting%29

-- 
  Servus, Gregor
-- 
http://mail.python.org/mailman/listinfo/python-list