itools 0.15.1 released

2007-01-15 Thread J. David Ibáñez
itools is a Python library, it groups a number of packages into a single
meta-package for easier development and deployment:

  itools.catalogitools.http itools.uri
  itools.cmsitools.i18n itools.vfs
  itools.csvitools.ical itools.web
  itools.datatypes  itools.rss  itools.workflow
  itools.gettextitools.schemas  itools.xhtml
  itools.handlers   itools.stl  itools.xliff
  itools.html   itools.tmx  itools.xml

This release brings some new features to itools.cms, and a lot of aesthetic
and usability improvements:

  - Two new object types have been added, a forum and a wiki;
  - Added a contact form;
  - Added a forgotten password form;
  - Changed the layout of the menus;
  - Updated colors, icons and views here and there.

Other than this the focus of 0.15.1 has been to clean the code. Specially
the support for dates and times, and the programming interface of
configuration handlers, has been improved.


Credits:

 - Hervé Cauwelier contributed the Forum and Wiki objects, and worked to
   improve the user's experience;
 - J. David Ibáñez added the contact and forgotten password forms, and
   worked on the user interface and cleaning the source code;
 - Sylvain Taverne fixed the Dublin Core schema.



Resources
-

Download
http://download.ikaaro.org/itools/itools-0.15.1.tar.gz

Home
http://www.ikaaro.org/itools

Mailing list
http://mail.ikaaro.org/mailman/listinfo/itools

Bug Tracker
http://bugs.ikaaro.org/


-- 
J. David Ibáñez
Itaapy http://www.itaapy.com Tel +33 (0)1 42 23 67 45
9 rue Darwin, 75018 Paris  Fax +33 (0)1 53 28 27 88 

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

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


[ANN] Aspen 0.7 -- WSGI + filesystem = sweet webserver

2007-01-15 Thread Chad Whitacre
Greetings, program!

I've just released Aspen 0.7. Aspen is a Python webserver, and 
this is the first version to be used in production. As such, I'm 
announcing it generally as well as to the Web-SIG.

This release is about making Aspen easy to configure, and making 
that configuration easy to get to from your WSGI modules. I'm 
pleased with the result, and would love to hear your feedback.

Also, allow me to thank the following for being Aspen's first 
contributors:

   * Giorgi Lekishvili, for initial optimization work
   * Maciek Starzyk, for keeping us honest on Windows
   * Vasilis Dimos, for providing benchmarks
   * alefnula, for feedback on supporting Range requests


Downloads, docs, and links are here:

   http://www.zetadev.com/software/aspen/


Thanks!



yours,
Chad Whitacre



http://www.zetadev.com/  - FOSS
http://tech.whit537.org/ - blog
-- 
http://mail.python.org/mailman/listinfo/python-announce-list

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


Re: Class list of a module

2007-01-15 Thread Gabriel Genellina

At Monday 15/1/2007 04:27, you wrote:


I want to get all classes of a module in a list. I wrote this code but I
wonder
if there's not a simpler solution


import inspect

def getClassList(aModule):
return [getattr(aModule, attName) \
for attName in aModule.__dict__  \
if inspect.isclass(getattr(aModule, attName))]


Looks rather simple to me... Anyway, you could avoid calling getattr 
twice, if you iterate over vars(aModule).itervalues()


def getClassList(aModule):
return [cls for cls in vars(aModule).itervalues()
if inspect.isclass(cls)]

(And note that there is no need for using \ at the line ends, because 
of the [])



--
Gabriel Genellina
Softlab SRL 







__ 
Preguntá. Respondé. Descubrí. 
Todo lo que querías saber, y lo que ni imaginabas, 
está en Yahoo! Respuestas (Beta). 
¡Probalo ya! 
http://www.yahoo.com.ar/respuestas 

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

Re: How naive is Python?

2007-01-15 Thread John Machin

[EMAIL PROTECTED] wrote:
 John How naive (in the sense that compiler people use the term) is the
 John current Python system?  For example:

 John   def foo() :
 John   s = This is a test
 John   return(s)

 John  s2 = foo()

 John How many times does the string get copied?

 Never.  s and s2 just refer to the same object (strings are immutable).
 Executing this:

 def foo() :
 print id(This is a test)
 s = This is a test
 print id(s)
 return(s)

 s2 = foo()
 print id(s2)

 prints the same value three times.

 John Or, for example:

 John   s1 = Test1
 John   s2 = Test2
 John   s3 = Test3
 John   s = s1 + s2 + s3

 John Any redundant copies performed, or is that case optimized?

 Not optimized.  You can see that using the dis module:

   4   0 LOAD_CONST   1 ('Test1')
   3 STORE_FAST   0 (s1)

   5   6 LOAD_CONST   2 ('Test2')
   9 STORE_FAST   1 (s2)

   6  12 LOAD_CONST   3 ('Test3')
  15 STORE_FAST   2 (s3)

   7  18 LOAD_FAST0 (s1)
  21 LOAD_FAST1 (s2)
  24 BINARY_ADD
  25 LOAD_FAST2 (s3)
  28 BINARY_ADD
  29 STORE_FAST   3 (s)
  32 LOAD_CONST   0 (None)
  35 RETURN_VALUE

 The BINARY_ADD opcode creates a new string.

 John How about this?

 John   kcount = 1000
 John   s = ''
 John   for i in range(kcount) :
 John   s += str(i) + ' '

 John Is this O(N) or O(N^2) because of recopying of s?

 O(N).  Here's a demonstration of that:

 #!/usr/bin/env python

 from __future__ import division

 def foo(kcount):
 s = ''
 for i in xrange(kcount) :
 s += str(i) + ' '

 import time

 for i in xrange(5,25):
 t = time.time()
 foo(2**i)
 t = time.time() - t
 print 2**i, t, t/2**i

 On my laptop t roughly doubles for each iteration and prints around 5e-06
 for t/2**i in all cases.

Sorry, Skip, but I find that very hard to believe. The foo() function
would take quadratic time if it were merely adding on pieces of
constant size -- however len(str(i)) is not a constant, it is
O(log10(i)), so the time should be super-quadratic. Following are the
results I got with Python 2.5, Windows XP Pro, 3.2Ghz Intel dual-core
processor with the last line changed to print i, 2**i, t, t/2**i coz I
can't do log2() in my head :-)

[snip]
18 262144 0.88866486 3.39508005709e-006
19 524288 3.21900010109 6.13975544184e-006
20 1048576 12.296313 1.17273330034e-005
21 2097152 54.25 2.58684158325e-005
22 4194304 229.0 5.45978546143e-005
[k/b interrupt]

Cheers,
John

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


Re: Class list of a module

2007-01-15 Thread bearophileHUGS
Gabriel Genellina:
 import inspect
 def getClassList(aModule):
  return [cls for cls in vars(aModule).itervalues()
  if inspect.isclass(cls)]

This is short enough too:

from inspect import isclass
getclasses = lambda module: filter(isclass, vars(module).itervalues())

Bye,
bearophile

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


Re: How naive is Python?

2007-01-15 Thread Duncan Booth
Roy Smith [EMAIL PROTECTED] wrote:

 All of those just move around pointers to the same (interned) string.

Correct about the pointers, but the string is not interned:

Steven D'Aprano [EMAIL PROTECTED] wrote:

 s1 = foo()
 s2 = foo()
 s1 == s2, s1 is s2
 (True, True)
 
 So the string This is a test within foo is not copied each time the
 function is called. However, the string This is a test is duplicated
 between foo and foo2 (the two functions don't share the same string
 instance):
 
 s3 = foo2()
 s3 == s1, s3 is s1
 (True, False)
 

In this specific example the two functions don't share the same string, but 
that won't always be the case: if the string had been interned this would 
have printed (True, True).

e.g. Removing all the spaces from the string produces a string which is 
interned.

 def foo():
s = Thisisatest
return s

 def foo2():
return Thisisatest

 s1 = foo()
 s2 = foo2()
 s1 is s2
True

Bottom line, never make assumptions about when two literal strings will 
share the same object and when they won't.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python web app. (advice sought)

2007-01-15 Thread Torabisu

Duncan Smith wrote:
 Hello,
  I find myself in the, for me, unusual (and at the moment unique)
 position of having to write a web application.  I have quite a lot of
 existing Python code that will form part of the business logic.  This
 relies on 3rd party libraries (such as numpy) which would make porting
 to e.g. IronPython difficult (I would imagine).  I was thinking LAMP
 (the P standing for Python, of course), particularly as I was originally
 encouraged to go for open source solutions.

 The application will provide some basic statistical analyses of data
 contained in database tables and associated plots (R / matplotlib /
 graphviz).  There will also be some heavier duty Monte Carlo simulation
 and graphical modelling / MCMC.  The user(s) will need to be able to set
 model parameters; maybe even tinker with model structure, so it will be
 very interactive (AJAX?).

 I've had a look at Django, Turbogears and Plone, and at the moment I am
 torn between Turbogears and Plone.  I get the impression that Turbogears
 will require me to write more non-Python code, but maybe Plone is more
 than I need (steeper learning curve?).  Maybe Turbogears will lead to a
 more loosely coupled app. than Plone?

 The disconcerting thing is that others on the project (who won't be
 developing) have started to talk about a LAMP back end with an IIS front
 end, .NET, and the benefits of sharepoint.  The emphasis is supposed to
 be on rapid development, and these technologies are supposed to help.
 But I have no real familiarity with them at all; just Python, C and SQL
 to any realistic level of competence.

 Any advice would be greatly appreciated.  I have to do much of the
 statistical work too, so I need to make good choices (and hopefully be
 able to justify them so nobody else on the project makes inappropriate
 choices for me).  e.g. I don't mind learning Javascript if it doesn't
 take too long.  The physical server will initially be a multiprocessor
 machine with several GB of RAM.  But we also have a cluster (I have no
 details, I only started the project a week ago).  So any advice
 regarding parallelisation would also be appreciated (or, in fact, any
 useful advice / pointers at all).  Thanks.

 Duncan

I was in a similar boat a while back, needing to make a decision on
what to use for our web development.  I had worked with Plone
previously and found that for our needs it wasn't going to work.  Our
web development was quite specific and didn't fit ideally into the
standard content management realm.  I also looked at Django and
TurboGears, installing and working with each.  I eventually went with
Django, and I've really enjoyed working with it.  Was a personal choice
and I'm sure our development would have been as successful if I'd
chosen TurboGears.

If you want the strength of persistent layers, MVC, templating etc etc
but want to stay away from the heavier frameworks, another possibility
is http://webpy.org/.  Very simple to implement, lightweight yet still
fairly full of features.

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


python and MOV or MPEG

2007-01-15 Thread siggi
Hi all,

does Python support MPEG or MOV videoclips? I couldn't find anything about
it online.

Thank you,

Siggi




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


Re: pygame and python 2.5

2007-01-15 Thread siggi
Thanks, I'll try that!

Siggi

Laurent Pointal [EMAIL PROTECTED] schrieb im Newsbeitrag
news:[EMAIL PROTECTED]
 siggi a écrit :
 Hi all,

 when I rtry to install pygame (pygame-1.7.1release.win32-py2.4.exe, the
 most
 ciurrent version I found) it requires Python 2.4! Will I really have to
 uninstall my Python 2.5  and install the old Python 2.4 in order to use
 pygame?

 Note: You can have both versions installed, just be sure to use the
 right one when using pygame (until there is a 2.5 compatible version).




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

Re: Maths error

2007-01-15 Thread Nick Maclaren

In article [EMAIL PROTECTED],
Tim Roberts [EMAIL PROTECTED] writes:
| Hendrik van Rooyen [EMAIL PROTECTED] wrote:
| 
|  What I don't know is how much precision this approximation loses when
|  used in real applications, and I have never found anyone else who has
|  much of a clue, either.
|  
| I would suspect that this is one of those questions which are simple
| to ask, but horribly difficult to answer - I mean - if the hardware has 
| thrown it away, how do you study it - you need somehow two
| different parallel engines doing the same stuff, and comparing the 
| results, or you have to write a big simulation, and then you bring 
| your simulation errors into the picture - There be Dragons...
| 
| Actually, this is a very well studied part of computer science called
| interval arithmetic.  As you say, you do every computation twice, once to
| compute the minimum, once to compute the maximum.  When you're done, you
| can be confident that the true answer lies within the interval.

The problem with it is that it is an unrealistically pessimal model,
and there are huge classes of algorithm that it can't handle at all;
anything involving iterative convergence for a start.  It has been
around for yonks (I first dabbled with it 30+ years ago), and it has
never reached viability for most real applications.  In 30 years, it
has got almost nowhere.

Don't confuse interval methods with interval arithmetic, because you
don't need the latter for the former, despite the claims that you do.

| For people just getting into it, it can be shocking to realize just how
| wide the interval can become after some computations.

Yes.  Even when you can prove (mathematically) that the bounds are
actually quite tight :-)


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


