psycopg simplest problem

2005-07-08 Thread Glauco
I'm rebuilding my old library i've done some year ago using python and 
postgres.

My problem is to do a middle layer over pycopg for eliminate type 
casting problem in postgres in all direction.

i've resolved this doing a C extension in python and manipulating only 
string and int in my application.

this is my example:
import sqlvar

sql = """insert into mytable (myint, mytext, maydate)
  values
  (%d,%s,%s);""" % (sqlvar.number(myvalue1), 
sqlvar.text(myvalue2), sqlvar.date(myvalue3) )

all problem concerning quoting, " ' -> ''", null, None, 0, empty string 
is solved by the sqlvar lib.


I want to eliminate this problem forever, i want to manipulate only 
correct type as DateTime obj in my application so i want to arrive at 
this solution:


sql = """insert into mytable (myint, mytext, maydate)
  values
  (%s,%s,%s);""" % (myvalue1, myvalue2, myvalue3)

without all time check for none, empty string and so on...

I've seen API of psycopg and some procedure for the solution but all are 
too spaghetti for me.

I'm only with this problem ?


Glauco


-- 

  \\\|///
\\  - -  //
 (  @ @  )
+-oOOo-( )-oOOo--+
||
| I have a dream that one day this nation will rise up and   |
|   live out the true meaning of its creed: "We hold these   |
|   truths to be self-evident:that all men are created equal.|
| I have a dream that one day on the red hills of Georgia|
|   the sons of former slaves and the sons of former |
|   slaveowners will be able to sit down together at a table |
|   of brotherhood.  |
| I have a dream that one day even the state of Mississippi, |
|   a desert state, sweltering with the heat of injustice|
|   and oppression, will be transformed into an oasis of |
|   freedom and justice. |
| I have a dream that my four children will one day live in  |
|   a nation where they will not be judged by the color of   |
|   their skin but by the content of their character.|
| I have a dream today.  |
||
|Martin Luther King, Jr  28 Ago 1963 |
++
|glauco(at)uriland.it|
|  www.uriland.it  .oooOICQ: 115323690   |
+- (   )-- Oooo.-+
 \ ((   )
  \_)) /
(_/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: psycopg simplest problem

2005-07-08 Thread Glauco
Gerhard Haering wrote:
> On Fri, Jul 08, 2005 at 04:23:50PM +0200, Glauco wrote:
> 
>>[...]
>>My problem is to do a middle layer over pycopg for eliminate type 
>>casting problem in postgres in all direction.
>>
>>i've resolved this doing a C extension in python and manipulating only 
>>string and int in my application.
>>
>>this is my example:
>>import sqlvar
>>
>>sql = """insert into mytable (myint, mytext, maydate)
>>  values
>>  (%d,%s,%s);""" % (sqlvar.number(myvalue1), 
>>sqlvar.text(myvalue2), sqlvar.date(myvalue3) )
>>
>>all problem concerning quoting, " ' -> ''", null, None, 0, empty string 
>>is solved by the sqlvar lib. [...]
> 
> 
> Instead of quoting Python values yourself appropriately for each type,
> just let the DB-API module do its work. Use parametrized queries and
> then supply the arguments to the query:
> 
> cur = con.cursor()
> intVal = 42
> textVal = "Jason's house"
> dateVal = datetime.date(2005, 7, 8)
> cur.execute("""
> insert into mytable(myint, mytext, mydate)
> values (%s, %s, %s)
> """, (intval, textVal, dateVal))
> 
> The execute(many) method has an optional second parameter, which is a
> tuple of values for your parametrized query.
> 
> There are different styles to parametrize queries among the various
> DB-API modules. psycopg uses the pyformat one, where you just use %s as
> placeholders.
> 
> It will happily quote all Python values of types int, str, date, float,
> etc.  for you. It's also possible to teach it how to quote other custom
> data types, but you'll normally not need this.
> 
> HTH,
> 
> -- Gerhard

Gerhard thank you very much, this example explain me some idea, but 
anyway don't resolve the core question.
In you example when dateVal is a None or textVal is none.
argument x must be DateTime, not None.
so i must manipulate for the empty string or None cases



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


Dictionary, keys and alias

2005-07-18 Thread Glauco
I want to insert a concept of alias in a dict_based class.

The idea  is to have a facoltative name in the same dict that correspond 
at the same value. With this alias i can change original value.

example:

mydict['a'] = 1
I must define an alias  example: myFunctAlias( mydict, 'a', 'b')
print mydict
{'a':1, 'b':1}
mydict['b'] = 2
print mydict
{'a':2, 'b':2}


The only idea i have is to implement two dictionary one for convert 
name, alias in two keys with the same value (eg.numeric) in the first 
dict. The second for store only one time the k, v .


Any suggestion ?
Glauco



-- 

  \\\|///
\\  - -  //
 (  @ @  )
+-oOOo-( )-oOOo--+
||
| I have a dream that one day this nation will rise up and   |
|   live out the true meaning of its creed: "We hold these   |
|   truths to be self-evident:that all men are created equal.|
| I have a dream that one day on the red hills of Georgia|
|   the sons of former slaves and the sons of former |
|   slaveowners will be able to sit down together at a table |
|   of brotherhood.  |
| I have a dream that one day even the state of Mississippi, |
|   a desert state, sweltering with the heat of injustice|
|   and oppression, will be transformed into an oasis of |
|   freedom and justice. |
| I have a dream that my four children will one day live in  |
|   a nation where they will not be judged by the color of   |
|   their skin but by the content of their character.|
| I have a dream today.  |
||
|Martin Luther King, Jr  28 Ago 1963 |
++
|glauco(at)uriland.it|
|  www.uriland.it  .oooOICQ: 115323690   |
+- (   )-- Oooo.-+
 \ ((   )
  \_)) /
