Re: How to determine that if a folder is empty?

2005-08-09 Thread Peter Hansen
could ildg wrote:
> On 8/8/05, Peter Hansen <[EMAIL PROTECTED]> wrote:
>>could ildg wrote:
>>>I want to check if a folder named "foldername" is empty.
>>>I use os.listdir(foldername)==[] to do this,
>>>but it will be very slow if the folder has a lot of sub-files.
>>>Is there any efficient ways to do this?
>>
>>I'm just curious to know under what circumstances where it's important
>>to know whether a directory is empty it's also important that the
>>operation occur with lightning speed...
> 
> I want to know this because I want to zip a directory and all of its
> sub-files and sub-directories to a zip file. zipfile module of python
> will not automatically include the empty directories, so I have to
> check if a dir is empty and do this manually. I did this with java,
> it's very fast, but when I do this with python. I use the code to
> backup a directory every morning after I get up. It is not import if
> it's fast or not. I just want to know whether their is better
> solutions.

Thanks for the reply.  I'll only point out, in case it's not now 
obvious, that in a situation where you are already going to be 
compressing (or have just compressed) a potentially large number of 
files in a potentially not empty subdirectory, the extremely slight 
extra cost of another os.listdir() will *never* be seen in the overall 
runtime of the code.

Note also that any decent OS will have some sort of caching of directory 
info going on, so os.listdir() will probably do very little actual disk 
access and you shouldn't bother trying to optimize it away.

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


.pth files

2005-08-09 Thread Sylvain Thenault
Hi there !

I've some questions regarding pth files (which btw are undocumented in the
python reference, is this intentional ?)

I thought that I could use a .pth file to be able to import zope products
from both INSTANCE_HOME/Products and ZOPE_HOME/lib/python/Products from
outside zope:


[EMAIL PROTECTED]:~$ cat cvs_work/Products.pth 
/home/syt/local/Zope-2.8.1-b1/Products
/home/syt/local/Zope-2.8.1-b1/lib/python/Products
[EMAIL PROTECTED]:~$ 
[EMAIL PROTECTED]:~$ python
Python 2.3.5 (#2, Jun 19 2005, 13:28:00) 
[GCC 3.3.6 (Debian 1:3.3.6-6)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys
>>> print sys.path
['', '/home/syt/cvs_work', '/home/syt/cvs_work/prive/soft', 
 '/home/syt/local/lib/python2.3/site-packages',
 '/home/syt/local/lib/python', '/usr/lib/python23.zip',
 '/usr/lib/python2.3', '/usr/lib/python2.3/plat-linux2',
 '/usr/lib/python2.3/lib-tk', '/usr/lib/python2.3/lib-dynload',
 '/usr/local/lib/python2.3/site-packages',
 '/usr/lib/python2.3/site-packages',
 '/usr/lib/python2.3/site-packages/Numeric',
 '/usr/lib/python2.3/site-packages/PIL',
 '/usr/lib/python2.3/site-packages/gtk-2.0',
 '/usr/lib/python2.3/site-packages/vtk_python', '/usr/lib/site-python']

But as you can see, 
1. the Products.pth file isn't considered at all, while for example
   PIL.pht in the site-packages is correctly detected
2. I'm not even sure that I can put several paths in a .pth file

Is there a restriction on .pth location ? Is it possible to have multiple
path in a pth file ?

-- 
Sylvain Thénault   LOGILAB, Paris (France).

http://www.logilab.com   http://www.logilab.fr  http://www.logilab.org


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


Re: .pth files

2005-08-09 Thread Adriano Varoli Piazza
Sylvain Thenault ha scritto:
> Hi there !
> 
> I've some questions regarding pth files (which btw are undocumented in the
> python reference, is this intentional ?)
> 
> I thought that I could use a .pth file to be able to import zope products
> from both INSTANCE_HOME/Products and ZOPE_HOME/lib/python/Products from
> outside zope:
> 
> 
> [EMAIL PROTECTED]:~$ cat cvs_work/Products.pth 
> /home/syt/local/Zope-2.8.1-b1/Products
> /home/syt/local/Zope-2.8.1-b1/lib/python/Products
> [EMAIL PROTECTED]:~$ 
> [EMAIL PROTECTED]:~$ python
> Python 2.3.5 (#2, Jun 19 2005, 13:28:00) 
> [GCC 3.3.6 (Debian 1:3.3.6-6)] on linux2
> Type "help", "copyright", "credits" or "license" for more information.
> 
import sys
print sys.path
> 
> ['', '/home/syt/cvs_work', '/home/syt/cvs_work/prive/soft', 
>  '/home/syt/local/lib/python2.3/site-packages',
>  '/home/syt/local/lib/python', '/usr/lib/python23.zip',
>  '/usr/lib/python2.3', '/usr/lib/python2.3/plat-linux2',
>  '/usr/lib/python2.3/lib-tk', '/usr/lib/python2.3/lib-dynload',
>  '/usr/local/lib/python2.3/site-packages',
>  '/usr/lib/python2.3/site-packages',
>  '/usr/lib/python2.3/site-packages/Numeric',
>  '/usr/lib/python2.3/site-packages/PIL',
>  '/usr/lib/python2.3/site-packages/gtk-2.0',
>  '/usr/lib/python2.3/site-packages/vtk_python', '/usr/lib/site-python']
> 
> But as you can see, 
> 1. the Products.pth file isn't considered at all, while for example
>PIL.pht in the site-packages is correctly detected
> 2. I'm not even sure that I can put several paths in a .pth file
> 
> Is there a restriction on .pth location ? Is it possible to have multiple
> path in a pth file ?
> 

 From Learning Python, 2nd Ed:
"a relatively new feature of Python allows users to add valid 
directories to the module search path by simply listing them, one per 
line, in a text file whose name ends in a .pth suffix.

See also the docs for the site module in the Python Library reference.

-- 
Adriano Varoli Piazza
The Inside Out: http://moranar.com.ar
MSN: [EMAIL PROTECTED]
ICQ: 4410132
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: issues with doctest and threads

2005-08-09 Thread Michele Simionato
Thank you for your replies Jeff & Tim. The snippet I submitted is
unfortunate,
since I was writing an example (for a Python course I am going to give
in
September) to show that you cannot reliably assume that you will get
exactly 9 dots, because of the limitations of 'sleep'. Mindlessly, I
have
cut & pasted that snippet, but my real question was not "how many dots
I get", it was:
"why the error message talks about 'thread' not being in the globals?"
It's true that I can avoid it with a thread.join() (which I had
forgot),
but still I really cannot understand the reason for such message. Why
it
is so misleading? Can something be done about it?
TIA,
  Michele Simionato

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


Re: .pth files

2005-08-09 Thread Sylvain Thenault
On Tue, 09 Aug 2005 09:37:47 +, Adriano Varoli Piazza wrote:

> Sylvain Thenault ha scritto:
>> Hi there !
>> 
>> I've some questions regarding pth files (which btw are undocumented in
>> the python reference, is this intentional ?)
>> 
>> I thought that I could use a .pth file to be able to import zope
>> products from both INSTANCE_HOME/Products and
>> ZOPE_HOME/lib/python/Products from outside zope:
>> 
>> 
>> [EMAIL PROTECTED]:~$ cat cvs_work/Products.pth
>> /home/syt/local/Zope-2.8.1-b1/Products
>> /home/syt/local/Zope-2.8.1-b1/lib/python/Products [EMAIL PROTECTED]:~$
>> [EMAIL PROTECTED]:~$ python
>> Python 2.3.5 (#2, Jun 19 2005, 13:28:00) [GCC 3.3.6 (Debian 1:3.3.6-6)]
>> on linux2 Type "help", "copyright", "credits" or "license" for more
>> information.
>> 
>import sys
>print sys.path
>> 
>> ['', '/home/syt/cvs_work', '/home/syt/cvs_work/prive/soft',
>>  '/home/syt/local/lib/python2.3/site-packages',
>>  '/home/syt/local/lib/python', '/usr/lib/python23.zip',
>>  '/usr/lib/python2.3', '/usr/lib/python2.3/plat-linux2',
>>  '/usr/lib/python2.3/lib-tk', '/usr/lib/python2.3/lib-dynload',
>>  '/usr/local/lib/python2.3/site-packages',
>>  '/usr/lib/python2.3/site-packages',
>>  '/usr/lib/python2.3/site-packages/Numeric',
>>  '/usr/lib/python2.3/site-packages/PIL',
>>  '/usr/lib/python2.3/site-packages/gtk-2.0',
>>  '/usr/lib/python2.3/site-packages/vtk_python', '/usr/lib/site-python']
>> 
>> But as you can see,
>> 1. the Products.pth file isn't considered at all, while for example
>>PIL.pht in the site-packages is correctly detected
>> 2. I'm not even sure that I can put several paths in a .pth file
>> 
>> Is there a restriction on .pth location ? Is it possible to have
>> multiple path in a pth file ?
>> 
>> 
>  From Learning Python, 2nd Ed:
> "a relatively new feature of Python allows users to add valid directories
> to the module search path by simply listing them, one per line, in a text
> file whose name ends in a .pth suffix.
> 
> See also the docs for the site module in the Python Library reference.

ha, so that's where it's documented ! 
so answer are:
1. Products.pth are only considered in standard site-packages and
   site-python directories
2. yes, it's possible

Now, the question become: why can't we use pth files in other path
specified by the PYTHONPATH environement variable ?

-- 
Sylvain Thénault   LOGILAB, Paris (France).

http://www.logilab.com   http://www.logilab.fr  http://www.logilab.org


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


Re: python for microcontrollers

2005-08-09 Thread Damir Hakimov
David Cuthbert wrote:

>Paul Rubin wrote:
>  
>
>>I don't think you want to do this.  Runtime type tags and the overhead
>>of checking them on every operation will kill you all by themselves.
>>Processors like that haven't been used much as Lisp targets either,
>>for the same reasons.  Pick a different language.
>>
>>
>
>I was thinking that you could avoid this by adding some type inference 
>to Python and/or reducing everything to two basic types (strings and 
>ints), but the end result would require a lot of work and not look much 
>like Python.
>
>  
>
Use Fort.


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


Re: .pth files

2005-08-09 Thread Richie Hindle

[Sylvain]
> I've some questions regarding pth files (which btw are undocumented in the
> python reference, is this intentional ?)

http://google.com/search?q=site:docs.python.org%20pth

The first hit explains how .pth files work (although it's the sort of
documentation that makes Xah Lee explode with fury).

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


Re: .pth files

2005-08-09 Thread Erik Max Francis
Richie Hindle wrote:

> http://google.com/search?q=site:docs.python.org%20pth
> 
> The first hit explains how .pth files work (although it's the sort of
> documentation that makes Xah Lee explode with fury).

That just makes it all the more delicious.

-- 
Erik Max Francis && [EMAIL PROTECTED] && http://www.alcyone.com/max/
San Jose, CA, USA && 37 20 N 121 53 W && AIM erikmaxfrancis
   There is another world, which is not of men.
   -- Li Bai
-- 
http://mail.python.org/mailman/listinfo/python-list


new python debugger

2005-08-09 Thread mrelectron
hi:

Nir Aides who wrote the rpdb debugger has enhanced it and stuck a
frontend on it whoo-hoo. it is fantastico! see and download it at
http://www.digitalpeers.com/pythondebugger/

cheers mark

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


Re: .pth files

2005-08-09 Thread Neil Benn
Sylvain Thenault wrote:

>On Tue, 09 Aug 2005 09:37:47 +, Adriano Varoli Piazza wrote:
>
>  
>
>>Sylvain Thenault ha scritto:
>>
>>
>>>Hi there !
>>>
>>>I've some questions regarding pth files (which btw are undocumented in
>>>the python reference, is this intentional ?)
>>>
>>>I thought that I could use a .pth file to be able to import zope
>>>products from both INSTANCE_HOME/Products and
>>>ZOPE_HOME/lib/python/Products from outside zope:
>>>
>>>
>>>[EMAIL PROTECTED]:~$ cat cvs_work/Products.pth
>>>/home/syt/local/Zope-2.8.1-b1/Products
>>>/home/syt/local/Zope-2.8.1-b1/lib/python/Products [EMAIL PROTECTED]:~$
>>>[EMAIL PROTECTED]:~$ python
>>>Python 2.3.5 (#2, Jun 19 2005, 13:28:00) [GCC 3.3.6 (Debian 1:3.3.6-6)]
>>>on linux2 Type "help", "copyright", "credits" or "license" for more
>>>information.
>>>
>>>  
>>>
>>import sys
>>print sys.path
>>
>>
>>>['', '/home/syt/cvs_work', '/home/syt/cvs_work/prive/soft',
>>> '/home/syt/local/lib/python2.3/site-packages',
>>> '/home/syt/local/lib/python', '/usr/lib/python23.zip',
>>> '/usr/lib/python2.3', '/usr/lib/python2.3/plat-linux2',
>>> '/usr/lib/python2.3/lib-tk', '/usr/lib/python2.3/lib-dynload',
>>> '/usr/local/lib/python2.3/site-packages',
>>> '/usr/lib/python2.3/site-packages',
>>> '/usr/lib/python2.3/site-packages/Numeric',
>>> '/usr/lib/python2.3/site-packages/PIL',
>>> '/usr/lib/python2.3/site-packages/gtk-2.0',
>>> '/usr/lib/python2.3/site-packages/vtk_python', '/usr/lib/site-python']
>>>
>>>But as you can see,
>>>1. the Products.pth file isn't considered at all, while for example
>>>   PIL.pht in the site-packages is correctly detected
>>>2. I'm not even sure that I can put several paths in a .pth file
>>>
>>>Is there a restriction on .pth location ? Is it possible to have
>>>multiple path in a pth file ?
>>>
>>>
>>>  
>>>
>> From Learning Python, 2nd Ed:
>>"a relatively new feature of Python allows users to add valid directories
>>to the module search path by simply listing them, one per line, in a text
>>file whose name ends in a .pth suffix.
>>
>>See also the docs for the site module in the Python Library reference.
>>
>>
>
>ha, so that's where it's documented ! 
>so answer are:
>1. Products.pth are only considered in standard site-packages and
>   site-python directories
>2. yes, it's possible
>
>Now, the question become: why can't we use pth files in other path
>specified by the PYTHONPATH environement variable ?
>
>  
>
Hello,

  I've been doing some work on that recently, if your do want to 
include .pth files specified by a different location then you have to do 
some work, here are a couple of solutions:

* Site.py is prompted to load a sitecustomise.py file which is
  located in the Lib directory - if it is there.  This file is
  automatically executed on the start up of python.  Here you can
  look for a command line argument (or a local config file) passed
  in - you can then go and find the .pth file yourself.  The code to
  pull in .pth stuff is located in the site.py file - you can import
  this function and use it but I don't do that for two reasons
  (instead I pull across my own copy - effectivly freezing that
  implementation):

 1. You are creating a circular reference
 2. I can find no docs or imformation about using the functions
in the site.py file so therefore I have to assume that the
functions in the site.py file are not designed to be used
this way and therefore shouldn't be relied upon to be stable
or even present across python releases (I'm a conservative
programmer.

   This however can be problematic if you are managing a large 
number of client installs as you will need to have a local file on the 
local box - thereby making upgrading the clients installs difficult.

* I created a python module which can receive command line arguments
  setting up site-package directories and pythonpath which executes
  as a file, this also receives an argument of which python file to
  execute after this.  This means that the file which does this work
  can be located anywhere (ie on your company server) - making
  release management easier.  However this solution requires more work.
* You could copy the java method using zip files with a manifest in
  the same way Java uses jar files - I say could because I havn't
  done this but it is the way I distribute Java apps - nice and
  clean, also installed my own JRE with my program - that way I have
  complete control (anyone that complains about using hard drive
  space can go back to using their ZX81 :-)) over my environment.


If you are not worried about managing the release stuff and 
sitecustomise works fine for you then this is the way to go as it is the 
simplest (less code means more reliable).  However be aware that the 
sitepackage directory on the python ins

Re: .pth files

2005-08-09 Thread Peter Hansen
Neil Benn wrote:
>* Site.py is prompted to load a sitecustomise.py file which is
>  located in the Lib directory - if it is there.  This file is
>  automatically executed on the start up of python.  Here you can
>  look for a command line argument (or a local config file) passed
>  in - you can then go and find the .pth file yourself.  The code to
>  pull in .pth stuff is located in the site.py file - you can import
>  this function and use it but I don't do that for two reasons
>  (instead I pull across my own copy - effectivly freezing that
>  implementation):
> 
> 1. You are creating a circular reference

The "import sitecustomize" stuff is placed effectively at the end of 
site.py, so it should be quite safe to "import site" from your 
sitecustomize.py file and use the functions there.

> 2. I can find no docs or imformation about using the functions
>in the site.py file so therefore I have to assume that the
>functions in the site.py file are not designed to be used
>this way and therefore shouldn't be relied upon to be stable
>or even present across python releases (I'm a conservative
>programmer.

While I can't fault your caution, we've been using a few things in 
site.py from sitecustomize for a while with no problems (across releases 
from Python 1.5.2 to Python 2.4).  The functions are documented in the 
site.py source itself, of course, at least in a cursory fashion, and 
while there have been changes over versions, I don't recall anything 
causing breakage.  Normally I'd quite agree about staying away, but for 
something like this (i.e. not a core part of an application, but 
something to set up the environment instead) I'd say "go for it".

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


Re: Point and click GUI builder for Python

2005-08-09 Thread Benji York
Madhusudan Singh wrote:
> Is there such a thing for python ? Like Qt Designer for instance ?

I've had great success with wxDesigner (http://www.roebling.de/).  It is 
a commercial product ($129 for a single license), but it does an 
exceptional job.
--
Benji York


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


Gotchas in user-space matplotlib install?

2005-08-09 Thread Matt Feinstein
Hi all--

I'm planning to try to do a completely local install of matplotlib (in
Fedora Core 1)-- the system administrator isn't going to stop me-- but
he isn't going to cooperate either. I've got the tarballs for python,
numeric, numarray, matplotlib,  ipython, wxpython and freetype-- which
I think covers the various pre-requisites and post-requisites. One
semi-obvious question is where to put the freetype library (the system
version in FC1 is not up to the required level)-- but I can only
wonder what other trouble I'm going to get into. Any advice before I
take the plunge would be appreciated. TIA...


Matt Feinstein

--
There is no virtue in believing something that can be proved to be true.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Point and click GUI builder for Python

2005-08-09 Thread Asbjørn Sæbø
Madhusudan Singh <[EMAIL PROTECTED]> writes:

> Is there such a thing for python ? Like Qt Designer for instance ?

Glade?


>From http://glade.gnome.org/ :
-
Glade is a free user interface builder for GTK+ and GNOME, released
under the GNU GPL License.

The user interfaces designed in Glade are saved as XML, and by using
the libglade library these can be loaded by applications dynamically
as needed. (Glade can also generate C code, though this isn't
recommended for large applications.)

By using libglade, Glade XML files can be used in numerous programming
languages including C, C++, Java, Perl, Python, C#, Pike, Ruby,
Haskell, Objective Caml and Scheme. Adding support for other languages
is easy too.  


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


Re: gettext again

2005-08-09 Thread cantabile
Ok, I'll try that.
Thanks again Stasz !
-- 
http://mail.python.org/mailman/listinfo/python-list


namespaces

2005-08-09 Thread Paolino
Why descriptor mechanism doesn't apply to modules?

I suspect another anomaly in the namespaces implementations.
class Mosse(object):
   def __get__(self,*_):
 print 'HERE'

m=Mosse()
m # doesn't work

import new
mod=new.module('hopeless')
mod.m=Mosse()
assert 'm' in mod.__dict__ # this is said to be the key for descriptors
# to be called
mod.m # doesn't work



Thanks Paolino


___ 
Yahoo! Messenger: chiamate gratuite in tutto il mondo 
http://it.beta.messenger.yahoo.com
-- 
http://mail.python.org/mailman/listinfo/python-list


[ANN] Dabo 0.4 Released

2005-08-09 Thread Ed Leafe
We are pleased to announce Dabo 0.4, the fourth major release of our data 
application framework. The Dabo framework is a true 3-tier design, with data 
access and UI code separated from your business logic. And since it's Python, 
and uses wxPython for its UI, it is completely cross-platform, having been 
tested on Linux, Windows and OS X.

Download from http://dabodev.com/download

This is the first major release of Dabo that doesn't involve major changes to 
the way things work; nearly all the changes were bugfixes and 
'under-the-hood' tightening up of the code. I suppose that this is a good 
sign, and indicates that we have progressed further than a '0.4' version 
indicates, but we are being deliberately conservative with our version 
numbering. Nearly all the changes involve the UI layer, demonstrating both 
the complexity of wrapping a UI toolkit as well as the maturity and stability 
of our business object and database layers.

Anyone interested in contributing to Dabo, or who just want to find out what 
it is all about is encouraged to join our mailing lists:
dabo-users: for those interested in learning how to work with Dabo to create 
applications, and for general help with Dabo. 
http://leafe.com/mailman/listinfo/dabo-users
dabo-dev: for those interested in the ongoing development of Dabo. This list 
contains lots of lively discussion on design issues, as well as notices of 
all commits to the code repository.
http://leafe.com/mailman/listinfo/dabo-dev


Here is a brief summary of what's new in Dabo 0.4:

The dGrid class has been re-written. It allows you to directly work with 
Column and Header objects, where setting properties of these objects changes 
the appearance and behavior of the grid. It also has several convenience 
methods, such as 'buildFromDataSet()', which allows you to pass it a set of 
data, and have the grid construct itself to properly display that data. Added 
the property 'HeaderBackgroundColor' to the Column class to control the 
background color of that column's header.

Added the ability to edit values in a grid, which is toggled by a single 
boolean property of the grid named 'Editable'. Created basic renderer and 
editor classes for various data types that allow you to control how values 
are displayed and edited, respectively.

Created several visual variations of the 'pageframe' object (called a 
'Notebook' in wxPython). The standard 'dPageFrame' uses tabs to select the 
various pages, but now there are also 'dPageList', which uses a listbox to 
select its pages, and 'dPageSelect', which uses a dropdown list. There is 
also a new class 'dPageNoTabs', which, as its name suggests, has no visible 
means of changing pages. This class is used for those situations where you 
only want to change pages programmatically (e.g., a wizard form).

Updated the DataNav framework to take advantage of these pageframe changes. 
The Form class has two new attributes: 'pageFrameStyle', which is one of 
'Tabs', 'List' or 'Select'; and 'tabPosition', which is one of 'Top', 
'Bottom', 'Left' or 'Right'.

Simplified many of the functions that previously required creating instances 
of the various dialog types, showing them, and then later destroying them. 
Now, instead of going through all that, simply make a call such as 
'dabo.ui.getColor("green")', and Dabo will display a Color Selection dialog, 
default to the color you specified, and then return the color the user 
selected, or None if they canceled. The new functions (all part of dabo.ui) 
are: getFont(), getColor(), getString(), getFile(), getSaveAs() and 
getFolder(). Also moved the common informational dialogs here: areYourSure(), 
info() and stop().

Added the 'fontMetric()' method to the UI module. Specify a string, as well as 
the font properties you want to use to display that string, and it returns a 
(width, height) tuple for that string in that font.

Added two properties to all controls that allow you to programmatically 
interact with the sizers that determine how that control appears: 
ControllingSizer and ControllingSizerItem.

Added support for the Decimal class that was added in Python 2.4. Code written 
to run in Python 2.3 will still work, though.

Created the dToolBar class for displaying toolbars associated with forms. 
We're still working on creating independent floating toolbars.

And, of course, lots of bug fixes and code tweaks!


The Dabo Demo project is largely unchanged, although the demos have been 
updated to take advantage of changes to the underlying framework. There are 
now three basic demos in the 'tutorial' directory that help to demonstrate 
the basics of creating applications in Dabo.


The Dabo IDE project has also been updated to version 0.2, and I feel that 
this version number is accurate. We're still exploring the best way to create 
Dabo classes visually, and have made some great progress, but this is still 
very much an unfinished product. 

The Class Designer has progressed to the point wher

Re: namespaces

2005-08-09 Thread Peter Otten
Paolino wrote:

> Why descriptor mechanism doesn't apply to modules?

Because modules are instances of the module class and the descriptor has to
be defined in the class in order to work with the instance. E. g.:

>>> import sys
>>> class Descr(object):
... def __get__(*args): print "__get__%r" % (args,)
...
>>> module = type(sys)
>>> class Module(module):
... descr = Descr()
...
>>> m = Module("noname")
>>> m.descr
__get__(<__main__.Descr object at 0x4029372c>, ,
)
>>>

Peter

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


don't understand instanse creation

2005-08-09 Thread Maksim Kasimov

Hello,

i have a class, such as below.
when i try to make instances of the class,
fields __data1 and __data2 gets different values: __data1 behaves like private 
field, __data2 - like static
which is the thing i've missed?

thanks for help.




import time
class my:

 __data1 = []
 __data2 = []

 def __init__(self):

 print "__data1: ", self.__data1
 print "__data2: ", self.__data2

 for i in time.localtime():
 self.__data2.append(i)
 self.__data1 = self.__data2[:]

 print "__data1: ", self.__data1
 print "__data2: ", self.__data2





Python 2.2.3
FreeBSD

 >>> m1 = my.my()
__data1:  []
__data2:  []
__data1:  [2005, 8, 9, 16, 25, 18, 1, 221, 1]
__data2:  [2005, 8, 9, 16, 25, 18, 1, 221, 1]
 >>>
 >>>
 >>> m2 = my.my()
__data1:  []
__data2:  [2005, 8, 9, 16, 25, 18, 1, 221, 1]
__data1:  [2005, 8, 9, 16, 25, 18, 1, 221, 1, 2005, 8, 9, 16, 25, 25, 1, 221, 1]
__data2:  [2005, 8, 9, 16, 25, 18, 1, 221, 1, 2005, 8, 9, 16, 25, 25, 1, 221, 1]





-- 
Best regards,
Maksim Kasimov
mailto: [EMAIL PROTECTED]
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: don't understand instanse creation

2005-08-09 Thread Dan Sommers
On Tue, 09 Aug 2005 16:39:51 +0300,
Maksim Kasimov <[EMAIL PROTECTED]> wrote:

> Hello,

> i have a class, such as below.
> when i try to make instances of the class,
> fields __data1 and __data2 gets different values: __data1 behaves like 
> private field, __data2 - like static
> which is the thing i've missed?

> thanks for help.

> 


> import time
> class my:

>  __data1 = []
>  __data2 = []

>  def __init__(self):

>  print "__data1: ", self.__data1
>  print "__data2: ", self.__data2

>  for i in time.localtime():
>  self.__data2.append(i)

The above line changes the existing class attribute __data2, which is
shared by all instances of this class.

>  self.__data1 = self.__data2[:]

The above line creates a new instance attribute __data1, and binds it to
a copy of __data2.

>  print "__data1: ", self.__data1
>  print "__data2: ", self.__data2

[ example snipped ]

HTH,
Dan

-- 
Dan Sommers

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


Recommendations for CVS systems

2005-08-09 Thread geskerrett
I was wondering if anyone could make recomendations/comments about CVS
systems, their experiences and what perhaps the strengths of each.

Currently we have 2 developers but expect to grow to perhaps 5.

Most of the developement is Python, but some C, Javascript, HTML, etc.

The IDE what have been using/experimenting with are drPython and
eclipse with PyDev.


TIA

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


Python 32 and Python 64 bit

2005-08-09 Thread Nx
Suse Linux 9.2 64
Python 2.3 64 bit
Python 2.4 32 bit

My question is :

I have a python prog which is installed for python 2.3
but I need some variables filled with data, which I only can
get with running a python prog via python 2.4
(data is comming from a firebird database server via kinterbase
  all needs to be 32 bit).

How do I call python 2.4 from within python 2.3 and
load my variables with the data from the python 2.4 run ?


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

Re: Recommendations for CVS systems

2005-08-09 Thread Neil Benn
[EMAIL PROTECTED] wrote:

>I was wondering if anyone could make recomendations/comments about CVS
>systems, their experiences and what perhaps the strengths of each.
>
>Currently we have 2 developers but expect to grow to perhaps 5.
>
>Most of the developement is Python, but some C, Javascript, HTML, etc.
>
>The IDE what have been using/experimenting with are drPython and
>eclipse with PyDev.
>
>
>TIA
>
>  
>
I use SVN which is excellent (http://subversion.tigris.org/), on a 
windows box as a client I use TortoiseSVN which is also excellent.  I 
have the server running in Apache.

To work in SVN with eclipse you will need an eclipse plugin : 
http://subclipse.tigris.org/#subclipse

Neil

-- 

Neil Benn
Senior Automation Engineer
Cenix BioScience
BioInnovations Zentrum
Tatzberg 47
D-01307
Dresden
Germany

Tel : +49 (0)351 4173 154
e-mail : [EMAIL PROTECTED]
Cenix Website : http://www.cenix-bioscience.com

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


Re: namespaces

2005-08-09 Thread Paolino
Peter Otten wrote:
> Paolino wrote:
> 
> 
>>Why descriptor mechanism doesn't apply to modules?
> 
> 
> Because modules are instances of the module class and the descriptor has to
> be defined in the class in order to work with the instance. E. g.:
> 
> 
Got it,thanks.
Then there is no way of having descriptors at module level,as 'module' 
class is not updatable.





___ 
Yahoo! Mail: gratis 1GB per i messaggi e allegati da 10MB 
http://mail.yahoo.it
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Recommendations for CVS systems

2005-08-09 Thread Jorge Godoy
[EMAIL PROTECTED] wrote:

> The IDE what have been using/experimenting with are drPython and
> eclipse with PyDev.

Eclipse has a fine integration with both CVS and Subversion.  If you'll be
having a lot of images and binary objects or you don't have the design
right by the time you start coding, I'd recommend on using Subversion.  If
you do, both are good.

Why Subversion?  Because you'll be able to move files around without loosing
their history or without loosing the old filename in the repository.

One dawback is that you'll have to install the Subclipse plugin to use
Subversion, while CVS is already there...  But it's as easy as pointing a
new update/install site and clicking on the desired package.

We use both here and recently we've migrated to Subversion as our main VCS. 
We noticed that there was a reduction in disk space that can be very
significative depending on the type of file that you'll be working with.

-- 
Jorge Godoy  <[EMAIL PROTECTED]>

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


Re: don't understand instanse creation

2005-08-09 Thread Maksim Kasimov

i see, thaks you very match!

Dan Sommers wrote:
> On Tue, 09 Aug 2005 16:39:51 +0300,
> Maksim Kasimov <[EMAIL PROTECTED]> wrote:
> 
> 
>>Hello,
> 
> 
>>i have a class, such as below.
>>when i try to make instances of the class,
>>fields __data1 and __data2 gets different values: __data1 behaves like 
>>private field, __data2 - like static
>>which is the thing i've missed?
> 
> 
>>thanks for help.
> 
> 
>>
> 
> 
> 
>>import time
>>class my:
> 
> 
>> __data1 = []
>> __data2 = []
> 
> 
>> def __init__(self):
> 
> 
>> print "__data1: ", self.__data1
>> print "__data2: ", self.__data2
> 
> 
>> for i in time.localtime():
>> self.__data2.append(i)
> 
> 
> The above line changes the existing class attribute __data2, which is
> shared by all instances of this class.
> 
> 
>> self.__data1 = self.__data2[:]
> 
> 
> The above line creates a new instance attribute __data1, and binds it to
> a copy of __data2.
> 
> 
>> print "__data1: ", self.__data1
>> print "__data2: ", self.__data2
> 
> 
> [ example snipped ]
> 
> HTH,
> Dan
> 


-- 
Best regards,
Maksim Kasimov
mailto: [EMAIL PROTECTED]
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python -- (just) a successful experiment?

2005-08-09 Thread Michael Hudson
Robert Kern <[EMAIL PROTECTED]> writes:

> What I'm trying to say is that posting to c.l.py is absolutely
> ineffective in achieving that goal. Code attracts people that like
> to code. Tedious, repetitive c.l.py threads attract people that like
> to write tedious, repetitive c.l.py threads.

+1 QOTW, though I may be too late (I've become rather temporally
confused when it comes to clpy).

Cheers,
mwh

-- 
  Monte Carlo sampling is no way to understand code.
  -- Gordon McMillan, comp.lang.python
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: don't understand instanse creation

2005-08-09 Thread Christopher Subich
Maksim Kasimov wrote:

 >
 > Hello,
 >
 > i have a class, such as below.
 > when i try to make instances of the class,
 > fields __data1 and __data2 gets different values: __data1 behaves 
like private field, __data2 - like static
 > which is the thing i've missed?


Firstly, you get interesting behaviour of data1 and data2 because 
they're defined as mutable objects in the class sitself.  All instances 
of that class then share the same binding to the list, so appending to 
it in one instance will show up in other instances.

(Incidentally, be sure what you really want is name-mangled private 
variables, it's fairly uncommon for instance variables and methods to be 
private in Python code).

Your second issue is why data1 behaves differently.  This line:

 > self.__data1 = self.__data2[:]


is the culprit.  Here, you assing __data1 to a *new* list, generated by 
copying __data2 (the : slice -- slices create a shallow copy, not a 
reference, of lists).  This rebinds the name __data1 to a new object, so 
the __data1 in the class definition is never modified like __data2 (with 
the .append).  You can demonstrate this by looking at the 'address' of 
the lists.  Modify the constructor thusly:

class my:

 __data1 = []
 __data2 = []

 def __init__(self):

 print "__data1: ", self.__data1, object.__repr__(self.__data1)
 print "__data2: ", self.__data2, object.__repr__(self.__data1)

 for i in time.localtime():
 self.__data2.append(i)
 self.__data1 = self.__data2[:]

 print "__data1: ", self.__data1, object.__repr__(self.__data1)
 print "__data2: ", self.__data2, object.__repr__(self.__data1)

And your tests now become:
 >>> m1 = my()
__data1:  [] 
__data2:  [] 
__data1:  [2005, 8, 9, 10, 5, 54, 1, 221, 1] 
__data2:  [2005, 8, 9, 10, 5, 54, 1, 221, 1] 
 >>> m2 = my()
__data1:  [] 
__data2:  [2005, 8, 9, 10, 5, 54, 1, 221, 1] 
__data1:  [2005, 8, 9, 10, 5, 54, 1, 221, 1, 2005, 8, 9, 10, 5, 56, 1, 
221, 1] 
__data2:  [2005, 8, 9, 10, 5, 54, 1, 221, 1, 2005, 8, 9, 10, 5, 56, 1, 
221, 1] 

Notice how the 'address' of __data1 changes after executing the 
constructor.  This change, made in __init__, is reflected only in that 
instance's copy of the name.  Also notice how __data2 in both m1 and m2 
share the same address; this is why changes in one instance are 
reflected in the others.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python-Excel: How to paste selected cells (range) to different location on the same sheet in Excel

2005-08-09 Thread Stuart Corrie
Did you use the excel macro recorder and look at the results to help you 
write that program? It seems to bear all the hallmarks of code generated 
that way. The macro recorder can be great, but almost always it is 
possible to speed up code by altering it afterwards, to condense and 
speed up the VBA code. A slightly tighter version of your code is shown 
below:

import win32com.client
xl=win32com.client.Dispatch("Excel.Application")
xl.Visible=1
wb = xl.Workbooks.Add( )
sh=wb.Worksheets(1)
sh.Cells(1,1).Value = "Hello World!"
sh.Cells(3,3).Value = "Hello World!"
sh.Range(sh.Cells(1,1),sh.Cells(3,3)).Copy(sh.Cells(4,1))
sh.Range(sh.Cells(4,1),sh.Cells(6,3)).Select()

The first 7 lines are identical to yours. The way you work with excel in 
when entering data and formulae interactively, and so the way the macro 
recorder must work, involves lots of selection (or activation for 
switching workbooks) which can be slow and often not required when using 
code to manipulate excel's objects through COM from an external language 
or VBA in excel. Line 7 in your program 
"sh.Range(sh.Cells(1,1),sh.Cell­s(3,3)).Select()" actually does nothing 
because the range is specified again in line 8.

The copy method of a range object can take a parameter for a paste 
destination. The macro recorder will never generate code like this 
because it must record the selection between the copy and the paste 
operations.

The only minor drawback of the revised line 7 is that the range selected 
after the paste operation is the parameter given to copy not the data 
pasted, if this is required, line 8 fixes this.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: issues with doctest and threads

2005-08-09 Thread Tim Peters
[Michele Simionato]
> Thank you for your replies Jeff & Tim. The snippet I submitted is
> unfortunate, since I was writing an example (for a Python course I am
> going to give in September) to show that you cannot reliably assume
> that you will get exactly 9 dots, because of the limitations of 'sleep'.
> Mindlessly, I have cut & pasted that snippet, but my real question
> was not "how many dots I get", it was:  "why the error message talks
> about 'thread' not being in the globals?"  It's true that I can avoid it with
> a thread.join() (which I had forgot), but still I really cannot understand  
> the
> reason for such message.

Because the program is buggy:  synchronizing threads isn't a "do it if
you feel like it" thing, it's essential to correct threaded behavior. 
If you're going to show students bad thread practice, they're going to
get mysteries a lot deeper and more damaging than this one <0.5 wink>.

Add some more prints:

"""
>>> import time, threading
>>> def example():
... thread.out = []
... while thread.running:
... time.sleep(.01)
... print [11]
... thread.out.append(".")
... print [12]
... print [13]
>>> thread = threading.Thread(None, example)
>>> thread.running = True; thread.start()
>>> time.sleep(.1)
>>> thread.running = False
>>> print thread.out
['.', '.', '.', '.', '.', '.', '.', '.', '.']
"""

if __name__ == "__main__":
   import doctest
   doctest.testmod()
   print [2]

Here's a typical run on my box:

File "blah.py", line 13, in __main__
Failed example:
time.sleep(.1)
Expected nothing
Got:
[11]
[12]
[11]
[12]
[11]
[12]
[11]
[12]
[11]
[12]
[11]
[12]
[11]
[12]
[11]
[12]
[11]
[12]
**
1 items had failures:
   1 of   7 in __main__
***Test Failed*** 1 failures.
[2]
[11]
Exception in thread Thread-1:
Traceback (most recent call last):
  File "C:\Code\python\lib\threading.py", line 444, in __bootstrap
self.run()
  File "C:\Code\python\lib\threading.py", line 424, in run
self.__target(*self.__args, **self.__kwargs)
  File "", line 6, in example
NameError: global name 'thread' is not defined

Note that [2] is printed _while_ the spawned thread is still running
([13] is never printed):  the call to doctest.testmod() is completely
finished, but you're still letting a thread spawned _by_ doctest run. 
The environment doctest set up for that thread is gone too.  Although
it doesn't actually matter in this specific example, because the main
thread (not just doctest) is also entirely done, the Python
interpreter starts tearing itself down. Why that last doesn't matter
in this example would take some time to explain; I don't think it's
needed here, because the test case got into mortal trouble for an
earlier reason.

> Why it is so misleading?

Simply because bad thread programming has allowed a thread to run
beyond the time resources it relies on have vanished.  It may sound
harsh, but this is tough love :  it's pilot error.

> Can something be done about it?

Properly synchronize the thread, to enforce what the code requires but
cannot hope to obtain by blind luck.  All it takes is the
thread.join() I suggested.  I don't understand why you're fighting
that, because it's basic proper thread practice -- it's not like I
suggested an obscure expert-level hack here.  If a student doesn't
know to join() a thread before they rely on that thread being done,
their thread career will be an endless nightmare.

All that said, this specific failure would _happen_ to go away too, if
in doctest's DocTestRunner.run(), the final 'test.globs.clear()" were
removed.  If you feel it's necessary to let threads spawned by a
doctest run beyond the time doctest completes, you can arrange to
invoke DocTestRunner.run() with clear_globs=False.  That's not an
intended use case, but it will work.  The intended use case is
explained in run's docstring:

The examples are run in the namespace `test.globs`.  If
`clear_globs` is true (the default), then this namespace will
be cleared after the test runs, to help with garbage
collection.  If you would like to examine the namespace after
the test completes, then use `clear_globs=False`.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python -- (just) a successful experiment?

2005-08-09 Thread Michael Hudson
Michael Hudson <[EMAIL PROTECTED]> writes:

> Robert Kern <[EMAIL PROTECTED]> writes:
>
>> What I'm trying to say is that posting to c.l.py is absolutely
>> ineffective in achieving that goal. Code attracts people that like
>> to code. Tedious, repetitive c.l.py threads attract people that like
>> to write tedious, repetitive c.l.py threads.
>
> +1 QOTW, though I may be too late

Not only was I late, I was unoriginal!  Oh well.

Cheers,
mwh

-- 
  Every day I send overnight packages filled with rabid weasels to
  people who use frames for no good reason.
 -- The Usenet Oracle, Oracularity #1017-1
-- 
http://mail.python.org/mailman/listinfo/python-list


Passing arguments to function - (The fundamentals are confusing me)

2005-08-09 Thread Gregory Piñero
Hey guys, would someone mind giving me a quick rundown of how
references work in Python when passing arguments into functions?  The
code below should highlight my specific confusion:



bool1=True
lst1=[1,2,3]

def func1(arg1): arg1.append(4)

def func2(arg1): arg1=False

>>func1(lst1)
>>lst1
[1,2,3,4]

>>func2(bool1)
>>bool1
True



Why does my list variable get changed for the rest of the program, but
my boolean variable doesn't.  What am I not understanding?

-- 
Gregory Piñero
Chief Innovation Officer
Blended Technologies
(www.blendedtechnologies.com)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Passing arguments to function - (The fundamentals are confusing me)

2005-08-09 Thread Christopher Subich
Gregory Piñero wrote:
> Hey guys, would someone mind giving me a quick rundown of how
> references work in Python when passing arguments into functions?  The
> code below should highlight my specific confusion:

All arguments are passed by reference, but in Python equality rebinds 
the name.

> 
> 
> 
> bool1=True
> lst1=[1,2,3]
> 
> def func1(arg1): arg1.append(4)

In C++, pretending it had dynamic typing, this would be equivalent to:
void func1( * arg1){
arg1->append(4);
}

> 
> def func2(arg1): arg1=False
void func2 ( * arg2) {
arg2 = &(False);

> Why does my list variable get changed for the rest of the program, but
> my boolean variable doesn't.  What am I not understanding?

In Python, "x = y" has a very definite meaning of "y is assigned to the 
name of x."  This change does not affect whatever was in x to start 
with, and it certainly would not affect anything else which holds a 
reference to the object formerly known as x.

In contrast, calling a function which mutates the object (like .append 
on lists, or assignment by lst[index]=something) actually changes the 
object itself, which is of course reflected by all other names that hold 
a reference to the object.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Why does __init__ not get called?

2005-08-09 Thread Rob Conner
Ah ok, thats interesting I hadn't even tried a valid date yet. Now how
do I get this thing to call __init__ when I pass in an invalid date and
the ValueError is thrown and caught within __new__.

dt = DateTime(2005, 02, 30)

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


What are modules really for?

2005-08-09 Thread N.Davis
I am very new to Python, but have done plenty of development in C++ and 
Java.

One thing I find weird about python is the idea of a module. Why is this 
needed when there are already the ideas of class, file, and package?

To my mind, although one CAN put many classes in a file, it is better to 
put one class per file, for readability and maintainability.

One can then create packages and libraries, using groups of files, one 
class per file.

Python seems to let you group classes together in one file and call it a 
module, but what for?

I find that this, combined with mixins, makes it difficult to find out 
where code is inherited from.

With single inheritance in C++ or Java, if you wanted to see what a 
method did and it appeared to be inherited, you would simply look in the 
base class's file, and if necessary recurse up the inheritance hierarchy 
until you found the method.

With Python an inherited method could be in one of many base classes 
and/or mixins and there seems no particular logic as to what the 
filename would be.

Am I missing something?

Any comments would be appreciated.

Thanks
Nick Davis

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


Re: namespaces

2005-08-09 Thread Scott David Daniels
Paolino wrote:
> Peter Otten wrote:
>> Paolino wrote:
>>> Why descriptor mechanism doesn't apply to modules?
>> Because modules are instances of the module class and the descriptor 
>> has to be defined in the class in order to work with the instance
> Then there is no way of having descriptors at module level,as 'module' 
> class is not updatable.

Well, an entry in the dictionary "sys.modules" is what is returned by
imports, so you could either pre-replace or post-replace a module by
an object which uses the descriptor technique to get to some (but not
necessarily all) of the attributes.  Think of this technique as a
hack to get to a goal, rather than a good technique to use; good for
debugging, not so nice for production work.  If you still don't know
how to do this from this admittedly sketchy description, I'd suggest
you avoid trying it altogether.

--Scott David Daniels
-- 
http://mail.python.org/mailman/listinfo/python-list


sqlobject vs mysqldb module

2005-08-09 Thread yaffa
dear group,

i have a python script that scrapes contents from an html file and i
would like to have the script write values to a mysql db.  do you
recommend i go with the sqlobject or the mysqldb module?

thank you

yaffa

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


Re: What are modules really for?

2005-08-09 Thread skip

Nick> One thing I find weird about python is the idea of a module. Why
Nick> is this needed when there are already the ideas of class, file,
Nick> and package?

A module is a namespace object that maps one-to-one to a file (ignoring the
new module's features).  A file by itself is just a collection of bytes and
has no features to interpret the structure of its contents as a namespace.

Nick> Python seems to let you group classes together in one file and
Nick> call it a module, but what for?

You can define many other types of objects in modules besides classes.

Nick> With Python an inherited method could be in one of many base
Nick> classes and/or mixins and there seems no particular logic as to
Nick> what the filename would be.

I agree mixins can be troublesome.  That's a problem peculiar to multiple
inheritance, not strictly to Python.  I'm sure you can create file/class
relationships in Java or C++ that make it challenging to find the definition
of a mixin.  I don't view multiple inheritance as a gotta-have feature of
OOP and avoid it when I can.  Smalltalk has lived happily without multiple
inheritance for a few decades now.

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


Re: What are modules really for?

2005-08-09 Thread Richard Brodie

"N.Davis" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED]


> To my mind, although one CAN put many classes in a file, it is better to
> put one class per file, for readability and maintainability.

Zero classes in a file works well too ;)


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


Re: Passing arguments to function - (The fundamentals are confusing me)

2005-08-09 Thread Rocco Moretti
Christopher Subich wrote:
> Gregory Piñero wrote:
> 
>> Hey guys, would someone mind giving me a quick rundown of how
>> references work in Python when passing arguments into functions?  The
>> code below should highlight my specific confusion:

This URL is always tossed out:

http://starship.python.net/crew/mwh/hacks/objectthink.html

> All arguments are passed by reference, but in Python equality rebinds 
> the name.

Bingo

>> Why does my list variable get changed for the rest of the program, but
>> my boolean variable doesn't.  What am I not understanding?

Booleans are immutable, lists are mutable. You change (mutate) the same 
list, but you are referencing a different (immutable) Bool

> In Python, "x = y" has a very definite meaning of "y is assigned to the 
> name of x."  

Change it to "the object referenced by y is assigned to the name of x", 
and you're closer to the truth.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: sqlobject vs mysqldb module

2005-08-09 Thread skip
yaffa> i have a python script that scrapes contents from an html file
yaffa> and i would like to have the script write values to a mysql db.
yaffa> do you recommend i go with the sqlobject or the mysqldb module?

They are really quite different beasts.  You'll have to consider your
requirements to decide which to use.

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


Re: What are modules really for?

2005-08-09 Thread infidel
> I am very new to Python, but have done plenty of development in C++ and
> Java.

And therein lies the root of your question, I believe.

> One thing I find weird about python is the idea of a module. Why is this
> needed when there are already the ideas of class, file, and package?

One reason is that functions need a place to exist too.  In Java, every
function, even "static" ones has to be a class method.  In Python,
"static" functions are best kept in a module.  Another thing is that
packages were a later addition to the language.

> To my mind, although one CAN put many classes in a file, it is better to
> put one class per file, for readability and maintainability.

Personally I find it easier to maintain a set of related classes when
they're all in the same file.  I've got a few modules that I'm
currently hacking on, each of which contains a handful of classes.
Maybe it's just a matter of scale, since these are both fairly small
libraries, but I just don't see any advantage to splitting them up into
multiple files.

> One can then create packages and libraries, using groups of files, one
> class per file.

Since Java's compiler enforces this, perhaps you've just come to accept
it as "normal".

> Python seems to let you group classes together in one file and call it a
> module, but what for?

What if one of your classes creates/manipulates other classes.  If
they're in the same module then they all exist in the same namespace
and you don't have to have modules importing each other or such things.

> I find that this, combined with mixins, makes it difficult to find out
> where code is inherited from.

Perhaps you are relying too much on inheritance, then?

> With single inheritance in C++ or Java, if you wanted to see what a
> method did and it appeared to be inherited, you would simply look in the
> base class's file, and if necessary recurse up the inheritance hierarchy
> until you found the method.
>
> With Python an inherited method could be in one of many base classes
> and/or mixins and there seems no particular logic as to what the
> filename would be.

It shouldn't be too hard to figure out, unless someone was being
intentially vague.  You could always fire up the interpreter, import
your class, and check it's .mro property (method resolution order),
which lists the classes in the order they will be examined to find a
method named at runtime.

> Am I missing something?

I just think you're thinking in terms of Java.  You'll pick things up
quickly, though :-)

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


Re: Passing arguments to function - (The fundamentals are confusing me)

2005-08-09 Thread infidel
> in Python equality rebinds the name

Assignment (=) rebinds the name.  Equality (==) is something else
entirely.

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


Illegal IMail List Server Command!

2005-08-09 Thread List Server
IMail List Server for Windows NT, Ipswitch, Inc. 


   Valid Commands are:

   To subscribe to a list, send a mail message to "imailsrv" at
   this address with the following in the body of the message:

   subscribe listname your_full_name

   To unsubscribe from a list, send a mail message to "imailsrv" at
   this address with the following in the body of the message:

   unsubscribe listname

   To receive a list of the lists supported here:

   list

   To receive a list of users on a given list
   (If enabled for that particular list):

   list listname

   To receive help send:

   help [listname]

   To change to digest mode, send a mail message to "imailsrv" at
   this address with the following in the body of the message:

   set mode digest listname

   To change back to standard mode, send a mail message to "imailsrv" at
   this address with the following in the body of the message:

   set mode standard listname

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


Re: Advanced concurrancy

2005-08-09 Thread Matt Hammond
Hi Stefan,

On Fri, 05 Aug 2005 07:20:36 +0100, Stefan Rank <[EMAIL PROTECTED]>  
wrote:

>>> So do you plan on including a kind of scheduler-aware blocking
>>> communication (like the `channels` of the `tasklets` in stackless)?

Not at the moment. The kinds of applications we've mainly been looking at,  
whilst developing, have been multimedia data-flow oriented, so blocking  
communication would be used as a rate limiting mechanism. However, we've  
found we can achieve that by putting explicit feedback links in.

I think we are also trying to stick with the asynchronous way, if  
possible, because it may well make things simpler and more efficient when  
it comes to distributing components across processes / networked  
computers. Synchronous links will lead to handshaking latencies, more data  
needing to flow etc. IMO that kind of facility could always be built on  
top - for example - using a feedback inbox->outbox path to 'request' new  
data ... if you really need it.

... it also simplifies the scheduler. We've tried, so far, to keep the  
underlying microprocess model decoupled from the components and  
inbox/outbox layer. That said, that may have to change eventually!

> this communication infrastructure is definitely a Good Thing (TM), the  
> same holds for a standard environment or registry (wassitsname, your CAT  
> thing) as you need at least one well-known point of reference in a  
> 'distributed' system.

yep its a CAT (Coordinating Assistant Tracker). Nothing to do with the  
project logo ... nooo! :-)