Re: python and MOV or MPEG

2007-01-15 Thread Diez B. Roggisch
siggi wrote:

 Hi all,
 
 does Python support MPEG or MOV videoclips? I couldn't find anything about
 it online.

Weak in googling today? Must have been a rough weekend.

There are several options, including pymedia and pygame.

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


Re: Python web app. (advice sought)

2007-01-15 Thread Tim Williams
On 15 Jan 2007 00:52:33 -0800, Torabisu [EMAIL PROTECTED] wrote:

 Duncan Smith wrote:
  Hello,
   I find myself in the, for me, unusual (and at the moment unique)
  position of having to write a web application.  I have quite a lot of
  existing Python code that will form part of the business logic.  This
  relies on 3rd party libraries (such as numpy) which would make porting
  to e.g. IronPython difficult (I would imagine).  I was thinking LAMP
  (the P standing for Python, of course), particularly as I was originally
  encouraged to go for open source solutions.
 
  The application will provide some basic statistical analyses of data
  contained in database tables and associated plots (R / matplotlib /
  graphviz).  There will also be some heavier duty Monte Carlo simulation
  and graphical modelling / MCMC.  The user(s) will need to be able to set
  model parameters; maybe even tinker with model structure, so it will be
  very interactive (AJAX?).
 
  I've had a look at Django, Turbogears and Plone, and at the moment I am
  torn between Turbogears and Plone.  I get the impression that Turbogears
  will require me to write more non-Python code, but maybe Plone is more
  than I need (steeper learning curve?).  Maybe Turbogears will lead to a
  more loosely coupled app. than Plone?
 
  The disconcerting thing is that others on the project (who won't be
  developing) have started to talk about a LAMP back end with an IIS front
  end, .NET, and the benefits of sharepoint.  The emphasis is supposed to
  be on rapid development, and these technologies are supposed to help.
  But I have no real familiarity with them at all; just Python, C and SQL
  to any realistic level of competence.
 
  Any advice would be greatly appreciated.  I have to do much of the
  statistical work too, so I need to make good choices (and hopefully be
  able to justify them so nobody else on the project makes inappropriate
  choices for me).  e.g. I don't mind learning Javascript if it doesn't
  take too long.  The physical server will initially be a multiprocessor
  machine with several GB of RAM.  But we also have a cluster (I have no
  details, I only started the project a week ago).  So any advice
  regarding parallelisation would also be appreciated (or, in fact, any
  useful advice / pointers at all).  Thanks.
 
  Duncan

 I was in a similar boat a while back, needing to make a decision on
 what to use for our web development.  I had worked with Plone
 previously and found that for our needs it wasn't going to work.  Our
 web development was quite specific and didn't fit ideally into the
 standard content management realm.  I also looked at Django and
 TurboGears, installing and working with each.  I eventually went with
 Django, and I've really enjoyed working with it.  Was a personal choice
 and I'm sure our development would have been as successful if I'd
 chosen TurboGears.

 If you want the strength of persistent layers, MVC, templating etc etc
 but want to stay away from the heavier frameworks, another possibility
 is http://webpy.org/.  Very simple to implement, lightweight yet still
 fairly full of features.


Don't overlook Karrigell either,  with a tiny learning curve its
always worth consideration, especially if you need rapid development
and a web server that will sit on top of your exising .py modules.

www.karrigell.com

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


Re: Boilerplate in rich comparison methods

2007-01-15 Thread Antoon Pardon
On 2007-01-13, Steven D'Aprano [EMAIL PROTECTED] wrote:
 I'm writing a class that implements rich comparisons, and I find myself
 writing a lot of very similar code. If the calculation is short and
 simple, I do something like this:


 class Parrot:
 def __eq__(self, other):
 return self.plumage() == other.plumage()
 def __ne__(self, other):
 return self.plumage() != other.plumage()
 def __lt__(self, other):
 return self.plumage()  other.plumage()
 def __gt__(self, other):
 return self.plumage()  other.plumage()
 def __le__(self, other):
 return self.plumage() = other.plumage()
 def __ge__(self, other):
 return self.plumage() = other.plumage()

Well one thing you could do is write the following class:

Comparators = SomeEnumWith(eq, ne, lt, gt, ge, le, ge)

class GeneralComparator:
  def __eq__(self, other):
return Comparators.eq in self.__compare__(self, other)
  def __ne__(self, other):
return Comparators.ne in self.__compare__(self, other)
  def __lt__(self, other):
return Comparators.lt in self.__compare__(self, other)
  def __le__(self, other):
return Comparators.le in self.__compare__(self, other)
  def __gt__(self, other):
return Comparators.gt in self.__compare__(self, other)
  def __ge__(self, other):
return Comparators.ge in self.__compare__(self, other)


Then write your Parrot class as follows:

  class Parrot (GeneralComparator):
def __compare__(self, other):
  return a set which defines which comparisons should return true.

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


Re: Python web app. (advice sought)

2007-01-15 Thread Torabisu

Tim Williams wrote:
 On 15 Jan 2007 00:52:33 -0800, Torabisu [EMAIL PROTECTED] wrote:
 
  Duncan Smith wrote:
   Hello,
I find myself in the, for me, unusual (and at the moment unique)
   position of having to write a web application.  I have quite a lot of
   existing Python code that will form part of the business logic.  This
   relies on 3rd party libraries (such as numpy) which would make porting
   to e.g. IronPython difficult (I would imagine).  I was thinking LAMP
   (the P standing for Python, of course), particularly as I was originally
   encouraged to go for open source solutions.
  
   The application will provide some basic statistical analyses of data
   contained in database tables and associated plots (R / matplotlib /
   graphviz).  There will also be some heavier duty Monte Carlo simulation
   and graphical modelling / MCMC.  The user(s) will need to be able to set
   model parameters; maybe even tinker with model structure, so it will be
   very interactive (AJAX?).
  
   I've had a look at Django, Turbogears and Plone, and at the moment I am
   torn between Turbogears and Plone.  I get the impression that Turbogears
   will require me to write more non-Python code, but maybe Plone is more
   than I need (steeper learning curve?).  Maybe Turbogears will lead to a
   more loosely coupled app. than Plone?
  
   The disconcerting thing is that others on the project (who won't be
   developing) have started to talk about a LAMP back end with an IIS front
   end, .NET, and the benefits of sharepoint.  The emphasis is supposed to
   be on rapid development, and these technologies are supposed to help.
   But I have no real familiarity with them at all; just Python, C and SQL
   to any realistic level of competence.
  
   Any advice would be greatly appreciated.  I have to do much of the
   statistical work too, so I need to make good choices (and hopefully be
   able to justify them so nobody else on the project makes inappropriate
   choices for me).  e.g. I don't mind learning Javascript if it doesn't
   take too long.  The physical server will initially be a multiprocessor
   machine with several GB of RAM.  But we also have a cluster (I have no
   details, I only started the project a week ago).  So any advice
   regarding parallelisation would also be appreciated (or, in fact, any
   useful advice / pointers at all).  Thanks.
  
   Duncan
 
  I was in a similar boat a while back, needing to make a decision on
  what to use for our web development.  I had worked with Plone
  previously and found that for our needs it wasn't going to work.  Our
  web development was quite specific and didn't fit ideally into the
  standard content management realm.  I also looked at Django and
  TurboGears, installing and working with each.  I eventually went with
  Django, and I've really enjoyed working with it.  Was a personal choice
  and I'm sure our development would have been as successful if I'd
  chosen TurboGears.
 
  If you want the strength of persistent layers, MVC, templating etc etc
  but want to stay away from the heavier frameworks, another possibility
  is http://webpy.org/.  Very simple to implement, lightweight yet still
  fairly full of features.
 

 Don't overlook Karrigell either,  with a tiny learning curve its
 always worth consideration, especially if you need rapid development
 and a web server that will sit on top of your exising .py modules.

 www.karrigell.com

 hth :)

Hmm, thanks for the link on Karrigell.  Never heard of it till now,
quite nice...

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


Re: getting the name of hyperlinks in a file

2007-01-15 Thread Laurent Rahuel
Hi,