(_/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Dictionary, keys and alias

2005-07-19 Thread Glauco
Steven D'Aprano wrote:
> On Mon, 18 Jul 2005 12:17:37 +0200, Glauco wrote:
> 
> 
>>I want to insert a concept of alias in a dict_based class.
>>
>>The idea  is to have a facoltative name in the same dict that correspond 
>>at the same value. With this alias i can change original value.
>>
>>example:
>>
>>mydict['a'] = 1
>>I must define an alias  example: myFunctAlias( mydict, 'a', 'b')
>>print mydict
>>{'a':1, 'b':1}
>>mydict['b'] = 2
>>print mydict
>>{'a':2, 'b':2}
>>
>>
>>The only idea i have is to implement two dictionary one for convert 
>>name, alias in two keys with the same value (eg.numeric) in the first 
>>dict. The second for store only one time the k, v .
> 
> 
> You need some sort of redirection, something like this (untested):
> 
> class Doubledict:
> def __init__(self, **kargs):
> self.data = {}
> self.aliases = {}
> for key in kargs:
> # Point the key to a hash.
> self.aliases[key] = hash(key)
> # And point the hash at the value.
> self.data[hash(key)] = kargs[key]
> 
> def setalias(self, key, alias):
> # Point the alias to the same hash as the real key.
> self.aliases[alias] = hash(key)
> 
> def __getitem__(self, key):
> return self.data[self.aliases[key]]
> 
> def __setitem__(self, key, value):
> self.data[self.aliases[key]] = value
> 
> 
> The only niggly worry I have is I'm not sure when hash can be used, when
> it is unique, or even if is it guaranteed to be unique.
> 

Thank Steve, the idea was the same...
but yours using hash is much elegant.

Thank you
Glauco

-- 

  \\\|///
\\  - -  //
 (  @ @  )
+-oOOo-( )-oOOo--+
||
| I have a dream that one day this nation will rise up and   |
|   live out the true meaning of its creed: "We hold these   |
|   truths to be self-evident:that all men are created equal.|
| I have a dream that one day on the red hills of Georgia|
|   the sons of former slaves and the sons of former |
|   slaveowners will be able to sit down together at a table |
|   of brotherhood.  |
| I have a dream that one day even the state of Mississippi, |
|   a desert state, sweltering with the heat of injustice|
|   and oppression, will be transformed into an oasis of |
|   freedom and justice. |
| I have a dream that my four children will one day live in  |
|   a nation where they will not be judged by the color of   |
|   their skin but by the content of their character.|
| I have a dream today.  |
||
|Martin Luther King, Jr  28 Ago 1963 |
++
|glauco(at)uriland.it|
|  www.uriland.it  .oooOICQ: 115323690   |
+- (   )-- Oooo.-+
 \ ((   )
  \_)) /
