CodeInvestigator 0.7.4

2008-03-03 Thread Martien Friedeman
CodeInvestigator version 0.7.4 was released on March 3.


This is a bug fix release.

It fixes a problem with non-ascii characters. Strings with non-ascii  
characters are now saved as part of the recording and can be used in  
searches.



CodeInvestigator is a tracing tool for Python programs.

Running a program through CodeInvestigator creates a recording.  
Program flow, function calls, variable values and conditions are all  
stored for every line the program executes.
The recording is then viewed with an interface consisting of the  
code. The code can be clicked: A clicked variable displays its value,  
a clicked loop displays its iterations.
You read code, and have at your disposal all the run time details of  
that code. A computerized desk check tool and another way to learn  
about your program.

http://sourceforge.net/project/showfiles.php?group_id=183942

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

Support the Python Software Foundation:
http://www.python.org/psf/donations.html


Re: Snackages [Re: is there enough information?]

2008-03-03 Thread Daniel Fetchinson
  Speak not of Wendy's -- they moved into town in my college days...
  The hot and juicy was commonly taken to mean: patty dipped in pan
  drippings, then nuked in microwave... And any CompSci person could
  figure out that the 256 different ways meant one had access to a tray
  of 8 condiments, and had any combination of on or off for each... 8
  condiments, let's see: ketchup, mayo, mustard, pickle, onion, lettuce,
  tomato, cheese?
 
  I went once to Wendy's, and couldn't finish my sandwich. It was
  ho-rri-ble. It was not a surprise when they closed all their restaurants
  in Argentina and leave the country, after being here for less than 4
 years.

 You have _got_ to be kidding me. Where do you guys live? In California
 (at least, Silicon Valley and Sacramento area), Wendy's and In-N-Out are
 the only fast food chains that sell anything that taste like real
 hamburgers. Way, _way_ better than the cardboard stuff at McD's and
 BK. Though Carl's Jr's $6 burgers are okay. And Carl's has _terrific_
 ice cream shakes, whereas Wendy's has... frosted dairy desserts. :p

 Great. Now I'm hungry.

I'm not a Wendy's fan but In-N-Out definitely rocks! :)
-- 
http://mail.python.org/mailman/listinfo/python-list


write float to Excel with pyExcelerator write

2008-03-03 Thread Cyril.Liu
I use pyExcelerator to generat Excel files in my project. it works good
before I found this bug:
run this code:

from pyExcelerator import *
wb = Workbook()
ws = wb.add_sheet(sheet)
for i  in xrange(1):
ws.write(i,0, 10474224.6)
wb.save(r'd:\error_float.xls')

open d:\error_float.xls with M$ Excle you'll find the number in the cell is
-263193.64 not 10474224.6


why? some body help me please.
PS: I'm not good at English, I hope you can understand what i said. :)
Thx
-- 
About Cyril.Liu
---
Cyril
是一个程序员,
现在是个穷光蛋,
他常常跟自己说:我�找���有理想牛仔仔
-- 
http://mail.python.org/mailman/listinfo/python-list

How to subclass ints to prevent comparisons?

2008-03-03 Thread Bronner, Gregory
I'm trying to create a type-safe subclass of int (SpecialInt) such that
instances of the class can only be compared with 
ints, longs, and other subclasses of SpecialInt -- I do not want them to
be compared with floats, bools, or strings, which the native int
implementation supports.

Obviously, I could overload __lt_, __eq__, __le__, etc, and write a
bunch of boilerplate code.

Should this code throw an exception if the types are not comparable?
What would I lose by doing that? 


The native implementation of int goes to great lengths to allow
illogical comparisons such as the one below.

 import xml as x
 x
 module 'xml' from 'c:\python25\lib\xml\__init__.pyc'

 x4
True
 x4
False
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
- - - -

This message is intended only for the personal and confidential use of the 
designated recipient(s) named above.  If you are not the intended recipient of 
this message you are hereby notified that any review, dissemination, 
distribution or copying of this message is strictly prohibited.  This 
communication is for information purposes only and should not be regarded as an 
offer to sell or as a solicitation of an offer to buy any financial product, an 
official confirmation of any transaction, or as an official statement of Lehman 
Brothers.  Email transmission cannot be guaranteed to be secure or error-free.  
Therefore, we do not represent that this information is complete or accurate 
and it should not be relied upon as such.  All information is subject to change 
without notice.


IRS Circular 230 Disclosure:
Please be advised that any discussion of U.S. tax matters contained within this 
communication (including any attachments) is not intended or written to be used 
and cannot be used for the purpose of (i) avoiding U.S. tax related penalties 
or (ii) promoting, marketing or recommending to another party any transaction 
or matter addressed herein.
-- 
http://mail.python.org/mailman/listinfo/python-list


write float to Excel with pyExcelerator write

2008-03-03 Thread Cyril.Liu
I use pyExcelerator to generat Excel files in my project. it works good
before I found this bug:
run this code:

from pyExcelerator import *
wb = Workbook()
ws = wb.add_sheet(sheet)
for i  in xrange(1):
ws.write(i,0, 10474224.6)
wb.save(r'd:\error_float.xls')

open d:\error_float.xls with M$ Excle you'll find the number in the cell is
-263193.64 not 10474224.6


why? some body help me please.
PS: I'm not good at English, I hope you can understand what i said. :)
Thx
-- 
About Cyril.Liu
---
Cyril
是一个程序员,
现在是个穷光蛋,
他常常跟自己说:我�找���有理想牛仔仔
-- 
http://mail.python.org/mailman/listinfo/python-list

Trouble using XML Reader

2008-03-03 Thread Mike D
Hello,

I'm using XML Reader (xml.sax.xmlreader.XMLReader) to create an rss reader.

I can parse the file but am unsure how to extract the elements I require.
For example: For each item element I want the title and description.

I have some stub code; I want to create a list of objects which include a
title and description.

I have the following code (a bit hacked up):

import sys
from xml.sax import make_parser
from xml.sax import handler

class rssObject(object):
objectList=[]
def addObject(self,object):
rssObject.objectList.append(object)

class rssObjectDetail(object):
title = 
content = 


class SimpleHandler(handler.ContentHandler):
def startElement(self,name,attrs):
print name

def endElement(self,name):
print name

def characters(self,data):
print data


class SimpleDTDHandler(handler.DTDHandler):
def notationDecl(self,name,publicid,systemid):
print Notation:  , name, publicid, systemid

def unparsedEntityDecl(self,name,publicid,systemid):
print UnparsedEntity:  , name, publicid, systemid, ndata

p= make_parser()
c = SimpleHandler()
p.setContentHandler(c)
p.setDTDHandler(SimpleDTDHandler())
p.parse('topstories.xml')

And am using this xml file:

?xml version=1.0?
rss version=2.0
  channel
titleStuff.co.nz - Top Stories/title
linkhttp://www.stuff.co.nz/link
descriptionTop Stories from Stuff.co.nz. New Zealand, world, sport,
business amp; entertainment news on Stuff.co.nz. /description
languageen-nz/language
copyrightFairfax New Zealand Ltd./copyright
ttl30/ttl
image
  url/static/images/logo.gif/url
  titleStuff News/title
  linkhttp://www.stuff.co.nz/link
/image

item id=4423924 count=1
titlePrince Harry apos;wants to live in Africaapos;/title
linkhttp://www.stuff.co.nz/4423924a10.html?source=RSStopstories_20080303
/link
descriptionFor Prince Harry it must be the ultimate dark irony: to be in
such a privileged position and have so much opportunity, and yet be unable
to fulfil a dream of fighting for the motherland./description
authorEDMUND TADROS/author
guid isPermaLink=falsestuff.co.nz/4423924/guid
pubDateMon, 03 Mar 2008 00:44:00 GMT/pubDate
/item

  /channel
/rss

Is there something I'm missing? I can't figure out how to correctly
interpret the document using the SAX parser. I'm sure I;'m missing something
obvious :)

Any tips or advice would be appreciated! Also advice on correctly
implementing what I want to achieve would be appreciated as using
objectList=[] in the ContentHandler seems like a hack.

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

Regex loop question

2008-03-03 Thread Mike P
Hi Experts,

I've written a peice of code that works fine and fits, and passes
values into a peice of SPSS code, the problem is that it is not
dynamic, and so i though about how i can make it dynamic, (other code
may not have upto 10 some may have more) and came up with regex for an
idea, but i can't seem to make it work, can anyone offer any advice?
Below is current working code

time_variables = {ActivityTime: Activity_Time,
ExposureTime_Last:Exposure_Time_1,
ExposureTime_Last2:Exposure_Time_2,
ExposureTime_Last3:Exposure_Time_3,
ExposureTime_Last4:Exposure_Time_4,
ExposureTime_Last5:Exposure_Time_5,
ExposureTime_Last6:Exposure_Time_6,
ExposureTime_Last7:Exposure_Time_7,
ExposureTime_Last8:Exposure_Time_8,
ExposureTime_Last9:Exposure_Time_9,
ExposureTime_Last10:Exposure_Time_10}

for Var in time_variables.keys():
time_manips = (COMPUTE %s = SUBSTR(%s,(INDEX(%s,'T'))+1) .
COMPUTE %s = number(%s, TIME8).
VARIABLE LABEL %s.
VARIABLE LEVEL %s (SCALE).
FORMATS %s (TIME8).
VARIABLE WIDTH %s (8).
EXECUTE.) %(Var, Var,
Var,time_variables[Var],Var,time_variables[Var],time_variables[Var],time_variables[Var],time_variables[Var])
spss.Submit(time_manips)


Now to make it dynamic i've gone for the following...

reg_time = re.compile(^ExposureTime_Last([0-9]*)$)
reg_Activity = re.compile(^ActivityTime)
for Var in time_variables.keys():
if reg_time.match(Var):
match = reg_time.match(Var)
E_time = Exposure_Time_%s % match.groups()[0]
else:
match = reg_time.match(Var)
match.groups()[0] = Activity_Time


time_manips = (COMPUTE %s = SUBSTR(%s,(INDEX(%s,'T'))+1) .
COMPUTE %s = number(%s, TIME8).
VARIABLE LABEL %s.
VARIABLE LEVEL %s (SCALE).
FORMATS %s (TIME8).
VARIABLE WIDTH %s (8).
EXECUTE.) %(Var, Var,
Var,time_variables[Var],Var,time_variables[Var],time_variables[Var],time_variables[Var],time_variables[Var])
print(time_manips)

All help welcome, or if a different approach is better please let me
know

Mike


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


Re: First post from a Python newbiw

2008-03-03 Thread Arnaud Delobelle


Steve Turner wrote:
 I finally decided to have a go with Python and am working through the
 tutorial.

Great!

 On my old BBC Computer [...]

These were nice machines...

 In Python I thought I could do this with:

  a=[0,0,0]
  b=[a,a,a]
  b
 [[0, 0, 0], [0, 0, 0], [0, 0, 0]]
  b[1][1]='foo'
  b
 [[0, 'foo', 0], [0, 'foo', 0], [0, 'foo', 0]]
 

 I can understand why as b[1][1]='foo' is actually changing a[1]

 Apart from doing something like
 a=[0,0,0]
 b=[0,0,0]
 c=[0,0,0]
 d=[a,b,c]

 is there a better way of creating d??

It's a FAQ:
http://www.python.org/doc/faq/programming/#how-do-i-create-a-multidimensional-list

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


Re: write float to Excel with pyExcelerator write

2008-03-03 Thread Peter Otten
Cyril.Liu wrote:

 I use pyExcelerator to generat Excel files in my project. it works good
 before I found this bug:
 run this code:
 
 from pyExcelerator import *
 wb = Workbook()
 ws = wb.add_sheet(sheet)
 for i  in xrange(1):
 ws.write(i,0, 10474224.6)
 wb.save(r'd:\error_float.xls')
 
 open d:\error_float.xls with M$ Excle you'll find the number in the cell
 is -263193.64 not 10474224.6
 
 
 why? some body help me please.

It's probably a bug in pyExcelerator:

http://sourceforge.net/tracker/index.php?func=detailaid=1596642group_id=134081atid=730643

There's a patch by John Machin, 

http://sourceforge.net/tracker/index.php?func=detailaid=1618443group_id=134081atid=730645

and the problem should be fixed in subversion.

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


Re: RELEASED Python 2.6a1 and 3.0a3

2008-03-03 Thread Paul Boddie
On 2 Mar, 10:02, Kay Schluehr [EMAIL PROTECTED] wrote:
 On 2 Mrz., 06:53, Ben Finney [EMAIL PROTECTED]
 wrote:

  One of the stated goals of the migration is that the '2to3' program
  will only migrate Python 2.6 code - Python 3.0 code.

 Yes, I know. Why?

 The master said so isn't an entirely satisfying answer. What are the
 *technical reasons* that make it hard to apply '2to3' directly on
 Python 2.4 or Python 2.5?