> 
>now if someone could only cut the gordian knot of the
>GlobalInterpreterLock to make all this really concurrent... and then,
>when she's at it, allow transparent distribution of components in a
>network... ;-)
> 

I'll second that!

regards


Matt
-- 

| Matt Hammond
| R&D Engineer, BBC Research and Development, Tadworth, Surrey, UK.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Decline and fall of scripting languages ?

2005-08-09 Thread Bengt Richter
On 08 Aug 2005 20:37:01 -0700, Paul Rubin  wrote:
[...]
>Right now I'm mainly interested in OCaml, Haskell, Erlang, and maybe
>Occam.  Haskell seems to have the happiest users, which is always a
>good thing.  Erlang has been used for real-world systems and has
>built-in concurrency support.  OCaml seems to crush Haskell and Erlang
>(and even Java) in performance.  Occam isn't used for much practical
>any more, but takes a purist approach to concurrency that seems worth
>studying.
IIRC, I've seen something about a web server implemented in erlang
with tremendous performance at high levels of concurrency where other
implementations bog down. So I would want further details before I
believe that all OCaml versions "crush" all Erlang versions in performance.


>
>The idea is to use one of those languages for a personal project after
>my current work project wraps up pretty soon.  This would be both a
>learning effort and an attempt to write something useful.  I'm
>thinking of a web application like a discussion board or wiki,
>intended to outperform the existing ones, i.e. able to handle a
>Slashdot or Wikipedia sized load (millions of hits/day) on a single
>fast PC instead of a rack full.  "Single fast PC" will probably soon
>come to mean a two-cpu-chip motherboard in a 1U rack box, where each
>cpu chip is a dual core P4 or Athlon, so the application should be
>able to take advantage of at least 4-way multiprocessing, thus the
>interest in concurrency.
I'd suggest finding that Erlang web server writeup.