I guess you should take a look at BeautifulSoup
(http://www.crummy.com/software/BeautifulSoup/).

And take a clooser look at the findAll method.
http://www.crummy.com/software/BeautifulSoup/documentation.html#The%20basic%20find%20method
%20findAll(name,%20attrs,%20recursive,%20text,%20limit,%20**kwargs)

Regards,

Laurent

CSUIDL PROGRAMMEr wrote:

 folks,
 I am trying to write a script that would open a download server and
 download all the files  and store them in a list
 
 for example Download server is
 http://download.fedora.redhat.com/pub/fedora/linux/core/updates/5/SRPMS/
 
 
 is there any way this can be done in python??

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


Problem with win32pipe.popen2

2007-01-15 Thread diego
I'm trying to understand how popen2 works. Found in this group, that
popen2.popen2 can cause trouble so i chose win32pipe.popen2.

have a look a the listing of 2 files:
ekmain.py:
**
import win32pipe

(stdin1, stdout1) = win32pipe.popen2(test1.py)
stdin1.write(1\n)
print stdout1.readlines() # This will print the result.
**

test1.py:
**
a=raw_input(a=)
print ***a=,a
print finished!
**


i do not understand, why ekmain.py produces only following output:
['a=']

why is the stdin1.write(1\n) command ignored?

i tried to find an answer in this group by searching through existing
article, but i had no success.

tanks for you help!


ernst
p.s.: i working with python 2.3 on win2000.

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


Mail System Error - Returned Mail

2007-01-15 Thread asn_update
The original message was received at Mon, 15 Jan 2007 12:44:10 +0200
from adobe.com [142.121.237.185]

- The following addresses had permanent fatal errors -
python-list@python.org

- Transcript of session follows -
... while talking to 184.246.123.62:
554 python-list@python.org... Message is too large
554 python-list@python.org... Service unavailable

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

Problem with findinf wx modules solved

2007-01-15 Thread siggi
I included the ...\wxDemos path in PYTHONPATH. Everthing fine now!

siggi [EMAIL PROTECTED] schrieb im Newsbeitrag 
news:[EMAIL PROTECTED]
 Tim Roberts  wrote:

when I do sys.path in IDLE (winXP), i get a horrendously long list of
paths, paths I may have used during a lot of trials and errors. How can I
clean up sys.path? I mean, trim it of unnecessary paths?

 What do mean by used during a lot of trials and errors?  sys.path is
 recreated from scratch every time Python starts.  It doesn't accumulate
 over time, other than from new packages that you install.
 -- 
 Tim Roberts, [EMAIL PROTECTED]
 Providenza  Boekelheide, Inc.


 Sorry Tim, my statement was not correct, due to my inexperience with 
 Python.
 And sorry, too, for my somewhat lengthy reply:
 After having had inspected my current sys.path...

 ['C:\\Documents and Settings\\User\\My Documents\\My Python files',
 'C:\\Documents and Settings\\User\\My Documents\\Python25\\Lib\\idlelib',
 'C:\\Documents and Settings\\User\\My Documents\\Python25\\python25.zip',
 'C:\\Documents and Settings\\User\\My Documents\\Python25\\DLLs',
 'C:\\Documents and Settings\\User\\My Documents\\Python25\\lib',
 'C:\\Documents and Settings\\User\\My Documents\\Python25\\lib\\plat-win',
 'C:\\Documents and Settings\\User\\My Documents\\Python25\\lib\\lib-tk',
 'C:\\Documents and Settings\\User\\My Documents\\Python25', 'C:\\Documents
 and Settings\\User\\My Documents\\Python25\\lib\\site-packages',
 'C:\\Documents and Settings\\User\\My
 Documents\\Python25\\lib\\site-packages\\PIL', 'C:\\Documents and
 Settings\\User\\My Documents\\Python25\\lib\\site-packages\\win32',
 'C:\\Documents and Settings\\User\\My
 Documents\\Python25\\lib\\site-packages\\win32\\lib', 'C:\\Documents and
 Settings\\User\\My Documents\\Python25\\lib\\site-packages\\Pythonwin',
 'C:\\Documents and Settings\\User\\My
 Documents\\Python25\\lib\\site-packages\\wx-2.8-msw-ansi']

 or in plain DOS:

 C:\Documents and Settings\User\My Documents\My Python files
 C:\Documents and Settings\User\My Documents\Python25\Lib\idlelib
 C:\Documents and Settings\User\My Documents\Python25\python25.zip
 C:\Documents and Settings\User\My Documents\Python25\DLLs
 C:\Documents and Settings\User\My Documents\Python25\lib
 C:\Documents and Settings\User\My Documents\Python25\lib\plat-win
 C:\Documents and Settings\User\My Documents\Python25\lib\lib-tk
 C:\Documents and Settings\User\My Documents\Python25
 C:\Documents and Settings\User\My Documents\Python25\lib\site-packages
 C:\Documents and Settings\User\My Documents\Python25\lib\site-packages\PIL
 C:\Documents and Settings\User\My 
 Documents\Python25\lib\site-packages\win32
 C:\Documents and Settings\User\My
 Documents\Python25\lib\site-packages\win32\lib
 C:\Documents and Settings\User\My
 Documents\Python25\lib\site-packages\Pythonwin
 C:\Documents and Settings\User\My
 Documents\Python25\lib\site-packages\wx-2.8-msw-ansi

 ...it just looked horrible to me at first sight!

 If I interpret your explanation correctly, all these paths are necessary,
 and not relics of previous installations and deinstallations.

 What puzzles me, though, is, that e.g., when I run the wxPython 
 application
 AnalogClock.py with IDLE or in the command line , this works only in the
 directory ...\My Python files\wxDemos\ . This directory contains all 
 files
 and folders from the original \wx-2.8-msw-ansi\demos\).

 When I copy AnalogClock.py to ...\My Python Files\  , nothing happens 
 after
 running it with IDLE or in the command line.
 Appending 'C:\Documents and Settings\User\My Documents\My Python
 files\wxDemos ' to the sys.path does not help either.

 Thinking that I am clever, I  changed my sys.path with sclicing and
 concatenation such that my sys.path starts with

 'C:\Documents and Settings\User\My Documents\My Python files', 
 'C:\Documents
 and Settings\User\My Documents\My Python files\wxDemos'. Now \wxDemos\ is
 being searched very early.

 ... no way! After running AnalogClock.py again, this error message 
 appears:

 --
 Traceback (most recent call last):
  File C:\Documents and Settings\My Documents\My Python
 files\wxAnalogClock.py, line 14, in module
import wx
 ImportError: No module named wx.
 --

 Very strange! Because all this wx stuff IS IN the directory 'C:\Documents
 and Settings\User\My Documents\My Python files\wxDemos'. And 
 AnalogClock.py
 does work when residing in that directory.

 Can you help me again?

 Thanks,

 siggi

 P.S. On another PC where the python program is in c:\programs\python25\, 
 same as above!





 


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


Re: Class list of a module

2007-01-15 Thread Laurent . LAFFONT-ST
 Looks rather simple to me... Anyway, you could avoid calling getattr
 twice, if you iterate over vars(aModule).itervalues()

 def getClassList(aModule):
 return [cls for cls in vars(aModule).itervalues()
 if inspect.isclass(cls)]

 (And note that there is no need for using \ at the line ends, because
 of the [])


That's what I've been looking for. Thank you.

Regards, 

Laurent Laffont 


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


Re: Python web app. (advice sought)

2007-01-15 Thread Michele Simionato
Duncan Smith wrote:
 Hello,
  I find myself in the, for me, unusual (and at the moment unique)
 position of having to write a web application.  I have quite a lot of
 existing Python code that will form part of the business logic.  This
 relies on 3rd party libraries (such as numpy) which would make porting
 to e.g. IronPython difficult (I would imagine).  I was thinking LAMP
 (the P standing for Python, of course), particularly as I was originally
 encouraged to go for open source solutions.

 The application will provide some basic statistical analyses of data
 contained in database tables and associated plots (R / matplotlib /
 graphviz).  There will also be some heavier duty Monte Carlo simulation
 and graphical modelling / MCMC.  The user(s) will need to be able to set
 model parameters; maybe even tinker with model structure, so it will be
 very interactive (AJAX?).

 I've had a look at Django, Turbogears and Plone, and at the moment I am
 torn between Turbogears and Plone.

I assume it will be an application with few users and no particular
need for
security. Read PEP 333, use the wsgiref server which is in the standard
library
(starting from Python 2.5+), have a look at Paste and write your own
solution.
At the least this is the way I did it.

 Michele Simionato

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


Re: python and MOV or MPEG

2007-01-15 Thread siggi

Diez B. Roggisch wrote:

 siggi wrote:

 Hi all,

 does Python support MPEG or MOV videoclips? I couldn't find anything
 about it online.

 Weak in googling today? Must have been a rough weekend.

 There are several options, including pymedia and pygame.

 Diez

Thanks, Diez.  I forgot to mention that I am learning Python with python 2.5
on WinXP. And both pymedia and pygame require somewhat older versions of
python, 1.3 and 2.4, respectively. And the updated binaries are still in the
offing. I was naive enough to think MPEG could be done using modules already
existing.

siggi



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


Re: python and MOV or MPEG

2007-01-15 Thread Godson

On 1/15/07, Diez B. Roggisch [EMAIL PROTECTED] wrote:


siggi wrote:

 Hi all,

 does Python support MPEG or MOV videoclips? I couldn't find anything
about
 it online.

Weak in googling today? Must have been a rough weekend.

There are several options, including pymedia and pygame.

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



Here is a way how you can do it!

http://godsongera.blogspot.com/2006/12/play-mpeg-file-with-python.html

--
Godson Gera,
http://godson.auroinfo.com
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: Python web app. (advice sought)

2007-01-15 Thread bruno . desthuilliers

Duncan Smith a écrit :
 Hello,
  I find myself in the, for me, unusual (and at the moment unique)
 position of having to write a web application.  I have quite a lot of
 existing Python code that will form part of the business logic.  This
 relies on 3rd party libraries (such as numpy) which would make porting
 to e.g. IronPython difficult (I would imagine).  I was thinking LAMP
 (the P standing for Python, of course), particularly as I was originally
 encouraged to go for open source solutions.

 The application will provide some basic statistical analyses of data
 contained in database tables and associated plots (R / matplotlib /
 graphviz).  There will also be some heavier duty Monte Carlo simulation
 and graphical modelling / MCMC.  The user(s) will need to be able to set
 model parameters; maybe even tinker with model structure, so it will be
 very interactive (AJAX?).

 I've had a look at Django, Turbogears and Plone, and at the moment I am
 torn between Turbogears and Plone.  I get the impression that Turbogears
 will require me to write more non-Python code,

???

 but maybe Plone is more
 than I need (steeper learning curve?).  Maybe Turbogears will lead to a
 more loosely coupled app. than Plone?

Plone is nice for content management (well, it's a CMS, isn't it ?),
but I certainly wouldn't choose it for the kind off application you are
describing. A simpler, lighter MVC framework would be far more
appropriate IMHO. Turbogears may be a good choice, but you may also
want to have a look at web.py and Pylons.

 The disconcerting thing is that others on the project (who won't be
 developing) have started to talk about a LAMP back end with an IIS front
 end, .NET, and the benefits of sharepoint.

My my my...

  The emphasis is supposed to
 be on rapid development, and these technologies are supposed to help.
 But I have no real familiarity with them at all; just Python, C and SQL
 to any realistic level of competence.

Then go for the simplest thing.
 
My 2 cents...

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

Re: indentation in python

2007-01-15 Thread Wolfgang Grafen
Dan Bishop wrote:
 On Jan 13, 8:49 pm, lee [EMAIL PROTECTED] wrote:
 Can anyone tell me the basics about indentation in python..how we
 use it in loops and constructs..etc
 
 It's just like indentation in other languages, except that it's
 syntactically required.
 
The indent rule is minimal:
- indent the following line after a colon (:)
- dedent when you leave that block to the level you wish to continue
- you cannot have an empty block; use pass or None for an otherwise empty block
- as always: have fun!
-- 
http://mail.python.org/mailman/listinfo/python-list


Conditional validation of documents (ignoring IDREFs)

2007-01-15 Thread zgolus
I'm working with one extra large XML file which consists of many parts.
Every part can be considered a stand-alone document with references to
other parts (IDs and IDREFs). I would like to be able to validate every
such part against a DTD but ignoring errors which arise from broken
references. Can I do it with pyxml?

Thanks in advance!

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


Re: python and MOV or MPEG

2007-01-15 Thread Bjoern Schliessmann
siggi wrote:

 Thanks, Diez.  I forgot to mention that I am learning Python with
 python 2.5 on WinXP. And both pymedia and pygame require somewhat
 older versions of python, 1.3 and 2.4, respectively.

1.3? I've found both for 2.4, and in one site's forum some guy
offers windows binaries for 2.5.

Regards,


Björn

-- 
BOFH excuse #303:

fractal radiation jamming the backbone

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


Re: python and MOV or MPEG

2007-01-15 Thread siggi
Bjoern Schliessmann wrote:

 1.3? I've found both for 2.4, and in one site's forum some guy
 offers windows binaries for 2.5.

The links, please!

Thank you,

siggi


Bjoern Schliessmann [EMAIL PROTECTED] schrieb 
im Newsbeitrag news:[EMAIL PROTECTED]
 siggi wrote:

 Thanks, Diez.  I forgot to mention that I am learning Python with
 python 2.5 on WinXP. And both pymedia and pygame require somewhat
 older versions of python, 1.3 and 2.4, respectively.

 1.3? I've found both for 2.4, and in one site's forum some guy
 offers windows binaries for 2.5.

 Regards,


 Björn

 -- 
 BOFH excuse #303:

 fractal radiation jamming the backbone
 


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

Re: Python web app. (advice sought)

2007-01-15 Thread Istvan Albert

Duncan Smith wrote:

 I've had a look at Django, Turbogears and Plone, and at the moment I am
 torn between Turbogears and Plone.  I

Plone is not suited for the type of application you are building (as
others have pointed out in this thread).

Take a second look at TurboGears (or CherryPy for that matter). You
might have discounted Django a bit too soon. It has the best
documentation and it is the most consistent framework.

You might end up bringing in new people into your project and that will
go a lot easier when you have good docs to help them as well. 

i.

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


check if there is data in stdin without blocking

2007-01-15 Thread hg
Hi,

Is there a way ? ... select ?



hg

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


Re: How naive is Python?

2007-01-15 Thread skip

John Sorry, Skip, but I find that very hard to believe. The foo()
John function would take quadratic time if it were merely adding on
John pieces of constant size -- however len(str(i)) is not a constant,
John it is O(log10(i)), so the time should be
John super-quadratic.

Sorry, I should have pointed out that I'm using the latest version of
Python.  I believe += for strings has been optimized to simply extend s when
there is only a single reference to it.

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


Default event handlers in wxPython

2007-01-15 Thread Tom Wright
Hi all

I'm writing my first wxPython app and am having a problem with event
handlers.  I've set up a multi-part status bar and would like all the
tooltips, menu help strings etc. to go into the second part of it.  Is
there some easy way of doing this?

I've not found one, so have set up the following for the menu:

 self.Bind(wx.EVT_MENU_HIGHLIGHT, self.OnMenuHighlight)

def OnMenuHighlight(self, event):
 self.SetStatusText(event.GetEventObject().GetHelpString(event.GetMenuId()),
1)

...this works fine.  I've tried to set up the same for the toolbar:

 self.Bind(wx.EVT_TOOL_ENTER, self.OnToolbarHighlight)
def OnToolbarHighlight(self, event):
self.SetStatusText(event.GetEventObject().GetToolLongHelp(event.GetSelection()),
 1)

...and this doesn't work.  Well, it puts the text in the second part of the
toolbar as requested, but the default handler is still being called and
this messes up the first part of the toolbar which I want it to leave
alone.  How do I completely override the default handler for the toolbar?
This method worked fine for menus and I'm a bit stuck.

(ignore the indentation on the above examples - I know it's wrong, but long
lines and usenet don't mix)


-- 
I'm at CAMbridge, not SPAMbridge
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: check if there is data in stdin without blocking

2007-01-15 Thread hg
hg wrote:

 Hi,
 
 Is there a way ? ... select ?
 
 
 
 hg
PS:

import sys
import select

l_r = select.select([sys.stdin],[],[],0)

gives me:
  File select.py, line 2, in ?
import select
  File /home/philippe/Desktop/select.py, line 4, in ?
l_r = select.select([sys.stdin],[],[],0)
TypeError: 'module' object is not callable


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


Re: check if there is data in stdin without blocking

2007-01-15 Thread Laurent Pointal
hg a écrit :
 hg wrote:
 
 Hi,

 Is there a way ? ... select ?



 hg
 PS:
 
 import sys
 import select
 
 l_r = select.select([sys.stdin],[],[],0)
 
 gives me:
   File select.py, line 2, in ?
 import select
   File /home/philippe/Desktop/select.py, line 4, in ?
 l_r = select.select([sys.stdin],[],[],0)
 TypeError: 'module' object is not callable
 
 

Wont work under Windows:
 help(select.select)
...zip...
*** IMPORTANT NOTICE ***
On Windows, only sockets are supported; on Unix, all file descriptors.



If under Unix, maybe sys.stdin.fileno() is a valid descriptor for
select. Just test it.

And if under Windows, you may take a look at
22.1 msvcrt - Useful routines from the MS VC++ runtime
22.1.2 Console I/O
kbhit( ) - Return true if a keypress is waiting to be read.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: check if there is data in stdin without blocking

2007-01-15 Thread hg
Laurent Pointal wrote:

 hg a écrit :
 hg wrote:
 
 Hi,

 Is there a way ? ... select ?



 hg
 PS:
 
 import sys
 import select
 
 l_r = select.select([sys.stdin],[],[],0)
 
 gives me:
   File select.py, line 2, in ?
 import select
   File /home/philippe/Desktop/select.py, line 4, in ?
 l_r = select.select([sys.stdin],[],[],0)
 TypeError: 'module' object is not callable
 
 
 
 Wont work under Windows:
 help(select.select)
 ...zip...
 *** IMPORTANT NOTICE ***
 On Windows, only sockets are supported; on Unix, all file descriptors.
 
 
 
 If under Unix, maybe sys.stdin.fileno() is a valid descriptor for
 select. Just test it.
 
 And if under Windows, you may take a look at
 22.1 msvcrt - Useful routines from the MS VC++ runtime
 22.1.2 Console I/O
 kbhit( ) - Return true if a keypress is waiting to be read.


Well I'm testing under Linux but need support under Windows ... is there any
way to poll stdin somehow under both plateform ?

thanks,

hg





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


Re: check if there is data in stdin without blocking

2007-01-15 Thread Paul Boddie
hg wrote:
 import select

[...]

   File /home/philippe/Desktop/select.py, line 4, in ?

Consider which module Python is trying to import here: the standard
library select module or your own program?

Paul

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


__getattr__ equivalent for a module

2007-01-15 Thread Maksim Kasimov
Hi,

in any python class it is possible to define __getattr__ method so that if we 
try to get some value of not actually exists instance attribute, we can get 
some default value.

For example:

class MyClass:

def __getattr__(self, attname):

if attname.startswith('a'):
return *


i = MyClass()
...
i.aValue # it gives * if i.aValue will not be set before this call


i need to define the same behavior for a module:

import mymodule
mymodule.anyattribute
or
from mymodule import anyattribute

anyattribute is not actually defined in the module, but gives some attribute 
of the module

so my question is: how to tune up a module get default attribute if we try to 
get access to not actually exists attribute of a module?

(python 2.4 or 2.2)

many thanks for help.


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


Re: Conflicting needs for __init__ method

2007-01-15 Thread Mark Dickinson
On Jan 14, 7:49 pm, Ziga Seilnacht [EMAIL PROTECTED] wrote:
 Mark wrote:[a lot of valid, but long concerns about types that return
  an object of their own type from some of their methods]

 I think that the best solution is to use an alternative constructor
 in your arithmetic methods. That way users don't have to learn about
 two different factories for the same type of objects. It also helps
 with subclassing, because users have to override only a single method
 if they want the results of arithmetic operations to be of their own
 type.

Aha.  I was wondering whether __new__ might appear in the solution
somewhere, but couldn't figure out how that would work;  I'd previously
only ever used it for its advertised purpose of subclassing immutable
types.

 Hope this helps,

It helps a lot.  Thank you.

Mark

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


Re: __getattr__ equivalent for a module

2007-01-15 Thread Leif K-Brooks
Maksim Kasimov wrote:
 so my question is: how to tune up a module get default attribute if we 
 try to get access to not actually exists attribute of a module?

You could wrap it in an object, but that's a bit of a hack.

import sys

class Foo(object):
 def __init__(self, wrapped):
 self.wrapped = wrapped

 def __getattr__(self, name):
 try:
 return getattr(self.wrapped, name)
 except AttributeError:
 return 'default'

sys.modules[__name__] = Foo(sys.modules[__name__])
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Conflicting needs for __init__ method

2007-01-15 Thread Mark Dickinson


On Jan 14, 10:43 pm, Steven D'Aprano
[EMAIL PROTECTED] wrote:
 On Sun, 14 Jan 2007 15:32:35 -0800, dickinsm wrote:
  (You could include the normalization in __init__, but that's wasteful
 Is it really? Have you measured it or are you guessing? Is it more or less
 wasteful than any other solution?

Just guessing :).  But when summing the reciprocals of the first 2000
positive integers, for example, with:

sum((Rational(1, n) for n in range(1, 2001)), Rational(0))

the profile module tells me that the whole calculation takes 8.537
seconds, 8.142 of which are spent in my gcd() function.  So it seemed
sensible to eliminate unnecessary calls to gcd() when there's an easy
way to do so.

 def __copy__(self):
 cls = self.__class__
 obj = cls.__new__(cls)
 obj.numerator = self.numerator
 obj.denominator = self.denominator
 return obj

Thank you for this.

Mark

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


Re: check if there is data in stdin without blocking

2007-01-15 Thread hg
Paul Boddie wrote:

 hg wrote:
 import select
 
 [...]
 
   File /home/philippe/Desktop/select.py, line 4, in ?
 
 Consider which module Python is trying to import here: the standard
 library select module or your own program?
 
 Paul

Argh  ;-)



thanks


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


Re: How naive is Python?

2007-01-15 Thread skip

John Sorry, Skip, but I find that very hard to believe. The foo()
John function would take quadratic time if it were merely adding on
John pieces of constant size -- however len(str(i)) is not a constant,
John it is O(log10(i)), so the time should be super-quadratic.

me Sorry, I should have pointed out that I'm using the latest version
me of Python.  I believe += for strings has been optimized to simply
me extend s when there is only a single reference to it.

Actually, it isn't until I work my way back to 2.3 that I start to see
quadratic behavior:

% python2.6 strcopy.py 
32 0.00022292137146 6.96629285812e-06
64 0.000907897949219 1.41859054565e-05
128 0.000649929046631 5.0775706768e-06
256 0.00111794471741 4.36697155237e-06
512 0.00260806083679 5.09386882186e-06
1024 0.00437998771667 4.27733175457e-06
2048 0.00921607017517 4.50003426522e-06
4096 0.0191979408264 4.68699727207e-06
8192 0.0694131851196 8.47328919917e-06
16384 0.0976829528809 5.96209429204e-06
32768 0.194766998291 5.94381708652e-06
% python2.5 strcopy.py 
32 0.000439167022705 1.37239694595e-05
64 0.000303030014038 4.73484396935e-06
128 0.000631809234619 4.93600964546e-06
256 0.00112318992615 4.38746064901e-06
512 0.00279307365417 5.45522198081e-06
1024 0.00446391105652 4.35928814113e-06
2048 0.00953102111816 4.65381890535e-06
4096 0.0198018550873 4.83443727717e-06
8192 0.175454854965 2.14178289752e-05
16384 0.103327989578 6.30663998891e-06
32768 0.191411972046 5.84142981097e-06
% python2.4 strcopy.py 
32 0.000230073928833 7.18981027603e-06
64 0.000307083129883 4.79817390442e-06
128 0.00114107131958 8.91461968422e-06
256 0.00116014480591 4.53181564808e-06
512 0.00231313705444 4.51784580946e-06
1024 0.00459003448486 4.4824162e-06
2048 0.00974178314209 4.75673004985e-06
4096 0.019122838974 4.66866185889e-06
8192 0.0717267990112 8.75571276993e-06
16384 0.112125873566 6.84362021275e-06
32768 0.188065052032 5.73928991798e-06
% python2.3 strcopy.py 
32 0.000223875045776 6.99609518051e-06
64 0.000385999679565 6.03124499321e-06
128 0.000766038894653 5.98467886448e-06
256 0.00154304504395 6.02751970291e-06
512 0.00309181213379 6.03869557381e-06
1024 0.0065929889679 6.43846578896e-06
2048 0.0147500038147 7.20215030015e-06
4096 0.14589214325 3.56181990355e-05
8192 0.778324127197 9.50102694333e-05
16384 3.20213103294 0.000195442567929
32768 14.7389230728 0.000449796236353
% python2.2 strcopy.py
32 0.00031590461731 9.87201929092e-06
64 0.000494003295898 7.71880149841e-06
128 0.00090217590332 7.04824924469e-06
256 0.00173211097717 6.76605850458e-06
512 0.00362610816956 7.08224251866e-06
1024 0.00711607933044 6.94929622114e-06
2048 0.0158200263977 7.7246222645e-06
4096 0.152237892151 3.71674541384e-05
8192 0.89648604393 0.000109434331534
16384 3.14483094215 0.000191945247934
32768 13.3367011547 0.000407003819419

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


Re: __getattr__ equivalent for a module

2007-01-15 Thread Maksim Kasimov

Hi Leif, many thanks - it works

Leif K-Brooks wrote:
 Maksim Kasimov wrote:
 so my question is: how to tune up a module get default attribute if we 
 try to get access to not actually exists attribute of a module?
 
 You could wrap it in an object, but that's a bit of a hack.
 
 import sys
 
 class Foo(object):
 def __init__(self, wrapped):
 self.wrapped = wrapped
 
 def __getattr__(self, name):
 try:
 return getattr(self.wrapped, name)
 except AttributeError:
 return 'default'
 
 sys.modules[__name__] = Foo(sys.modules[__name__])


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


Looking for Job

2007-01-15 Thread fhk6431
Hi,

Any one looking for job.. I need someone good at phyton to do black box
and white box testing

Contact me at [EMAIL PROTECTED]

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


catching signals in an object

2007-01-15 Thread hg
Hi,

I need to catch a signal SIGUSR1 in an object ... and I need the signal
def that traps is to access the object context ... is that possible  ?
(*nix and windows)

ex:

class test:
def __init__(self):
self.Set_Signal()

def Set_Signal(self):
import signal
signal.signal(..., Func)
def Func(.):
#I need to get access to self


or can signal.signal take a method as param ?

Thanks

hg

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


Re: How naive is Python?

2007-01-15 Thread John Nagle
[EMAIL PROTECTED] wrote:
 John Sorry, Skip, but I find that very hard to believe. The foo()
 John function would take quadratic time if it were merely adding on
 John pieces of constant size -- however len(str(i)) is not a constant,
 John it is O(log10(i)), so the time should be
 John super-quadratic.
 
 Sorry, I should have pointed out that I'm using the latest version of
 Python.  I believe += for strings has been optimized to simply extend s when
 there is only a single reference to it.

I'd heard that, but wasn't sure.  That's the kind of answer I was
looking for.

That kind of optimization is a huge win.

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


Re: catching signals in an object

2007-01-15 Thread robert
hg wrote:
 Hi,
 
 I need to catch a signal SIGUSR1 in an object ... and I need the signal
 def that traps is to access the object context ... is that possible  ?
 (*nix and windows)
 
 ex:
 
 class test:
 def __init__(self):
 self.Set_Signal()
 
 def Set_Signal(self):
 import signal
 signal.signal(..., Func)
 def Func(.):
 #I need to get access to self
 
 
 or can signal.signal take a method as param ?
 

Just do it! Python is a functional language.
You have access to self (search for the term closure) and 
self.method is bound - thus a 'function'

objects are nothing special in Python.


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


can't get import to work!

2007-01-15 Thread corsairdgr
 I am brand new to jython/python.
 
 I want to use my own Java class from within a Jython script.
 
 In Java, I created a class called Fubar and put this in a jar file called 
testit.jar.
 The Fubar class is in the just.for.fun package and this path shows up in the
 testit.jar file. I then modified the jython.bat file (I'm using windows) to 
include
 the testit.jar file in the classpath. When jython starts from the command line,
 it notices testit.jar and generates some cache information.
 
 Next I want to use the Fubar class in a jython script. I start jython from the 
command line and type:
 
 from just.for.fun import Fubar
 This doesn't work. The following error is displayed:
 ImportError: No module named for
 
 I also try
 
 import just.for.fun.Fubar
 
 This gives the same error.
 
 I can enter import java.util.HashMap and other such imports and these work. 
 
 Can someone please tell me what I could be doing wrong ?
 
 Thanks,
 
 
 
  

Check out the new AOL.  Most comprehensive set of free safety and security 
tools, free access to millions of high-quality videos from across the web, free 
AOL Mail and more.
-- 
http://mail.python.org/mailman/listinfo/python-list

Segfault with tktreectrl on python-2.5 on linux

2007-01-15 Thread klappnase
Hello,

I use the tktreectrl Tk extension (http://tktreectrl.sourceforge.net)
through the python wrapper module
(http://klappnase.zexxo.net/TkinterTreectrl/index.html).
With python-2.5 it seems that each time some text is inserted into the
treectrl widget a segfault occurs (on linux, on windows2000 it seemed
to work).
Some people sent me mail describing the same problem, so I think it is
not a problem with my installation of python-2.5. The treectrl widget
itself works well when running from Tcl or from python2.4, so i suspect
that it is a bug in python-2.5.
Below the output from gdb when running the dirtree demo from the
TkinterTreectrl package:

(gdb) run
Starting program: /usr/local/bin/python2.5
/home/pingu/projekte/TkinterTreectrl/TkinterTreectrl-0.6/demo/dirtree.py
[Thread debugging using libthread_db enabled]
[New Thread -1209842944 (LWP 21831)]

Program received signal SIGSEGV, Segmentation fault.
[Switching to Thread -1209842944 (LWP 21831)]
block_alloc (b=0x1, size=16) at Python/pyarena.c:109
109 if (b-ab_offset + size  b-ab_size) {
(gdb) bt
#0  block_alloc (b=0x1, size=16) at Python/pyarena.c:109
#1  0x080d829e in PyArena_Malloc (arena=0x82b2790, size=16) at
Python/pyarena.c:192
#2  0x081129ca in Ellipsis (arena=0x10) at Python/Python-ast.c:1764
#3  0xb77731ef in DisplayProcText () from
/usr/lib/treectrl2.2/libtreectrl2.2.so

Any ideas?

Regards

Michael

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


compile your python programs with rpython

2007-01-15 Thread Simon Burton
The pypy'ers have written a brief description on
using rpython to create standalone executables:

http://codespeak.net/pypy/dist/pypy/doc/standalone-howto.html

This is definately worth playing around with, it's very nice writing
(r)python code that gets executed as if it were c code.

Simon.

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


Re: check if there is data in stdin without blocking

2007-01-15 Thread Gabriel Genellina

At Monday 15/1/2007 05:55, hg wrote:


Well I'm testing under Linux but need support under Windows ... is there any
way to poll stdin somehow under both plateform ?


I think you may want this portable getch function:
http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/134892


--
Gabriel Genellina
Softlab SRL 







__ 
Preguntá. Respondé. Descubrí. 
Todo lo que querías saber, y lo que ni imaginabas, 
está en Yahoo! Respuestas (Beta). 
¡Probalo ya! 
http://www.yahoo.com.ar/respuestas 

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

Re: compile your python programs with rpython

2007-01-15 Thread Bjoern Schliessmann
Simon Burton wrote:

 The pypy'ers have written a brief description on
 using rpython to create standalone executables:
 
 http://codespeak.net/pypy/dist/pypy/doc/standalone-howto.html
 
 This is definately worth playing around with, it's very nice
 writing (r)python code that gets executed as if it were c code.

Needless to say, RPython code has some restrictions over normal
Python code.

Regards,


Björn

-- 
BOFH excuse #317:

Internet exceeded Luser level, please wait until a luser logs off
before attempting to log back on.

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


Re: Looking for Job

2007-01-15 Thread Bjoern Schliessmann
[EMAIL PROTECTED] wrote:

 Any one looking for job.. I need someone good at phyton

Sorry, you'll only sporadically find people competent with plants
here.

Regards,


Björn

-- 
BOFH excuse #83:

Support staff hung over, send aspirin and come back LATER.

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


Re: How can I integrate RPC with WSGI ???

2007-01-15 Thread Bruno Desthuilliers
வினோத் a écrit :
 How can I integrate RPC 

You mean xmlrpc or Soap ?

 with WSGI ???
  is any methods for it??
 

What's your problem exactly ?
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: How to write code to get focuse the application which is open from server

2007-01-15 Thread vithi
Dennis,
I am sorry that was a typing error. I try like that
app.Print.OK.Click() but it was not working. The printer window was not
IdentifiedIs their any method I can use to achive the same goal. How
the window title was used as class name?. Could you please help me to
solve this problem.
thanks
this is the error meassage

Traceback (most recent call last):
  File C:\Python24\test1.py, line 10, in -toplevel-
app.Print.Ok.CloseClick()
  File c:\python24\pywinauto\pywinauto\application.py, line 237, in
__getattr__
ctrls = _resolve_control(
  File c:\python24\pywinauto\pywinauto\application.py, line 854, in
_resolve_control
ctrl = _get_ctrl(criteria)
  File c:\python24\pywinauto\pywinauto\application.py, line 622, in
_get_ctrl
dialog = controls.WrapHandle(
  File c:\python24\pywinauto\pywinauto\findwindows.py, line 62, in
find_window
windows = find_windows(**kwargs)
  File c:\python24\pywinauto\pywinauto\findwindows.py, line 177, in
find_windows
windows = findbestmatch.find_best_control_matches(
  File c:\python24\pywinauto\pywinauto\findbestmatch.py, line 483, in
find_best_control_matches
raise MatchError(items = name_control_map.keys(), tofind =
search_text)
MatchError: Could not find 'Print' in '['', u'Transparent Windows
Client0', u'Transparent Windows Client2', u'Transparent Windows
Client1', u'Print - Remote', u'Transparent Windows Client', u'Print
- RemoteTransparent Windows Client']'

This is the code
import sys
import time
import application
app = application.Application()
qi=app.window_(title_re = .*ArcView.*)
time.sleep(2)
qi.TypeKeys(%FP)
time.sleep(2)

app.Print.Ok.CloseClick()


Dennis Lee Bieber wrote:
 On 14 Jan 2007 21:11:35 -0800, vithi [EMAIL PROTECTED] declaimed
 the following in comp.lang.python:

 
  my code goes like that

   goes like?  Don't type similarities from memory -- cutpaste the
 actual code (or, preferably, a stripped down version that you've
 actually run) that shows the behavior in question.

  app=application.Application()
  qi = app.window_(title_re = .*arcMap.*)
  qi.TypeKeys(%FP)
  app,Print.OK.Click()
 
   And what is that last line supposed to be doing. app,anything is
 two separate objects: an application object, and something called Print
 with an attribute called OK which itself has a method called Click

   I suspect, at a minimum, that last line is supposed to be
 
 app.Print.OK.Click()
^  period, not

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


Re: How to write code to get focuse the application which is open from server

2007-01-15 Thread vithi
Dennis,
I am sorry that was a typing error. I try like that
app.Print.OK.Click() but it was not working. The printer window was not
IdentifiedIs their any method I can use to achive the same goal. How
the window title was used as class name?. Could you please help me to
solve this problem.
thanks
this is the error meassage

Traceback (most recent call last):
  File C:\Python24\test1.py, line 10, in -toplevel-
app.Print.Ok.CloseClick()
  File c:\python24\pywinauto\pywinauto\application.py, line 237, in
__getattr__
ctrls = _resolve_control(
  File c:\python24\pywinauto\pywinauto\application.py, line 854, in
_resolve_control
ctrl = _get_ctrl(criteria)
  File c:\python24\pywinauto\pywinauto\application.py, line 622, in
_get_ctrl
dialog = controls.WrapHandle(
  File c:\python24\pywinauto\pywinauto\findwindows.py, line 62, in
find_window
windows = find_windows(**kwargs)
  File c:\python24\pywinauto\pywinauto\findwindows.py, line 177, in
find_windows
windows = findbestmatch.find_best_control_matches(
  File c:\python24\pywinauto\pywinauto\findbestmatch.py, line 483, in
find_best_control_matches
raise MatchError(items = name_control_map.keys(), tofind =
search_text)
MatchError: Could not find 'Print' in '['', u'Transparent Windows
Client0', u'Transparent Windows Client2', u'Transparent Windows
Client1', u'Print - Remote', u'Transparent Windows Client', u'Print
- RemoteTransparent Windows Client']'

This is the code
import sys
import time
import application
app = application.Application()
qi=app.window_(title_re = .*ArcView.*)
time.sleep(2)
qi.TypeKeys(%FP)
time.sleep(2)

app.Print.Ok.CloseClick()


Dennis Lee Bieber wrote:
 On 14 Jan 2007 21:11:35 -0800, vithi [EMAIL PROTECTED] declaimed
 the following in comp.lang.python:

 
  my code goes like that

   goes like?  Don't type similarities from memory -- cutpaste the
 actual code (or, preferably, a stripped down version that you've
 actually run) that shows the behavior in question.

  app=application.Application()
  qi = app.window_(title_re = .*arcMap.*)
  qi.TypeKeys(%FP)
  app,Print.OK.Click()
 
   And what is that last line supposed to be doing. app,anything is
 two separate objects: an application object, and something called Print
 with an attribute called OK which itself has a method called Click

   I suspect, at a minimum, that last line is supposed to be
 
 app.Print.OK.Click()
^  period, not

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


Re: Segfault with tktreectrl on python-2.5 on linux

2007-01-15 Thread Anton Hartl
Hi,

On 2007-01-15, klappnase [EMAIL PROTECTED] wrote:

 Some people sent me mail describing the same problem, so I think it is
 not a problem with my installation of python-2.5. The treectrl widget
 itself works well when running from Tcl or from python2.4, so i suspect
 that it is a bug in python-2.5.
 Below the output from gdb when running the dirtree demo from the
 TkinterTreectrl package:

 (gdb) run
 Starting program: /usr/local/bin/python2.5
 /home/pingu/projekte/TkinterTreectrl/TkinterTreectrl-0.6/demo/dirtree.py
 [Thread debugging using libthread_db enabled]
 [New Thread -1209842944 (LWP 21831)]

 Program received signal SIGSEGV, Segmentation fault.
 [Switching to Thread -1209842944 (LWP 21831)]
 block_alloc (b=0x1, size=16) at Python/pyarena.c:109
 109 if (b-ab_offset + size  b-ab_size) {
 (gdb) bt
 #0  block_alloc (b=0x1, size=16) at Python/pyarena.c:109
 #1  0x080d829e in PyArena_Malloc (arena=0x82b2790, size=16) at
 Python/pyarena.c:192
 #2  0x081129ca in Ellipsis (arena=0x10) at Python/Python-ast.c:1764
 #3  0xb77731ef in DisplayProcText () from
 /usr/lib/treectrl2.2/libtreectrl2.2.so

 Any ideas?

Yes. And a solution as well :)

Here is the story:

- libpython2.5.so contains a global symbol Ellipsis; this is
  new in 2.5 and came in with the new AST/compiler code

- starting python2.5 loads libpython2.5.so (obviously)

- now you do something like:

tk.call(package, require, tktreectrl)

this loads libtktreectrl2.2.so

- libtktreectrl2.2.so contains a global symbol Ellipsis

- and now disaster happens: references in libtktreectrl2.2.so
  to Ellipsis are NOT resolved to the Ellipsis symbol
  in libtktreectrl2.2.so but rather to the Ellipsis symbol
  in libpython2.5.so

- this is not what you want, but is correct behaviour of
  symbol resolution in shared shared libraries (and is
  equivalant to the behaviour with static libs btw)

Solutions:

a) convince Python developers to prefix ALL new (wrt. 2.5)
   global symbols with a prefix like _PyAST_ or equivalent;
   this would be consistent with how it is done anyway,
   unfortunately the new AST symbols deviate from this practise
   (there are symbols like Assert, If, Then, ...)

 or b) apply an equivalent rule to the global symbols in
   tktreectrl that are global by accident, i.e. because
   of the way the library is structured and built

Best Regards,
Anton

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


Re: How to write code to get focuse the application which is open from server

2007-01-15 Thread Gabriel Genellina

At Monday 15/1/2007 15:53, vithi wrote:


I am sorry that was a typing error. I try like that
app.Print.OK.Click() but it was not working. The printer window was not
IdentifiedIs their any method I can use to achive the same goal. How
the window title was used as class name?. Could you please help me to
solve this problem.


app.Print looks for a window whose title contains the word Print 
(does it exist?), inside, looks for a control with OK (presumably a 
button), and sends it a mouse click event.

There is a forum specific for pywinauto questions - see its homepage.


--
Gabriel Genellina
Softlab SRL  







__ 
Preguntá. Respondé. Descubrí. 
Todo lo que querías saber, y lo que ni imaginabas, 
está en Yahoo! Respuestas (Beta). 
¡Probalo ya! 
http://www.yahoo.com.ar/respuestas 

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

Re: Type casting a base class to a derived one?

2007-01-15 Thread Frederic Rentsch
Chris Mellon wrote:
 On 11 Jan 2007 15:01:48 +0100, Neil Cerutti [EMAIL PROTECTED] wrote:
   
 On 2007-01-11, Frederic Rentsch [EMAIL PROTECTED] wrote:
 
 If I derive a class from another one because I need a few extra
 features, is there a way to promote the base class to the
 derived one without having to make copies of all attributes?

 class Derived (Base):
def __init__ (self, base_object):
   # ( copy all attributes )
   ...

 This looks expensive. Moreover __init__ () may not be available
 if it needs to to something else.

 Thanks for suggestions
   
 How does it make sense to cast a base to a derived in your
 application?

 

 I can't figure out any circumstance when you'd need to do this in
 Python. Upcasting like this is something you do in statically typed
 languages. I suspect that the OP doesn't really believe dynamic
 casting works and doesn't want to pass a derived class for some
 reason.
   
What for? If an instance needs to collect a substantial amount of data 
and needs to perform a substantial amount of processing in order to 
analyze that data, and if the appropriate type of the instance depends 
on the analysis, I thought that the instance might at that point just 
kind of slip into the appropriate identity.
  After studying the various helpful suggestions, some of which, 
like this one, question the wisdom of such an approach, I think I see 
the light: I'd have a class that does the collecting and the analyzing, 
or even two classes: one collecting the other analyzing and then, 
depending on the outcome of the analysis, make the appropriate processor 
and hand it the data it needs. Right?
 
Thank you all very much for your input.

Frederic (OP)


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


Re: check if there is data in stdin without blocking

2007-01-15 Thread hg
Gabriel Genellina wrote:

 At Monday 15/1/2007 05:55, hg wrote:
 
Well I'm testing under Linux but need support under Windows ... is there
any way to poll stdin somehow under both plateform ?
 
 I think you may want this portable getch function:
 http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/134892
 
 
 --
 Gabriel Genellina
 Softlab SRL
 
 
 
 
 
 
 __
 Preguntá. Respondé. Descubrí.
 Todo lo que querías saber, y lo que ni imaginabas,
 está en Yahoo! Respuestas (Beta).
 ¡Probalo ya!
 http://www.yahoo.com.ar/respuestas

will take a look, thanks.

hg

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


Watch log

2007-01-15 Thread Salvatore Di Fazio
Hi guys,
I've an application that writes a log file.
I need to write an application with python that will read this file.

I would like wait until a new line will be write in the file.

Something like the watch cat Log command on Linux os.

How can I check the eof and restart the reading?

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


Re: How naive is Python?

2007-01-15 Thread John Machin

[EMAIL PROTECTED] wrote:
 John Sorry, Skip, but I find that very hard to believe. The foo()
 John function would take quadratic time if it were merely adding on
 John pieces of constant size -- however len(str(i)) is not a constant,
 John it is O(log10(i)), so the time should be super-quadratic.

 me Sorry, I should have pointed out that I'm using the latest version
 me of Python.  I believe += for strings has been optimized to simply
 me extend s when there is only a single reference to it.

Sorry, I should have pointed out that you need to read up about
time.time() -- what is its resolution on your box? -- and time.clock()
and the timeit module.


 Actually, it isn't until I work my way back to 2.3 that I start to see
 quadratic behavior:

 % python2.6 strcopy.py
 32 0.00022292137146 6.96629285812e-06
 64 0.000907897949219 1.41859054565e-05
 128 0.000649929046631 5.0775706768e-06
 256 0.00111794471741 4.36697155237e-06
 512 0.00260806083679 5.09386882186e-06
 1024 0.00437998771667 4.27733175457e-06
 2048 0.00921607017517 4.50003426522e-06
 4096 0.0191979408264 4.68699727207e-06
 8192 0.0694131851196 8.47328919917e-06
 16384 0.0976829528809 5.96209429204e-06
 32768 0.194766998291 5.94381708652e-06
 % python2.5 strcopy.py
 32 0.000439167022705 1.37239694595e-05
 64 0.000303030014038 4.73484396935e-06
 128 0.000631809234619 4.93600964546e-06
 256 0.00112318992615 4.38746064901e-06
 512 0.00279307365417 5.45522198081e-06
 1024 0.00446391105652 4.35928814113e-06
 2048 0.00953102111816 4.65381890535e-06
 4096 0.0198018550873 4.83443727717e-06
 8192 0.175454854965 2.14178289752e-05
 16384 0.103327989578 6.30663998891e-06
 32768 0.191411972046 5.84142981097e-06
[snip]

Your ability to see quadratic behavoiur appears to be impaired by (1)
the low resolution and/or erratic nature of time.time() on your system
(2) stopping the experiment just before the results become interesting.

Try this with the latest *production* release (2.5):

C:\junkcat fookount.py
def foo(kcount):
s = ''
for i in xrange(kcount) :
s += str(i) + ' '

C:\junkfor /L %n in (10,1,19) do \python25\python -mtimeit -sfrom
fookount import foo foo(2**%n)

C:\junk\python25\python -mtimeit -sfrom fookount import foo
foo(2**10)
100 loops, best of 3: 1.1 msec per loop

C:\junk\python25\python -mtimeit -sfrom fookount import foo
foo(2**11)
100 loops, best of 3: 2.34 msec per loop

C:\junk\python25\python -mtimeit -sfrom fookount import foo
foo(2**12)
100 loops, best of 3: 4.79 msec per loop

C:\junk\python25\python -mtimeit -sfrom fookount import foo
foo(2**13)
10 loops, best of 3: 9.57 msec per loop

C:\junk\python25\python -mtimeit -sfrom fookount import foo
foo(2**14)
10 loops, best of 3: 19.8 msec per loop

C:\junk\python25\python -mtimeit -sfrom fookount import foo
foo(2**15)
10 loops, best of 3: 40.7 msec per loop

C:\junk\python25\python -mtimeit -sfrom fookount import foo
foo(2**16)
10 loops, best of 3: 82.1 msec per loop

C:\junk\python25\python -mtimeit -sfrom fookount import foo
foo(2**17)
10 loops, best of 3: 242 msec per loop

C:\junk\python25\python -mtimeit -sfrom fookount import foo
foo(2**18)
10 loops, best of 3: 886 msec per loop

C:\junk\python25\python -mtimeit -sfrom fookount import foo
foo(2**19)
10 loops, best of 3: 3.21 sec per loop

Cheers,
John

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


Anyone has a nice view_var procedure ?

2007-01-15 Thread Stef Mientki
hello,

Is there some handy/ nice manner to view the properties of some variable ?
As a newbie, I often want to see want all the properties of a var,
and also some corner values (large arrays) etc.

Probably it's not so difficult,
but I don't see how to distinguish for example between a string and an 
array. An array has a shape, a string not etc.


thanks,
Stef Mientki
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Newbie - converting csv files to arrays in NumPy - Matlab vs. Numpy comparison

2007-01-15 Thread Travis E. Oliphant
oyekomova wrote:
 Thanks to everyone for their excellent suggestions. I was able to
 acheive the following results with all your suggestions. However, I am
 unable to cross file size of 6 million rows. I would appreciate any
 helpful suggestions on avoiding memory errors. None of the solutions
 posted was able to cross this limit.

Did you try using numpy.fromfile ?

This will not require you to allocate more memory than needed.   If you 
specify a count, it will also not have to re-allocate memory in blocks 
as the array size grows.

It's limitation is that it is not a very sophisticated csv reader (it 
only understands a single separator (plus line-feeds are typically seen 
as a separator).

-Travis

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


Re: Maths error

2007-01-15 Thread Rhamphoryncus
Nick Maclaren wrote:
 The problem with it is that it is an unrealistically pessimal model,
 and there are huge classes of algorithm that it can't handle at all;
 anything involving iterative convergence for a start.  It has been
 around for yonks (I first dabbled with it 30+ years ago), and it has
 never reached viability for most real applications.  In 30 years, it
 has got almost nowhere.

 Don't confuse interval methods with interval arithmetic, because you
 don't need the latter for the former, despite the claims that you do.

 | For people just getting into it, it can be shocking to realize just how
 | wide the interval can become after some computations.

 Yes.  Even when you can prove (mathematically) that the bounds are
 actually quite tight :-)

I've been experimenting with a fixed-point interval type in python.  I
expect many algorithms would require you to explicitly
round/collapse/whatever-term the interval as they go along, essentially
making it behave like a float.  Do you think it'd suitable for
general-use, assuming you didn't mind the explicit rounding?

Unfortunately I lack a math background, so it's unlikely to progress
past an experiment.

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


Re: Maths error

2007-01-15 Thread Nick Maclaren

In article [EMAIL PROTECTED],
Rhamphoryncus [EMAIL PROTECTED] writes:
| 
| I've been experimenting with a fixed-point interval type in python.  I
| expect many algorithms would require you to explicitly
| round/collapse/whatever-term the interval as they go along, essentially
| making it behave like a float.

Yes, quite.

| Do you think it'd suitable for
| general-use, assuming you didn't mind the explicit rounding?

I doubt it.  Sorry.

| Unfortunately I lack a math background, so it's unlikely to progress
| past an experiment.

As the same is true for what plenty of people have done, despite them
having good backgrounds in mathematics, don't feel inferior!


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


Re: Watch log

2007-01-15 Thread Bjoern Schliessmann
Salvatore Di Fazio wrote:

 I would like wait until a new line will be write in the file.
 
 Something like the watch cat Log command on Linux os.

Why not read the file continuously and only do something if a new
line is complete (i. e.  a newline char is detected)?

 How can I check the eof and restart the reading?

Why do you want to check for an EOF character?

Regards,


Björn

-- 
BOFH excuse #212:

Of course it doesn't work. We've performed a software upgrade.

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


Re: Watch log

2007-01-15 Thread Salvatore Di Fazio
Bjoern Schliessmann ha scritto:

 Why not read the file continuously and only do something if a new
 line is complete (i. e.  a newline char is detected)?

How can I read the file continuously?

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


Re: Conflicting needs for __init__ method

2007-01-15 Thread Ben Finney
[EMAIL PROTECTED] writes:

 Suppose you're writing a class Rational for rational numbers.  The
 __init__ function of such a class has two quite different roles to
 play.

That should be your first clue to question whether you're actually
needing separate functions, rather than trying to force one function
to do many different things.

 First, it's supposed to allow users of the class to create Rational
 instances; in this role, __init__ is quite a complex beast.

The __init__ function isn't the constructor you find in other
languages. Its only purpose is to initialise an already-created
instance, not make a new one.

 It needs to allow arguments of various types---a pair of integers, a
 single integer, another Rational instance, and perhaps floats, Decimal
 instances, and suitably formatted strings.  It has to validate the
 input and/or make sure that suitable exceptions are raised on invalid
 input.  And when initializing from a pair of integers---a numerator
 and denominator---it makes sense to normalize: divide both the
 numerator and denominator by their greatest common divisor and make
 sure that the denominator is positive.

All of this points to having a separate constructor function for each
of the inputs you want to handle.

 But __init__ also plays another role: it's going to be used by the
 other Rational arithmetic methods, like __add__ and __mul__, to
 return new Rational instances.

No, it won't; those methods won't use the __init__ method. They will
use a constructor, and __init__ is not a constructor (though it does
get *called by* the construction process).

 For this use, there's essentially no need for any of the above
 complications: it's easy and natural to arrange that the input to
 __init__ is always a valid, normalized pair of integers.

Therefore, make your __init__ handle just the default, natural case
you identify.

class Rational(object):
def __init__(self, numerator, denominator):
self.numerator = numerator
self.denominator = denominator

 So the question is: (how) do people reconcile these two quite
 different needs in one function?

By avoiding the tendency to crowd a single function with disparate
functionality. Every function should do one narrowly-defined task and
no more.

@classmethod
def from_string(input):
(n, d) = parse_elements_of_string_input(input)
return Rational(n, d)

@classmethod
def from_int(input):
return Rational(input, 1)

@classmethod
def from_rational(input):
(n, d) = (input.numerator, input.denominator)
return Rational(n, d)

def __add__(self, other):
result = perform_addition(self, other)
return result

def __sub__(self, other):
result = perform_subtraction(self, other)
return result

Put whatever you need to for 'parse_elements_of_string_input',
'perform_addition', 'perform_subtraction', etc; either the calculation
itself, if simple, or a call to a function that can contain the
complexity.

Use Python's exception system to avoid error-checking all over the
place; if there's a problem with the subtraction, for instance, let
the exception propagate up to the code that gave bad input.

The alternate constructors are decorated as '@classmethod' since they
won't be called as instance methods, but rather:

foo = Rational.from_string(355/113)
bar = Rational.from_int(17)
baz = Rational.from_rational(foo)

-- 
 \  If you can't beat them, arrange to have them beaten.  -- |
  `\ George Carlin |
_o__)  |
Ben Finney

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


ReportLab - Frames - Images

2007-01-15 Thread Chuck
I have been trying all day to get this to work. My complete code is
below. I can get my text into the PDF, I can get my image in the PDF.
What I can't get to work is frames so that the image (logo) appears to
the right of the text. The image always appears first and then the text
below on the next line.

Please help.


Chuck

*** CUT ***
from reportlab.pdfgen import *

from reportlab.platypus import *

from reportlab.lib.units import inch
from reportlab.platypus  import SimpleDocTemplate
from reportlab.platypus  import flowables
from reportlab.lib.enums import TA_LEFT, TA_RIGHT, TA_CENTER,
TA_JUSTIFY

from reportlab.lib.pagesizes import letter



#precalculate some basics
top_margin = letter[1] - inch
bottom_margin = inch
left_margin = inch
right_margin = letter[0] - inch
frame_width = right_margin - left_margin

def bill(canvas, doc):
canvas.saveState()
canvas.restoreState()

def run():
doc = []
from reportlab.lib.styles import ParagraphStyle
from reportlab.platypus import Image

pdf = SimpleDocTemplate('bill2.pdf', pagesize = letter)

#need a style
normal = ParagraphStyle('normal')

doc.append(Image(pic.jpg, 100, 71))  #Logo

para = Paragraph(Some text1, normal)
doc.append(para)
para = Paragraph(Some text2, normal)
doc.append(para)
para = Paragraph(Some text3, normal)
doc.append(para)
para = Paragraph(Some text4, normal)
doc.append(para)
para = Paragraph( , normal)
doc.append(para)
doc.append(HRFlowable(color=black, thickness=3, width=100%))


pdf.build(doc,bill)

run()
*** CUT ***

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


download win32file

2007-01-15 Thread jim-on-linux


Where can I download win32file / win32ui?

The links below are broken.  Mark Hammond should 
be made aware of this.


URL below has two links that send you no place
http://mail.python.org/pipermail/python-list/2002-October/167638.html


Links:
http://starship.python.net/crew/mhammond/win32/Downloads.html

http://starship.python.net/crew/mhammond/downloads/win32all-148.exe


Produce;

 The requested URL was not found on this server. 
The link on the referring page seems to be wrong 
or outdated. Please inform the author of that 
page about the error.

jim-on-linux



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


The curious behavior of integer objects

2007-01-15 Thread Jim B. Wilson
Am I nuts? Or only profoundly confused? I expected the this little script
to print 0:

class foo(int): 
  def __init__(self, value):
self = value  0xF

print foo(0x10)

Instead, it prints 16 (at least on python 2.4.4 (Linux) and 2.5 (Wine).

Jim Wilson
GNV, FL
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: download win32file

2007-01-15 Thread hg
jim-on-linux wrote:

 
 
 Where can I download win32file / win32ui?
 
 The links below are broken.  Mark Hammond should
 be made aware of this.
 
 
 URL below has two links that send you no place
 http://mail.python.org/pipermail/python-list/2002-October/167638.html
 
 
 Links:
 http://starship.python.net/crew/mhammond/win32/Downloads.html
 
 http://starship.python.net/crew/mhammond/downloads/win32all-148.exe
 
 
 Produce;
 
  The requested URL was not found on this server.
 The link on the referring page seems to be wrong
 or outdated. Please inform the author of that
 page about the error.
 
 jim-on-linux
Do you mean PyWin32 ?

http://sourceforge.net/projects/pywin32/

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


whats wrong with my reg expression ?

2007-01-15 Thread Gert Cuykens
 rex2=re.compile('^(?Pvalue[^]*)$',re.M)

  File /usr/lib/python2.5/re.py, line 180, in compile
return _compile(pattern, flags)
  File /usr/lib/python2.5/re.py, line 233, in _compile
raise error, v # invalid expression
sre_constants.error: unexpected end of regular expression

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


[ANN] Py2Py 0.0.1 - python code reformatter, initial dev release

2007-01-15 Thread Andrey Khavryuchenko
Folks,

We release development preview snapshot of Py2Py code reformatter [1].

It is a byproduct of the PyBeast project aimed to create the python
mutation tester.

Now Py2Py code reformatter ignores all comments and 80-char line length
requirement. Nevertheless, it produces the same AST as the original code.

The code is developed in a test-first manner and has 100% test coverage.

Feedback, criticism and bug reports are welcome.

Links: 
[1] http://trac.kds.com.ua/project/pybeast/  
[2] http://www.kds.com.ua/wp/2007/01/16/py2py-001-initial-development-snapshot/

-- 
Andrey V Khavryuchenko
Software Development Company http://www.kds.com.ua/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: whats wrong with my reg expression ?

2007-01-15 Thread James Stroud
Gert Cuykens wrote:
 rex2=re.compile('^(?Pvalue[^]*)$',re.M)
 
  File /usr/lib/python2.5/re.py, line 180, in compile
return _compile(pattern, flags)
  File /usr/lib/python2.5/re.py, line 233, in _compile
raise error, v # invalid expression
 sre_constants.error: unexpected end of regular expression
 
 ?
You probably want

rex2=re.compile('^(?Pvalue[\^]*)$',re.M)

Because [] is a bracketed group and the ^ within a bracketed group is a 
negation, but you have negated nothing before closing the group.
Alternatively:

rex2=re.compile('^(?Pvalue\^*)$',re.M)

Would have the same meaning, avoiding the bracketed group altogether.

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


Re: The curious behavior of integer objects

2007-01-15 Thread Calvin Spealman
As it turns out, this has little to do with integers and the
operations you are trying to do on them. I'll explain in more detail.

Integers are immutable, which you may already know. This presents a
problem with subclassing them and using the usual special method
__init__, because the int object has already been created by this
point and can not change. Another special method, __new__, is called
passing the class object itself (foo, in this case) for the first
argument (traditionally named cls, instead of self). The return of
this should be an integer which will be the value of your new foo
int-subclass.

The following will do as you expected your own example to do.

class foo(int):
def __new__(cls, value):
return value  0xF

assert foo(0x10) == 0  # Assertions are much better tests than prints :-)

On 1/15/07, Jim B. Wilson [EMAIL PROTECTED] wrote:
 Am I nuts? Or only profoundly confused? I expected the this little script
 to print 0:

 class foo(int):
   def __init__(self, value):
 self = value  0xF

 print foo(0x10)

 Instead, it prints 16 (at least on python 2.4.4 (Linux) and 2.5 (Wine).

 Jim Wilson
 GNV, FL
 --
 http://mail.python.org/mailman/listinfo/python-list



-- 
Read my blog! I depend on your acceptance of my opinion! I am interesting!
http://ironfroggy-code.blogspot.com/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: The curious behavior of integer objects

2007-01-15 Thread Robert Kern
Jim B. Wilson wrote:
 Am I nuts? Or only profoundly confused? I expected the this little script
 to print 0:
 
 class foo(int): 
   def __init__(self, value):
 self = value  0xF

That statement only rebinds the local name self to something else. It does not
modify the object at all or change the result of instantiating foo(). You need
to override __new__ to get the behavior that you want.

  http://www.python.org/download/releases/2.2.3/descrintro/#__new__

-- 
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: The curious behavior of integer objects

2007-01-15 Thread Gabriel Genellina

At Monday 15/1/2007 19:28, Jim B. Wilson wrote:


Am I nuts? Or only profoundly confused? I expected the this little script
to print 0:

class foo(int):
  def __init__(self, value):
self = value  0xF

print foo(0x10)

Instead, it prints 16 (at least on python 2.4.4 (Linux) and 2.5 (Wine).


Integers are immutable. Insert a print statement and you'll see your 
__init__ is never called. Anyway, what would you expect from self = 
something?

Use __new__ instead:

py class foo(int):
...   def __new__(cls, value):
... return int(value  0xF)
...
py foo(1)
1
py foo(0x10)
0

See Special method names inside the Python Reference Manual.


--
Gabriel Genellina
Softlab SRL 







__ 
Preguntá. Respondé. Descubrí. 
Todo lo que querías saber, y lo que ni imaginabas, 
está en Yahoo! Respuestas (Beta). 
¡Probalo ya! 
http://www.yahoo.com.ar/respuestas 

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

Re: download win32file

2007-01-15 Thread jim-on-linux
On Monday 15 January 2007 10:37, hg wrote:
 jim-on-linux wrote:
  Where can I download win32file / win32ui?
 
  The links below are broken.  Mark Hammond
  should be made aware of this.
 
 
  URL below has two links that send you no
  place
  http://mail.python.org/pipermail/python-list/
 2002-October/167638.html
 
 
  Links:
  http://starship.python.net/crew/mhammond/win3
 2/Downloads.html
 
  http://starship.python.net/crew/mhammond/down
 loads/win32all-148.exe
 
 
  Produce;
 
   The requested URL was not found on this
  server. The link on the referring page seems
  to be wrong or outdated. Please inform the
  author of that page about the error.
 
  jim-on-linux

 Do you mean PyWin32 ?

?? Do I have to download pywin32 to get win32ui, 
or win32file, or win32api


 http://sourceforge.net/projects/pywin32/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: whats wrong with my reg expression ?

2007-01-15 Thread Gabriel Genellina

At Monday 15/1/2007 19:41, Gert Cuykens wrote:


rex2=re.compile('^(?Pvalue[^]*)$',re.M)


[^set-of-forbidden-characters]


--
Gabriel Genellina
Softlab SRL 







__ 
Preguntá. Respondé. Descubrí. 
Todo lo que querías saber, y lo que ni imaginabas, 
está en Yahoo! Respuestas (Beta). 
¡Probalo ya! 
http://www.yahoo.com.ar/respuestas 

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

Re: download win32file

2007-01-15 Thread Bill Tydeman



?? Do I have to download pywin32 to get win32ui,
or win32file, or win32api




Yes

--
There is no reason for any individual to have a computer in his home.
   Ken Olsen, President, Digital Equipment, 1977
   US computer engineer  industrialist (1926 - )
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: download win32file

2007-01-15 Thread jim-on-linux
On Monday 15 January 2007 18:02, Bill Tydeman 
wrote:
  ?? Do I have to download pywin32 to get
  win32ui, or win32file, or win32api

 Yes
Got it.
Thank you.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Anyone has a nice view_var procedure ?

2007-01-15 Thread Gabriel Genellina

At Monday 15/1/2007 17:45, Stef Mientki wrote:


Is there some handy/ nice manner to view the properties of some variable ?
As a newbie, I often want to see want all the properties of a var,
and also some corner values (large arrays) etc.


You can try dir(x), vars(x). If you want a nice print, see the pprint module.

py import csv
py x = csv.DictReader('') # a bogus object
py x
csv.DictReader instance at 0x00BC79B8
py dir(x)
['__doc__', '__init__', '__iter__', '__module__', 'fieldnames', 
'next', 'reader'

, 'restkey', 'restval']
py vars(x)
{'restkey': None, 'restval': None, 'fieldnames': None, 'reader': 
_csv.reader ob

ject at 0x00BC98B8}
py from pprint import pprint
py pprint(vars(x))
{'fieldnames': None,
 'reader': _csv.reader object at 0x00BC98B8,
 'restkey': None,
 'restval': None}
py


Probably it's not so difficult,
but I don't see how to distinguish for example between a string and an
array. An array has a shape, a string not etc.


Yes, strings share a lot of functionality with other sequence types: 
[], len, in, etc. You can test if an object is a string using 
isinstance(obj, str). If you want to include unicode objects too, use 
isinstance(obj, basestring).



--
Gabriel Genellina
Softlab SRL 







__ 
Preguntá. Respondé. Descubrí. 
Todo lo que querías saber, y lo que ni imaginabas, 
está en Yahoo! Respuestas (Beta). 
¡Probalo ya! 
http://www.yahoo.com.ar/respuestas 

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

Re: can't get import to work!

2007-01-15 Thread Gabriel Genellina

At Monday 15/1/2007 14:35, [EMAIL PROTECTED] wrote:


from just.for.fun  import Fubar
This doesn't work.  The following error is displayed:
ImportError: No module named  for


You can't have a module named for, it's a reserved word. Try using 
For instead (or any other legal name!).



--
Gabriel Genellina
Softlab SRL 







__ 
Preguntá. Respondé. Descubrí. 
Todo lo que querías saber, y lo que ni imaginabas, 
está en Yahoo! Respuestas (Beta). 
¡Probalo ya! 
http://www.yahoo.com.ar/respuestas 

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

Re: ReportLab - Frames - Images

2007-01-15 Thread Robin Becker
Chuck wrote:
 I have been trying all day to get this to work. My complete code is
 below. I can get my text into the PDF, I can get my image in the PDF.
 What I can't get to work is frames so that the image (logo) appears to
 the right of the text. The image always appears first and then the text
 below on the next line.
 
 Please help.


you'll get more help at the reportlab users list (see

http://two.pairlist.net/pipermail/reportlab-users/ )

Anyhow I got some output from your script, by making two changes


 *** CUT ***
 from reportlab.pdfgen import *
..
 
   pdf = SimpleDocTemplate('bill2.pdf', pagesize = letter)
 
   #need a style
   normal = ParagraphStyle('normal')
 
   doc.append(Image(pic.jpg, 100, 71))  #Logo
 
   para = Paragraph(Some text1, normal)
   doc.append(para)
   para = Paragraph(Some text2, normal)
   doc.append(para)
   para = Paragraph(Some text3, normal)
   doc.append(para)
   para = Paragraph(Some text4, normal)
   doc.append(para)
   para = Paragraph( , normal)
   doc.append(para)
   doc.append(HRFlowable(color=black, thickness=3, width=100%))

change(1)
doc.append(flowables.HRFlowable(color=black, thickness=3, 
width=100%))
 
 
   pdf.build(doc,bill)

change(2)

pdf.build(doc)

 
 run()
 *** CUT ***
 


I also had to change the name of the image to one on my system.

Hope this helps
-- 
Robin Becker
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: whats wrong with my reg expression ?

2007-01-15 Thread Gert Cuykens
thx

PS i also cant figure out what is wrong here ?

rex=re.compile('^(?Pvalue[^]*)$',re.M)
for v in l:
v=rex.match(v).group('value')
v=v.replace('','')
return(l)

v=rex.match(v).group('value')
AttributeError: 'NoneType' object has no attribute 'group'
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: download win32file

2007-01-15 Thread hg
jim-on-linux wrote:

 On Monday 15 January 2007 10:37, hg wrote:
 jim-on-linux wrote:
  Where can I download win32file / win32ui?
 
  The links below are broken.  Mark Hammond
  should be made aware of this.
 
 
  URL below has two links that send you no
  place
  http://mail.python.org/pipermail/python-list/
 2002-October/167638.html
 
 
  Links:
  http://starship.python.net/crew/mhammond/win3
 2/Downloads.html
 
  http://starship.python.net/crew/mhammond/down
 loads/win32all-148.exe
 
 
  Produce;
 
   The requested URL was not found on this
  server. The link on the referring page seems
  to be wrong or outdated. Please inform the
  author of that page about the error.
 
  jim-on-linux

 Do you mean PyWin32 ?
 
 ?? Do I have to download pywin32 to get win32ui,
 or win32file, or win32api
 

 http://sourceforge.net/projects/pywin32/

To my knowledge, yes.

hg

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


Re: Anyone has a nice view_var procedure ?

2007-01-15 Thread Adam

Stef Mientki wrote:

 hello,

 Is there some handy/ nice manner to view the properties of some variable ?
 As a newbie, I often want to see want all the properties of a var,
 and also some corner values (large arrays) etc.

 Probably it's not so difficult,
 but I don't see how to distinguish for example between a string and an
 array. An array has a shape, a string not etc.


 thanks,
 Stef Mientki

I am also a newbie so if this is not what you want I can't give much
more as of yet.

You can use type() to check what a Variable is. Usage:
#-Python Code-
 aVar = [zero, 1, float(2)]
 type(aVar)
type 'list'
 type(aVar[0])
type 'str'
 type(aVar[1])
type 'int'
 type(aVar[2])
type 'float'
 if type(aVar[1]) == int:
print test

test
#-End Code---


There are also  function like len(). Usage:
#-Python Code-
 len(aVar)
3
 len(aVar[0])
4
#-End Code---

Hope this helps.
Adam

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


Cygwin Python/PIL TCL/TK fork rebase solution

2007-01-15 Thread Ross Patterson
I recently was forced to build PIL under Cygwin Python 2.4.3 and ran
into the Cygwin fork/rebase issue with TCL/TK yet again.
Unfortunately, none of the rebase workarounds I found through my
copious STFWing worked this time.

Through trial and error I found that the following worked:

rebase -b 0x10 /bin/tk84.dll

I post this here mostly for documenatation so that others can find a
more current solution than what's already available through STFWing.

But I'm also curious about rebase and to understand more about how one
chooses what base address and offset to use.  In my trial and error I
found that the default base address of 0x7000 didn't work, nor did
the value of 0x6800 I found through my STFWing.  I found the value
of 0x10 by incrementing from 0x1000 to 0x2000 to
0x3000 and so on until I found one that worked.

So if anyone wants to explain to me how to choose base address and
offset values, that would be cool.

Ross

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


Re: Problem with win32pipe.popen2

2007-01-15 Thread Gabriel Genellina

At Monday 15/1/2007 07:24, diego wrote:


I'm trying to understand how popen2 works. Found in this group, that
popen2.popen2 can cause trouble so i chose win32pipe.popen2.

have a look a the listing of 2 files:
ekmain.py:
**
import win32pipe

(stdin1, stdout1) = win32pipe.popen2(test1.py)
stdin1.write(1\n)
print stdout1.readlines() # This will print the result.
**

test1.py:
**
a=raw_input(a=)
print ***a=,a
print finished!
**


i do not understand, why ekmain.py produces only following output:
['a=']

why is the stdin1.write(1\n) command ignored?


Using popen4 instead of popen2 we get stderr too, and there is a traceback:
['a=Traceback (most recent call last):\n', '  File 
C:\\TEMP\\test1.py, line 1,

 in ?\n', 'a=raw_input(a=)\n', 'EOFError: EOF when reading a line\n']

Using python test1.py as the popen4 argument we get the expected result:

C:\TEMPmain.py
['a=***a= 1\n', 'finished!\n']

(I don't know why)


p.s.: i working with python 2.3 on win2000.


I used 2.4 on XPSP2.


--
Gabriel Genellina
Softlab SRL 







__ 
Preguntá. Respondé. Descubrí. 
Todo lo que querías saber, y lo que ni imaginabas, 
está en Yahoo! Respuestas (Beta). 
¡Probalo ya! 
http://www.yahoo.com.ar/respuestas 

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

Re: Conflicting needs for __init__ method

2007-01-15 Thread fumanchu
Steven D'Aprano wrote:
  class Rational(object):
  def __init__(self, numerator, denominator):
  print lots of heavy processing here...
  # processing ints, floats, strings, special case arguments,
  # blah blah blah...
  self.numerator = numerator
  self.denominator = denominator
  def __copy__(self):
  cls = self.__class__
  obj = cls.__new__(cls)
  obj.numerator = self.numerator
  obj.denominator = self.denominator
  return obj
  def __neg__(self):
  obj = self.__copy__()
  obj.numerator *= -1
  return obj


 Here's a variation on that which is perhaps better suited for objects with
 lots of attributes:

 def __copy__(self):
 cls = self.__class__
 obj = cls.__new__(cls)
 obj.__dict__.update(self.__dict__) # copy everything quickly
 return obj

I recently had to do something similar for my ORM, where a
user-instantiated object gets expensive default values, but the back
end just overwrites those defaults when resurrecting objects, so it
shouldn't pay the price. However (and this is the tricky part), I also
wanted to allow subclasses to extend the __init__ method, so just using
cls.__new__(cls) didn't quite go far enough. Here's what I ended up
with [1]:

def __init__(self, **kwargs):
self.sandbox = None

cls = self.__class__
if self._zombie:
# This is pretty tricky, and deserves some detailed
explanation.
# When normal code creates an instance of this class, then
the
# expensive setting of defaults below is performed
automatically.
# However, when a DB recalls a Unit, we have its entire
properties
# dict already and should skip defaults in the interest of
speed.
# Therefore, a DB which recalls a Unit can write:
# unit = UnitSubClass.__new__(UnitSubClass)
# unit._zombie = True
# unit.__init__()
# unit._properties = {...}
# instead of:
# unit = UnitSubClass()
# unit._properties = {...}
# If done this way, the caller must make CERTAIN that all
of
# the values in _properties are set, and must call
cleanse().
self._properties = dict.fromkeys(cls.properties, None)
else:
# Copy the class properties into self._properties,
# setting each value to the UnitProperty.default.
self._properties = dict([(k, getattr(cls, k).default)
 for k in cls.properties])

# Make sure we cleanse before assigning properties from
kwargs,
# or the new unit won't get saved if there are no further
changes.
self.cleanse()

for k, v in kwargs.iteritems():
setattr(self, k, v)

The _zombie argument is therefore a flag which allows you to keep the
initialization code inside __init__ (rather than repeating it inside
every method).


Robert Brewer
System Architect
Amor Ministries
[EMAIL PROTECTED]

[1] http://projects.amor.org/dejavu/browser/trunk/units.py#l552

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


Re: whats wrong with my reg expression ?

2007-01-15 Thread Gabriel Genellina

At Monday 15/1/2007 20:43, Gert Cuykens wrote:


PS i also cant figure out what is wrong here ?

rex=re.compile('^(?Pvalue[^]*)$',re.M)
for v in l:
v=rex.match(v).group('value')
v=v.replace('','')
return(l)

v=rex.match(v).group('value')
AttributeError: 'NoneType' object has no attribute 'group'


match() returns None when there is no match, so you have to split 
that in two steps:


m = rex.match(v)
if m:
v = m.group('value')
else:
# no match found!


--
Gabriel Genellina
Softlab SRL 







__ 
Preguntá. Respondé. Descubrí. 
Todo lo que querías saber, y lo que ni imaginabas, 
está en Yahoo! Respuestas (Beta). 
¡Probalo ya! 
http://www.yahoo.com.ar/respuestas 

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

Re: ReportLab - Frames - Images

2007-01-15 Thread Chuck
Thanks for the help. I made you changes but it still puts the picture
above the text, not beside the text.

I also found a user group at
http://news.gmane.org/gmane.comp.python.reportlab.user . It may be the
same. I have now posted there.

Chuck

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


Re: How naive is Python?

2007-01-15 Thread John Bauman
[EMAIL PROTECTED] wrote:
 Actually, it isn't until I work my way back to 2.3 that I start to see
 quadratic behavior:

Yes, that's because the behavior was changed for 2.4, so it wouldn't be 
quadratic in this case.
-- 
http://mail.python.org/mailman/listinfo/python-list


Can't find module named 'svn' in python

2007-01-15 Thread [EMAIL PROTECTED]
Hi,

i have a simple test which tries to load 'svn' moddule.

# python -c from svn import client
Traceback (most recent call last):
 File string, line 1, in ?
ImportError: No module named svn

I have checked I have sub-directories 'libsvn', 'svn' under
/usr/local/lib/svn-python/

 cd /usr/local/lib/svn-python/
[EMAIL PROTECTED] svn-python]# ls
libsvn  svn

But python still can't find it. Please tell me what am I missing. I
appreciate your help.

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


Re: Watch log

2007-01-15 Thread Larry Bates
Salvatore Di Fazio wrote:
 Hi guys,
 I've an application that writes a log file.
 I need to write an application with python that will read this file.
 
 I would like wait until a new line will be write in the file.
 
 Something like the watch cat Log command on Linux os.
 
 How can I check the eof and restart the reading?
 
You didn't provide much info so here goes.  If you use the
logger module built into Python you can set up a logger that
uses sockets.  Have your program log to a socket and have the
other program read from the socket.  That way you will always
have the latest log entries in the monitor program.

If you can't control the program that writes the log file,
have your monitoring program look for change in the length
of the logfile (you can use the os.stat module for this).
When it changes, open the file, seek to the old length and
read bytes up to the new length and close the logfile.
What is read will be the new log entry (or entries).
Reset the logfile length high water mark and loop.

Hope information helps.

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


Re: Anyone has a nice view_var procedure ?

2007-01-15 Thread Larry Bates
Stef Mientki wrote:
 hello,
 
 Is there some handy/ nice manner to view the properties of some variable ?
 As a newbie, I often want to see want all the properties of a var,
 and also some corner values (large arrays) etc.
 
 Probably it's not so difficult,
 but I don't see how to distinguish for example between a string and an
 array. An array has a shape, a string not etc.
 
 
 thanks,
 Stef Mientki

Others have given some suggestions, but I thought I'd put in my
thoughts also.  When I first started using Python I was looking for
exactly what you describe.  After using a while, you begin to understand
that the objects in Python can be so complex (lists of dictionaries that
contain lists and other dictionaries, lists of class instances that can
contain other class instances, that can contain, you get the picture).
You have to begin to think about navigating through this by using dir(),
vars() and pprint.pprint().  Unlike older programming languages there is
no limit to how you can mix/match values within an object.

Also in standard Python lists (arrays?) don't have shape (there are add
on modules that give you this type of feature).  Everything is a
collection of objects.

class foo:
def __init__(self):
self.x=1
self.y=2

l=[[1,2,3], 'test', 6, 3.14159, {'a':1, 'b':2}, foo()]

a list with:
a list as first element
a string as the second element
an integer as the third element
a float as the third element
a dictionary as the fourth element
a class instance as the fifth element

The tutorial is a good place to start if you haven't already looked at
it.

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


for v in l:

2007-01-15 Thread Gert Cuykens
is there a other way then this to loop trough a list and change the values

i=-1
for v in l:
i=i+1
l[i]=v+x

something like

for v in l:
l[v]=l[v]+x
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: for v in l:

2007-01-15 Thread Nanjundi
Try:
l = [i+x for i in l]
OR
l = map(lambda i: i+x, l)

-N

Gert Cuykens wrote:
 is there a other way then this to loop trough a list and change the values

 i=-1
 for v in l:
 i=i+1
 l[i]=v+x

 something like
 
 for v in l:
 l[v]=l[v]+x

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


Re: Can't find module named 'svn' in python

2007-01-15 Thread Nanjundi
My first thought:
Check if you have /usr/local/lib/svn-python/ in your PYTHONPATH
environment variable (echo $PYTHONPATH).

If its missing, set it in the environment.
export PYTHONPATH=$PYTHONPATH:/usr/local/lib/svn-python

-N

[EMAIL PROTECTED] wrote:
 Hi,

 i have a simple test which tries to load 'svn' moddule.

 # python -c from svn import client
 Traceback (most recent call last):
  File string, line 1, in ?
 ImportError: No module named svn

 I have checked I have sub-directories 'libsvn', 'svn' under
 /usr/local/lib/svn-python/

  cd /usr/local/lib/svn-python/
 [EMAIL PROTECTED] svn-python]# ls
 libsvn  svn

 But python still can't find it. Please tell me what am I missing. I
 appreciate your help.

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


  1   2   >