I imagine that in Python 2.6 there are some semantic changes
(conveniences, really), plus some expansion of the language syntax to
overlap with Python 3, both of which let the 2to3 tool work as
intended. Obviously 2to3 doesn't do too much complicated stuff, and I
imagine (or have deduced from what I've heard) that you have to write
code that is obvious to the tool so that it can translate it
correctly. Perhaps 2.5 and earlier don't permit such obvious code to
be written.

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


Re: Beautiful Code in Python?

2008-03-03 Thread Bruno Desthuilliers
js a écrit :
 Hi,
 
 Have you ever seen Beautiful Python code?
 Zope? Django? Python standard lib? or else?
 
 Please tell me what code you think it's stunning.

FormEncode has some very interesting parts IMHO.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Can one get for x in y to work for non builtin classes?

2008-03-03 Thread M.-A. Lemburg
On 2008-03-02 15:06, Preben Randhol wrote:
 Hi
 
 I'm making a kind of ordered dictionary class. It is not exactly a
 dictionary, but it uses a list and dictionary to store the data. 
 
 Something like:
 
   class dbase(list):
   '''Database class keeping track of the order and data'''
 
   def __init__(self):
   self.__data = {}
   self.__order = []
   self.__uniq_id = 0
 
 I'm just wondering if it is possible to get my class to work so that if
 one do:
 
 
   d=dbase()
   d.append(Data)
   d.append([1,2])
   
 one can do like this to iterate over the data.
 
   for x in d:
   ...
 
 I'm looking at the list class but I don't quite understand from pydoc
 which __ __ methods I have to implement to get the above to work.

The easiest is to implement an iterator which then get's
returned by the .__iter__() method.

http://www.python.org/doc/lib/typeiter.html

It's also possible to implement .__getitem__() and .__len__()
methods and have Python create an iterator on-the-fly. That's
how Python used to work before iterators were added to the
language.

-- 
Marc-Andre Lemburg
eGenix.com

Professional Python Services directly from the Source  (#1, Mar 03 2008)
  Python/Zope Consulting and Support ...http://www.egenix.com/
  mxODBC.Zope.Database.Adapter ... http://zope.egenix.com/
  mxODBC, mxDateTime, mxTextTools ...http://python.egenix.com/


 Try mxODBC.Zope.DA for Windows,Linux,Solaris,MacOSX for free ! 


eGenix.com Software, Skills and Services GmbH  Pastor-Loeh-Str.48
 D-40764 Langenfeld, Germany. CEO Dipl.-Math. Marc-Andre Lemburg
Registered at Amtsgericht Duesseldorf: HRB 46611
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Can one get for x in y to work for non builtin classes?

2008-03-03 Thread Marc 'BlackJack' Rintsch
On Mon, 03 Mar 2008 12:17:39 +0100, M.-A. Lemburg wrote:

 It's also possible to implement .__getitem__() and .__len__()
 methods and have Python create an iterator on-the-fly. That's
 how Python used to work before iterators were added to the
 language.

A suitable `__getitem__()` is enough.  The end will be signaled by an
`IndexError`.

Ciao,
Marc 'BlackJack' Rintsch
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Regex loop question

2008-03-03 Thread Peter Otten
Mike P wrote:

 Hi Experts,
 
 I've written a peice of code that works fine and fits, and passes
 values into a peice of SPSS code, the problem is that it is not
 dynamic, and so i though about how i can make it dynamic, (other code
 may not have upto 10 some may have more) and came up with regex for an
 idea, but i can't seem to make it work, can anyone offer any advice?
 Below is current working code
 
 time_variables = {ActivityTime: Activity_Time,
 ExposureTime_Last:Exposure_Time_1,
 ExposureTime_Last2:Exposure_Time_2,
 ExposureTime_Last3:Exposure_Time_3,
 ExposureTime_Last4:Exposure_Time_4,
 ExposureTime_Last5:Exposure_Time_5,
 ExposureTime_Last6:Exposure_Time_6,
 ExposureTime_Last7:Exposure_Time_7,
 ExposureTime_Last8:Exposure_Time_8,
 ExposureTime_Last9:Exposure_Time_9,
 ExposureTime_Last10:Exposure_Time_10}
 
 for Var in time_variables.keys():
 time_manips = (COMPUTE %s = SUBSTR(%s,(INDEX(%s,'T'))+1) .
 COMPUTE %s = number(%s, TIME8).
 VARIABLE LABEL %s.
 VARIABLE LEVEL %s (SCALE).
 FORMATS %s (TIME8).
 VARIABLE WIDTH %s (8).
 EXECUTE.) %(Var, Var,
 Var,time_variables[Var],Var,time_variables[Var],
 time_variables[Var],time_variables[Var],time_variables[Var]) 
 spss.Submit(time_manips)
 
 
 Now to make it dynamic i've gone for the following...
 
 reg_time = re.compile(^ExposureTime_Last([0-9]*)$)
 reg_Activity = re.compile(^ActivityTime)
 for Var in time_variables.keys():
 if reg_time.match(Var):
 match = reg_time.match(Var)
 E_time = Exposure_Time_%s % match.groups()[0]
 else:
 match = reg_time.match(Var)
 match.groups()[0] = Activity_Time
 
 
 time_manips = (COMPUTE %s = SUBSTR(%s,(INDEX(%s,'T'))+1) .
 COMPUTE %s = number(%s, TIME8).
 VARIABLE LABEL %s.
 VARIABLE LEVEL %s (SCALE).
 FORMATS %s (TIME8).
 VARIABLE WIDTH %s (8).
 EXECUTE.) %(Var, Var,
 Var,time_variables[Var],Var,time_variables[Var],time_variables[Var],
 time_variables[Var],time_variables[Var]) 
 print(time_manips)
 
 All help welcome, or if a different approach is better please let me
 know

I'd clean up the original code a bit rather than introducing another source
of errors (the regexes):

# no warranties
time_variables = [
(ActivityTime, Activity_Time),
(ExposureTime_Last,Exposure_Time_1)]
time_variables.extend((ExposureTime_Last%d % i, Exposure_Time_%d % i)
for i in range(2, 11))

for key, value in time_variables:
time_manips = COMPUTE %(key)s = SUBSTR(%(key)s
(INDEX(%(key)s,'T'))+1) .
COMPUTE %(value)s = number(%(key)s, TIME8).
VARIABLE LABEL %(value)s.
VARIABLE LEVEL %(value)s (SCALE).
FORMATS %(value)s (TIME8).
VARIABLE WIDTH %(value)s (8).
EXECUTE. % dict(key=key, value=value)
spss.Submit(time_manips)

It might be even better to move the logic into SPSS and to replace the
numerical suffices with array indices (if supported), but I can't help you
with that.

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


Delete hidden files on unix

2008-03-03 Thread loial
How can I delete hidden files on unix with python, i.e I want to do
equivalent of

rm  .lock*






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


Python logging: Retrieving the last log record from a handler

2008-03-03 Thread Frank Aune
Hi,

I'm using a log hierarchy in my application, and sometimes I find myself 
wanting to retrieve the latest log message written to the root logger. 
(Typical usage might be displaying the latest log message at all times in a 
GUI).

The only way I've found how to solve this, is by adding a custom loghandler:

---
class LastRecordHandler(logging.Handler):

def __init__(self):
logging.Handler.__init__(self)
self.lastRecord = None  

def emit(self, record):
self.lastRecord = record

def getRecord(self):
return self.lastRecord.getMessage()
---

I will be fairly surprised if this functionality is not already built-in for 
the default logging handlers, but so far I've been unable to figure out how 
to pull it of without the custom loghandler above.

The kind of functionality I'm looking for is something like:

self.log = logging.getLogger('GUI')
(...)
lastRecord = self.log.getLastRecord()
# Display lastRecord in GUI

Is this possible in some way, or do I need to extend the default logging 
handlers in order to archieve this?

Thanks,
Frank


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


Re: Delete hidden files on unix

2008-03-03 Thread Peter Otten
loial wrote:

 How can I delete hidden files on unix with python, i.e I want to do
 equivalent of
 
 rm  .lock*

 for fn in glob.glob(.lock*):
... os.remove(fn)
...

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


Re: write float to Excel with pyExcelerator write

2008-03-03 Thread John Machin
On Mar 1, 5:59 pm, Cyril.Liu [EMAIL PROTECTED] wrote:
 I use pyExcelerator to generat Excel files in my project. it works good
 before I found this bug:
 run this code:

 from pyExcelerator import *
 wb = Workbook()
 ws = wb.add_sheet(sheet)
 for i  in xrange(1):
 ws.write(i,0, 10474224.6)
 wb.save(r'd:\error_float.xls')

 open d:\error_float.xls with M$ Excle you'll find the number in the cell is
 -263193.64 not 10474224.6

 why?

The author assumed unsigned integers instead of signed integers.

 1047422460 - 2**30
-26319364

See the following, previously posted here:

http://mail.python.org/pipermail/python-list/2007-May/441633.html

Cheers,
John


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


Re: [Python-Dev] [ANN] Python 2.3.7 and 2.4.5, release candidate 1

2008-03-03 Thread Barry Warsaw
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

On Mar 3, 2008, at 1:48 AM, Martin v. Löwis wrote:

 But it would be really nice if the configure fix for 2.5 was
 backported to 2.4.5 since Zope is still on 2.4 and Mac OS X skipped
 system builds for 2.4 going direct from 2.3 - 2.5.


 Yes, it would be very nice if this worked out of the box on Mac OS X
 10.5.2.  It's definitely a surprise for those of us who built our  
 2.4.4
 on Mac OS X 10.4.x.

 I can put a notice in the release notes, but I definitely won't change
 it to work out of the box. If 2.4.4 compiled out of the box on this  
 box,
 it would have been a regression and would have to be fixed. IIUC,  
 2.4.4
 won't compile on 10.5, either, and Python 2.4.5 will have no code to
 port it to new platforms.

Can you also add a note to the 2.3 and 2.4 web pages?

- -Barry

-BEGIN PGP SIGNATURE-
Version: GnuPG v1.4.8 (Darwin)

iQCVAwUBR8vsPHEjvBPtnXfVAQJVpgP5AbRU+BENEa7fv7vGUykjtQRftaF6ATQz
yTo9018UiQZ20bFv2PIvgHltsET1ksTuieSdDjGbQ3rGu3vo1tldiGYxUQJgi++C
q8ntOyLUo+nHSlKm11TTyMiNX4igl+X0bes5PlgJZbWOnw0vBvWbVRrwgMUsJqfi
ox/d8+2jWc4=
=HLja
-END PGP SIGNATURE-
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: RELEASED Python 2.6a1 and 3.0a3

2008-03-03 Thread dave_mikesell
On Mar 1, 10:53 pm, Kay Schluehr [EMAIL PROTECTED] wrote:
 On 1 Mrz., 19:51, Barry Warsaw [EMAIL PROTECTED] wrote:

  Python 2.6 is not only the next advancement in the Python 2 series, it
  is also a transitionary release, helping developers begin to prepare
  their code for Python 3.0.

 Isn't this a silly idea? People have to migrate from 2.5 or lower
 releases to Python 2.6 first just to migrate to Python 3.0? What are
 the inherent / technical reasons that prevent migration directly from
 2.5 to 3.0?

Not only that, you have to wait for your library providers to migrate
first (PyOpenGL, PyGame, PIL, etc for me).   Hopefully this is the
last quantum shift for a while.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: RELEASED Python 2.6a1 and 3.0a3

2008-03-03 Thread dave_mikesell
On Mar 1, 10:53 pm, Kay Schluehr [EMAIL PROTECTED] wrote:
 On 1 Mrz., 19:51, Barry Warsaw [EMAIL PROTECTED] wrote:

  Python 2.6 is not only the next advancement in the Python 2 series, it
  is also a transitionary release, helping developers begin to prepare
  their code for Python 3.0.

 Isn't this a silly idea? People have to migrate from 2.5 or lower
 releases to Python 2.6 first just to migrate to Python 3.0? What are
 the inherent / technical reasons that prevent migration directly from
 2.5 to 3.0?

Not only that, you have to wait for your library providers to migrate
first (PyOpenGL, PyGame, PIL, etc for me).   Hopefully this is the
last quantum shift for a while.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Delete hidden files on unix

2008-03-03 Thread Philipp Pagel
loial [EMAIL PROTECTED] wrote:
 How can I delete hidden files on unix with python, i.e I want to do
 equivalent of

 rm  .lock*

Here is one way to do it:

import os, glob
for filename in glob.glob('.lock*'):
os.unlink(filename)


Alternatively, you could also do this:

import os
os.system('rm .lock*')


cu
Philipp

-- 
Dr. Philipp Pagel
Lehrstuhl f. Genomorientierte Bioinformatik
Technische Universität München
http://mips.gsf.de/staff/pagel
-- 
http://mail.python.org/mailman/listinfo/python-list


Cant run application as ./myapp.py

2008-03-03 Thread Robert Rawlins
Hello Guys,

 

I've got an application here which for some reason won't start using the
following syntax from the command line:

 

Cd /mydirectory

./MyApplication.py

 

I have to run this as a fully qualified python launch such as:

 

Cd /mydirectory

python MyApplication.py

 

This is a little bit confusing to me as I have other applications which run
just fine using the ./somthing.py syntax. Is there any reason why this
doesn't work?

 

Cheers,

 

Robert

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

Re: is there enough information?

2008-03-03 Thread Jean-Paul Calderone
On Tue, 26 Feb 2008 21:45:24 -0800, Dennis Lee Bieber [EMAIL PROTECTED] wrote:
 [snip]

   Threads, in Python, are good for parallel processing of items that
tend to be I/O bound -- that is, stuff that blocks on lots of I/O calls
allowing other threads to execute until they block too. Due to the GIL
in the common Python implementation, threading is not useful for
number-crunching (CPU bound) processing.

   Now, there is a very vocal group that recommend Twisted style
asynchronous call-backs for everything in the world... But I think that
group tends to forget that Windows I/O is incompatible with the
low-level select() call often used to do parallel I/O -- leaving it only
useful for the network socket I/O, but not local file I/O processing.

I'm not sure, but you seem to be implying that the only way to use Windows'
asynchronous I/O APIs is with threads.  Actually, it is possible (and Twisted
allows you) to use these as well without writing a threaded application.

Perhaps you think it would be better to use them with threads, but that's
certainly not the _only_ way to use them as you implied.

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


compiling plpython compilation error

2008-03-03 Thread Gerardo Herzig
Hi all. Im having a hard time trying to compile the plpython package.
This is the error make gives me:

[EMAIL PROTECTED]:/usr/local/src/postgresql-8.2.5/src/pl/plpython make
gcc -O2 -Wall -Wmissing-prototypes -Wpointer-arith -Winline 
-Wdeclaration-after-statement -Wendif-labels -fno-strict-aliasing -fpic 
-shared -Wl,-soname,libplpython.so.0   plpython.o 
-L/usr/lib/python2.5/config -L../../../src/port -lpython2.5 -lpthread 
-ldl -lutil -lm -Wl,-rpath,'/usr/lib/python2.5/config' -o libplpython.so.0.0
/usr/lib64/gcc/x86_64-suse-linux/4.2.1/../../../../x86_64-suse-linux/bin/ld: 
/usr/lib/python2.5/config/libpython2.5.a(abstract.o): relocation 
R_X86_64_32 against `a local symbol' can not be used when making a 
shared object; recompile with -fPIC
/usr/lib/python2.5/config/libpython2.5.a: could not read symbols: Bad value
collect2: ld returned 1 exit status
make: *** [libplpython.so.0.0] Error 1


This runs on OpenSuse 10.3.
python 2.5
postgres 8.2.5 ( and 8.3.0)

Any clues?
Thanks!

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


Re: Cant run application as ./myapp.py

2008-03-03 Thread Nils Oliver Kröger
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

Hi Robert,

I have to guesses:

a) The user as which you are trying to run the script is missing the
execute right - fix by chmod u+x MyApplication.px

b) You did not specify the interpreter - the first line of your script
should look something like #!/usr/bin/python

If none of this is the problem please post the error message you
(hopefully) get.

hth

Nils

Robert Rawlins schrieb:
 Hello Guys,
 
  
 
 I’ve got an application here which for some reason won’t start using the
 following syntax from the command line:
 
  
 
 Cd /mydirectory
 
 ./MyApplication.py
 
  
 
 I have to run this as a fully qualified python launch such as:
 
  
 
 Cd /mydirectory
 
 python MyApplication.py
 
  
 
 This is a little bit confusing to me as I have other applications which
 run just fine using the ./somthing.py syntax. Is there any reason why
 this doesn’t work?
 
  
 
 Cheers,
 
  
 
 Robert
 
-BEGIN PGP SIGNATURE-

iD8DBQFHzALBzvGJy8WEGTcRAtE8AJ4jGFTjZ8G8ayZM2AUcLcArnF5d1QCdH0gj
kCdp0414HwPaIMIDv/SSTZA=
=tF3K
-END PGP SIGNATURE-
begin:vcard
fn;quoted-printable:Nils Oliver Kr=C3=B6ger
n;quoted-printable:Kr=C3=B6ger;Nils Oliver
email;internet:[EMAIL PROTECTED]
version:2.1
end:vcard

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

Re: Is it possible to return a variable and use it...?

2008-03-03 Thread Alan Isaac
Nathan Pinno wrote:

 Is it possible to return a variable and then use it



I think you are asking about the ``global`` statement.

URL:http://docs.python.org/ref/global.html



 like the following:



Presumably not.  ;-)



Cheers,

Alan Isaac


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


Re: Cant run application as ./myapp.py

2008-03-03 Thread Gabriel Genellina
En Mon, 03 Mar 2008 10:35:30 -0200, Robert Rawlins  
[EMAIL PROTECTED] escribió:

 I've got an application here which for some reason won't start using the
 following syntax from the command line:


 Cd /mydirectory

 ./MyApplication.py


 I have to run this as a fully qualified python launch such as:


 Cd /mydirectory

 python MyApplication.py


 This is a little bit confusing to me as I have other applications which  
 run
 just fine using the ./somthing.py syntax. Is there any reason why this
 doesn't work?

See this thread from last year:  
http://groups.google.com/group/comp.lang.python/browse_thread/thread/b1d0fd05b3615057/

-- 
Gabriel Genellina

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


Re: Delete hidden files on unix

2008-03-03 Thread subeen
On Mar 3, 6:13 pm, Philipp Pagel [EMAIL PROTECTED]
wrote:
 loial [EMAIL PROTECTED] wrote:
  How can I delete hidden files on unix with python, i.e I want to do
  equivalent of
  rm  .lock*

 Here is one way to do it:

 import os, glob
 for filename in glob.glob('.lock*'):
 os.unlink(filename)

 Alternatively, you could also do this:

 import os
 os.system('rm .lock*')

 cu
 Philipp

 --
 Dr. Philipp Pagel
 Lehrstuhl f. Genomorientierte Bioinformatik
 Technische Universität Münchenhttp://mips.gsf.de/staff/pagel

Another way is to execute the linux command directly :)
Check here: 
http://love-python.blogspot.com/2008/02/execute-linux-commands-in-python.html

regards,
subeen.
http://love-python.blogspot.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: is there enough information?

2008-03-03 Thread castironpi
On Mar 3, 7:11 am, Jean-Paul Calderone [EMAIL PROTECTED] wrote:
 On Tue, 26 Feb 2008 21:45:24 -0800, Dennis Lee Bieber [EMAIL PROTECTED] 
 wrote:

  [snip]

     Threads, in Python, are good for parallel processing of items that
 tend to be I/O bound -- that is, stuff that blocks on lots of I/O calls
 allowing other threads to execute until they block too. Due to the GIL
 in the common Python implementation, threading is not useful for
 number-crunching (CPU bound) processing.

     Now, there is a very vocal group that recommend Twisted style
 asynchronous call-backs for everything in the world... But I think that
 group tends to forget that Windows I/O is incompatible with the
 low-level select() call often used to do parallel I/O -- leaving it only
 useful for the network socket I/O, but not local file I/O processing.

 I'm not sure, but you seem to be implying that the only way to use Windows'
 asynchronous I/O APIs is with threads.  Actually, it is possible (and Twisted
 allows you) to use these as well without writing a threaded application.

 Perhaps you think it would be better to use them with threads, but that's
 certainly not the _only_ way to use them as you implied.

 Jean-Paul

What's the API call for it?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Problem with the strip string method

2008-03-03 Thread Harold Fellermann
 Thanks to all respondents, Steve Holden
 is right, I expected more than I should
 have.

Others have explained why all your examples work as they should.
From your exmaples, it seems like you would like strip to
remove the leading and trailing characters from EVERY LINE in
your string. This can be done by the simple construct

 my_string = '  foo\n bar   '
 '\n'.join(line.strip() for line in my_string.split('\n'))
'foo\nbar'

If you need this construct at several places, define a function

def line_strip(string,sep='\n') :
return sep.join(line.strip() for line in string.split(sep))

cheers,

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


Exception or not

2008-03-03 Thread Monica Leko
Suppose you have some HTML forms which you would like to validate.
Every field can have different errors.  For example, this are the
forms:

username
password
etc

And you want to validate them with some class.  Is this good pattern:

class Foo(object):
def validateUsername(username):
  if username isn't correct:
raise ValidationError()
def validatePassword(password):
  if password isn't correct:
raise ValidationError()

code:
try:
  usernameError = validateUsername()
except ValidationError:
  usernameError = error from exception
try:
  passwordError = validatePassword()
except ValidationError:
  passwordError = error from exception

So, if there wasn't any errors, usernameError and passwordError both
contains None, and there was error, both contains some string?  Should
I use exception or just return None or some string without
exception?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Book Recomendations

2008-03-03 Thread rockingred
The Python Forum has a good set of selections in their General
Forum section:

http://python-forum.org/pythonforum/viewtopic.php?f=1t=12st=0sk=tsd=asid=9b04b79b60f9afb56e4237856910d354start=20
-- 
http://mail.python.org/mailman/listinfo/python-list


Talking to a usb device (serial terminal)

2008-03-03 Thread blaine
Hey everyone,
  We have a usb spectrometer device that we have finally got working
in linux (we were provided linux only drivers).  The device has a
Silicon Instruments cp2101 serial-to-usb chip onboard, and we loaded
the kernel module cp2101.c after taking the device apart to see what
was on the inside.  Using minicom we are able to set a baud rate and
open up a terminal when pointing to the device /dev/ttyusb0 (I
think).  Anyway, I want to be able to talk to our cool device using
python.  I haven't been able to find many resources specifically in
this area, but there are a few package that are vaguely mentioned,
including fcntl and termios.  But the web doesn't seem to have a lot
of documentation on fcntl, particularly information thats from the
past 8 years.

So my question is this - what is the easiest way to interface to this
serial device?

I don't imagine a straight read() and write() command to /dev/ttyusb0
is the most efficient (if it even works) especially since we would
need to set a baud rate.  My experience with terminal communication is
pretty limited.

Any advice that can be offered would be awesome. Thanks!
PS: The device that we will be using python on will be an embedded ARM
system.  Currently we are testing using a linux laptop and cross
compiling the kernel over to the embedded device.  The device has
Python 2.4, and does have both the termios and fcntl packages
available.

Python 2.4.2 (#1, Feb 20 2008, 11:07:36)
[GCC 4.1.1] on linux2

uname -a:
Linux gumstix 2.6.21gum #1 Wed Feb 20 02:53:01 EST 2008 armv5tel
unknown

Blaine Booher
University of Cincinnati

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


Re: Book Recomendations

2008-03-03 Thread apatheticagnostic
On Mar 2, 6:16 am, David Cook [EMAIL PROTECTED] wrote:
 On 2008-03-02, Jeff Schwab [EMAIL PROTECTED] wrote:

  Python In A Nutshell:
 http://www.oreilly.com/catalog/pythonian2/

 Another vote for the Nutshell book, which I find a very useful and practical
 book.

 I never found the Dive in book useful.

 Dave Cook

Here's another vote for Python in a Nutshell. If you have a lot of
experience with other languages, it should be all you need to get up
to speed with python quickly.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Talking to a usb device (serial terminal)

2008-03-03 Thread Mike Kent

 So my question is this - what is the easiest way to interface to this
 serial device?


http://pyserial.sourceforge.net/

or perhaps

http://pyusb.berlios.de/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Exception or not

2008-03-03 Thread Nils Oliver Kröger
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

Hello,

I don't think it is a good pattern because you are kind of mixing
exceptions with return codes which makes the code a lot less readable
later on.

I personally would strongly opt for return codes in this case as one
would intuitively expect a function named validateThisAndThat to return
the result of a validation. This might me a simple true/false, a numeric
code with 0=OK, 1=password not correct, 2=user does not exist or a
string, whatever you need.

In my opinion, such a function should raise an exception if it is unable
to fullfill its task. For example lost connection to user database or
things like that. A function should never propagate an expected result
as an exception.

Greetings Nils

Monica Leko schrieb:
| Suppose you have some HTML forms which you would like to validate.
| Every field can have different errors.  For example, this are the
| forms:
|
| username
| password
| etc
|
| And you want to validate them with some class.  Is this good pattern:
|
| class Foo(object):
| def validateUsername(username):
|   if username isn't correct:
| raise ValidationError()
| def validatePassword(password):
|   if password isn't correct:
| raise ValidationError()
|
| code:
| try:
|   usernameError = validateUsername()
| except ValidationError:
|   usernameError = error from exception
| try:
|   passwordError = validatePassword()
| except ValidationError:
|   passwordError = error from exception
|
| So, if there wasn't any errors, usernameError and passwordError both
| contains None, and there was error, both contains some string?  Should
| I use exception or just return None or some string without
| exception?

-BEGIN PGP SIGNATURE-
Version: GnuPG v1.4.6 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFHzCGhzvGJy8WEGTcRAvbGAJoDjn39xCmiOLmkc//0RTfeVXJFTACePRIG
uYoDiQBZwRsShUn60LN/9oQ=
=zvAY
-END PGP SIGNATURE-
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Import, how to change sys.path on Windows, and module naming?

2008-03-03 Thread bockman
On 1 Mar, 20:17, Steve Holden [EMAIL PROTECTED] wrote:
 Jeremy Nicoll - news posts wrote:



  Jeremy Nicoll - news posts [EMAIL PROTECTED] wrote:

  If I understand correctly, when I import something under Windows, Python
  searches the directory that the executing script was loaded from, then
  other directories as specified in sys.path.

  Sorry to followup my own question, but I ran

   for p,q in enumerate(sys.path): print p, q

  and got:

  0 C:\Documents and Settings\Laptop\My Documents\JN_PythonPgms
  1 C:\Program Files\~P-folder\Python25\Lib\idlelib
  2 C:\WINDOWS\system32\python25.zip
  3 C:\Program Files\~P-folder\Python25\DLLs
  4 C:\Program Files\~P-folder\Python25\lib
  5 C:\Program Files\~P-folder\Python25\lib\plat-win
  6 C:\Program Files\~P-folder\Python25\lib\lib-tk
  7 C:\Program Files\~P-folder\Python25
  8 C:\Program Files\~P-folder\Python25\lib\site-packages
  9 C:\Program Files\~P-folder\Python25\lib\site-packages\win32
  10 C:\Program Files\~P-folder\Python25\lib\site-packages\win32\lib
  11 C:\Program Files\~P-folder\Python25\lib\site-packages\Pythonwin

  Does every Windows user have: 2 C:\WINDOWS\system32\python25.zip
  in their sys.path?  What's the point of having a zip in the path?

 So that the files inside the zip can be imported as modules and
 packsges, of course.

  Also, looking in  C:\WINDOWS\system32\   I don't actually have a file called
  python25.zip, but I do have one called  python25.dll - so has something gone
  wrong in creation of sys.path?

 No. I'm not sure why the zip file is on there by default.

 regards
   Steve
 --
 Steve Holden        +1 571 484 6266   +1 800 494 3119
 Holden Web LLC              http://www.holdenweb.com/- Nascondi testo tra 
 virgolette -

 - Mostra testo tra virgolette -

I believe the answer is in how the new import protocol (PEP 302)
works: when you install a new path handler in sys.import_hooks, this
is called for each element of sys.path; the path handler has two
options: either to raise
ImportError, which means that cannot handle the specific path, or to
return an object with the methods defined
in the PEP, which means that the returned object - and only that one -
will be used to import modules in the specific path.

This means that only one path handler can be used for each element of
sys.path. Therefore, if you want to add a
path handler that does not interfere with the other ones, one way to
do it is to add something in sys.path that
is rejected by all path handlers except yours. I believe that
python25.zip is that 'something' that is used by the
zipimporter path handler, which allows to import directly from zip
files.

I did something similar in my toy experiment with the import hooks,
half-believing that there was something I missed. Nice to see that the
'big guys' did the same trick  :-)
(unless of course I _did_ miss something and my guess is completely
wrong; I should have done some experiment
before posting, but I'm too lazy for that).

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


Re: Exception or not

2008-03-03 Thread Arnaud Delobelle


Monica Leko wrote:

 Suppose you have some HTML forms which you would like to validate.
 Every field can have different errors.  For example, this are the
 forms:

 username
 password
 etc

 And you want to validate them with some class.  Is this good pattern:
[...]

You could have a look at how django [http://www.djangoproject.com] and
how they handle forms:

http://www.djangoproject.com/documentation/newforms/

In fact their newforms module should work fine as a standalone.
--
Arnaud
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: [SQL] compiling plpython compilation error

2008-03-03 Thread Tom Lane
Gerardo Herzig [EMAIL PROTECTED] writes:
 Hi all. Im having a hard time trying to compile the plpython package.
 This is the error make gives me:

 /usr/lib/python2.5/config/libpython2.5.a(abstract.o): relocation 
 R_X86_64_32 against `a local symbol' can not be used when making a 
 shared object; recompile with -fPIC

Well, I'd try following the error message's advice: use -fPIC not
-fpic.  Note that it's not real clear whether this needs to be done
for plpython, or libpython, or perhaps both; so you might well be
in for making a custom libpython installation.

regards, tom lane
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Exception or not

2008-03-03 Thread Bruno Desthuilliers
Monica Leko a écrit :
 Suppose you have some HTML forms which you would like to validate.
 Every field can have different errors.  For example, this are the
 forms:
 
 username
 password
 etc
 
 And you want to validate them with some class.  

This is what the FormEncode package is for.

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


Re: Import, how to change sys.path on Windows, and module naming?

2008-03-03 Thread bockman
On 3 Mar, 17:12, [EMAIL PROTECTED] wrote:

 (unless of course I _did_ miss something and my guess is completely
 wrong; I should have done some experiment
 before posting, but I'm too lazy for that).

 Ciao
 ---
 FB- Nascondi testo tra virgolette -

 - Mostra testo tra virgolette -

Oops... I tried removing python25.zip from sys.path, and I can still
import packages from zip files ...
so my guess was wrong and my lazyness has been punished :-)

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


Re: How about adding rational fraction to Python?

2008-03-03 Thread Paul Rubin
Jeff Schwab [EMAIL PROTECTED] writes:
  User defined types in python are fairly heavyweight compared with the
  built-in types,
 
 Yet they continue to form the basis of almost all non-trivial Python
 programs.  Anyway, it's a bit soon to be optimizing. :)

Large python programs usually have some classes for complex data
structures, but it's not typical Pythonic practice to define new
classes for things as small as integers.

  and a type like that is just another thing for the user to have to
  remember.
 
 How so?  A well-written function generally shouldn't depending on the
 exact types of its arguments, anyway.  

By another thing to remember I mean doing the right thing should
happen with the normal integers that result from writing literals like
1 and 2, without resorting to a nonstandard user defined type.  

 If someone has written a
 function to find (e.g.) the median of a collection of numbers, their
 code should already be prepared to accept values of user-defined
 numeric types.

It's important to be able to write such generic or polymorphic
functions, but most typical functions are monomorphic.

 If I want to call such a function with my hand-rolled
 DivisionSafeInteger type, it should just work,

Sure, however, the Pythonic approach is to make the defaults do the
right thing without requiring such user-written workarounds.  Of course
there is occasional unclarity about what the right thing is.

  file) and size_t, so if you pass an off_t to a function that expects a
  size_t as that arg, the compiler notices the error.
 
 On what compiler?  I've never seen a C compiler that would mind any
 kind of calculation involving two native, unsigned types.

You are right, C is even worse than I remembered.

  But they are
  really just integers and they compile with no runtime overhead.
 
 They do indeed have run-time overhead, as opposed to (e.g.) meta-types
 whose operations are performed at compile-time. 

Not sure what you mean; by no runtime overhead I just mean they
compile to the same code as regular ints, no runtime checks.  OK, it
turns out that for all intents and purposes it looks like they ARE
regular ints even at compile time, but in other languages it's not
like that.

 If you mean they have less overhead than types whose operations
 perform run-time checks, then yes, of course that's true.  You
 specifically stated (then snipped) that you would be happier if
 int/int always threw an error.  The beauty of a language with such
 extensive support for user-defined types that can be used like
 built-in type is that you are free to define types that meet your
 needs. 

But those are not ints then.  We're discussing an issue of language
design, which is what the behavior of the ordinary, standard, default
ints should be.  My reason for suggesting int/int-error is that I
think it would increase program reliability in general.  But that is
only if it applies to all the ints by default, with int/int=float
being a possible result of a nonstandard user-defined type.  From the
zen list: In the face of ambiguity, refuse the temptation to guess.

 My understanding is that Python will easily support lots of different
 types of just about anything.  That's the point.

No I don't think so.  Also from the zen list: There should be one--
and preferably only one --obvious way to do it.

  There's an interesting talk linked from LTU about future languages:
http://lambda-the-ultimate.org/node/1277
 
 Thanks, but that just seems to have links to the slides.  Is there a
 written article, or a video of Mr. Sweeney's talk?

I don't think there's an article.  There might be video somewhere.  I
thought the slides were enough to get the ideas across so I didn't
have much interest in sitting through a video.
-- 
http://mail.python.org/mailman/listinfo/python-list


SQLObject 0.9.4

2008-03-03 Thread Oleg Broytmann
Hello!

I'm pleased to announce the 0.9.4 release of SQLObject.


What is SQLObject
=

SQLObject is an object-relational mapper.  Your database tables are described
as classes, and rows are instances of those classes.  SQLObject is meant to be
easy to use and quick to get started with.

SQLObject supports a number of backends: MySQL, PostgreSQL, SQLite, and
Firebird.  It also has newly added support for Sybase, MSSQL and MaxDB (also
known as SAPDB).


Where is SQLObject
==

Site:
http://sqlobject.org

Development:
http://sqlobject.org/devel/

Mailing list:
https://lists.sourceforge.net/mailman/listinfo/sqlobject-discuss

Archives:
http://news.gmane.org/gmane.comp.python.sqlobject

Download:
http://cheeseshop.python.org/pypi/SQLObject/0.9.4

News and changes:
http://sqlobject.org/News.html


What's New
==

News since 0.9.3


Bug Fixes
~

* Use list.reverse() in manager/command.py for Python 2.2 compatibility.

* Prevent MultipleJoin from removing the intermediate table if it was not
  created by the Join.

* Fixed a bug with no default when defaultSQL is defined for the column.

* Recognize POINT data type as string in PostgresConnection.columnsFromSchema().

For a more complete list, please see the news:
http://sqlobject.org/News.html

Oleg.
-- 
 Oleg Broytmannhttp://phd.pp.ru/[EMAIL PROTECTED]
   Programmers don't die, they just GOSUB without RETURN.
-- 
http://mail.python.org/mailman/listinfo/python-list


urlsafe_b64decoding of xml node text

2008-03-03 Thread kaush
Hi All,

I am running Apache with mod_python. A post message to my server
contains an xml of the form
a
b(some base64 ur-safe-encoded data)/b
/a

I use minidom to parse the xml posted, and now try to decode the data
using the following

import minidom
import base64

decData = base64.urlsafe_b64decode(data) #data is the above mentioned
url-safe-encoded data

This line fails with the following error

Error : type 'exceptions.TypeError'
Error : character mapping must return integer, None or unicode
Error : traceback object at 0x1b38e40

If i run the same data through a script on the terminal, I am able to
successfully decode the data.

What could be the reason for this error? Can it be because of some
encoding introduced by minidom?

I think urlsafe_b64decode takes ascii string.

Thanks,
Kaushik
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Decorators and buffer flushing

2008-03-03 Thread Ethan Metsger
Hi, Gabriel.  I missed this message initially; I apologize for not  
responding sooner.

On Thu, 28 Feb 2008 18:53:28 -0500, Gabriel Genellina  
[EMAIL PROTECTED] wrote:

 I can reproduce the issue in the console.  I'm not convinced it's  
 actually
 a bug, unless for some reason the interpreter is preventing a buffer  
 flush.

 Try starting the interpreter with python -u xxx.py (-u = unbuffered) but  
 I don't really think this might be the cause. Are you sure the code  
 actually says sys.stdout.flush() and not sys.stdout.flush?

As I mentioned in another message, I haven't had any luck with adding '-u'  
to the invocation of the interpreter.  I am sure I'm not looking at the  
callable object rather than calling flush().

sys.stdout.write (%s % (self.name.ljust(30),))

 Usually written as:
 sys.stdout.write(%-30s % self.name)

Thanks for the tips!

[...]

 Is it possible that flushing is prohibited until __exit__ is called?

 I don't think so... What's your platform/OS?

I'm running Ubuntu Feisty with Python 2.5.1:

Python 2.5.1 (r251:54863, May  2 2007, 16:56:35)
[GCC 4.1.2 (Ubuntu 4.1.2-0ubuntu4)] on linux2

 Try to post a minimal example showing the problem - copy  paste it,  
 don't retype. Maybe in the process of reducing your code to find the  
 minimal example, you find the problem yourself.

The minimal example is a little long, but I think in the end I figured out  
what was happening.  The initial build step took the longest amount of  
time to complete, but the other steps were nearly instantaneous.

So the post-build '.' would appear, and the very fast run of the other  
steps made it appear as though everything was being buffered when it  
wasn't.  Adding in a short delay (time.sleep(0.05) seemed to work) helped  
demonstrate that the data actually were unbuffered.

 Are you aware of the existing framework for unit tests? the unittest  
 module?

Yes.  I haven't investigated its uses in this context due to the  
constraints of the legacy system and general inertia.  I'm trying to  
duplicate functionality while addressing certain annoyances with the  
previous system.


Thanks again for your help!

Best,

Ethan

-- 
Ethan Metsger
http://uppertank.net/ethanm/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Talking to a usb device (serial terminal)

2008-03-03 Thread Bjoern Schliessmann
blaine wrote:

 So my question is this - what is the easiest way to interface to
 this serial device?
 
 I don't imagine a straight read() and write() command to
 /dev/ttyusb0 is the most efficient (if it even works) 

It doesn't only work, it's the preferred way (if you don't use
advanced wrappers like pyserial). For the basics see

http://www.easysw.com/~mike/serial/serial.html

 especially since we would need to set a baud rate.

What is the relationship between read/write, the baud rate, and
efficiency? The serial port is configured using POSIX terminal
interface (termios).

Regards,


Björn

-- 
BOFH excuse #89:

Electromagnetic energy loss

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


Inheritance issue...

2008-03-03 Thread MooMaster
I'm trying to use inheritance to create a simple binary tree, but it's
not going so well... here's what I pull from the documentation for
super()
super( type[, object-or-type])

Return the superclass of type. If the second argument is omitted the
super object returned is unbound. If the second argument is an object,
isinstance(obj, type) must be true. If the second argument is a type,
issubclass(type2, type) must be true. super() only works for new-style
classes.
A typical use for calling a cooperative superclass method is:

class C(B):
def meth(self, arg):
super(C, self).meth(arg)


So here's what I do:

class Node:
def __init__(self, val=0, prnt = None):
self.value = val
self.parent = prnt

class Tree(Node):
def __init__(self, val=0):
self.root = super(Tree, self).__init__(val)
self.leftChild = None
self.rightChild = None

def addChild(self, value):
if self.root == None:
self.__init__(value)
else:
n = self.root
while(n is not None):
if(n.leftChild == None and n.rightChild == None):
n.leftChild = Node(value, n)
elif(n.rightChild == None):
n.rightChild = Node(value, n)
else:
if(n.leftChild.leftChild is not None and
n.leftChild.rightChild is not None):
n = n.rightChild
else:
n = n.leftChild

def printTree(self):
if self.root == None:
print None
else:
n = self.root
print n.value
while(n is not None):
if(n.leftChild is None):
print str(n.value) + 's left child is None
elif(n.rightChild is None):
print str(n.value) + 's right child is None
else:
if(n.leftChild.leftChild is not None and
n.leftChild.rightChild is not None):
n = n.rightChild
else:
n = n.leftChild
def main():
play = Tree(1)
play.addChild(2)
play.addChild(3)
play.addChild(4)
play.addChild(5)
play.printTree()

if __name__ == __main__:
main()



...and here's what I get:

Traceback (most recent call last):
  File C:/Users/The_N_Channel/Desktop/funWithTrees.py, line 53, in
module
main()
  File C:/Users/The_N_Channel/Desktop/funWithTrees.py, line 45, in
main
play = Tree(1)
  File C:/Users/The_N_Channel/Desktop/funWithTrees.py, line 8, in
__init__
self.root = super(Tree, self).__init__(val)
TypeError: super() argument 1 must be type, not classobj

Looks to me like the super(Tree, self)__init__(val) follows the
example in the documentation, but I may be a witch. Anyone know why
this doesn't work?
-- 
http://mail.python.org/mailman/listinfo/python-list


clocking subprocesses

2008-03-03 Thread barnburnr
Hi,

I've seen several threads on this subject, but haven't (yet) run
across one that answers my specific questions.  This should be really
easy for someone, so here goes:

I'm running some numerical simulations under Ubuntu, and using Python
as my scripting language to automatically manage input and output.  I
need to have a precise performance measurement (CPU time) of how long
it takes to run my simulations.

Right now I have something like:

stime = time.time()
subprocess.call([./mysim,args])
ftime = time.time()
print ftime-stime

However, time.time() only gives wall-clock time, so I'm also measuring
the time it takes to run other processes running at the same time.
What I'd rather have is:

stime = time.clock()
subprocess.call([./mysim,args])
ftime = time.clock()
print ftime-stime

But this, of course, usually outputs 0, because time.clock() does not
count the CPU ticks of the subprocess.

So, long story short, I need to get CPU time of something I call using
subprocess.call().  I don't want to have to profile my code, since it
will significantly reduce computation time.

Thanks for the advice.

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


News from Jython world

2008-03-03 Thread Sébastien Boisgérault

Frank Wierzbicki and Ted Leung have been hired by Sun. Frank is a
key Jython developer and is specifically hired to work full time on
Jython, a version of the Python interpreter that runs on top of the
JVM and provides full access to Java libraries. After a period where
the development had slowed, Jython was recently getting seriously
back on track. Now it's getting even better !

Don't wait too much ... Jython is very useful RIGHT NOW if you live
in the Java Universe.

More details at:
 - http://www.infoworld.com/article/08/03/03/hirings-python_1.html
 - http://fwierzbicki.blogspot.com/2008/02/jythons-future-looking-sunny.html

Cheers,

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


Re: Inheritance issue...

2008-03-03 Thread Matimus
On Mar 3, 9:37 am, MooMaster [EMAIL PROTECTED] wrote:
 I'm trying to use inheritance to create a simple binary tree, but it's
 not going so well... here's what I pull from the documentation for
 super()
 super( type[, object-or-type])

 Return the superclass of type. If the second argument is omitted the
 super object returned is unbound. If the second argument is an object,
 isinstance(obj, type) must be true. If the second argument is a type,
 issubclass(type2, type) must be true. super() only works for new-style
 classes.
 A typical use for calling a cooperative superclass method is:

 class C(B):
 def meth(self, arg):
 super(C, self).meth(arg)
 

 So here's what I do:

 class Node:
 def __init__(self, val=0, prnt = None):
 self.value = val
 self.parent = prnt

 class Tree(Node):
 def __init__(self, val=0):
 self.root = super(Tree, self).__init__(val)
 self.leftChild = None
 self.rightChild = None

 def addChild(self, value):
 if self.root == None:
 self.__init__(value)
 else:
 n = self.root
 while(n is not None):
 if(n.leftChild == None and n.rightChild == None):
 n.leftChild = Node(value, n)
 elif(n.rightChild == None):
 n.rightChild = Node(value, n)
 else:
 if(n.leftChild.leftChild is not None and
 n.leftChild.rightChild is not None):
 n = n.rightChild
 else:
 n = n.leftChild

 def printTree(self):
 if self.root == None:
 print None
 else:
 n = self.root
 print n.value
 while(n is not None):
 if(n.leftChild is None):
 print str(n.value) + 's left child is None
 elif(n.rightChild is None):
 print str(n.value) + 's right child is None
 else:
 if(n.leftChild.leftChild is not None and
 n.leftChild.rightChild is not None):
 n = n.rightChild
 else:
 n = n.leftChild
 def main():
 play = Tree(1)
 play.addChild(2)
 play.addChild(3)
 play.addChild(4)
 play.addChild(5)
 play.printTree()

 if __name__ == __main__:
 main()

 ...and here's what I get:

 Traceback (most recent call last):
   File C:/Users/The_N_Channel/Desktop/funWithTrees.py, line 53, in
 module
 main()
   File C:/Users/The_N_Channel/Desktop/funWithTrees.py, line 45, in
 main
 play = Tree(1)
   File C:/Users/The_N_Channel/Desktop/funWithTrees.py, line 8, in
 __init__
 self.root = super(Tree, self).__init__(val)
 TypeError: super() argument 1 must be type, not classobj

 Looks to me like the super(Tree, self)__init__(val) follows the
 example in the documentation, but I may be a witch. Anyone know why
 this doesn't work?


Node should inherit from `object'. Unless you inherit from object you
are using old-style classes, which do not derive from type and cannot
use the super method.

Example:
class Node(object):

Also, __init__ does not return anything, ever. This doesn't make
sense:
 self.root = super(Tree, self).__init__(val)

When you call the __init__ method of a base class, it will operate on
self.

Example:

 class CBase(object):
... def __init__(self, a):
... self.a = a
...
 class C(CBase):
... def __init__(self, a, b):
... super(C, self).__init__(a)
... self.b = b
...
 c = C(1,2)
 c.a
1
 c.b
2

Doing things like self.__init__(val) doesn't make sense.

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


Re: Inheritance issue...

2008-03-03 Thread Diez B. Roggisch
MooMaster schrieb:
 I'm trying to use inheritance to create a simple binary tree, but it's
 not going so well... here's what I pull from the documentation for
 super()
 super( type[, object-or-type])
 
 Return the superclass of type. If the second argument is omitted the
 super object returned is unbound. If the second argument is an object,
 isinstance(obj, type) must be true. If the second argument is a type,
 issubclass(type2, type) must be true. super() only works for new-style
 classes.

The last sentence contains the important bit. You need to use 
new-style-classes, which means they have to have the ancestor object 
somewhere in their inheritance-graph.

Like this:

class Foo(object): pass

Certainly one of the somewhat uglier corners of Python...

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


Re: Delete hidden files on unix

2008-03-03 Thread [EMAIL PROTECTED]
On Mar 3, 9:38 am, subeen [EMAIL PROTECTED] wrote:
 On Mar 3, 6:13 pm, Philipp Pagel [EMAIL PROTECTED]
 wrote:



  loial [EMAIL PROTECTED] wrote:
   How can I delete hidden files on unix with python, i.e I want to do
   equivalent of
   rm  .lock*

  Here is one way to do it:

  import os, glob
  for filename in glob.glob('.lock*'):
  os.unlink(filename)

  Alternatively, you could also do this:

  import os
  os.system('rm .lock*')

  cu
  Philipp

  --
  Dr. Philipp Pagel
  Lehrstuhl f. Genomorientierte Bioinformatik
  Technische Universität Münchenhttp://mips.gsf.de/staff/pagel

 Another way is to execute the linux command directly :)
 Check 
 here:http://love-python.blogspot.com/2008/02/execute-linux-commands-in-pyt...


Note that that can get dangerous with shell expansions:

e.g. (don't run in a directory with files you want to keep!)
import os
open(--help, w)
os.system(rm *help)

will actually run rm --help, printing the help for rm rather than
removing the file named --help.  There are a lot of security
implications to allowing this kind of shell expansion of commands.
The system-call method with os.unlink is easier to get right.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: clocking subprocesses

2008-03-03 Thread Preston Landers
On Mar 3, 11:57 am, [EMAIL PROTECTED] wrote:

 So, long story short, I need to get CPU time of something I call using
 subprocess.call().  

Run your command through the time program.  You can parse the output
format of time, or set a custom output format.  This mostly applies
to Unix-like systems but there is probably an equivalent somewhere on
Windows.

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


Re: Beautiful Code in Python?

2008-03-03 Thread Jonathan Gardner
On Mar 2, 8:35 am, Michele Simionato [EMAIL PROTECTED]
wrote:
 On Mar 2, 5:23 pm, js [EMAIL PROTECTED] wrote:

  Hi,

  Have you ever seen Beautiful Python code?
  Zope? Django? Python standard lib? or else?

  Please tell me what code you think it's stunning.

 The doctest module in the standard library.

  M.S.

The first thing of beauty I found in Python (coming from C, C++, and
perl) was the way Python handled variables, or as someone recently
described them, names.

Python's for statement is always beautiful to look at. Especially
when someone uses the else clause rather than trying to detect if the
list was exhausted. I sometimes avoid using the comprehensions just to
get an excuse to write another for loop in Python. There can never be
enough for loops written in Python!

Also, Python's iterator interface is by far the most beautiful thing I
have ever seen in the world of programming. Of course, the reason why
the for loop is so beautiful is because iterators are so beautiful.
-- 
http://mail.python.org/mailman/listinfo/python-list


Polymorphism using constructors

2008-03-03 Thread K Viltersten
I'm writing a class for rational numbers
and besides the most obvious constructor

  def __init__ (self, nomin, denom):

i also wish to have two supporting ones

  def __init__ (self, integ):
self.__init__ (integ, 1)
  def __init__ (self):
self.__init__ (0, 1)

but for some reason (not known to me at
this point) i get errors. My suspicion 
is that it's a syntax issue.

Suggestions?

--
Regards
Konrad Viltersten

sleep- a substitute for coffee for the poor
ambition - lack of sense to be lazy

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


Re: How about adding rational fraction to Python?

2008-03-03 Thread Arnaud Delobelle
On Mar 3, 4:39 pm, Paul Rubin http://[EMAIL PROTECTED] wrote:
[...]
 You are right, C is even worse than I remembered.

It's good enough to be the language used for the reference
implementation of python :-)

[...]
--
Arnaud

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


Re: Polymorphism using constructors

2008-03-03 Thread Diez B. Roggisch
K Viltersten schrieb:
 I'm writing a class for rational numbers
 and besides the most obvious constructor
 
  def __init__ (self, nomin, denom):
 
 i also wish to have two supporting ones
 
  def __init__ (self, integ):
self.__init__ (integ, 1)
  def __init__ (self):
self.__init__ (0, 1)
 
 but for some reason (not known to me at
 this point) i get errors. My suspicion is that it's a syntax issue.
 
 Suggestions?

errors is not much of an error-description. That's what stacktraces 
are for.

Apart from that, you won't succeed with the above. Python has no 
signature-based polymorphism. Instead, you use default arguments, like this:


def __init__(nomin=0, denom=1):
 ...

That should suffice.

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


Re: Inheritance issue...

2008-03-03 Thread MooMaster
On Mar 3, 11:49 am, Diez B. Roggisch [EMAIL PROTECTED] wrote:
 MooMaster schrieb:

  I'm trying to use inheritance to create a simple binary tree, but it's
  not going so well... here's what I pull from the documentation for
  super()
  super( type[, object-or-type])

  Return the superclass of type. If the second argument is omitted the
  super object returned is unbound. If the second argument is an object,
  isinstance(obj, type) must be true. If the second argument is a type,
  issubclass(type2, type) must be true. super() only works for new-style
  classes.

 The last sentence contains the important bit. You need to use
 new-style-classes, which means they have to have the ancestor object
 somewhere in their inheritance-graph.

 Like this:

 class Foo(object): pass

 Certainly one of the somewhat uglier corners of Python...

 Diez

Thanks guys, I hadn't even heard of the distinction between old and
new style classes...is this in the tutorial somewhere? I didn't see
it in Classes...
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: clocking subprocesses

2008-03-03 Thread barnburnr
On Mar 3, 12:41 pm, Preston  Landers [EMAIL PROTECTED] wrote:

 Run your command through the time program.  You can parse the output
 format of time, or set a custom output format.  This mostly applies
 to Unix-like systems but there is probably an equivalent somewhere on
 Windows.

 Preston

Thanks for the quick answer.  That seems to work, though, I'll write a
timesubprocess() function which runs the program through time and
spits the formatted out to a file, then parses that file, then returns
the execution time.  There doesn't appear to be a more elegant way to
do this.

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


FW: unable to download PyGEP

2008-03-03 Thread Blubaugh, David A.


 __ 
 From: Blubaugh, David A.  
 Sent: Monday, March 03, 2008 3:39 PM
 To:   '[EMAIL PROTECTED]'
 Subject:  unable to download PyGEP
 
 Dear Sir,
 
 I have been having issues installing PyGEP.  I have tried the
 following:
 
 at MS-DOS command prompt
 
 
 cd C:\python25\PyGEP-0.3.0.dev-r117
 
 
 I then enter setup.py on command prompt.  
 
 
 
 It then states that it could not find a module named setuptools in
 order to install.  Can you help me with this issue ??  Thanks
 
 
 
 David Blubaugh

This e-mail transmission contains information that is confidential and may be 
privileged. It is intended only for the addressee(s) named above. If you 
receive 
this e-mail in error, please do not read, copy or disseminate it in any manner. 
If you are not the intended recipient, any disclosure, copying, distribution or 
use of the contents of this information is prohibited. Please reply to the 
message immediately by informing the sender that the message was misdirected. 
After replying, please erase it from your computer system. Your assistance in 
correcting this error is appreciated.

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

sympy: what's wrong with this picture?

2008-03-03 Thread Mensanator
Notice anything funny about the random choices?

import sympy
import time
import random

f = [i for i in sympy.primerange(1000,1)]

for i in xrange(10):
  f1 = random.choice(f)
  print f1,
  f2 = random.choice(f)
  print f2,
  C = f1*f2
  ff = None
  ff = sympy.factorint(C)
  print ff

##  7307 7243 [(7243, 1), (7307, 1)]
##  4091 6829 [(4091, 1), (6829, 1)]
##  8563 2677 [(2677, 1), (8563, 1)]
##  4091 6829 [(4091, 1), (6829, 1)]
##  8563 2677 [(2677, 1), (8563, 1)]
##  4091 6829 [(4091, 1), (6829, 1)]
##  8563 2677 [(2677, 1), (8563, 1)]
##  4091 6829 [(4091, 1), (6829, 1)]
##  8563 2677 [(2677, 1), (8563, 1)]
##  4091 6829 [(4091, 1), (6829, 1)]

As in, they're NOT random.

The random number generator is broken by the sympy.factorint()
function.

Random.choice() works ok if the factorint() function commented out.

##  6089 1811 None
##  6449 1759 None
##  9923 4639 None
##  4013 4889 None
##  4349 2029 None
##  6703 8677 None
##  1879 1867 None
##  5153 5279 None
##  2011 4937 None
##  7253 5507 None

This makes sympy worse than worthless, as it fucks up other modules.

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


Re: Beautiful Code in Python?

2008-03-03 Thread babycode
 Please tell me what code you think it's stunning.

Pexpect is (almost) pseudocode is (almost) poetry to my ears. And
there's a lot of narrative in it as well:

http://pexpect.svn.sourceforge.net/viewvc/*checkout*/pexpect/trunk/pexpect/pexpect.py?content-type=text%2Fplain
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: sympy: what's wrong with this picture?

2008-03-03 Thread Carl Banks
On Mar 3, 3:40 pm, Mensanator [EMAIL PROTECTED] wrote:
 Notice anything funny about the random choices?

 import sympy
 import time
 import random

 f = [i for i in sympy.primerange(1000,1)]

 for i in xrange(10):
   f1 = random.choice(f)
   print f1,
   f2 = random.choice(f)
   print f2,
   C = f1*f2
   ff = None
   ff = sympy.factorint(C)
   print ff

 ##  7307 7243 [(7243, 1), (7307, 1)]
 ##  4091 6829 [(4091, 1), (6829, 1)]
 ##  8563 2677 [(2677, 1), (8563, 1)]
 ##  4091 6829 [(4091, 1), (6829, 1)]
 ##  8563 2677 [(2677, 1), (8563, 1)]
 ##  4091 6829 [(4091, 1), (6829, 1)]
 ##  8563 2677 [(2677, 1), (8563, 1)]
 ##  4091 6829 [(4091, 1), (6829, 1)]
 ##  8563 2677 [(2677, 1), (8563, 1)]
 ##  4091 6829 [(4091, 1), (6829, 1)]

 As in, they're NOT random.

 The random number generator is broken by the sympy.factorint()
 function.

 Random.choice() works ok if the factorint() function commented out.

 ##  6089 1811 None
 ##  6449 1759 None
 ##  9923 4639 None
 ##  4013 4889 None
 ##  4349 2029 None
 ##  6703 8677 None
 ##  1879 1867 None
 ##  5153 5279 None
 ##  2011 4937 None
 ##  7253 5507 None

 This makes sympy worse than worthless, as it f***s up other modules.

Dude, relax.

It's just a bug--probably sympy is messing with the internals of the
random number generator.  It would be a simple fix.  Instead of
bing about it, file a bug report.  Or better yet, submit a patch.


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


Re: Talking to a usb device (serial terminal)

2008-03-03 Thread blaine
On Mar 3, 12:31 pm, Bjoern Schliessmann usenet-
[EMAIL PROTECTED] wrote:
 It doesn't only work, it's the preferred way (if you don't use
 advanced wrappers like pyserial). For the basics see

 http://www.easysw.com/~mike/serial/serial.html
[...]
 What is the relationship between read/write, the baud rate, and
 efficiency? The serial port is configured using POSIX terminal
 interface (termios).

Thank you so much for that reference link, it was very helpful.  I now
understand the difference in the modules - termios and fctnl.

As far as PySerial goes - were trying to stick to built-in modules
since cross compiling to an arm processor is being a little bit of a
pain for us. Thank you for the suggestion though!

Thanks!
Blaine
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Inheritance issue...

2008-03-03 Thread Carl Banks
On Mar 3, 3:14 pm, MooMaster [EMAIL PROTECTED] wrote:
 On Mar 3, 11:49 am, Diez B. Roggisch [EMAIL PROTECTED] wrote:



  MooMaster schrieb:

   I'm trying to use inheritance to create a simple binary tree, but it's
   not going so well... here's what I pull from the documentation for
   super()
   super( type[, object-or-type])

   Return the superclass of type. If the second argument is omitted the
   super object returned is unbound. If the second argument is an object,
   isinstance(obj, type) must be true. If the second argument is a type,
   issubclass(type2, type) must be true. super() only works for new-style
   classes.

  The last sentence contains the important bit. You need to use
  new-style-classes, which means they have to have the ancestor object
  somewhere in their inheritance-graph.

  Like this:

  class Foo(object): pass

  Certainly one of the somewhat uglier corners of Python...

  Diez

 Thanks guys, I hadn't even heard of the distinction between old and
 new style classes...is this in the tutorial somewhere? I didn't see
 it in Classes...

Here's some reading material (it can get deep):

http://www.python.org/doc/newstyle/
http://www.python.org/download/releases/2.2.3/descrintro/


New style classes have been a part of Python since 2.2, but
unfortunately many documents intended for newbies don't even mention
them, which seems to cause more confusion than it prevents, such as
when newbies go Googling for code examples and see incompatible usage
of new-style classes.  For simple uses, new-style and old-style
classes behave similarly enough that it doesn't matter which you use,
but new-style classes support lots of things that old-style classes
don't, and usage of these features is getting more and more common.
Newbies who aren't being alerted to this are getting a raw deal.

Thankfully old-style classes are getting the axe in Python 3.0 and
hopefully this confusion will go away.

Until you switch to 3.0, inherit your base classes from object; it
will ensure that more recent additions like properties and super()
calls work.

class Node(object):



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


Re: Polymorphism using constructors

2008-03-03 Thread Raymond Hettinger
On Mar 3, 12:21 pm, K Viltersten [EMAIL PROTECTED] wrote:
 I'm writing a class for rational numbers
 and besides the most obvious constructor

   def __init__ (self, nomin, denom):

 i also wish to have two supporting ones

   def __init__ (self, integ):
 self.__init__ (integ, 1)
   def __init__ (self):
 self.__init__ (0, 1)

For this particular use case, providing default arguments will
suffice:

class Fraction:
  def __init__(self, numerator=0, denomiator=1):
   ...

Since Python doesn't support having two methods with the same name,
the usual solution is to provide alternative constructors using
classmethod():

  @classmethod
  def from_decimal(cls, d)
sign, digits, exp = d.as_tuple()
digits = int(''.join(map(str, digits)))
if sign:
digits = -digits
if exp = 0:
return cls(digits * 10 ** exp)
return cls(digits, 10 ** -exp)


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


Re: Talking to a usb device (serial terminal)

2008-03-03 Thread Grant Edwards
On 2008-03-03, blaine [EMAIL PROTECTED] wrote:

 As far as PySerial goes - were trying to stick to built-in
 modules since cross compiling to an arm processor is being a
 little bit of a pain for us.

pyserial is pure python, so I don't see how it's going to be
any more painful than something you write yourself.  If you
want something that's more of a transparent object wrapper
aroudn the Posix serial interface, there's PosixSerial.py (upon
which pyserial's posix support is based):

ftp://ftp.visi.com/users/grante/python/PosixSerial.py

-- 
Grant Edwards   grante Yow! Everybody gets free
  at   BORSCHT!
   visi.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How about adding rational fraction to Python?

2008-03-03 Thread Lie
On Mar 2, 11:36 pm, Paul Rubin http://[EMAIL PROTECTED] wrote:
 Lie [EMAIL PROTECTED] writes:
  You hit the right note, but what I meant is the numeric type
  unification would make it _appear_ to consist of a single numeric type
  (yeah, I know it isn't actually, but what appears from outside isn't
  always what's inside).

 That is clearly not intended; floats and decimals and integers are
 really different from each other and Python has to treat them distinctly.

In certain operations it would, such as:
a = Decimal('32.324')
b = 90.3453
c = 43
d = a + b + cthis should work without manual type casting

This behavior is what is intended in numeric type unification, floats
and decimals and integers should work together flawlessly without the
need for manual type casting. This gives the _impression_ of a single
numeric type (although programmers should still be aware that the
underlying type still exists). It's true Python have to treat them
differently, but programmers would be able to treat them all the same
(at least in most parts)

   Try with a=7, b=25

  They should still compare true, but they don't. The reason why they
  don't is because of float's finite precision, which is not exactly
  what we're talking here since it doesn't change the fact that
  multiplication and division are inverse of each other.

 What?  Obviously they are not exact inverses for floats, as that test
 shows.  They would be inverses for mathematical reals or rationals,
 but Python does not have those.

When I said multiplication and division are inverse, I was pointing
out the fact that even though float's inexactness make them imperfect
inverse, mult  div are still inverse of each other. In-practice, the
inversing behavior is impossible unless we have a way to represent
real number (which we don't), and the *workaround* to make them work
is to do epsilon comparison.

When I'm talking about things I usually talk in purely theoretical
condition first and considers practical implementations that doesn't
work that way as making up a workaround inside their limitations. In
this case, the theoretical condition is that multiplication and
division is inverse of each other. The practical consideration is
float is inexact and reals is impossible, and thus epsilon comparison
is necessary to walk around float's limitations so multiplication and
division could still be inverses.

Aside: Python would have rationals

  One way to handle this situation is to do an epsilon aware
  comparison (as should be done with any comparison involving floats),
  but I don't do it cause my intention is to clarify the real problem
  that multiplication is indeed inverse of division and I want to
  avoid obscuring that with the epsilon comparison.

 I think you are a bit confused.  That epsilon aware comparison thing
 acknowledges that floats only approximate the behavior of mathematical
 reals.  

Yes, I realized that floats aren't the same as reals.

 When we do float arithmetic, we accept that equal often
 really only means approximately equal.  But when we do integer
 arithmetic, we do not expect or accept equality as being approximate.
 Integer equality means equal, not approximately equal.  That is why
 int and float arithmetic cannot work the same way.

No, no, they don't work the same way, but they should appear to work
the same way as reals in pure mathematics do. Again, I'm talking in
theory first: ints and floats should work the same way, but since
practical considerations make them impossible, then they should at
least appear to work the same way (or they would have become
completely different things, remember duck typing?).
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Talking to a usb device (serial terminal)

2008-03-03 Thread blaine
 pyserial is pure python, so I don't see how it's going to be
 any more painful than something you write yourself.  If you
 want something that's more of a transparent object wrapper
 aroudn the Posix serial interface, there's PosixSerial.py (upon
 which pyserial's posix support is based):

 ftp://ftp.visi.com/users/grante/python/PosixSerial.py

 --
 Grant Edwards   grante Yow! Everybody gets free
   at   BORSCHT!
visi.com

Oh - good point. There wouldn't be any compilation issues with the C
api.  Nevermind! :)

I do have a question though.  In the termios module, I am attempting
to set the baud rate to 921600, which is what we use with
'cutecom' (because minicom does not have this as an option) and is
what the supplier recommends.  When I try to set the rate using
termios.tcsetattr(), I get an Argument Error.  I do not get this when
I use an existing baud rate, such as termios.B9600.  Is there a way I
can get around this? We would like to use it at full speed.

Thank you,
Blaine
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: sympy: what's wrong with this picture?

2008-03-03 Thread Mensanator
On Mar 3, 2:49 pm, Carl Banks [EMAIL PROTECTED] wrote:
 On Mar 3, 3:40 pm, Mensanator [EMAIL PROTECTED] wrote:





  Notice anything funny about the random choices?

  import sympy
  import time
  import random

  f = [i for i in sympy.primerange(1000,1)]

  for i in xrange(10):
    f1 = random.choice(f)
    print f1,
    f2 = random.choice(f)
    print f2,
    C = f1*f2
    ff = None
    ff = sympy.factorint(C)
    print ff

  ##  7307 7243 [(7243, 1), (7307, 1)]
  ##  4091 6829 [(4091, 1), (6829, 1)]
  ##  8563 2677 [(2677, 1), (8563, 1)]
  ##  4091 6829 [(4091, 1), (6829, 1)]
  ##  8563 2677 [(2677, 1), (8563, 1)]
  ##  4091 6829 [(4091, 1), (6829, 1)]
  ##  8563 2677 [(2677, 1), (8563, 1)]
  ##  4091 6829 [(4091, 1), (6829, 1)]
  ##  8563 2677 [(2677, 1), (8563, 1)]
  ##  4091 6829 [(4091, 1), (6829, 1)]

  As in, they're NOT random.

  The random number generator is broken by the sympy.factorint()
  function.

  Random.choice() works ok if the factorint() function commented out.

  ##  6089 1811 None
  ##  6449 1759 None
  ##  9923 4639 None
  ##  4013 4889 None
  ##  4349 2029 None
  ##  6703 8677 None
  ##  1879 1867 None
  ##  5153 5279 None
  ##  2011 4937 None
  ##  7253 5507 None

  This makes sympy worse than worthless, as it f***s up other modules.

 Dude, relax.

 It's just a bug--probably sympy is messing with the internals of the
 random number generator.  It would be a simple fix.  Instead of
 bing about it, file a bug report.  

I did.

 Or better yet, submit a patch.

I would if I knew what the problem was.

I posted it here because someone recommended it.
I'm simply un-recommending it. Those who don't care
needn't pay any attention. Those who do should be
glad that faults are pointed out when found.


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


Re: Polymorphism using constructors

2008-03-03 Thread Carl Banks
On Mar 3, 4:17 pm, Raymond Hettinger [EMAIL PROTECTED] wrote:
 Since Python doesn't support having two methods with the same name,
 the usual solution is to provide alternative constructors using
 classmethod():

   @classmethod
   def from_decimal(cls, d)
 sign, digits, exp = d.as_tuple()
 digits = int(''.join(map(str, digits)))
 if sign:
 digits = -digits
 if exp = 0:
 return cls(digits * 10 ** exp)
 return cls(digits, 10 ** -exp)


Note that even some of Python's built in types (dict *cough*)
implement homemade function overloading.

The OP wanted to write a constructor that could accept either a pair
of integers or a rational, there would be a good precedent for it.

However, I would advise the OP to use the constructor only for the
most common arguments, and use classmethods for more obscure, less
common arguments (such as decimal or even float).


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


Re: sympy: what's wrong with this picture?

2008-03-03 Thread Robert Kern
Mensanator wrote:
 On Mar 3, 2:49 pm, Carl Banks [EMAIL PROTECTED] wrote:

 It's just a bug--probably sympy is messing with the internals of the
 random number generator.  It would be a simple fix.  Instead of
 bing about it, file a bug report.  
 
 I did.
 
 Or better yet, submit a patch.
 
 I would if I knew what the problem was.

Did you even try to figure it out? It took me all of 5 minutes to find the 
mistake.

 I posted it here because someone recommended it.
 I'm simply un-recommending it.

It was a mistake, an easily remedied mistake, not a big unchangeable design 
decision. If you want to recommend against sympy as a package, there is a 
larger 
burden of proof that you have yet to meet.

-- 
Robert Kern

I have come to believe that the whole world is an enigma, a harmless enigma
  that is made terrible by our own mad attempt to interpret it as though it had
  an underlying truth.
   -- Umberto Eco

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


Re: Talking to a usb device (serial terminal)

2008-03-03 Thread Grant Edwards
On 2008-03-03, blaine [EMAIL PROTECTED] wrote:

 I do have a question though.  In the termios module, I am attempting
 to set the baud rate to 921600, which is what we use with
 'cutecom' (because minicom does not have this as an option) and is
 what the supplier recommends.  When I try to set the rate using
 termios.tcsetattr(), I get an Argument Error.

What values are you using for ispeed and ospeed?  Those values
are special (and rather arbitrary) constant bit-patterns and
not simply integers like 9600 or 115200.

 I do not get this when I use an existing baud rate, such as
 termios.B9600.  Is there a way I can get around this? We would
 like to use it at full speed.

It looks like the fastest speed supported by python termios on
Linux is B460800 (uses a constant of 0x1004).  If you look in
/usr/include/..., baud rates do go up to 921600 (which uses a
constant of 0x1007).

Try using the appropriate constant from /usr/include/... (for
the target platform, of course).

-- 
Grant Edwards   grante Yow! Please come home with
  at   me ... I have Tylenol!!
   visi.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Beautiful Code in Python?

2008-03-03 Thread [EMAIL PROTECTED]
On Mar 2, 1:18 pm, [EMAIL PROTECTED] wrote:
 On Mar 2, 12:01 pm, John DeRosa [EMAIL PROTECTED] wrote:

  On Mon, 3 Mar 2008 01:23:32 +0900, js [EMAIL PROTECTED] wrote:
  Hi,

  Have you ever seen Beautiful Python code?
  Zope? Django? Python standard lib? or else?

  Please tell me what code you think it's stunning.

  Just about any Python code I look at.

 Decorators, with, and namedtuple.

IMO, decorators are functional but far from beautiful.  They're a
special, somewhat ugly syntax for something that was already handled
by normal constructs (foo=classmethod(foo)) that you didn't need
extra knowledge to understand.

On balance I think it's worth it in order to get those declarations
up by the function defs, but it's sort of a tradeoff of magical non-
explicitness for pragmatism over purity.  A worthwile tradeoff, but
not what I'd ever call beautiful.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: First post from a Python newbiw

2008-03-03 Thread Christoph Zwerschke
Arnaud Delobelle schrieb:
 It's a FAQ:
 http://www.python.org/doc/faq/programming/#how-do-i-create-a-multidimensional-list

Somewhere on my todo list I have read through the whole Python FAQ, 
but so far never got round doing it. Should probably set it to prio A.

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


Re: [Python-Dev] [ANN] Python 2.3.7 and 2.4.5, release candidate 1

2008-03-03 Thread Martin v. Löwis
 Can you also add a note to the 2.3 and 2.4 web pages?

You mean the 2.3.7 and 2.4.5 web pages? Sure.
(If you mean some other web pages, please give precise
URLs).

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


Re: sympy: what's wrong with this picture?

2008-03-03 Thread Carl Banks
On Mar 3, 4:47 pm, Mensanator [EMAIL PROTECTED] wrote:
 On Mar 3, 2:49 pm, Carl Banks [EMAIL PROTECTED] wrote:



  On Mar 3, 3:40 pm, Mensanator [EMAIL PROTECTED] wrote:

   Notice anything funny about the random choices?

   import sympy
   import time
   import random

   f = [i for i in sympy.primerange(1000,1)]

   for i in xrange(10):
 f1 = random.choice(f)
 print f1,
 f2 = random.choice(f)
 print f2,
 C = f1*f2
 ff = None
 ff = sympy.factorint(C)
 print ff

   ##  7307 7243 [(7243, 1), (7307, 1)]
   ##  4091 6829 [(4091, 1), (6829, 1)]
   ##  8563 2677 [(2677, 1), (8563, 1)]
   ##  4091 6829 [(4091, 1), (6829, 1)]
   ##  8563 2677 [(2677, 1), (8563, 1)]
   ##  4091 6829 [(4091, 1), (6829, 1)]
   ##  8563 2677 [(2677, 1), (8563, 1)]
   ##  4091 6829 [(4091, 1), (6829, 1)]
   ##  8563 2677 [(2677, 1), (8563, 1)]
   ##  4091 6829 [(4091, 1), (6829, 1)]

   As in, they're NOT random.

   The random number generator is broken by the sympy.factorint()
   function.

   Random.choice() works ok if the factorint() function commented out.

   ##  6089 1811 None
   ##  6449 1759 None
   ##  9923 4639 None
   ##  4013 4889 None
   ##  4349 2029 None
   ##  6703 8677 None
   ##  1879 1867 None
   ##  5153 5279 None
   ##  2011 4937 None
   ##  7253 5507 None

   This makes sympy worse than worthless, as it f***s up other modules.

  Dude, relax.

  It's just a bug--probably sympy is messing with the internals of the
  random number generator.  It would be a simple fix.  Instead of
  bing about it, file a bug report.

 I did.

  Or better yet, submit a patch.

 I would if I knew what the problem was.

 I posted it here because someone recommended it.
 I'm simply un-recommending it. Those who don't care
 needn't pay any attention. Those who do should be
 glad that faults are pointed out when found.

1. You can point out the faults of a program without insults and
vulgarity

2. You must be terribly difficult to please if one bug is enough to
recommend against a program as worse than worthless

3. You must be terribly naive if you expect a freeware program with a
version number of 0.5.12 not to have bugs


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


Re: sympy: what's wrong with this picture?

2008-03-03 Thread apatheticagnostic
I swear, this is one of the most polite-oriented groups I've ever
seen.

Not that that's a bad thing or anything, it's nice to be nice.

(This has been Captain Universal Truth, over and out)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: clocking subprocesses

2008-03-03 Thread Matt Nordhoff
[EMAIL PROTECTED] wrote:
 On Mar 3, 12:41 pm, Preston  Landers [EMAIL PROTECTED] wrote:
 Run your command through the time program.  You can parse the output
 format of time, or set a custom output format.  This mostly applies
 to Unix-like systems but there is probably an equivalent somewhere on
 Windows.

 Preston
 
 Thanks for the quick answer.  That seems to work, though, I'll write a
 timesubprocess() function which runs the program through time and
 spits the formatted out to a file, then parses that file, then returns
 the execution time.  There doesn't appear to be a more elegant way to
 do this.
 
 Kevin

subprocess can do that easily.

What about something like this?

def timecall(args):
p = subprocess.Popen(['time', '--format', '%e %U %S'] + args,
 stderr=subprocess.PIPE)
p.wait()
timings = p.stderr.readline().split()
assert len(timings) == 3
timings = tuple(float(t) for t in timings)
return timings

It returns (real, user, sys), in seconds. The program's stdout goes to
sys.stdout, I don't know where the program's stderr goes, and it really
doesn't handle errors, but it's got the basic idea.
-- 
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Altering imported modules

2008-03-03 Thread Tro
On Sunday 02 March 2008, Paul McGuire wrote:
 On Mar 2, 3:48 pm, Tro [EMAIL PROTECTED] wrote:
  On Sunday 02 March 2008, Terry Reedy wrote:
   Tro [EMAIL PROTECTED] wrote in message
  news:[EMAIL PROTECTED]
  
   | Hi, list.
   |
   | I've got a simple asyncore-based server. However, I've modified the
  
   asyncore
  
   | module to allow me to watch functions as well as sockets. The
   | modified asyncore module is in a specific location in my project and
   | is imported
  
   as
  
   | usual from my classes.
   |
   | Now I'd like to use the tlslite library, which includes an asyncore
   | mixin class. However, tlslite imports asyncore, which doesn't
   | include my own modifications.
   |
   | I'd like to know if it's possible to make tlslite load *my* asyncore
  
   module
  
   | without changing any of the tlslite code.
  
   If your module is also 'asyncore' and comes earlier in the search path,
   I would expect the import to get yours.
 
  It's not. It has a package prefix like my.package.asyncore. I think I can
  either move my version of asyncore up a couple of levels or add the
  my.package directory to sys.path.
 
  My version of asyncore imports several functions from the built-in
  asyncore. Now that my version of it is imported as asyncore, how would it
  import the built-in version from python2.5/site-packages?
 
  Thanks,
  Tro
 
  

 What happens if you do import my.package.asyncore as asyncore?

 If that doesn't work (trying the simplest hack first), I know that
 there are various hooks in the import mechanism that should help.

In the classes that use my version of asyncore currently, that is how I do it. 
I import my version as import my.package.asyncore as asyncore. In my 
asyncore module I do import asyncore, because I override a few functions 
from the asyncore module included with python. However, if I were to 
add my.package to sys.path, then I wouldn't be able to import asyncore 
from my own asyncore module. I'd have to do some trickery with sys.path to 
take the my.package component out, import standard asyncore, readd 
the my.package component, so that other modules can import asyncore and 
get my version.

Is there a way to import the standard python asyncore module in this scenario?

Thanks,
Tro
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: News from Jython world

2008-03-03 Thread George Sakkis
On Mar 3, 1:40 pm, Sébastien Boisgérault
[EMAIL PROTECTED] wrote:
 Frank Wierzbicki and Ted Leung have been hired by Sun. Frank is a
 key Jython developer and is specifically hired to work full time on
 Jython, a version of the Python interpreter that runs on top of the
 JVM and provides full access to Java libraries. After a period where
 the development had slowed, Jython was recently getting seriously
 back on track. Now it's getting even better !

 Don't wait too much ... Jython is very useful RIGHT NOW if you live
 in the Java Universe.

 More details at:
  -http://www.infoworld.com/article/08/03/03/hirings-python_1.html
  -http://fwierzbicki.blogspot.com/2008/02/jythons-future-looking-sunny

 Cheers,

 SB

Great news! Having to go back to the Java world might not be such a
turn-off in the near future ;-)

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


os.system with cgi

2008-03-03 Thread G
Hi,

   I have the following peace of code

def getBook(textid, path):
url = geturl(textid)
if os.path.isfile(path + textid):
f = open(path + textid)
else:
os.system('wget -c ' + url + ' -O ' path + textid)
f = open(path + textid)
return f

The reason I am not using urllib is that I want to have random access within
the downloaded file.

When i execute the file from a regular python script I get the file
downloaded and a handle for the file returned.
When I execute the file from a python cgi script i get an error saying that
the file doesn't exist. In other words the call to os.system is not running.
Could someone please point out what the problem with that peace of code
running as a cgi script.

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

Re: sympy: what's wrong with this picture?

2008-03-03 Thread Mensanator
On Mar 3, 4:08 pm, Robert Kern [EMAIL PROTECTED] wrote:
 Mensanator wrote:
  On Mar 3, 2:49 pm, Carl Banks [EMAIL PROTECTED] wrote:
  It's just a bug--probably sympy is messing with the internals of the
  random number generator.  It would be a simple fix.  Instead of
  bing about it, file a bug report.  

  I did.

  Or better yet, submit a patch.

  I would if I knew what the problem was.

 Did you even try to figure it out? It took me all of 5 minutes to find the 
 mistake.

Could I trouble you to share? Then I could continue my testing.


  I posted it here because someone recommended it.
  I'm simply un-recommending it.

 It was a mistake, an easily remedied mistake,

But I didn't know that (and still don't).

 not a big unchangeable design decision.

I didn't know that either. For all I know, I might have to
wait for the next version, and who knows when that will be?

 If you want to recommend against sympy as a package, there is a larger
 burden of proof that you have yet to meet.

What kind of burden of proof must one have to recommend it in the
first place?


 --
 Robert Kern

 I have come to believe that the whole world is an enigma, a harmless enigma
   that is made terrible by our own mad attempt to interpret it as though it 
 had
   an underlying truth.
    -- Umberto Eco

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


Re: os.system with cgi

2008-03-03 Thread Matt Nordhoff
G wrote:
 Hi,
 
I have the following peace of code
 
 def getBook(textid, path):
 url = geturl(textid)
 if os.path.isfile(path + textid):
 f = open(path + textid)
 else:
 os.system('wget -c ' + url + ' -O ' path + textid)
 f = open(path + textid)
 return f
 
 The reason I am not using urllib is that I want to have random access
 within the downloaded file.
 
 When i execute the file from a regular python script I get the file
 downloaded and a handle for the file returned.
 When I execute the file from a python cgi script i get an error saying
 that the file doesn't exist. In other words the call to os.system is not
 running.
 Could someone please point out what the problem with that peace of code
 running as a cgi script.
 
 Best.

Ew. You could at least use subprocess and not be vulnerable to someone
passing ; rm -rf ~; echo or something as the path.

If you need random access like that, and urllib2 can't do it, you could
use urllib2 and a StringIO or temporary file or something.

Using wget makes it much harder to handle errors.

Heck, you could just read the file into a string and use slicing, if
it's not too large...
-- 
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Import, how to change sys.path on Windows, and module naming?

2008-03-03 Thread Gabriel Genellina
En Mon, 03 Mar 2008 14:39:20 -0200, [EMAIL PROTECTED] escribió:
 On 3 Mar, 17:12, [EMAIL PROTECTED] wrote:

 Oops... I tried removing python25.zip from sys.path, and I can still
 import packages from zip files ...

Yes, python25.zip is in sys.path by default, not to enable zipimport  
(which is enabled by default, if zlib is available), but to allow the  
entire Python library to be distributed in a .zip

When Python starts, it imports site.py (and a *lot* of other modules, too  
much for my taste); that script is responsible of building sys.path,  
adding lib/site-packages and looking for .pth files and so. Before that,  
sys.path contains a minimal set of dirs. If there were no .zip already in  
sys.path, site.py (and all the modules it uses) should exist on an actual  
directory already present on sys.path in order to be imported - so the  
entire library could not reside on a zip file.
Having python25.zip in sys.path by default (*before* processing site.py)  
allows to distribute the whole std library (and possibly other packages  
too) in a single zip file.

-- 
Gabriel Genellina

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


Re: sympy: what's wrong with this picture?

2008-03-03 Thread Robert Kern
Mensanator wrote:
 On Mar 3, 4:08 pm, Robert Kern [EMAIL PROTECTED] wrote:
 Mensanator wrote:
 On Mar 3, 2:49 pm, Carl Banks [EMAIL PROTECTED] wrote:
 It's just a bug--probably sympy is messing with the internals of the
 random number generator.  It would be a simple fix.  Instead of
 bing about it, file a bug report.  
 I did.
 Or better yet, submit a patch.
 I would if I knew what the problem was.
 Did you even try to figure it out? It took me all of 5 minutes to find the 
 mistake.
 
 Could I trouble you to share? Then I could continue my testing.

I posted the patch on the bug tracker:

   http://code.google.com/p/sympy/issues/detail?id=729

 I posted it here because someone recommended it.
 I'm simply un-recommending it.
 It was a mistake, an easily remedied mistake,
 
 But I didn't know that (and still don't).
 
 not a big unchangeable design decision.
 
 I didn't know that either. For all I know, I might have to
 wait for the next version, and who knows when that will be?

The point is that you didn't try to figure it out. And you assumed the worst 
rather than giving anyone the benefit of the doubt. You didn't even wait to get 
a response from the package maintainer about how serious the issue was before 
you came here to un-recommend it.

All software has bugs.

Good software has bugs.

Finding a single bug in a package is not sufficient cause to warn people away 
as 
if it had the plague.

 If you want to recommend against sympy as a package, there is a larger
 burden of proof that you have yet to meet.
 
 What kind of burden of proof must one have to recommend it in the
 first place?

Significantly less. It was useful to me, is sufficient.

-- 
Robert Kern

I have come to believe that the whole world is an enigma, a harmless enigma
  that is made terrible by our own mad attempt to interpret it as though it had
  an underlying truth.
   -- Umberto Eco

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


Re: sympy: what's wrong with this picture?

2008-03-03 Thread Mensanator
On Mar 3, 4:53 pm, Carl Banks [EMAIL PROTECTED] wrote:
 On Mar 3, 4:47 pm, Mensanator [EMAIL PROTECTED] wrote:





  On Mar 3, 2:49 pm, Carl Banks [EMAIL PROTECTED] wrote:

   On Mar 3, 3:40 pm, Mensanator [EMAIL PROTECTED] wrote:

Notice anything funny about the random choices?

import sympy
import time
import random

f = [i for i in sympy.primerange(1000,1)]

for i in xrange(10):
  f1 = random.choice(f)
  print f1,
  f2 = random.choice(f)
  print f2,
  C = f1*f2
  ff = None
  ff = sympy.factorint(C)
  print ff

##  7307 7243 [(7243, 1), (7307, 1)]
##  4091 6829 [(4091, 1), (6829, 1)]
##  8563 2677 [(2677, 1), (8563, 1)]
##  4091 6829 [(4091, 1), (6829, 1)]
##  8563 2677 [(2677, 1), (8563, 1)]
##  4091 6829 [(4091, 1), (6829, 1)]
##  8563 2677 [(2677, 1), (8563, 1)]
##  4091 6829 [(4091, 1), (6829, 1)]
##  8563 2677 [(2677, 1), (8563, 1)]
##  4091 6829 [(4091, 1), (6829, 1)]

As in, they're NOT random.

The random number generator is broken by the sympy.factorint()
function.

Random.choice() works ok if the factorint() function commented out.

##  6089 1811 None
##  6449 1759 None
##  9923 4639 None
##  4013 4889 None
##  4349 2029 None
##  6703 8677 None
##  1879 1867 None
##  5153 5279 None
##  2011 4937 None
##  7253 5507 None

This makes sympy worse than worthless, as it f***s up other modules.

   Dude, relax.

   It's just a bug--probably sympy is messing with the internals of the
   random number generator.  It would be a simple fix.  Instead of
   bing about it, file a bug report.

  I did.

   Or better yet, submit a patch.

  I would if I knew what the problem was.

  I posted it here because someone recommended it.
  I'm simply un-recommending it. Those who don't care
  needn't pay any attention. Those who do should be
  glad that faults are pointed out when found.

 1. You can point out the faults of a program without insults and
 vulgarity

Did I insult someone?

And fuck in the context I used it means messes with.
Now you know that the writer of that superbowl commercial
for almonds wanted to say Robert Goulet fucks with your stuff.
But, due to censorship, changed it to messes with.


 2. You must be terribly difficult to please if one bug is enough to
 recommend against a program as worse than worthless

While we're on the subject of English, the word worthless
means has no value. So, a program that doesn't work would
generally be worthless. One that not only doesn't work but
creates side effects that cause other programs to not work
(which don't have bugs) would be worse than worthless.

I'm not hard to please at all. I'm planning a later report
where I test sympy's factoring with that of the MIRACL library's
factor.exe program. It too, has a serious bug (and I'm not
a good enough C programmer to know how to fix it) but I have
a Python based workaround even though the MIRACL library
has no Python interface. But any mention I ever make of this
program will mention this bug in case anyone wants to use it.


 3. You must be terribly naive if you expect a freeware program with a
 version number of 0.5.12 not to have bugs

No, but I guess I'm naive thinking that when someone posts a link to
such a program that he's recommending going and trying it out. That
is why they're making it available, isn't it? For people to try out
so they can get free testing? Aren't I doing my part? Should I just
uninstall it and forget it?


 Carl Banks

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


Re: sympy: what's wrong with this picture?

2008-03-03 Thread Carl Banks
On Mar 3, 7:24 pm, Mensanator [EMAIL PROTECTED] wrote:
 On Mar 3, 4:53 pm, Carl Banks [EMAIL PROTECTED] wrote:



  On Mar 3, 4:47 pm, Mensanator [EMAIL PROTECTED] wrote:

   On Mar 3, 2:49 pm, Carl Banks [EMAIL PROTECTED] wrote:

On Mar 3, 3:40 pm, Mensanator [EMAIL PROTECTED] wrote:

 Notice anything funny about the random choices?

 import sympy
 import time
 import random

 f = [i for i in sympy.primerange(1000,1)]

 for i in xrange(10):
   f1 = random.choice(f)
   print f1,
   f2 = random.choice(f)
   print f2,
   C = f1*f2
   ff = None
   ff = sympy.factorint(C)
   print ff

 ##  7307 7243 [(7243, 1), (7307, 1)]
 ##  4091 6829 [(4091, 1), (6829, 1)]
 ##  8563 2677 [(2677, 1), (8563, 1)]
 ##  4091 6829 [(4091, 1), (6829, 1)]
 ##  8563 2677 [(2677, 1), (8563, 1)]
 ##  4091 6829 [(4091, 1), (6829, 1)]
 ##  8563 2677 [(2677, 1), (8563, 1)]
 ##  4091 6829 [(4091, 1), (6829, 1)]
 ##  8563 2677 [(2677, 1), (8563, 1)]
 ##  4091 6829 [(4091, 1), (6829, 1)]

 As in, they're NOT random.

 The random number generator is broken by the sympy.factorint()
 function.

 Random.choice() works ok if the factorint() function commented out.

 ##  6089 1811 None
 ##  6449 1759 None
 ##  9923 4639 None
 ##  4013 4889 None
 ##  4349 2029 None
 ##  6703 8677 None
 ##  1879 1867 None
 ##  5153 5279 None
 ##  2011 4937 None
 ##  7253 5507 None

 This makes sympy worse than worthless, as it f***s up other modules.

Dude, relax.

It's just a bug--probably sympy is messing with the internals of the
random number generator.  It would be a simple fix.  Instead of
bing about it, file a bug report.

   I did.

Or better yet, submit a patch.

   I would if I knew what the problem was.

   I posted it here because someone recommended it.
   I'm simply un-recommending it. Those who don't care
   needn't pay any attention. Those who do should be
   glad that faults are pointed out when found.

  1. You can point out the faults of a program without insults and
  vulgarity

 Did I insult someone?

Yes, the intelligence of most people here, if you think anyone's going
to buy your rationalization of your spiteful behavior.

Four posts is more than enough of you.
*PLONK*


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


Re: sympy: what's wrong with this picture?

2008-03-03 Thread Robert Kern
Mensanator wrote:
 On Mar 3, 4:53 pm, Carl Banks [EMAIL PROTECTED] wrote:

 3. You must be terribly naive if you expect a freeware program with a
 version number of 0.5.12 not to have bugs
 
 No, but I guess I'm naive thinking that when someone posts a link to
 such a program that he's recommending going and trying it out. That
 is why they're making it available, isn't it? For people to try out
 so they can get free testing? Aren't I doing my part? Should I just
 uninstall it and forget it?

Finding the issue and reporting it to the sympy bug tracker is commendable.

Coming here and un-recommending sympy before the issue was resolved is not.

-- 
Robert Kern

I have come to believe that the whole world is an enigma, a harmless enigma
  that is made terrible by our own mad attempt to interpret it as though it had
  an underlying truth.
   -- Umberto Eco

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


Re: Altering imported modules

2008-03-03 Thread castironpi
On Mar 3, 5:09 pm, Tro [EMAIL PROTECTED] wrote:
 On Sunday 02 March 2008, Paul McGuire wrote:





  On Mar 2, 3:48 pm, Tro [EMAIL PROTECTED] wrote:
   On Sunday 02 March 2008, Terry Reedy wrote:
Tro [EMAIL PROTECTED] wrote in message
   news:[EMAIL PROTECTED]

| Hi, list.
|
| I've got a simple asyncore-based server. However, I've modified the

asyncore

| module to allow me to watch functions as well as sockets. The
| modified asyncore module is in a specific location in my project and
| is imported

as

| usual from my classes.
|
| Now I'd like to use the tlslite library, which includes an asyncore
| mixin class. However, tlslite imports asyncore, which doesn't
| include my own modifications.
|
| I'd like to know if it's possible to make tlslite load *my* asyncore

module

| without changing any of the tlslite code.

If your module is also 'asyncore' and comes earlier in the search path,
I would expect the import to get yours.

   It's not. It has a package prefix like my.package.asyncore. I think I can
   either move my version of asyncore up a couple of levels or add the
   my.package directory to sys.path.

   My version of asyncore imports several functions from the built-in
   asyncore. Now that my version of it is imported as asyncore, how would it
   import the built-in version from python2.5/site-packages?

   Thanks,
   Tro

  What happens if you do import my.package.asyncore as asyncore?

  If that doesn't work (trying the simplest hack first), I know that
  there are various hooks in the import mechanism that should help.

 In the classes that use my version of asyncore currently, that is how I do it.
 I import my version as import my.package.asyncore as asyncore. In my
 asyncore module I do import asyncore, because I override a few functions
 from the asyncore module included with python. However, if I were to
 add my.package to sys.path, then I wouldn't be able to import asyncore
 from my own asyncore module. I'd have to do some trickery with sys.path to
 take the my.package component out, import standard asyncore, readd
 the my.package component, so that other modules can import asyncore and
 get my version.

 Is there a way to import the standard python asyncore module in this scenario?

 Thanks,
 Tro- Hide quoted text -

 - Show quoted text -

Are you trying to interfere with the default module on only your
machine?  Just rename it.  If something in the std. lib. imports
asyncore, they get yours too that way.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Beautiful Code in Python?

2008-03-03 Thread castironpi
On Mar 3, 4:30 pm, [EMAIL PROTECTED] [EMAIL PROTECTED] wrote:
 On Mar 2, 1:18 pm, [EMAIL PROTECTED] wrote:

  On Mar 2, 12:01 pm, John DeRosa [EMAIL PROTECTED] wrote:

   On Mon, 3 Mar 2008 01:23:32 +0900, js [EMAIL PROTECTED] wrote:
   Hi,

   Have you ever seen Beautiful Python code?
   Zope? Django? Python standard lib? or else?

   Please tell me what code you think it's stunning.

   Just about any Python code I look at.

  Decorators, with, and namedtuple.

 IMO, decorators are functional but far from beautiful.  They're a
 special, somewhat ugly syntax for something that was already handled
 by normal constructs (foo=classmethod(foo)) that you didn't need
 extra knowledge to understand.

 On balance I think it's worth it in order to get those declarations
 up by the function defs, but it's sort of a tradeoff of magical non-
 explicitness for pragmatism over purity.  A worthwile tradeoff, but
 not what I'd ever call beautiful.

Someone study architecture.  What are the Palmer House, the Rookery,
and the Lyric Opera?
-- 
http://mail.python.org/mailman/listinfo/python-list


metaclasses

2008-03-03 Thread castironpi
What are metaclasses?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: sympy: what's wrong with this picture?

2008-03-03 Thread Mensanator
On Mar 3, 6:21 pm, Robert Kern [EMAIL PROTECTED] wrote:
 Mensanator wrote:
  On Mar 3, 4:08 pm, Robert Kern [EMAIL PROTECTED] wrote:
  Mensanator wrote:
  On Mar 3, 2:49 pm, Carl Banks [EMAIL PROTECTED] wrote:
  It's just a bug--probably sympy is messing with the internals of the
  random number generator.  It would be a simple fix.  Instead of
  bing about it, file a bug report.  
  I did.
  Or better yet, submit a patch.
  I would if I knew what the problem was.
  Did you even try to figure it out? It took me all of 5 minutes to find the 
  mistake.

  Could I trouble you to share? Then I could continue my testing.

 I posted the patch on the bug tracker:

    http://code.google.com/p/sympy/issues/detail?id=729

Thanks, I think I actually figured out how to use it.


  I posted it here because someone recommended it.
  I'm simply un-recommending it.
  It was a mistake, an easily remedied mistake,

  But I didn't know that (and still don't).

  not a big unchangeable design decision.

  I didn't know that either. For all I know, I might have to
  wait for the next version, and who knows when that will be?

 The point is that you didn't try to figure it out.

Give me a break, I'm not a developer, just an end user.

 And you assumed the worst

Wasn't my assumption correct? That it really was messing
outside it's domain?

 rather than giving anyone the benefit of the doubt.

As in maybe it only fails for me? Was I crying that the
sky was falling?

 You didn't even wait to get a response from the package
 maintainer

I have no experience with those web sites. I think this is
the first time I was able to successfully report a bug and
have no clue what the turnaround time is.

 about how serious the issue was

The symptom was serious although the fix was simple.

 before you came here to un-recommend it.

As an end user, I get most of my information here.
Since I saw the link to sympy here on this newsgroup,
I thought it would be irresponsible to file a bug report
without simultaneously mentioning it here.


 All software has bugs.

 Good software has bugs.

Are bugs off-topic here?


 Finding a single bug in a package is not sufficient cause to warn people away 
 as
 if it had the plague.

It DID have the plague. It affected anything else that tried
to use random numbers.


  If you want to recommend against sympy as a package, there is a larger
  burden of proof that you have yet to meet.

  What kind of burden of proof must one have to recommend it in the
  first place?

 Significantly less. It was useful to me, is sufficient.

Really? That's sufficient? Ok, but how is my pointing out a verifyable
problem that affects the entire system not a sufficient burden of
proof against recommending the package? Or should I just have worded
it differently?

Aren't I at least going to get credit for having found it?


 --
 Robert Kern

 I have come to believe that the whole world is an enigma, a harmless enigma
   that is made terrible by our own mad attempt to interpret it as though it 
 had
   an underlying truth.
    -- Umberto Eco

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


Re: sympy: what's wrong with this picture?

2008-03-03 Thread Mensanator
On Mar 3, 6:49 pm, Robert Kern [EMAIL PROTECTED] wrote:
 Mensanator wrote:
  On Mar 3, 4:53 pm, Carl Banks [EMAIL PROTECTED] wrote:
  3. You must be terribly naive if you expect a freeware program with a
  version number of 0.5.12 not to have bugs

  No, but I guess I'm naive thinking that when someone posts a link to
  such a program that he's recommending going and trying it out. That
  is why they're making it available, isn't it? For people to try out
  so they can get free testing? Aren't I doing my part? Should I just
  uninstall it and forget it?

 Finding the issue and reporting it to the sympy bug tracker is commendable.

 Coming here and un-recommending sympy before the issue was resolved is not.

Bad choice of words I guess. I'll try to keep that in mind.


 --
 Robert Kern

 I have come to believe that the whole world is an enigma, a harmless enigma
   that is made terrible by our own mad attempt to interpret it as though it 
 had
   an underlying truth.
    -- Umberto Eco

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


tools to install not in python tree?

2008-03-03 Thread commander_coder
Hello,

I have some materials for a project that I am working on that I keep
in a source code control system (svn now, but I'm experimenting with
mercurial).  I want to install these things from the repository, but
not into site-packages/ as Distutils wants to do.

For instance there are some administrative scripts I want to put in ~/
admin/  and some programs that I want in ~/public_html/ .   I also
want to run some post-install routines (for instance, reset the
database tables on my development machine).  So I'm looking for a tool
to take things from a repository and install them into place.
Something like:
  install_from_repository.py -version 1.2.7
if there is a bug in 1.2.7 that I need to work on.

Some of the things that I am looking for are like what setup.py does
(for instance, changing the #! line on scripts or having a
convenient .cfg file).  But as I understand it setup only targets
installing below sys.prefix; is that right?

I can write routines for myself but other people must need to do these
things also and a tested solution is obviously better.  Is there such
a tool?

Thanks for any help,
Jim
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: metaclasses

2008-03-03 Thread Daniel Fetchinson
 What are metaclasses?

http://www.google.com/search?q=python+metaclass

HTH,
Daniel
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: sympy: what's wrong with this picture?

2008-03-03 Thread castironpi
 All software has bugs.
 Good software has bugs.
Therefore, good software is software.

 This makes sympy worse than worthless, as it f***s up other modules.
What is it still good for?

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


'normal' shell with curses

2008-03-03 Thread Michael Goerz
Hi,

I'm trying to print out text in color. As far as I know, curses is the 
only way to do that (or not?). So, what I ultimately want is a curses 
terminal that behaves as closely as possible as a normal terminal, i.e. 
it breaks lines and scrolls automatically, so that I can implement a 
function myprint(color, text) that does what print() does, only in color.

So, my first tests brought up some problems:

#!/usr/bin/python

from time import sleep
import curses
import sys

stdscr = curses.initscr()
stdscr.addstr(Initialized\n)
stdscr.refresh()
(maxlines, maxcolumns) = stdscr.getmaxyx()
try:
 for counter in xrange(24):
 stdscr.addstr(Hello world %s\n % counter)
 stdscr.refresh()
 if counter = maxlines:
 stdscr.scroll()
 stdscr.refresh()
except Exception, data:
 sys.stderr.write(Exception: \n);
 sys.stderr.write(str(data));
finally:
 sleep(5)
 curses.endwin()

Instead of scrolling, the program throws an exception. Any hints?

Also, is there a way leave the curses output on the screen after 
curses.endwin(), instead of returning to the normal terminal without a 
trace of curses.

Thanks,
Michael
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: _struct in Python 2.5.2

2008-03-03 Thread Nanjundi
On Feb 24, 10:39 am, Olaf Schwarz [EMAIL PROTECTED] wrote:
 Hi,

 I am trying to run this 
 applicationhttp://svn.navi.cx/misc/trunk/python/bemused/
 on uNSLUng Linux 6.10 using the optware python packages.

 As I obtained segmentation faults using Python 2.4, I have upgraded to
 2.5.2. Now the execution terminates a lot earlier with this error
 message:

   File /usr/local/bemused_mpd/bemused-mpd.py, line 33, in module
 import bemused
   File /usr/local/bemused_mpd/bemused.py, line 27, in module
 import bluetooth, syslog
   File /opt/lib/python2.5/site-packages/bluetooth.py, line 2, in
 module
 import struct
   File /opt/lib/python2.5/struct.py, line 30, in module
 from _struct import Struct, error
 ImportError: No module named _struct

 I found out that there has been a file named _struct.so in 2.5.1 but
 it has disappeared in 2.5.2. With no package available for downgrading
 to 2.5.1 and no idea how to resolve this I am stuck at this point.

 Any help appreciated.

 Thank you
 Olaf

Hi Olaf,
If you are still stuck, run
./configure
make
make install

if you skip the command make, then the required files (python-install-
pathlib/python2.5/lib-dynload/_struct.so) doesn't get created. Get
the latest 2.5.2 rpm from python.org, it works.

Good luck.
-N
-- 
http://mail.python.org/mailman/listinfo/python-list


  1   2   >