Hm, some googling ...
I think this is the graph I saw:

http://www.sics.se/~joe/apachevsyaws.html

Can't vouch for what it means, but taken at face value
would seem to warrant a further look into details.

This turned up also

http://eddie.sourceforge.net/txt/WP_1.0.html

which I hadn't seen before, and which looks interesting
though maybe stale?


I guess this is a home for erlang:
http://www.erlang.se/

Much other stuff, but you know how to google ;-)

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


Re: Passing arguments to function - (The fundamentals are confusing me)

2005-08-09 Thread Gregory Piñero
Ahh, so it's a mutable thing.  That makes sense that I can't change a
mutable object and thus can't affect it outside of the function.  Does
that mean Python functions aren't always byref, but are sometimes
byval for nonmutables?

-Greg


On 8/9/05, Dennis Lee Bieber <[EMAIL PROTECTED]> wrote:
> On Tue, 9 Aug 2005 10:53:15 -0400, Gregory Piñero <[EMAIL PROTECTED] >
> declaimed the following in comp.lang.python:
> 
>  Is this the third time this week that this has come
> up?
> 
> > Hey guys, would someone mind giving me a quick rundown of how
> > references work in Python when passing arguments into functions?  The
> > code below should highlight my specific confusion:
> >
> They work just like they do everywhere else...
> 
> Read the manuals on mutable and immutable objects. (I'd suggest
> language reference chapter 3 and 4, library reference chapter 2.3.6,
> 2.3.7)
> 
> "names" in Python are movable labels attached to objects; they
> are not fixed locations in memory to which object are copied; hence they
> do not behave like variables in traditional languages.
> 
> >
> > bool1=True
> 
> immutable object -- "bool1" is a label attached to a fixed
> object
> 
> > lst1=[1,2,3]
> >
> mutable object  -- "lst1" is a label attached to a box
> containing objects
> 
> > def func1(arg1): arg1.append(4)
> >
> 
> "arg1" is a label attached to whatever object was passed in...
> .append is an operation that changes what is /inside/ that
> object
> 
> > def func2(arg1): arg1=False
> >
> "arg1" is a label attached to whatever was passed in...
> Assignment (especially of an immutable object) takes that label
> OFF of the object that was passed in, and moves it the object of the
> assignment. It does not move the label that is outside the call.
> 
> > >>func1(lst1)
> > >>lst1
> > [1,2,3,4]
> >
> "lst1" is the label of the box; inside of func1, that box has
> two labels: "lst1" and "arg1". You used the "arg1" label to locate the
> box, and then you changed what was inside the box. Outside the function,
> you used the "lst1" label to find the /same/ box and report what was
> inside it.
> 
> > >>func2(bool1)
> > >>bool1
> > True
> >
> "bool1" is the label of a non-box -- a "true". Inside the
> function "true" has initially two labels: "bool1" and "arg1". You then
> moved the "arg1" label from "true" to a different object "false".
> "bool1" does not move, and still references the "true".
> 
> 
> --
>  > == <
>  >   [EMAIL PROTECTED]  | Wulfraed  Dennis Lee Bieber  KD6MOG <
>  >  [EMAIL PROTECTED] |   Bestiaria Support Staff   <
>  > == <
>  >   Home Page: <
>  >Overflow Page: <
> --
> http://mail.python.org/mailman/listinfo/python-list 
> 