(_/
-- 
http://mail.python.org/mailman/listinfo/python-list


EOF occurred in violation of protocol

2006-01-17 Thread Glauco
Hi all,
I have an urgent issue using some WebServices in ZSI and python 2.3.3.
The Server Was obviously an ISS and today all my comunication end  with:

File "/opt/sfera/python2.3.3/lib/python2.3/socket.py", line 73, in ssl
 return _realssl(sock, keyfile, certfile)
socket.sslerror: (8, 'EOF occurred in violation of protocol')


I'm in trouble because i've tryed some workaround on httplib.py and 
socket.py but they don't work never.


Some soggestion or workaround for bypass this problem?

Thank you anyway.
Glauco
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: File to dict

2007-12-07 Thread Glauco
[EMAIL PROTECTED] ha scritto:
> Hello everyone,
> 
> I have written this small utility function for transforming legacy
> file to Python dict:
> 
> 
> def lookupdmo(domain):
> lines = open('/etc/virtual/domainowners','r').readlines()
> lines = [ [y.lstrip().rstrip() for y in x.split(':')] for x in
> lines]
> lines = [ x for x in lines if len(x) == 2 ]
> d = dict()
> for line in lines:
> d[line[0]]=line[1]
> return d[domain]
> 

cache = None

def lookup( domain ):
if not cache:
   cache = dict( [map( lambda x: x.strip(), x.split(':'))  for x in 
open('/etc/virtual/domainowners','r').readlines()])
return cache.get(domain)





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


Re: File to dict

2007-12-07 Thread Glauco
david ha scritto:
> On Fri, 07 Dec 2007 16:46:56 +0100, Glauco wrote:
> 
>> [EMAIL PROTECTED] ha scritto:
>>> Hello everyone,
>>>
>>> I have written this small utility function for transforming legacy file
>>> to Python dict:
>>>
>>>
>>> def lookupdmo(domain):
>>> lines = open('/etc/virtual/domainowners','r').readlines() lines
>>> = [ [y.lstrip().rstrip() for y in x.split(':')] for x in
>>> lines]
>>> lines = [ x for x in lines if len(x) == 2 ] d = dict()
>>> for line in lines:
>>> d[line[0]]=line[1]
>>> return d[domain]
>>>
>>>
>> cache = None
>>
>> def lookup( domain ):
>> if not cache:
>>cache = dict( [map( lambda x: x.strip(), x.split(':'))  for x in
>> open('/etc/virtual/domainowners','r').readlines()])
>> return cache.get(domain)
>>
> 
>>>> lookup(1)
> Traceback (most recent call last):
>   File "", line 1, in 
>   File "", line 2, in lookup
> UnboundLocalError: local variable 'cache' referenced before assignment
> 
> You miss the:
> def lookup(domain):
>   global cache
>   ...
> 
> bye

yezzz!

you can use global or static


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


Re: string in files

2008-12-30 Thread Glauco


thanks brother
i mean how do i particularly assign (u = this)
(y = is)
in the strings up there. i have been able to split strings with any
character sign.




If i'm not wrong this is simple with RE:

In [1]: st  = 'this is a python coding group'

In [2]: import re

In [3]: re.compile( "(?P.*) (?P.*) (?P.*) (?P.*) 
(?P.*) (?P.*)" )

Out[3]: <_sre.SRE_Pattern object at 0x9e93ac0>

In [4]: rule = re.compile( "(?P.*) (?P.*) (?P.*) 
(?P.*) (?P.*) (?P.*)" )


In [5]: m  = rule.match( st )

In [6]: dir(m)
Out[6]:
['__copy__',  '__deepcopy__',
 'end',  'expand',
 'group',  'groupdict',
 'groups',  'span',  'start']

In [7]: m.groupdict().items()
Out[7]:
[('si', 'group'),
 ('second', 'is'),
 ('t', 'a'),
 ('fi', 'coding'),
 ('fo', 'python'),
 ('first', 'this')]

In [8]: dict(m.groupdict().items())
Out[8]:
{'fi': 'coding',
 'first': 'this',
 'fo': 'python',
 'second': 'is',
 'si': 'group',
 't': 'a'}



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


Re: string in files

2008-12-31 Thread Glauco

Steven D'Aprano ha scritto:

On Tue, 30 Dec 2008 11:53:17 +0100, Glauco wrote:



thanks brother
i mean how do i particularly assign (u = this)
(y = is)
in the strings up there. i have been able to split strings with any
character sign.



If i'm not wrong this is simple with RE:


If that's your idea of "simple", I'd hate to see what you consider 
complicated!


*Simple* is just using the split method.

a, b, c, d, e, f = 'this is a python coding group'.split()



I've done a lot of file import procedure and IMHO this solution help you 
 in all situation. You can validate line before import, you can do a 
specific RE for check a more detailed line and so on, it's more powerful.


For simple i mean simple programming code.


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


Re: itertools question

2009-05-14 Thread Glauco

Neal Becker ha scritto:
Is there any canned iterator adaptor that will 


transform:
in = [1,2,3]

into:
out = [(1,2,3,4), (5,6,7,8),...]

That is, each time next() is called, a tuple of the next N items is 
returned.





http://stackoverflow.com/questions/312443/how-do-you-split-a-list-into-evenly-sized-chunks-in-python



Gla

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


Re: Extract value and average

2009-06-09 Thread Glauco

Francesco Pietra ha scritto:

I come 'naked', which is unusual and unfair. However, I find it
difficult to give a correct start. The files consist, among other
things, of a huge number of blocks of the type


 NSTEP = 1000   TIME(PS) = 152.000  TEMP(K) =   298.54  PRESS =89.4
 Etot   =   -134965.2123  EKtot   = 41282.1781  EPtot  =   -176247.3905
 BOND   =  1771.7644  ANGLE   =  6893.3003  DIHED  =  4660.1650
 1-4 NB =  1931.6071  1-4 EEL =  7799.8343  VDWAALS= 19047.1551
 EELEC  =   -218354.9960  EHBOND  = 0.  RESTRAINT  = 3.7793
 EAMBER (non-restraint)  =   -176251.1698
 EKCMT  = 16048.2253  VIRIAL  = 14755.8154  VOLUME =669299.5681
Density= 0.9896
 Ewald error estimate:   0.8252E-05



(in attachment what surely is a correct reproduction of columns)

I would like to extract values corresponding to variable DIHED (here
4660.1650) and getting also the mean value from all DIHED.

Thanks for giving a possible attack

francesco pietra



If this format is fixed...



vals = [ float(l.split('=')[-1].strip())
 for l in file('file.txt','r')
 if ' DIHED ' in l ]

mean = sum(vals) / len(vals)

print vals
print mean


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


Problem in Dictionaries

2005-03-01 Thread Glauco Silva

I´m with problem in Dictionaries !
I would like to know if the dictionary can sort with a function that i give to then!
Because i need to have a dictionary sort by key !
For exemple :
dict  = {}
dict[50] = "fifty"
dict[129] = "a hundred twenty nine"
print dict
{129: "a hundred twenty nine", 50: "fifty"}
 
But i need dict sort :
{ 50: "fifty", 129: "a hundred twenty nine"}
 
How can i do this ?
 
Thanks,
Glauco Buzini da Costa Silva

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

problem with py2exe !

2005-04-15 Thread Glauco Silva



Hi,
I´m with problem to create a executable program in 
python. 
I´m using py2exe but i don´t know if it´s 
right.
My setup.py:
 
from distutils.core import setupimport 
py2exefrom glob import glob
 
setup(    # The first three 
parameters are not required, if at least a    # 'version' is 
given, then a versioninfo resource is built from    # them 
and added to the executables.    version = 
"2.0",    description = "programa 
InVesalius",    name = "InVesalius",
 
    # targets to 
build    console = 
["C:\\promed2.0\\python\\MyMainModule.py"],    
data_files=[("icons", 
glob("C:\\promed2.0\\icons\\*.*")),    
("docs",glob("C:\\promed2.0\\docs\\*.*")),    
("config", 
["C:\\promed2.0\\setup.cfg"])    
],packages = ['vtk-windows', 
'vtk-windows.vtk',    
'vtk-windows.vtk.gtk', 
'vtk-windows.vtk.qt',    
'vtk-windows.vtk.tk', 
'vtk-windows.vtk.util',    
'vtk-windows.vtk.wx', 'vtk-windows.vtk.test'],      
)
When i run in prompt "python setup.py py2exe", 
appear in the end this:
 
###
The following modules appear to be missing[ 
'_imaging_gif','libVTKCommonPython', 'libVTKContribPython', 
'libVTKGraphicsPython', 'libVTKImagingPython', 'libVTKPatentedPython', 
libvtkCommonPython', 'libvtkFilteringPython', 'libvtkGraphicsPython', 
'libvtkHybridPython', 'libvtkIOPython', 
'libvtkImagingPython', 'libvtkParallelPython', 'libvtkPatentedPython', 
'libvtkRenderingPython', 'numarray.array', 'numarray.dot', 'numarray.fromfile', 
'numarray.size', 'numarray.zeros', 'vtk.vtkActor2D', 'vtk.vtkDCMParser', 
'vtk.vtkImageClip', 'vtk.vtkImageFlip', 'vtk.vtkImageImport', 
'vtk.vtkImageMagnify', 'vtk.vtkImageMapper', 'vtk.vtkImagePermute', 
'vtk.vtkImageReader', 'vtk.vtkImageResample', 
'vtk.vtkImageReslice', 'vtk.vtkImageShiftScale', 'vtk.vtkImageThreshold', 
'vtk.vtkImageViewer', 'vtk.vtkImageWriter', 'vtk.vtkRenderWindow', 
'vtk.vtkRenderer', 'vtk.vtkTextMapper', 'vtk.vtkTextProperty', 
'vtk.vtkTransform']
###
 
My PYTHONPATH = 
C:\Python23;C:\promed2.0\vtk-windows;C:\promed2.0\python
 
My dir:
##
promed2.0/  
         setup.cfg   
            
setup.py   icons/     
            
docs/            
    python/           
                
MyMainModule.py 
               
vtk-window/            
                
vtkpython.py            
                
vtkpythontk.py
 
        
                
    vtk.pth        
                
    vtkCommon.dll        
                
    vtkCommonPython.dll        
                
    vtkCommonTCL.dll   
                
                
    ...
 
vtk/ 

###
 
OS: win 2K
Python ver: 2.3.5py2exe ver: 
0.5.4
 

How can i solve this problem?
 
Thanks
Glauco
 

No virus found in this outgoing message.
Checked by AVG Anti-Virus.
Version: 7.0.308 / Virus Database: 266.9.11 - Release Date: 14/4/2005
-- 
http://mail.python.org/mailman/listinfo/python-list

Problem using py2exe

2005-04-18 Thread Glauco Silva




Hi,
I´m with problem to create a executable program in 
python. 
I´m using py2exe but i don´t know if it´s 
right.
My setup.py:
 
from distutils.core import setupimport 
py2exefrom glob import glob
 
setup(    # The first three 
parameters are not required, if at least a    # 'version' is 
given, then a versioninfo resource is built from    # them 
and added to the executables.    version = 
"2.0",    description = "programa 
InVesalius",    name = "InVesalius",
 
    # targets to 
build    console = 
["C:\\promed2.0\\python\\MyMainModule.py"],    
data_files=[("icons", 
glob("C:\\promed2.0\\icons\\*.*")),    
("docs",glob("C:\\promed2.0\\docs\\*.*")),    
("config", 
["C:\\promed2.0\\setup.cfg"])    
],packages = ['vtk-windows', 
'vtk-windows.vtk',    
'vtk-windows.vtk.gtk', 
'vtk-windows.vtk.qt',    
'vtk-windows.vtk.tk', 
'vtk-windows.vtk.util',    
'vtk-windows.vtk.wx', 'vtk-windows.vtk.test'],      
)
When i run in prompt "python setup.py py2exe", 
appear in the end this:
 
###
The following modules appear to be missing[ 
'_imaging_gif','libVTKCommonPython', 'libVTKContribPython', 
'libVTKGraphicsPython', 'libVTKImagingPython', 'libVTKPatentedPython', 
libvtkCommonPython', 'libvtkFilteringPython', 'libvtkGraphicsPython', 
'libvtkHybridPython', 'libvtkIOPython', 
'libvtkImagingPython', 'libvtkParallelPython', 'libvtkPatentedPython', 
'libvtkRenderingPython', 'numarray.array', 'numarray.dot', 'numarray.fromfile', 
'numarray.size', 'numarray.zeros', 'vtk.vtkActor2D', 'vtk.vtkDCMParser', 
'vtk.vtkImageClip', 'vtk.vtkImageFlip', 'vtk.vtkImageImport', 
'vtk.vtkImageMagnify', 'vtk.vtkImageMapper', 'vtk.vtkImagePermute', 
'vtk.vtkImageReader', 'vtk.vtkImageResample', 
'vtk.vtkImageReslice', 'vtk.vtkImageShiftScale', 'vtk.vtkImageThreshold', 
'vtk.vtkImageViewer', 'vtk.vtkImageWriter', 'vtk.vtkRenderWindow', 
'vtk.vtkRenderer', 'vtk.vtkTextMapper', 'vtk.vtkTextProperty', 
'vtk.vtkTransform']
###
 
My PYTHONPATH = 
C:\Python23;C:\promed2.0\vtk-windows;C:\promed2.0\python
 
My dir:
##
promed2.0/  
        setup.cfg   
            
setup.py   icons/     
            
docs/            
    python/           
                
MyMainModule.py 
               
vtk-window/            
                
vtkpython.py            
                
vtkpythontk.py
 
        
                
    vtk.pth        
                
    vtkCommon.dll        
                
    vtkCommonPython.dll        
                
    vtkCommonTCL.dll   
                
                
    ...
 
vtk/ 

###
 
OS: win 2K
Python ver: 2.3.5py2exe ver: 
0.5.4
 

How can i solve this problem?
 
Thanks
Glauco
No virus found in this outgoing message.
Checked by AVG Anti-Virus.
Version: 7.0.308 / Virus Database: 266.9.16 - Release Date: 18/4/2005
-- 
http://mail.python.org/mailman/listinfo/python-list

How can i solve this problem with py2exe ?

2005-04-27 Thread Glauco Silva





Hi,
I´m with problem to create a executable program in 
python. 
I´m using py2exe but i don´t know if it´s 
right.

When i run in prompt "python setup.py py2exe", 
appear in the end this:
 
###
The following modules appear to be missing[ 
'_imaging_gif','libVTKCommonPython', 'libVTKContribPython', 
'libVTKGraphicsPython', 'libVTKImagingPython', 'libVTKPatentedPython', 
libvtkCommonPython', 'libvtkFilteringPython', 'libvtkGraphicsPython', 
'libvtkHybridPython', 'libvtkIOPython', 
'libvtkImagingPython', 'libvtkParallelPython', 'libvtkPatentedPython', 
'libvtkRenderingPython', 'numarray.array', 'numarray.dot', 'numarray.fromfile', 
'numarray.size', 'numarray.zeros', 'vtk.vtkActor2D', 'vtk.vtkDCMParser', 
'vtk.vtkImageClip', 'vtk.vtkImageFlip', 'vtk.vtkImageImport', 
'vtk.vtkImageMagnify', 'vtk.vtkImageMapper', 'vtk.vtkImagePermute', 
'vtk.vtkImageReader', 'vtk.vtkImageResample', 
'vtk.vtkImageReslice', 'vtk.vtkImageShiftScale', 'vtk.vtkImageThreshold', 
'vtk.vtkImageViewer', 'vtk.vtkImageWriter', 'vtk.vtkRenderWindow', 
'vtk.vtkRenderer', 'vtk.vtkTextMapper', 'vtk.vtkTextProperty', 
'vtk.vtkTransform']
###
 

How can i solve this 
problem?
 
 
My setup.py:
 
from distutils.core import setupimport 
py2exefrom glob import glob
 
setup(    # The first three 
parameters are not required, if at least a    # 'version' is 
given, then a versioninfo resource is built from    # them 
and added to the executables.    version = 
"2.0",    description = "programa 
InVesalius",    name = "InVesalius",
 
    # targets to 
build    console = 
["C:\\promed2.0\\python\\MyMainModule.py"],    
data_files=[("icons", 
glob("C:\\promed2.0\\icons\\*.*")),    
("docs",glob("C:\\promed2.0\\docs\\*.*")),    
("config", 
["C:\\promed2.0\\setup.cfg"])    
],packages = ['vtk-windows', 
'vtk-windows.vtk',    
'vtk-windows.vtk.gtk', 
'vtk-windows.vtk.qt',    
'vtk-windows.vtk.tk', 
'vtk-windows.vtk.util',    
'vtk-windows.vtk.wx', 'vtk-windows.vtk.test'],      
)
 
My PYTHONPATH = 
C:\Python23;C:\promed2.0\vtk-windows;C:\promed2.0\python
 
My dir:
##
promed2.0/  
        setup.cfg   
            
setup.py   icons/ 
            
docs/            
    python/           
                
MyMainModule.py 
               
vtk-window/            
                
vtkpython.py            
                
vtkpythontk.py
 
        
                
    vtk.pth        
                
    vtkCommon.dll        
                
    vtkCommonPython.dll        
                
    vtkCommonTCL.dll   
                
                
    ...
 
vtk/ 

###
 
OS: win 2K
Python ver: 2.3.5py2exe ver: 
0.5.4

 
Thanks
Glauco
No virus found in this outgoing message.
Checked by AVG Anti-Virus.
Version: 7.0.308 / Virus Database: 266.10.3 - Release Date: 25/4/2005
-- 
http://mail.python.org/mailman/listinfo/python-list

problem in the compiler ?

2005-05-02 Thread Glauco Silva



when i creat a RadioButton and put a command = 
self.Function , this function is called in the creation of 
RadioButton.
It´s right this or it´s wrong ? 
Thank you
Glauco 
No virus found in this outgoing message.
Checked by AVG Anti-Virus.
Version: 7.0.308 / Virus Database: 266.11.1 - Release Date: 2/5/2005
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: problem in the compiler ?

2005-05-03 Thread Glauco Silva
I´m sorry if i don´t write correct.
My code is like this:

MyClass()

class MyClass:
 def __init__(self):
 btn = RadioButton(command=self.Function)
 def Function(self):
 print "Enter in the function"

python : 2.3.5
os: win 2K

When a do this, the function 'Function' is call. And i don´t want this.
What´s wrong ?
Thank you
Glauco

- Original Message - 
From: "Delaney, Timothy C (Timothy)" <[EMAIL PROTECTED]>
To: "Glauco Silva" <[EMAIL PROTECTED]>; 
Sent: Monday, May 02, 2005 8:50 PM
Subject: RE: problem in the compiler ?


Glauco Silva wrote:

> when i creat a RadioButton and put a command = self.Function , this
> function is called in the creation of RadioButton. It´s right this or
> it´s wrong ?

http://www.catb.org/~esr/faqs/smart-questions.html

I'm pretty sure I can guess exactly what the problem is. I suspect your code
looks somewhat like:

btn = RadioButton(command=self.Function())

Follow the instructions in the above link and you should be able to work out
why this is wrong.

If I've failed to read your mind correctly, the above link should also teach
you how to make it easier for me to do so.

Tim Delaney




-- 
No virus found in this outgoing message.
Checked by AVG Anti-Virus.
Version: 7.0.308 / Virus Database: 266.11.1 - Release Date: 2/5/2005

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


Re: problem in the compiler ?

2005-05-03 Thread Glauco Silva
The call of MyClass isn´t in this order... i only want to explain that i´m
calling the class 'MyClass' and when i do this the function "Function" is
call when the compiler pass for the RadioButton.
The same happened when i used Pmw.RadioSelect.
I solve this problem now using this:
radio = Pmw.RadioSelect()
radio.bind('', self.Function)

if i use :
Pmw.RadioSelect(command = self.Function)

the 'Function' is call.
And i think that this is wrong and i only want to tell to help solve this
bug.

so, my code is this:
file : MyClass.py
import Pmw
class MyClass:
def __init__(self):
radio = Pmw.RadioSelect()
radio.bind('', self.Function)
#Pmw.RadioSelect(command = self.Function)

def Funciton(self):
print "Enter in the Function"

if __name__ == '__main__' :
MyClass()

when i call in the console like this:
C:\python MyClass.py

if i using in the __init__ this :
Pmw.RadioSelect(command = self.Function)

so the string "Enter in the Function"  is print

Thank you
Glauco





- Original Message - 
From: "Scott David Daniels" <[EMAIL PROTECTED]>
To: 
Sent: Tuesday, May 03, 2005 11:21 AM
Subject: Re: problem in the compiler ?


Glauco Silva wrote:
> python : 2.3.5
> os: win 2K
This part is good enough (though sometimes it helps to mention the
service pack number
on windows systems).

> My code is like this:
>
> MyClass()
>
> class MyClass:
>  def __init__(self):
>  btn = RadioButton(command=self.Function)
>  def Function(self):
>  print "Enter in the function"

This is not good enough.  Show us a small actual example that exhibits
the problem behavior on your machine.  Often in the course of doing this
distillation, the original problem will become clear to you.  The code
above fails with:

Traceback (most recent call last):
   File "", line 1, in -toplevel-
 MyClass()
NameError: name 'MyClass' is not defined

on the initial call to MyClass().  I suspect this is not what you care
about.

Don't make people trying to help you do any work you cannot do yourself.
Imagine yourself browsing the newsgroup and trying to decide whether to
spend some time trying to help someone with a problem.  Would _you_ want
to spend time trying to guess what the code was with the problem as well
as what the problem was, or would you decide to help someone else out?

--Scott David Daniels
[EMAIL PROTECTED]




-- 
No virus found in this outgoing message.
Checked by AVG Anti-Virus.
Version: 7.0.308 / Virus Database: 266.11.2 - Release Date: 2/5/2005

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


Re: problem in the compiler ?

2005-05-05 Thread Glauco Silva
So , I will try to explain !
I´m trying to modify a code that doesn´t belong to me.

I thought that there was a bug in the compilation of Pmw.RadioSelect, but
there wans't.

I hadn't noticed that the code invoked the button of radioselect in another
part of it. Now I simply took off the part of the code which invoked the
button and the program is working as I expected. Thanks for your help.

Anyway, the code was this :
 -
self.myButton = Pmw.RadioSelect(frame, selectmode = MULTIPLE, command =
self.Function)
self.myButton.add('C1')
self.myButton.pack()
...

self.myButton.invoke('C1')

-


- Original Message - 
From: "Delaney, Timothy C (Timothy)" <[EMAIL PROTECTED]>
To: "Glauco Silva" <[EMAIL PROTECTED]>; 
Sent: Wednesday, May 04, 2005 8:20 PM
Subject: RE: problem in the compiler ?


Glauco Silva wrote:

> I´m sorry, I feel I didn't comunicate very well .
> The program I am writing is a part of a big project, so it would be
> no use to post it here as it involves many other things and concepts.

We wouldn't want the whole thing - that would be useless. What you need to
do is trim it down to the smallest piece of code that causes the problem.
Normally doing this reveals the actual problem, and you don't need to go to
the newsgroup.

> But i solve my problem and don´t have bug. My code was wrong.

Excellent. You should now post your solution to the newsgroup.

Tim Delaney




-- 
No virus found in this incoming message.
Checked by AVG Anti-Virus.
Version: 7.0.308 / Virus Database: 266.11.3 - Release Date: 3/5/2005




-- 
No virus found in this outgoing message.
Checked by AVG Anti-Virus.
Version: 7.0.308 / Virus Database: 266.11.5 - Release Date: 4/5/2005

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


Re: Multiple "cmp"s chained one after another

2005-05-16 Thread Glauco Silva
You can try this :
>>> l = [(2001, 5, 2),(2111,3,3),(1984, 3, 1), (2001, 1, 1)]
>>> l.sort(lambda x = l[0],y = l[1] : cmp((x[1],x[2]),(y[1],y[2])))

- Original Message - 
From: "Volker Grabsch" <[EMAIL PROTECTED]>
To: 
Sent: Saturday, May 14, 2005 7:09 AM
Subject: Multiple "cmp"s chained one after another


Hello!

Ich just found a very nice 'pythonic' solution for an often appearing
problem. I didn't find it documented anywhere, so I'm posting it here.
If this isn't new in any way, I'd really like to get to know it.

Example problem:
I have some "datetime" objects and want to sort them, as here:

birthdays = [d1,d2,d3,d4]
birthdays.sort()

However, I don't want to sort them the default way. These are birthdays,
so only the month and day do matter, not the year. E.g.:

2003-01-01  should be smaller than  1984-05-01

So I have to write the comparison on my own, e.g.

def cmp_birthdays(d1,d2):
if d1.month > d2.month: return 1
if d1.month < d2.month: return -1
if d1.day > d2.day: return 1
if d1.day < d2.day: return -1
return 0

...
birthdays.sort(cmp_birthdays)

This implementation of cmp_birthdays is very ugly. Image you want to
chain more than 2 values in that "cmp_birthdays". I also want to use the
builtin "cmp" function, not ">" and "<".

After thinking some minutes about it, I found a very nice solution:
I have some "cmp"s one aftter another. If one if them return 1 oder -1,
it sould be returned. If it returns 0, the next "cmp" is used. In other
words: I have a sequence of numbers, and want to get the first one that
is not 0. (or return 0, if all numbers were 0)

But this is exactly what the "or" operator does, due to short-circuit
evaluation. In this example, that means:

def cmp_bithdays(d1,d2):
return cmp(d1.month,d2.month) or cmp(d1.day,d2.day)

The generic pattern is:

return cmp(...) or cmp (...) or cmp(...) or ...

I'm not sure whether this pattern is already a "common recipe", but
I found it to be a very nice idea. :-)

Any opinions?


Greets,

Volker

-- 
Volker Grabsch
---<<(())>>---
\frac{\left|\vartheta_0\times\{\ell,\kappa\in\Re\}\right|}{\sqrt
[G]{-\Gamma(\alpha)\cdot\mathcal{B}^{\left[\oint\!c_\hbar\right]}}}




-- 
No virus found in this outgoing message.
Checked by AVG Anti-Virus.
Version: 7.0.308 / Virus Database: 266.11.10 - Release Date: 13/5/2005

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