-- 
Gregory Piñero
Chief Innovation Officer
Blended Technologies
(www.blendedtechnologies.com)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: new python debugger

2005-08-09 Thread Franz Steinhäusler
On 9 Aug 2005 03:52:00 -0700, "mrelectron" <[EMAIL PROTECTED]>
wrote:

>hi:
>
>Nir Aides who wrote the rpdb debugger has enhanced it and stuck a
>frontend on it whoo-hoo. it is fantastico! see and download it at
>http://www.digitalpeers.com/pythondebugger/
>
>cheers mark

Hello Mark,

thank you for this info.

I downloaded it, and yes, it looks really great!
Maybe I can dismiss Hap Debugger, because
also it is written in Python (wxPython) itself.

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


Build errors for Objects/complexobject.c

2005-08-09 Thread peter . havens
Hi all,

I'm attempting to build Python 2.4.1 on Solaris 10 using gcc 3.4.3. I
get the following build error:



gcc -c -fno-strict-aliasing -DNDEBUG -g -O3 -Wall -Wstrict-prototypes
-I. -I./Include  -DPy_BUILD_CORE -o Objects/complexobject.o
Objects/complexobject.c
Objects/complexobject.c: In function `complex_pow':
Objects/complexobject.c:479: error: invalid operands to binary ==
Objects/complexobject.c:479: error: wrong type argument to unary minus
Objects/complexobject.c:479: error: invalid operands to binary ==
Objects/complexobject.c:479: error: wrong type argument to unary minus
make: *** [Objects/complexobject.o] Error 1



I've poked around a bit, and it looks like there is a macro called
Py_ADJUST_ERANGE2 which is being called at that point in the code. It
uses a defined value for Py_HUGE_VAL. I'm guessing that the definition
of Py_HUGE_VAL is the problem. The comments above the define for
Py_HUGE_VAL, and the notes in the Misc/NEWS file lead me to believe
that I need to correct the defined value of Py_HUGE_VAL (which is set
to HUGE_VAL now, and I'm assuming that comes from a C standard).
However, I'm not sure what to set that value to.

I found two files in Solaris that seem to define HUGE_VAL in some way.

/usr/include/iso/math_c99.h
/usr/include/iso/math_iso.h

...and math_iso.h looks like the best choice. Here is the relevant
sections of the header:



#if !defined(_STDC_C99) && _XOPEN_SOURCE - 0 < 600 &&
!defined(__C99FEATURES__)
typedef union _h_val {
unsigned long _i[sizeof (double) / sizeof (unsigned long)];
double _d;
} _h_val;

#ifdef __STDC__
extern const _h_val __huge_val;
#else
extern _h_val __huge_val;
#endif
#undef  HUGE_VAL
#define HUGE_VAL __huge_val._d
#endif  /* !defined(_STDC_C99) && _XOPEN_SOURCE - 0 < 600 && ... */



...my C isn't very strong, so that doesn't make sense to me -- is
HUGE_VAL set to a type rather than a value? Anyway, I set Py_HUGE_VAL
to LONG_MAX. It compiled and 'make test' seems to work out. Will this
cause problems? Should I report this as a Python bug?

Thanks,
Pete

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


Re: Build errors for Objects/complexobject.c

2005-08-09 Thread peter . havens
Okay, after further review, I realized that 'make test' wasn't
completely successful. The test 'test_complex' passed, but 'test_long'
failed:


test_long
test test_long crashed -- exceptions.OverflowError: long int too large
to convert to float


...do you think my changes caused this failure?

Pete

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


Re: Passing arguments to function - (The fundamentals are confusing me)

2005-08-09 Thread Dan
> Does that mean Python functions aren't always byref, 
> but are sometimes byval for nonmutables?

Don't think of it as byref or byval (as they are used in Visual Basic).
All parameters are passed the same way: by reference instead of by copy.

It's a little difficult to get your head around, but I promise that once
you understand it it will seem simple and intuitive.

  def reassign(x):
  x = ['foo']

"reassign" has no effect, even on a mutable type like a list. It simply
changes what "x" refers to, which isn't very useful because the name "x"
only exists inside the function.

In Python everything is treated the same way. Even integers are objects:

   >>> n = 1
   >>> n.__hex__()
   '0x1'

What other programming languages do you know? Maybe we can draw a
comparison to something you're familiar with.

-- 
   Presumably, we're all fully qualified computer nerds here,
   so we are allowed to use "access" as a verb. Be advised,
   however, that the practice in common usage drives
   English-language purists to scowling fidgets.
  - from Sybex's "Perl, CGI and JavaScript", p. 256


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


Examples and tutorials about popen2/3, smtplib/multipart and icq/jabber?

2005-08-09 Thread Alessandro Bottoni
Is there any good tutorial/example about popen2 and popen3? I have to
execute a given command on Linux and Windows from within a Python program.
If possible, on Linux I would like to be able to set the executing user
(setuid) and the niceness level of the command. (and yes: I know it is a 
dangerous feature...)

Is there any good tutorial/example about smtplib and MIME multipart
messages? I need to send a bunch of e-mail messages (possibly in HTML
format) to many diverse recipients, each message with one or more
attachements (typically PDF files). 

BTW: how about using Twisted Matrix for this task? I heard it is able to
send e-mail messages asynchronously (leaving free the invoking program to
go on just after the call to the "send_msg" function).

Is there any good tutorial/example about Jabber or ICQ and Python? I have to
send a bunch of instant messages (possibly with one or more file and/or one
or more URL attached to them in some way) to many diverse recipients (I
normally do not use ICQ and/or Jabber and I know them very little. Any
advise or suggestion about this task is greatly welcome).

Thanks in advance

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


Re: Passing arguments to function - (The fundamentals are confusing me)

2005-08-09 Thread Rocco Moretti
Gregory Piñero wrote:
> Ahh, so it's a mutable thing.  That makes sense that I can't change a
> mutable object and thus can't affect it outside of the function.  

If you meant "immutable" for the second mutable, you're right.

> Does
> that mean Python functions aren't always byref, but are sometimes
> byval for nonmutables?

It'd probably do you good to get away from the by reference/by value 
thinking. Python isn't C/Basic/Fortran/etc.

Variables in Python are names. They aren't the cubbyholes into which you 
put values, they are sticky notes on the front of the cubby hole.

Parameter passing in Python always work the same way - you create a new 
name pointing to the passed object. Fin.

The confusion you're having isn't in parameter passing, it's in the 
difference between assignment and mutation. Mutation changes the object 
itself (what's in the cubby hole), so it doesn't matter what or how many 
names/variables it has (what sticky notes are on the front). Assigment 
just changes where names point, not the contents of objects. (It's 
moving that sticky note, and only that sticky note, from one cubby to a 
different one.) Assignment justs affects that name, not any other name 
which point to the same object, including the variables in the passing 
scope.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: namespaces

2005-08-09 Thread Bengt Richter
On 31 Jul 2005 21:03:36 -0700, Paul Rubin  wrote:

>Steven D'Aprano <[EMAIL PROTECTED]> writes:
>> Most languages can create self-modifying code. That's not the
>> question. The question is whether developers should write
>> self-modifying code, not whether language designers should prohibit it.
>
>There was no self-modifying code in that closure example.
>Self-modifying code means something entirely different.  
>
>Closures are a tried and true technique that are thematic in Lisp
>programming (Python tends to use class instances instead).  They take
>some getting used to, just like, say, recursion.  And like almost
>anything, they can be abused.  But they're a completely legitimate
>approach to lots of types of problems.
>
>See the book "Structure and Interpretation of Computer Programming"
>for an intro to programming based on closures.

If you are referring to the code that defines translate with a def
and also internally defines the same global translate with an internal
def that binds globally (because of the global declaration) when it executes,
then I agree, translate is not "self"-modifying, but it is
self's-global-binding-modifying, which seems like a close cousin to 
self-modification ;-)

Note that the global binding changes after the first execution:

 >>> def translate( text ):
 ... import string
 ... all=string.maketrans('','')
 ... badcars=all.translate(all,string.letters+string.digits)
 ... TABLE = string.maketrans(badcars,'_'*len(badcars))
 ... global translate
 ... def translate( text ):
 ... return text.translate(TABLE)
 ... return translate( text )
 ...
 >>> dir()
 ['__builtins__', '__doc__', '__name__', 'translate']

Here is what translate is bound to after the above def:

 >>> import dis
 >>> dis.dis(translate)
   2   0 LOAD_CONST   0 (None)
   3 IMPORT_NAME  0 (string)
   6 STORE_FAST   2 (string)

   3   9 LOAD_FAST2 (string)
  12 LOAD_ATTR1 (maketrans)
  15 LOAD_CONST   1 ('')
  18 LOAD_CONST   1 ('')
  21 CALL_FUNCTION2
  24 STORE_FAST   1 (all)

   4  27 LOAD_FAST1 (all)
  30 LOAD_ATTR3 (translate)
  33 LOAD_FAST1 (all)
  36 LOAD_FAST2 (string)
  39 LOAD_ATTR4 (letters)
  42 LOAD_FAST2 (string)
  45 LOAD_ATTR5 (digits)
  48 BINARY_ADD
  49 CALL_FUNCTION2
  52 STORE_FAST   3 (badcars)

   5  55 LOAD_FAST2 (string)
  58 LOAD_ATTR1 (maketrans)
  61 LOAD_FAST3 (badcars)
  64 LOAD_CONST   2 ('_')
  67 LOAD_GLOBAL  7 (len)
  70 LOAD_FAST3 (badcars)
  73 CALL_FUNCTION1
  76 BINARY_MULTIPLY
  77 CALL_FUNCTION2
  80 STORE_DEREF  0 (TABLE)

   7  83 LOAD_CLOSURE 0 (TABLE)
  86 LOAD_CONST   3 (",line 7>)
  89 MAKE_CLOSURE 0
  92 STORE_GLOBAL 3 (translate)

   9  95 LOAD_GLOBAL  3 (translate)
  98 LOAD_FAST0 (text)
 101 CALL_FUNCTION1
 104 RETURN_VALUE

Execute once:
 >>> translate('something')
 'something'

Now check what translate is bound to:

 >>> dis.dis(translate)
   8   0 LOAD_FAST0 (text)
   3 LOAD_ATTR1 (translate)
   6 LOAD_DEREF   0 (TABLE)
   9 CALL_FUNCTION1
  12 RETURN_VALUE

I.e., the original globally bound translate replaces its global binding
with the closure it creates on first execution, and also uses that closure
to get the first result, which is a little tricky, I'd say ;-)

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


Does any one recognize this binary data storage format

2005-08-09 Thread geskerrett
I am hoping someone can help me solve a bit of a puzzle.

We are working on a data file reader and extraction tool for an old
MS-DOS accounting system dating back to the mid 80's.

In the data files, the text information is stored in clearly readable
ASCII text, so I am comfortable that this file isn't EBCIDIC, however,
the some of the numbers are stored in a format that we can't seem to
recognize or unpack using the standard python tools (struct, binascii)
... or or atleast our understanding of how these tools work !


Any assistance would be appreciated.

Here are a few examples of telephone numbers;

Exmaple 1:

Phone 1: 5616864700
Hex On Disk: C0DBA8ECF441

Phone 2: 5616885403
Hex on Disk: B0E9ADECF4F1



Another example:
Phone 1: 8003346488
Hex On Disk: 800396d0fd41

Phone2: 9544261331
Hex On Disk: F8f50ec70142

Phone3: 9544278601
Hex On Disk: 481211c70142


TIA.

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


Re: Passing arguments to function - (The fundamentals are confusing me)

2005-08-09 Thread Christopher Subich
Dennis Lee Bieber wrote:
>   In a more simplistic view, I'd reverse the phrasing... The name
> "x" is assigned to the object "y" (implying it is no longer attached to
> whatever used to have the name)

No, because that'd imply that the object 'y' somehow keeps track of the 
names assigned to it, which is only true from a refcount perspective -- 
and only on some Python implementations at that.  The object is the 
property of the name, not vice versa.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Passing arguments to function - (The fundamentals are confusing me)

2005-08-09 Thread Christopher Subich
infidel wrote:
>>in Python equality rebinds the name
> 
> 
> Assignment (=) rebinds the name.  Equality (==) is something else
> entirely.

Good catch.  I was thinking of it as the "equals" operator.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Passing arguments to function - (The fundamentals are confusing me)

2005-08-09 Thread Christopher Subich
Rocco Moretti wrote:
> Variables in Python are names. They aren't the cubbyholes into which you 
> put values, they are sticky notes on the front of the cubby hole.

+1 MOTW (Metaphor of the Week)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: sqlobject vs mysqldb module

2005-08-09 Thread Jeffrey E. Forcier
Skip is correct, they're somewhat different:

SQLObject is an 'ORM' or 'Object-Relational Mapping', meaning that it
allows you to handle everything related to the database with objects.
The table handles are objects, the result set is an object, the
individual rows in a result set are objects with attributes for the
fields/columns. So instead of "SELECT id,name FROM people WHERE
location='New York'", you'd do something like the following:

for row in People.selectBy(location='New York'):
print "id: %s, name: %s" % (row.id,row.name)

This is nice if you value object-oriented code very highly, and don't
have any specific SQL-level tricks you wish to employ (although
SQLObject can handle those as well, I'm told, it's just not its main
function).

MySQLDB, while I haven't used it specifically, is probably similar to
its Postgres cousins pyPgSQL and psycopg, in that it just provides a
Python DB API compliant interface to the database (see
http://www.python.org/peps/pep-0249.html).

Such modules do not provide much or any object orientation, sticking
with a more low-level approach of making SQL calls and getting
dictionaries back, to wit:

conn = [module_name].connect(connection_args)
cursor = conn.cursor()
cursor.execute("SELECT id,name FROM people WHERE location='New York'")
print cursor.fetchall()


Anyway, sorry if that's over your head (it's hard to tell your
experience level from your post), but the basic gist is that SQLObject
is good for a higher-level and very easy-to-use database connection,
and MySQLDB is probably good if you're very comfortable with SQL and
not so much with object-oriented programming (or if you have any other
reason to prefer straight SQL queries).

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


Re: Recommendations for CVS systems

2005-08-09 Thread Jeffrey E. Forcier
Thirding the Subversion/SVN suggestions. It's generally a newer, better
CVS with some new features and a lot less of the negative features/lack
thereof, of the older system.

If any of your team has CVS experience they should have no real problem
with the switch, and anyone without prior version control experience
will just be that much better off starting with Subversion.

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


Re: namespaces

2005-08-09 Thread Bengt Richter
On Tue, 09 Aug 2005 08:35:38 -0700, Scott David Daniels <[EMAIL PROTECTED]> 
wrote:

>Paolino wrote:
>> Peter Otten wrote:
>>> Paolino wrote:
 Why descriptor mechanism doesn't apply to modules?
>>> Because modules are instances of the module class and the descriptor 
>>> has to be defined in the class in order to work with the instance
>> Then there is no way of having descriptors at module level,as 'module' 
>> class is not updatable.
>
>Well, an entry in the dictionary "sys.modules" is what is returned by
>imports, so you could either pre-replace or post-replace a module by
>an object which uses the descriptor technique to get to some (but not
>necessarily all) of the attributes.  Think of this technique as a
>hack to get to a goal, rather than a good technique to use; good for
>debugging, not so nice for production work.  If you still don't know
>how to do this from this admittedly sketchy description, I'd suggest
>you avoid trying it altogether.
>
I had the thought a while ago that it might be interesting to have
an import variant that could produce a subclassed module, where you
indicate the import name as usual (for __import__) and also supply
the subclass source text as an argument (string or file).
E.g., something like

subclass_source = """\
class MyModule(math):
twopi = property(lambda: math.pi*2.0')
"""

module_with_property = subclassing_import('math', subclass=subclass_source)

Another thought/bf would be a way to extend the attribute namespace of an 
arbitrary object
by chaining the attribute name spaces of a sequence of objects (this would be a 
language mod)
e.g., (sort of a dynamic instance attribute mixin)

 obj ..= a, b, c  # a sequence of objects

then

 obj.x  # looks for obj.x, then a.x then b.x then c.x before giving up with 
attribute error
 obj ..=()  # clears chained attribute name space ?

Then you could add a property to the namespace of a module by adding an object 
whose class defines
the property, like

 mod ..= objhavingproperty # same tuple ambiguity as with 'somestr' % x

something analogous to += on immutables would have to be done for builtin 
objects I suppose.

Just adding more mulch/worms to the idea garden ;-)

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


Re: Does any one recognize this binary data storage format

2005-08-09 Thread Christopher Subich
[EMAIL PROTECTED] wrote:
> I am hoping someone can help me solve a bit of a puzzle.
> 
> We are working on a data file reader and extraction tool for an old
> MS-DOS accounting system dating back to the mid 80's.
> 
> In the data files, the text information is stored in clearly readable
> ASCII text, so I am comfortable that this file isn't EBCIDIC, however,
> the some of the numbers are stored in a format that we can't seem to
> recognize or unpack using the standard python tools (struct, binascii)
> ... or or atleast our understanding of how these tools work !
> 
> 
> Any assistance would be appreciated.
> 
> Here are a few examples of telephone numbers;
> 
> Exmaple 1:
> 
> Phone 1: 5616864700
> Hex On Disk: C0DBA8ECF441
> 
> Phone 2: 5616885403
> Hex on Disk: B0E9ADECF4F1

Is this value a typo instead of ...F441?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Why does __init__ not get called?

2005-08-09 Thread Rob Conner
Not takers? This is my attempt to get some attention by bumping my own
post.

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


Re: Does any one recognize this binary data storage format

2005-08-09 Thread Dejan Rodiger
[EMAIL PROTECTED] said the following on 9.08.2005 19:29:
> We are working on a data file reader and extraction tool for an old
> MS-DOS accounting system dating back to the mid 80's.

Could you tell us what is the extension of those files?

Could you post full 5-10 records (ASCII + HEX)?

-- 
Dejan Rodiger - PGP ID 0xAC8722DC
Delete wirus from e-mail address
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Passing arguments to function - (The fundamentals are confusing me)

2005-08-09 Thread Rocco Moretti
Dennis Lee Bieber wrote:
> On Tue, 09 Aug 2005 10:39:29 -0500, Rocco Moretti
> <[EMAIL PROTECTED]> declaimed the following in comp.lang.python:
> 
> 
>>Change it to "the object referenced by y is assigned to the name of x", 
>>and you're closer to the truth.
> 
>   In a more simplistic view, I'd reverse the phrasing... The name
> "x" is assigned to the object "y" (implying it is no longer attached to
> whatever used to have the name)

I guess I was too subtle - my point was lost. The key thing is not to 
think of "the object 'y'" but to think of "the object referenced by 
(named) 'y'"  There is a distinction between the object (object) and the 
name (variable), which is essential to eliminating the OP's conundrum.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Passing arguments to function - (The fundamentals are confusing me)

2005-08-09 Thread Rocco Moretti
Christopher Subich wrote:
> Rocco Moretti wrote:
> 
>> Variables in Python are names. They aren't the cubbyholes into which 
>> you put values, they are sticky notes on the front of the cubby hole.
> 
> 
> +1 MOTW (Metaphor of the Week)

Thanks, but please note it's not really mine - I've seen it somewhere 
else before. I thought it was from the website I linked earlier[1], but 
now I'm a little embarrased to find out that isn't, and I have no clue 
where it's from.

[1] http://starship.python.net/crew/mwh/hacks/objectthink.html
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Does any one recognize this binary data storage format

2005-08-09 Thread Dejan Rodiger
[EMAIL PROTECTED] said the following on 9.08.2005 19:29:
> Phone 1: 5616864700
> Hex On Disk: C0DBA8ECF441

5616864700(10)=14ECA8DBC(16)
14 EC A8 DB Cleftshift by 4 bits (it will add 0 on last C)
C0 DB A8 EC 14 00 write bytes from right to left
C0 DB A8 EC F4 41 Add E041

> Phone 1: 8003346488
> Hex On Disk: 800396d0fd41

8003346488(10)=1DD096038(16)
1D D0 96 03 8
80 03 96 D0 1D 00
80 03 96 d0 fd 41 Add E041

But works only for Phone 1 :-)

-- 
Dejan Rodiger - PGP ID 0xAC8722DC
Delete wirus from e-mail address
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: What are modules really for?

2005-08-09 Thread en.karpachov
On Tue, 09 Aug 2005 16:32:31 +0100
N.Davis wrote:

> With single inheritance in C++ or Java, if you wanted to see what a 
> method did and it appeared to be inherited, you would simply look in the 
> base class's file, and if necessary recurse up the inheritance hierarchy 
> until you found the method.
> 
> With Python an inherited method could be in one of many base classes 

And Python doesn't differ from C++ in this matter, as C++ have multiple
inheritance during (more than) last 15 years. If you don't use it in C++
then feel free not to use it in Python as well.

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


Re: Why does __init__ not get called?

2005-08-09 Thread infidel
I think you have to call type.__new__ like this:

def __new__(cls, year, month, day, *args, **kw):
print "new called"
try:
return _datetime.__new__(cls, year, month, day, *args,
**kw)
except ValueError:
return type.__new__(cls, ...)

Are you sure you can specify arbitrary arguments to the __new__ method?
 I thought they had to be the class object, the tuple of bases, and the
dictionary of names.

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


Re: Why does __init__ not get called?

2005-08-09 Thread infidel
> Are you sure you can specify arbitrary arguments to the __new__ method?
> I thought they had to be the class object, the tuple of bases, and the
> dictionary of names.

Nevermind, I think I was imagining metaclasses rather than just regular
overriding of __new__

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


Re: Decline and fall of scripting languages ?

2005-08-09 Thread Donn Cave
In article 
<[EMAIL PROTECTED]>,
 Michael Hudson <[EMAIL PROTECTED]> wrote:

> Donn Cave <[EMAIL PROTECTED]> writes:
> 
> > On the contrary, there are a couple.  Ghc is probably the
> > leading implementation these days, and by any reasonable
> > measure, it is serious.
> >
> > Objective CAML is indeed not a pure functional language.
> 
> *cough* unsafePerformIO *cough*

(Hope that cough isn't anything serious.)  The way I
understand it, you'd be a fool to use unsafePerformIO
in a way that would generally compromise functional
purity.  It really is "unsafe", inasmuch as it violates
central assumptions of the language evaluation model.

Some people take "pure" too seriously.  In this context,
functional purity just means that we know that in principle,
the value of an expression is constant - given the same
inputs to a function, we always expect the same result.
It doesn't mean "free from blemish."  unsafePerformIO is
a sort of blemish, I suppose, but it's a pure functional
language in my book.

   Donn Cave, [EMAIL PROTECTED]
-- 
http://mail.python.org/mailman/listinfo/python-list


Import question

2005-08-09 Thread ncf
In file A, I have an instance of a class and then I import file B
(import fileB as fb). In file B, I need to access file A's class
instance. Is there anyway I can do this? (I hope that was descriptive
enough :\)

-Wes

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


Re: Passing arguments to function - (The fundamentals are confusing me)

2005-08-09 Thread Gregory Piñero
Thanks everyone.  I understand now.  Everything is a reference, all
that matters is whether I can go inside the "cubbyhole" and change
something.  Immutables don't allow this.

So what if I do want to share a boolean variable like so:

sharedbool=True
class cls1:pass
cl=cls1()
cl.sharedbool1=sharedbool

sharedbool=False

>>cl.sharedbool1
True   #but I wanted false!


My guess having read this threat would be to make a simple wrapper
class for a boolean so I'm changing something inside the object
instead of reassigning it?

class bigbool:
/t def __init__(self,tf):
/t/t self.val=tf
/t def setval(self,tf):
/t/t self.val=tf

Is there an easier way?


-Greg

On 8/9/05, Rocco Moretti <[EMAIL PROTECTED]> wrote:
> Christopher Subich wrote:
> > Rocco Moretti wrote:
> >
> >> Variables in Python are names. They aren't the cubbyholes into which
> >> you put values, they are sticky notes on the front of the cubby hole.
> >
> >
> > +1 MOTW (Metaphor of the Week)
> 
> Thanks, but please note it's not really mine - I've seen it somewhere
> else before. I thought it was from the website I linked earlier[1], but
> now I'm a little embarrased to find out that isn't, and I have no clue
> where it's from.
> 
> [1] http://starship.python.net/crew/mwh/hacks/objectthink.html 
> --
> http://mail.python.org/mailman/listinfo/python-list 
> 


-- 
Gregory Piñero
Chief Innovation Officer
Blended Technologies
(www.blendedtechnologies.com)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: namespaces

2005-08-09 Thread Aahz
In article <[EMAIL PROTECTED]>,
Paolino  <[EMAIL PROTECTED]> wrote:
>
>Why descriptor mechanism doesn't apply to modules?

The real answer: Because Guido doesn't want it to
-- 
Aahz ([EMAIL PROTECTED])   <*> http://www.pythoncraft.com/

The way to build large Python applications is to componentize and
loosely-couple the hell out of everything.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Import question

2005-08-09 Thread Lonnie Princehouse
Circular import issues can usually be resolved by moving import
statements into the bodies of functions which aren't executed when the
module itself is imported.  Simple example:

 fileA.py --

import fileB as fb
foo = 10# we're going to access foo from fileB

fb.do_something_with_foo()

 fileB.py --

def do_something_with_foo():
   import fileA as fa  # import is INSIDE the function
   print "foo is ", fa.foo

--

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


Re: Import question

2005-08-09 Thread Paul McNett
ncf wrote:
> In file A, I have an instance of a class and then I import file B
> (import fileB as fb). In file B, I need to access file A's class
> instance. Is there anyway I can do this? (I hope that was descriptive
> enough :\)

Let's see...

# -- fileA.py
class Test(object): pass

myInstance = Test()

import fileB as fb
fb.myInstance = myInstance
fb.test()

# -- fileB.py
myInstance = None

def test():
print "myInstance is %s" % myInstance

if __name__ == "__main__":
test()

# -- now to the command line to test:
[EMAIL PROTECTED]:~/projects/dabo/dabo/ui/uiwx $ python fileB.py
myInstance is None
[EMAIL PROTECTED]:~/projects/dabo/dabo/ui/uiwx $ python fileA.py
myInstance is <__main__.Test object at 0xb7dfcf6c>

Is this what you want? BTW, what you call "files", we refer to as 
"scripts" (if run) or "modules" (if imported).

-- 
Paul McNett
http://paulmcnett.com

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


Re: PEP: Specialization Syntax

2005-08-09 Thread Martin v. Löwis
Nicolas Fleury wrote:
> Well, I'm using the alternatives.

Perhaps not to the full power.

> __arrayTypes = {}
> def makeArrayType(arg1, arg2=someDefault):
> if (arg1, arg2) in __arrayTypes:
> return __arrayTypes[arg1, arg2]
> renamed_arg1 = arg1
> renamed_arg2 = arg2
> class Array:
> arg1 = renamed_arg1
> arg2 = renamed_arg2
> ...
> __arrayTypes[arg1, arg2] = Array
> return Array
> 
> Does it qualify as an "acceptable alternative"? when it could have been:
> 
> class Array[arg1, arg2=someDefault]:

So you don't want to write the makeArrayType function, right?

How about this:

# declaration
class Array(object):
  __typeargs__ = ['arg1', ('arg2', someDefault)]
  ...

# use
t = specialize(Array, arg1=Int32)

where specialize is defined as

def specialize(ptype, *args):
  result = type(ptype.__name__, (ptype,), args)
  for t in result.__typeargs__:
  if isinstance(t, string):
  if not hasattr(result, t):
  raise TypeError("missing parameter "+t)
  else:
  name,val = t
  if not hasattr(result, name):
  setattr(result, val)
   return result

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


Re: Why does __init__ not get called?

2005-08-09 Thread infidel
This doesn't work.  I'm out of my league here.

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


Re: Build errors for Objects/complexobject.c

2005-08-09 Thread Martin v. Löwis
[EMAIL PROTECTED] wrote:
> I'm attempting to build Python 2.4.1 on Solaris 10 using gcc 3.4.3. I
> get the following build error:

This is a GCC bug, which I think got fixed in gcc 4.0.1. You can work
around it by removing the definition of _XOPEN_SOURCE, POSIX_SOURCE,
XOPEN_SOURCE_EXTENDED from pyconfig.h.

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


Re: Does any one recognize this binary data storage format

2005-08-09 Thread geskerrett
the extension on the files is *.mas  but I a pretty sure it is not
relevant. I beleive it used by the application.

I can posted records as it will take up to much space.
But all three phone numbers are stored in 8 bytes with null bytes (ie.
00) stored in the leading positions (ie. the left hand side)

I do have some more examples;

I have inserted the leading null bytes and seperated with spaces for
clarity.

Ex #1)   333-
Hex On disk: 00 00 00 80 6a 6e 49 41

Ex #2) 666-
Hex On disk: 00 00 00 80 6a 6e 59 41

Ex#3) 777-
Hex On Disk: 00 00 00 40 7C AB 5D 41

Ex#4) 123-4567
Hex On Disk: 00 00 00 00 87 D6 32 41

Ex#5) 000-0001
Hex On disk: 00 00 00 00 00 00 F0 3F

Ex#6) 999-
Hex On disk: 00 00 00 E0 CF 12 63 41

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


Re: Does any one recognize this binary data storage format

2005-08-09 Thread Christopher Subich
Dejan Rodiger wrote:
> 8003346488(10)=1DD096038(16)
> 1D D0 96 03 8
> 80 03 96 D0 1D 00
> 80 03 96 d0 fd 41 Add E041

I'm pretty sure that the last full byte is a parity check of some sort. 
  I still thing that Phone2 (..F1) is a typo and should be 41.  Even if 
it's not, it could be a more detailed parity (crc-like?) check.

If the F1/41 is a typo, the last byte is ..41 if the parity of the other 
40 bits is odd, and ..42 if the parity is even. (Since ..41 and ..42 
each have two 1s, it does not change the parity of the entire string). 
If not, Lucy has some 'splaining to do.

Taking the last byte out of ther equation entirely, 40 bytes for 10 
decimal numbers is 4 bytes / number, meaning there is some redundancy 
still in the remainder (the full 10-digit number can be expressed with 
room to spare in 36 bits).

Thinking like an 80s Mess-Dos programmer, 32-bit math is out of the 
question since the CPU doesn't support it.  Five decimal digits already 
pushes the 16-bit boundary, so thinking of using the full phone number 
or any computation is insane.

#1/#2 and #4/#5 share both the first five digits of the real phone 
number and the last 16 bits of the remaining expression.  Both pairs 
*also* share bits 5-8 (the second hex digit).

Therefore, we may possibly conclude that digits 5-10 are stored in bits 
5-8 and 21-36.  This is an even 20 of the 40 data-bits.  In fact, bits 
6-8 of all expamples given were all 0, but since I can't find an 
equivalent always-x set for the other 5 digits I'm not sure that this is 
significant.

Therefore:
95442 = 8c701 = 1 + c701 (?)
56168 = 0ECF4 = 0 + ecf4 (?)

I'm not coming up with a terribly useful algorithm from this, though. :/ 
  My guess is that somewhere, there's a boolean check based on whether a 
digit is >= 6 [maybe 3?] (to prevent running afoul of 16-bitness).  I'm 
also 90% sure that the first and second halves of the phone number are 
processed separately, at mostly, for the same reason.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Why does __init__ not get called?

2005-08-09 Thread Lonnie Princehouse
What kinds of illegal date values are you trying to represent?  The
reason I ask is that it's not going to be as easy as subclassing
datetime... datetime is implemented in C.  and so enforcement of legal
values is going to be in the C code.  For the time.h functions, you're
also going to be constrained by the size of the time_t struct, which is
probably a long int on your platform.   See Modules/datetimemodule.c in
the Python source.

One thing you could do would be to copy datetimemodule.c and build your
own C extension type based on it... things like MAXYEAR  could be
changed that way.

The other thing would be to write a pure-python datetime class without
trying to inherit datetime.datetime.

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


Re: Passing arguments to function - (The fundamentals are confusing me)

2005-08-09 Thread Christopher Subich
Gregory Piñero wrote:
> So what if I do want to share a boolean variable like so:

Well, the easiest way is to wrap it in a list:

mybool = [True]
mybool[0] = False
mybool[0] = True

and so on.

Alternately, what is this boolean attached to that's so significant? 
Sharing an arbitrary boolean, without any context, is rather strange -- 
perhaps it would be best to include both the boolean and associated 
context in a single, larger object.

Also, remember that Python functions can return more than one value, 
through implicit tuple packing and unpacking.  This greatly reduces the 
need for C-like result = function(&other_result) - isms.

def myfunc():
return 1,2,3
(a,b,c) = myfunc()
a == 1
b == 2
c == 3
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Does any one recognize this binary data storage format

2005-08-09 Thread Roel Schroeven
Dejan Rodiger wrote:
> [EMAIL PROTECTED] said the following on 9.08.2005 19:29:
> 
>>Phone 1: 5616864700
>>Hex On Disk: C0DBA8ECF441
> 
> 
> 5616864700(10)=14ECA8DBC(16)
> 14 EC A8 DB Cleftshift by 4 bits (it will add 0 on last C)
> C0 DB A8 EC 14 00 write bytes from right to left
> C0 DB A8 EC F4 41 Add E041
> 
> 
>>Phone 1: 8003346488
>>Hex On Disk: 800396d0fd41
> 
> 
> 8003346488(10)=1DD096038(16)
> 1D D0 96 03 8
> 80 03 96 D0 1D 00
> 80 03 96 d0 fd 41 Add E041
> 
> But works only for Phone 1 :-)

E041 is some kind of checksum perhaps?

-- 
If I have been able to see further, it was only because I stood
on the shoulders of giants.  -- Isaac Newton

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


Re: Does any one recognize this binary data storage format

2005-08-09 Thread geskerrett
You are correct, that was a typo.
the second example should end in F441.

Thanks.

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


Re: Syntax error after upgrading to Python 2.4

2005-08-09 Thread Reinhold Birkenfeld
Michael Hudson wrote:
> [EMAIL PROTECTED] writes:
> 
>> On Sat, Aug 06, 2005 at 05:15:22PM -0400, Terry Reedy wrote:
>>> In any case letting developers add new features is part of the price of 
>>> getting unpaid bug fixes for free software.  But note that PSF does not 
>>> make you to upgrade.  Here is the current list of possible downloads.
>>> 
>> [a mere 8 versions]
>>
>> Oh, don't give such a short list!  Here's what I found on the python.org ftp 
>> site:
> 
> [...]
> 
>> And then there's CVS...
> 
> Which doesn't build for the really early versions.  I think
> python1.0.1.tar.gz is as old as it's easy to get.

Can we assume that the 0.9.1 version Guido posted to alt.sources does build?

Google Groups for "Python 0.9.1 group:alt.sources".

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


Re: Does any one recognize this binary data storage format

2005-08-09 Thread Grant Edwards
On 2005-08-09, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote:

> I can posted records as it will take up to much space. But all
> three phone numbers are stored in 8 bytes with null bytes (ie.
> 00) stored in the leading positions (ie. the left hand side)
>
> I do have some more examples;
>
> I have inserted the leading null bytes and seperated with spaces for
> clarity.
>
> Ex #1)   333-
> Hex On disk: 00 00 00 80 6a 6e 49 41
>
> Ex #2) 666-
> Hex On disk: 00 00 00 80 6a 6e 59 41

So there's only a 1-bit different between the on-disk
representation of 333- and 666-.

That sounds pretty unlikely.  Are you 100% sure you're looking
at the correct bytes?

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


pyuic and Qt Designer plugins

2005-08-09 Thread Madhusudan Singh
Hi

I managed to compile and install the FileChooser plugin (.so file)
in /usr/share/qt3/plugins/designer and use it in my form in Designer.

Then I tried to use pyuic which generated the .py code from the ui file. An
attempt to execute the python file quits with :

Traceback (most recent call last):
  File "measure.py", line 16, in ?
f = MEASURE()
  File "/home/m_singh/measure.py", line 422, in __init__
self.fileChooser1 = FileChooser(self.groupBox4,"fileChooser1")
NameError: global name 'FileChooser' is not defined

The wrapper in my .py file :

from qt import *
from measure import *
import sys
if __name__ == "__main__":
app = QApplication(sys.argv)
f = MEASURE()
f.show()
app.setMainWidget(f)
app.exec_loop()

What do I need to do to include the FileChooser plugin ?

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


Re: Does any one recognize this binary data storage format

2005-08-09 Thread geskerrett
Yes I double checked as I appreciate any help, but that is what is
stored on disk.

If it helps, we modified Ex#3. to be 777-777-
On disk this is now 00 00 10 87 77 F9 Fc 41

All the input fields are filled in this new example.

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


Re: python for microcontrollers

2005-08-09 Thread Evil Bastard
Paul Rubin wrote:
> I don't think you want to do this.  Runtime type tags and the overhead
> of checking them on every operation will kill you all by themselves.
> Processors like that haven't been used much as Lisp targets either,
> for the same reasons.  Pick a different language.

On thinking about it, you might be right.

Unless one implements a full dynamic OO engine, the prospect of
implementing python for microcontrollers resembles the task of moving a
palace's furnishings into a trailer park - you'll get a couple of things
into the trailer, but will have to leave the rest outside in the mud and
the rain.

Maybe I should clean up my forth compiler instead, and get it ready for
the prime time.

-- 
Cheers
EB

--

One who is not a conservative by age 20 has no brain.
One who is not a liberal by age 40 has no heart.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Does any one recognize this binary data storage format

2005-08-09 Thread Dejan Rodiger
[EMAIL PROTECTED] said the following on 9.08.2005 22:45:
> Yes I double checked as I appreciate any help, but that is what is
> stored on disk.
> 
> If it helps, we modified Ex#3. to be 777-777-
> On disk this is now 00 00 10 87 77 F9 Fc 41
> 
> All the input fields are filled in this new example.
> 

So for number with 10 digit numbers you could say that it is:
77(10)=1CF977871(16)
1CF977871 SHL 4 bits = 1C F9 77 87 10
write them from right to left and shift left for 8 bits
10 87 77 f9 1C 00
And then add F0 41

Could you also give some examples with nine to one digits?

-- 
Dejan Rodiger - PGP ID 0xAC8722DC
Delete wirus from e-mail address
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Does any one recognize this binary data storage format

2005-08-09 Thread Scott David Daniels
Grant Edwards wrote:
>>Ex #1)   333-
>>Hex On disk: 00 00 00 80 6a 6e 49 41
>>
>>Ex #2) 666-
>>Hex On disk: 00 00 00 80 6a 6e 59 41
> 
> So there's only a 1-bit different between the on-disk
> representation of 333- and 666-.
> 
> That sounds pretty unlikely.  Are you 100% sure you're looking
> at the correct bytes?

Perhaps the one bit is an exponent -- some kind of floating point
based format?  That matches the doubling of all digits.

--Scott David Daniels
[EMAIL PROTECTED]
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Does any one recognize this binary data storage format

2005-08-09 Thread Dejan Rodiger
Dejan Rodiger said the following on 9.08.2005 23:28:
> [EMAIL PROTECTED] said the following on 9.08.2005 22:45:
> 
>>Yes I double checked as I appreciate any help, but that is what is
>>stored on disk.
>>
>>If it helps, we modified Ex#3. to be 777-777-
>>On disk this is now 00 00 10 87 77 F9 Fc 41
>>
>>All the input fields are filled in this new example.
>>
> 
> 
> So for number with 10 digit numbers you could say that it is:
> 77(10)=1CF977871(16)
> 1CF977871 SHL 4 bits = 1C F9 77 87 10
> write them from right to left and shift left for 8 bits
> 10 87 77 f9 1C 00
> And then add F0 41

And add E041 (not F0 41)

-- 
Dejan Rodiger - PGP ID 0xAC8722DC
Delete wirus from e-mail address
-- 
http://mail.python.org/mailman/listinfo/python-list


Adding and attribute to an instance

2005-08-09 Thread J
Hi,


I am trying to add new data attributes to my extension classes from
within a script. I am under the impression that python allows
that implicity


This is the definition of my class

PyTypeObject CmdPlace::PyType =
{
PyObject_HEAD_INIT(NULL)
0,  /*ob_size*/
"Place",/*tp_name*/
sizeof(CmdPlace::PyStruct), /*tp_basicsize*/
0,  /*tp_itemsize*/
0,  /*tp_dealloc*/
0,  /*tp_print*/
0,  /*tp_getattr*/
0,  /*tp_setattr*/
0,  /*tp_compare*/
0,  /*tp_repr*/
0,  /*tp_as_number*/
0,  /*tp_as_sequence*/
0,  /*tp_as_mapping*/
0,  /*tp_hash */
0,  /*tp_call*/
0,  /*tp_str*/
PyObject_GenericGetAttr,/*tp_getattro*/
PyObject_GenericSetAttr,/*tp_setattro*/
0,  /*tp_as_buffer*/
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /*tp_flags*/
"CmdPlace", /* tp_doc */
0,  /* tp_traverse */
0,  /* tp_clear */
0,  /* tp_richcompare */
0,  /* tp_weaklistoffset */
0,  /* tp_iter */
0,  /* tp_iternext */
CmdPlace::sPyMethods,   /* tp_methods */
CmdPlace::sPyMembers,   /* tp_members */
CmdPlace::sPyGetSeters, /* tp_getset */
0,  /* tp_base */
0,  /* tp_dict */
0,  /* tp_descr_get */
0,  /* tp_descr_set */
0,  /* tp_dictoffset */
0,  /* tp_init */
0,  /* tp_alloc */
0,  /* tp_new */
};

I call

PyType_Ready(&PyType);
Py_INCREF(&PyType);

to initialize the type, and

PyObject_INIT((PyObject*)&mPyObject, &CmdPlace::PyType);

to initialize an object. Objects of this type are only ever
instantiated from C++. When I evaluate a sript I just add the object as
"MyObject" to the dicitonary passed to Py_Eval... All the
members and methods work fine, but when I do

MyObject.aNewAttribue = 12

I get at an error saying

object has no attribute "aNewAttribue".

I have looked at some of the source code in PyObject_GenericGetAttr and
it turns out that the object has no dictionary. It seens that the
address of the dictionary is computed somehow via tp_dictoffset in the
type object.

Basically my question is, how can I make this work.


Cheers
Jochen

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


MainThread blocks all others

2005-08-09 Thread Nodir Gulyamov
Hello All!
I met some strange situation. In MainThread my program wating changes of 
some variable. This variable should be changed in another thread, but loop, 
which wait changing variable blocks all other threads.
Code below:

class class1:
def __init__(self):
self.counter = 0
result = doSomeJob()

def increaseCounter(self):
self.counter += 1

doSomeJob(self):
# BLOCKING HERE ###
while counter != 1:
pass
# ... continue...

# this class subscribed to some observer which implements thread
class monitor:
def __init__(self, klass):
#do some init
self.c = klass
def update(self):
self.c.increaseCounter()

if __name__ == "__main__":
cl1 = class1()
m = monitor(cl1)
mo = MonitorObserver(m)


I am very confused how to resolve this problem. Any help will be 
appreciated.

Thanks in advance to All.

Best regards,
/Gelios 


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


Re: Embedding a runtime graph in Qt3 designer generated UI

2005-08-09 Thread Madhusudan Singh
Phil Thompson wrote:

>> 2. In the same vein, how does one embed a runtime plot in a qt3 UI ? It
>> will
>> need to be a python solution since I am using python libraries to acquire
>> the data.
> 
> Have a look at PyQwt which is a set of Python bindings for the Qt-based
> Qwt plotting library.
> 
> Phil

Can a designer plugin be used this way ?

I tried inserting a FileChooser (available as an .so file under designer
plugins) object onto the main window and then used pyuic.

Traceback (most recent call last):
  File "measure.py", line 16, in ?
f = MEASURE()
  File "/home/m_singh/measure.py", line 422, in __init__
self.fileChooser1 = FileChooser(self.groupBox4,"fileChooser1")
NameError: global name 'FileChooser' is not defined

The wrapper in my .py file :

from qt import *
from measure import *
import sys
if __name__ == "__main__":
app = QApplication(sys.argv)
f = MEASURE()
f.show()
app.setMainWidget(f)
app.exec_loop()

An attempt to use QwtPlot gives the same kind of error. Or is the only 
way
forward for me to generate a .py file from non-plugin objects, and then
hand code the pyqwt part into that result (Or use Python: in the ui).
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: PEP: Specialization Syntax

2005-08-09 Thread Nicolas Fleury
Martin v. Löwis wrote:
> Nicolas Fleury wrote:
> 
>>Well, I'm using the alternatives.
> 
> Perhaps not to the full power.

Not perhaps, surely;)  Who does anyway;)

> So you don't want to write the makeArrayType function, right?
> 
> How about this:
> 
> # declaration
> class Array(object):
>   __typeargs__ = ['arg1', ('arg2', someDefault)]
>   ...
> 
> # use
> t = specialize(Array, arg1=Int32)
> 
> where specialize is defined as
> 
> def specialize(ptype, *args):
>   result = type(ptype.__name__, (ptype,), args)
>   for t in result.__typeargs__:
>   if isinstance(t, string):
>   if not hasattr(result, t):
>   raise TypeError("missing parameter "+t)
>   else:
>   name,val = t
>   if not hasattr(result, name):
>   setattr(result, val)
>return result

That exact solution would not work for me, since that would replace the 
class metaclass, right?  However, you have a good point.  Such a 
function could be done by using the class metaclass instead of type, 
passing the base classes and dictionary (basically copying the class) 
and using a dictionary with args values as a key to avoid redundacies 
(can't see if there's something else).

Thx and regards,
Nicolas
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: gettext again

2005-08-09 Thread cantabile
stas a écrit :

> As a reminder, make sure that you install gettext in the namespace
> of your toplevel module.
> What I mean is this:
> 
> test1.py imports test2.py and test3.py
> test2.py imports test4.py
> 
> Now you have to place the gettext.install call in test1.py and
> then the other modules can access it.
> If you place the gettext call in, for example, test2.py then only
> test2.py and test4.py have access to it.
> So when it don't work as you expect make sure to check if every
> module has access to the "_" from gettext.
Noticed something :
I must import test2.py AFTER gettext.install('test1') and even then, if 
test3.py imports test2.py, messages won't be translated in test3.py. I 
have to import test3.py in test1.py too.
Is this normal behaviour or is there something I'm missing (again) ?

PS : your project looks nice !
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Does any one recognize this binary data storage format

2005-08-09 Thread Grant Edwards
On 2005-08-09, Scott David Daniels <[EMAIL PROTECTED]> wrote:
> Grant Edwards wrote:
>>>Ex #1)   333-
>>>Hex On disk: 00 00 00 80 6a 6e 49 41
>>>
>>>Ex #2) 666-
>>>Hex On disk: 00 00 00 80 6a 6e 59 41
>> 
>> So there's only a 1-bit different between the on-disk
>> representation of 333- and 666-.
>> 
>> That sounds pretty unlikely.  Are you 100% sure you're looking
>> at the correct bytes?
>
> Perhaps the one bit is an exponent -- some kind of floating point
> based format?  That matches the doubling of all digits.

That would just be sick.  I can't imagine anybody on an 8-bit
CPU using FP for a phone number.

-- 
Grant

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


SPE: New website & Mac Os X fund raising

2005-08-09 Thread spe . stani . be
SPE (Stani's Python Editor) is an open-source python IDE with auto
indentation & completion, call tips, syntax coloring & highlighting,
UML diagrams, class explorer, source index, auto todo list, sticky
notes, pycrust shell, file browsers, drag&drop, context help, Blender
support, ... Spe ships with Python debugger (remote & encrypted),
wxGlade (gui designer), PyChecker (source code doctor) and Kiki (regex
console).

To support the development of SPE for Mac, some enthousiastic mac SPE
users have started a fund raising campaign to buy a Mac for SPE:

"What it would be worth to you to have a new release of SPE running
on your Mac Os X the same day as it appears on other platforms? $50?
$75? $100? My company, Dartware, has contributed 250 Euros to start the
fundraising. We're willing to give a major boost because it's worth it
for us to have a nice environment for Python programming." - Rich
Brown (Dartware)

Acquiring a Mac for SPE will allow to optimize it properly and to
release it simultaneously for Mac Os X. Any donation is welcome, but of
course generous donations are necessary. Due to the high Paypal
commission fees, European users are explicitly requested to donate
through IBAN. More info on the donation page.

Until now people donated 314 Euros. 416 Euros is still required to make
the purchase (mini Mac & KVM switch) go through. If some people would
donate 50 euros, this target could easily get archieved. Otherwise if
you have an old Mac, which runs Os X and which you are ready to give to
SPE, contact me. If someone is able to convince Mac to do some
sponsering, please contact me as well.

The new version of SPE 0.7.5.b, which will include the debugger, will
be released soon. Subscribe to the mailing list or read more on the SPE
News Blog. Links and bookmarks to the SPE website should be updated to
http://pythonide.stani.be!

Stani (spe.stani.be at gmail.com)

Homepage:  http://pythonide.stani.be
Screenshots:   http://pythonide.stani.be/screenshots
How to donate: http://pythonide.stani.be/blog/sm_donate

Post which started the fund raising:
http://lists.berlios.de/pipermail/python-spe-mac/2005-August/54.html

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


  1   2   >