Re: Would there be support for a more general cmp/__cmp__

2005-10-21 Thread Antoon Pardon
Op 2005-10-20, Steve Holden schreef <[EMAIL PROTECTED]>:
> Antoon Pardon wrote:
>> 
> Ergo: use rich comparisons.

rich comparosons can only solve the problem partly.

Python does have the cmp function and that can give
totaly inconsistent results even when the order
defined by the rich comparison functions is consistent
but only partial.

I think it is a problem if cmp gives me the following
results.

>>>  a1 = foo(1)
>>>  a2 = foo(2)
>>>  b1 = foo(1)
>>>  b2 = foo(2)
>>>  cmp(a1,b1)
0
>>>  cmp(a2,b2)
0
>>>  cmp(a1,a2)
1
>>>  cmp(b1,a2)
1
>>>  cmp(a1,b2)
-1

It would be better if cmp would give an indication it
can't compare two objects instead of giving incorrect
and inconsistent results.

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


Re: Set an environment variable

2005-10-21 Thread Christian
> 
> The closest thing you can do is that:
> 
> -myScript.py--
> print 'export MY_VARIABLE=value'
> --
> 
> -myScript.sh--
> python myScript.py > /tmp/chgvars.sh
> . /tmp/chgvars.sh
> --

Can I write a .py script that calls a .sh script that executes the 
export command and then calls another .py script (and how would the 
first .py script look)?

That would be much more what is my basic problem.


Thanks

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


Re: Set an environment variable

2005-10-21 Thread Erik Max Francis
Christian wrote:

> Can I write a .py script that calls a .sh script that executes the 
> export command and then calls another .py script (and how would the 
> first .py script look)?

No, the shell script that the Python program would invoke would be a 
different process and so commands executed in it would have no effect on 
the state of another.

-- 
Erik Max Francis && [EMAIL PROTECTED] && http://www.alcyone.com/max/
San Jose, CA, USA && 37 20 N 121 53 W && AIM erikmaxfrancis
   Success and failure are equally disastrous.
   -- Tennessee Williams
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: sort problem

2005-10-21 Thread Michele Petrazzo
Kent Johnson wrote:
> or learn about decorate-sort-undecorate:
> 
> lst = [ ...whatever ] lst = [ x[3], i, x for i, x in enumerate(lst) ]
> 
I think that here the code must be changed (for the future):
lst = [ (x[3], i, x) for i, x in enumerate(lst) ]

> lst.sort() lst = [ x for _, _, x in lst ]


Wow, this work with my py 2.3!

> 
> Kent
> 

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


Re: classmethods, class variables and subclassing

2005-10-21 Thread Steve Holden
Andrew Jaffe wrote:
>>Andrew Jaffe wrote:
>>
>>
>>>Hi,
>>>
>>>I have a class with various class-level variables which are used to 
>>>store global state information for all instances of a class. These are 
>>>set by a classmethod as in the following
>>>
>>>class sup(object):
>>> cvar1 = None
>>> cvar2 = None
>>>
>>> @classmethod
>>> def setcvar1(cls, val):
>>> cls.cvar1 = val
>>>
>>> @classmethod
>>> def setcvar2(cls, val):
>>> cls.cvar2 = val
>>>
>>> @classmethod
>>> def printcvars(cls):
>>>print cls.cvar1, cls.cvar2
>>>
>>>Now, the problem comes when I want to subclass this class. If I 
>>>override the setcvar1 method to do some new things special to this 
>>>class, and then call the sup.setcvar1() method, it all works fine:
>>>
>>>class sub(sup):
>>> cvar1a = None
>>>
>>> @classmethod
>>> def setcvar1(cls, val, vala):
>>> cls.cvar1a = vala
>>> sup.setcvar1(val)
>>>
>>> @classmethod
>>> def printcvars(cls):
>>> print cls.cvar1a
>>> sup.printcvars()
>>>
>>>This works fine, and sets cvar and cvar2 for both classes.
>>>
>>>However, if  I *don't* override the setcvar2 method, but I call 
>>>sub.setcvar2(val) directly, then only sub.cvar2 gets set; it is no 
>>>longer identical to sup.cvar1!
>>>
>>>In particular,
>>> sub.setcvar1(1,10)
>>> sub.setcvar2(2)
>>> sub.printcvars()
>>>prints
>>>   10
>>>   1 None
>>>
>>>i.e. sub.cvar1, sub.cvar1a, sub.cvar2= 1 10 2
>>>but sup.cvar1, cvar2= 1 None
>>>
>>>This behavior is "expected", but is it desirable?
>>>
>>
>>You are experiencing this problem because you are using hard-wired class 
>>names. Try using (for example) self.__class__. That way, even if your 
>>method is inheroted by a subclass it will use the class of the object it 
>>finds itself a method of. No need to use classmethods.
> 
> 
> The problem is that I actually do want to call these methods on the 
> class itself, before I've made any instances.
> 
I see. I think. So what you are saying is that when you call 
sup.printcvars() from inside a sub method you want it to see the 
namespace of the sub class not the sup?

Since you have set all this up carefully you must have a use case, but 
it seems a little contorted (to me). Basically you appear to want the 
classes to behave statically the way that instances do dynamically?

Not sure I can help you here.

regards
  Steve
-- 
Steve Holden   +44 150 684 7255  +1 800 494 3119
Holden Web LLC www.holdenweb.com
PyCon TX 2006  www.python.org/pycon/

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


Re: Set an environment variable

2005-10-21 Thread Christian
Erik Max Francis wrote:
> Christian wrote:
> 
>> Can I write a .py script that calls a .sh script that executes the 
>> export command and then calls another .py script (and how would the 
>> first .py script look)?
> 
> No, the shell script that the Python program would invoke would be a 
> different process and so commands executed in it would have no effect on 
> the state of another.
> 

So executing an .sh script that calls a .py script works different when 
executed from a command promt than when executed from a starter .py script?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: classmethods, class variables and subclassing

2005-10-21 Thread Steve Holden
Andrew Jaffe wrote:
>>Andrew Jaffe wrote:
[...]
> 
> The problem is that I actually do want to call these methods on the 
> class itself, before I've made any instances.
> 
Except you could use staticmethods with an explicit class argument ...

regards
  Steve
-- 
Steve Holden   +44 150 684 7255  +1 800 494 3119
Holden Web LLC www.holdenweb.com
PyCon TX 2006  www.python.org/pycon/

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


python and outlook

2005-10-21 Thread dt
Hi everyone,

Are there any links or sites on how to read outlook mail boxes or address book?

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


Re: Set an environment variable

2005-10-21 Thread Sybren Stuvel
Mike Meyer enlightened us with:
> It's simpler to use eval and command substitution:
>
> eval $(python myScript.py)

This looks like the best solution to me.

Sybren
-- 
The problem with the world is stupidity. Not saying there should be a
capital punishment for stupidity, but why don't we just take the
safety labels off of everything and let the problem solve itself? 
 Frank Zappa
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Set an environment variable

2005-10-21 Thread Steve Holden
Christian wrote:
>>The closest thing you can do is that:
>>
>>-myScript.py--
>>print 'export MY_VARIABLE=value'
>>--
>>
>>-myScript.sh--
>>python myScript.py > /tmp/chgvars.sh
>>. /tmp/chgvars.sh
>>--
> 
> 
> Can I write a .py script that calls a .sh script that executes the 
> export command and then calls another .py script (and how would the 
> first .py script look)?
> 
> That would be much more what is my basic problem.
> 
You can do what you suggest without shell scripting, unless I 
misunderstand your intention: just set the environment variables you 
want your Python script to see and then run it using os.system():

::
one.py
::
import os
os.environ['STEVE'] = "You are the man"
os.system("python two.py")
print "Ran one"
::
two.py
::
import os
print "STEVE is", os.environ['STEVE']
print "Ran two"
[EMAIL PROTECTED] tmp]$ python one.py
STEVE is You are the man
Ran two
Ran one
[EMAIL PROTECTED] tmp]$

Hope this helps.

regards
  Steve
-- 
Steve Holden   +44 150 684 7255  +1 800 494 3119
Holden Web LLC www.holdenweb.com
PyCon TX 2006  www.python.org/pycon/

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


Re: override a property

2005-10-21 Thread Robin Becker
Kay Schluehr wrote:
> Robin Becker wrote:
> 
> 
>>I thought that methods were always overridable.
>>In this case the lookup on the
>>class changes the behaviour of the one and only property.
> 
> 
> How can something be made overridable that is actually overridable? I
> didn't know how to better express the broken polymorphism of Pythons
> properties than by stating it as a pleonasm about the used get and set
> methods. This way a property don't ever have to be redefined in
> subclasses if get_x, set_x etc. are changed. 
> 
> Kay
> 

well I guess that's the ambiguity of human language. Clearly when I 
assign to a normal attribute I am changing its value; assigning to a 
property or descriptor does something that is not so obvious. Changing 
the behaviour of such an attribute could be done by inheritance as 
suggested. The new class has overridden the property. When I want to do 
that on an instance I have first to create a mutable version of the 
descriptor where the mutability is on the instance not the class. I call 
the action of changing the base descriptor behaviour 'overriding', but 
perhaps that's not the correct word. What do you suggest?
-- 
Robin Becker
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python vs Ruby

2005-10-21 Thread Michele Simionato
Tom Anderson:
>> I have no idea what Scheme is, but I'll cettainly look it up as soon as
>> I'm done writing this.

> You won't like it. Give yourself another 5-10 years, and you might start
> to find it strangely intriguing. 

+1 ;-)


  Michele Simionato

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


Re: Set an environment variable

2005-10-21 Thread Chris F.A. Johnson
On 2005-10-21, Christian wrote:
> Erik Max Francis wrote:
>> Christian wrote:
>> 
>>> Can I write a .py script that calls a .sh script that executes the 
>>> export command and then calls another .py script (and how would the 
>>> first .py script look)?
>> 
>> No, the shell script that the Python program would invoke would be a 
>> different process and so commands executed in it would have no effect on 
>> the state of another.
>> 
>
> So executing an .sh script that calls a .py script works different when 
> executed from a command promt than when executed from a starter .py script?

No; it's always the same: an environment variable will only be
effective in the process in which it is set, and its children.

When you call another program, whether it's a shell script, python
script, or binary executable, you are starting a new process.
Environment variables set in that process will not affect its
parent (i.e., the process that called it).

-- 
Chris F.A. Johnson 
==
Shell Scripting Recipes: A Problem-Solution Approach, 2005, Apress

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


Re: Searching for txt file and importing to ms access

2005-10-21 Thread Mark Line
Once i have this working i was planing to kept all the txt files as logs, 
i'd have to give them a real name and stuff.

But thanks for you help so far

Mark


"Mike Meyer" <[EMAIL PROTECTED]> wrote in message 
news:[EMAIL PROTECTED]
> "Mark Line" <[EMAIL PROTECTED]> writes:
>> I'm managed to get some code to download a message from the email account
>> and save it to a text file, does any one have a link to some sample code 
>> to
>> search though a file until a string of characters is matched?  Or could
>> point me to some functions that may help me with this?
>
> datafile = open("c:\\myfile.txt", "r")
> data = datafile.read()
> datafile.close()
> start = data.index(myindicator)
>
> will leave start as the index in data where the the string in
> myindicator first appears. If you want the end of myendicator, use
> start = data.find(myindicator) + len(myindicator).
>
> Have you considered not saving the message to disk? You can manipulate
> it all in memory.
>
>> I've also managed to connect to my access database, and just print out a
>> field in a table, but I cant find anywhere on the web that will help me 
>> to
>> import data?  Any help would be great?!
>
> Can't help with that. The phrase "win32com" comes to mind, but I'm not
> a windows person.
>
>   -- 
> Mike Meyer <[EMAIL PROTECTED]> http://www.mired.org/home/mwm/
> Independent WWW/Perforce/FreeBSD/Unix consultant, email for more 
> information. 


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


Re: get a copy of a string leaving original intact

2005-10-21 Thread Fredrik Lundh
"Bell, Kevin" wrote:

> I'm having trouble with something that seems like it should be simple.
>
> I need to copy a file, say "abc-1.tif" to another directory, but if it's
> in there already, I need to transfer it named "abc-2.tif" but I'm going
> about it all wrong.
>
> Here's what doesn't work: (I'll add the copy stuff from shutil after
> figuring out the basic string manipulation.)

define "doesn't work".

> import os
>
> source = r"C:\Source"
> target = r"P:\Target"
>
> files = os.listdir(source)
>
> for f in files:
> if os.path.isfile(target + "\\" + f):  # if it already exists
> print f + " exists"
> s = f  # i'd like a copy to
> alter
> s = s.replace("-1", "-2")
> print "Altered it to be " + s
> print source + "\\" + s, target + "\\" + s

did you mean

print source + "\\" + f, target + "\\" + s

?

> else:
> print f + " IS NOT THERE YET"
> print source + "\\" + f, target + "\\" + f  # use the original
>
> -- 
> http://mail.python.org/mailman/listinfo/python-list

btw, note that

source + "\\" + f

is better written as

os.path.join(source, f)

e.g.

for f in os.listdir(source):
sourcefile = os.path.join(source, f)
targetfile = os.path.join(target, f)
if os.path.isfile(targetfile):
targetfile = os.path.join(target, f.replace("-1", "-2"))
print "copy", sourcefile, "to", targetfile
shutil.copy(sourcefile, targetfile)





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


Python extension module segmentation fault

2005-10-21 Thread Rolf Wester
Hi,

I' trying to make an extension module that passes Numeric arrays. The
wrapper function is (swig generated and modified by myself):

static PyObject *_wrap_my_func(PyObject *self, PyObject *args) {
PyObject * resultobj = 0 ;
PyObject * obj0 = 0 ;
PyArrayObject * mat = 0 ;

std::cout << __FILE__ << "  " <<  __LINE__ << std::endl;
if(!PyArg_ParseTuple(args,(char *)"O:my_func",&obj0)) goto fail;
std::cout << __FILE__ << "  " <<  __LINE__ <<  "  " << obj0 << 
std::endl;
mat = (PyArrayObject *) PyArray_ContiguousFromObject(obj0,
PyArray_DOUBLE, 1, 1);
std::cout << __FILE__ << "  " <<  __LINE__ <<  "  " << mat << std::endl;

Py_INCREF(Py_None); resultobj = Py_None;
return resultobj;
fail:
return NULL;
}

The shared object is build with:

g++ -c -g -fPIC -I./  -I/usr/local/include/python2.4
-I/usr/local/include/python2.4/Numeric  mytest_wrap.cpp -o mytest_wrap.o

g++ -shared -L/usr/local/lib/python2.4/config/  mytest_wrap.o
-lpython2.4 -lm   -o _mytest.so


the Python file reads:

import _mytest
from Numeric import *
mat = ones(100,Float64)
print _mytest.my_func(mat)

When running this I get the output:

mytest_wrap.cpp  1499
mytest_wrap.cpp  1502  0x402b55e8
Speicherzugriffsfehler (segmentation fault)

I also ran this with valgrind. Part of valgrinds output is:

==15792== Reading syms from
/mnt/pubdsk/A31/2003/DOKUMENTATION/WESTER/pr3/OPT/opt2.0/test/_mytest.so
(0x1BE7E000)
==15792== Reading syms from
/usr/local/lib/python2.4/site-packages/Numeric/multiarray.so (0x1B90F000)
==15792== Reading syms from
/usr/local/lib/python2.4/site-packages/Numeric/_numpy.so (0x1BFDB000)
==15792== Reading syms from
/usr/local/lib/python2.4/site-packages/Numeric/umath.so (0x1BFF1000)
==15792== Reading syms from
/usr/local/lib/python2.4/lib-dynload/strop.so (0x1B91A000)
==15792== Reading syms from /usr/local/lib/python2.4/lib-dynload/math.so
(0x1C103000)
==15792== Reading syms from
/usr/local/lib/python2.4/lib-dynload/struct.so (0x1C209000)
==15792== Reading syms from
/usr/local/lib/python2.4/lib-dynload/binascii.so (0x1C21)
==15792== Reading syms from
/usr/local/lib/python2.4/lib-dynload/cStringIO.so (0x1C216000)
mytest_wrap.cpp  1499
mytest_wrap.cpp  1502  0x1bca7610
==15792== Invalid read of size 4
==15792==at 0x1BECE794: _wrap_my_func (mytest_wrap.cpp:1503)
==15792==by 0x811E685: PyCFunction_Call (methodobject.c:93)
==15792==by 0x80C708F: PyEval_EvalFrame (ceval.c:1499)
==15792==by 0x80C8933: PyEval_EvalCodeEx (ceval.c:2736)
==15792==by 0x80C8B64: PyEval_EvalCode (ceval.c:484)
==15792==by 0x80F74A7: PyRun_SimpleFileExFlags (pythonrun.c:1265)
==15792==by 0x80558D6: Py_Main (main.c:484)
==15792==by 0x8054F86: main (python.c:23)
==15792==  Address 0x38 is not stack'd, malloc'd or (recently) free'd
==15792==
==15792== Process terminating with default action of signal 11 (SIGSEGV)
==15792==  Access not within mapped region at address 0x38
==15792==at 0x1BECE794: _wrap_my_func (mytest_wrap.cpp:1503)
==15792==by 0x811E685: PyCFunction_Call (methodobject.c:93)
==15792==by 0x80C708F: PyEval_EvalFrame (ceval.c:1499)
==15792==by 0x80C8933: PyEval_EvalCodeEx (ceval.c:2736)
==15792==by 0x80C8B64: PyEval_EvalCode (ceval.c:484)
==15792==by 0x80F74A7: PyRun_SimpleFileExFlags (pythonrun.c:1265)
==15792==by 0x80558D6: Py_Main (main.c:484)
==15792==by 0x8054F86: main (python.c:23)
==15792==
==15792== ERROR SUMMARY: 1 errors from 1 contexts (suppressed: 8093 from 7)
==15792==


I would be very appreciative for any help.

With kind regards

Rolf Wester




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


Re: connect to https unpossible. Please help.

2005-10-21 Thread Mark Delon
Hi Tim,

really than u very much!

I think u have helped me!

I will try, that what u said.

I have found probably simplier solution.
Is it so?

...but without success:-(.

I want to download some URLs via python script.
With some URLs I have success with some NOT.
Why?
I do following:
===
1. Login to https://brokerjet.ecetra.com/at/welcome/register/loginpage.phtml
via Mozzila browser 
2. I try to download some URLs using cookies: see script bellow:
3. Some pages works (e.g. news, but on some pages I get:
--
Traceback (most recent call last):
  File "test_stock.py", line 11, in ?
r =
opener.open("https://brokerjet.ecetra.com/at/trading/wt.phtml?isin=NL24&exid=ETR";)
  File "C:\Programme\Python24\lib\urllib2.py", line 358, in open
response = self._open(req, data)
  File "C:\Programme\Python24\lib\urllib2.py", line 376, in _open
'_open', req)
  File "C:\Programme\Python24\lib\urllib2.py", line 337, in _call_chain
result = func(*args)
  File "C:\Programme\Python24\lib\urllib2.py", line 1029, in https_open
return self.do_open(httplib.HTTPSConnection, req)
  File "C:\Programme\Python24\lib\urllib2.py", line 996, in do_open
raise URLError(err)
urllib2.URLError: 

Details- Script:
=
I make login via Mozilla browser 

import os, cookielib, urllib2

cj = cookielib.MozillaCookieJar()
os.environ['HOME']= r"C:\tmp\COOKIE"
cj.load(os.path.join(os.environ["HOME"], "cookies.txt"))
opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(cj))
# first URLs download works
r =
opener.open("http://brokerjet.ecetra.com/at/news/index.phtml?notation=7536885";)
# second URLs download DOES NOT work ... WHY?
r =
opener.open("https://brokerjet.ecetra.com/at/trading/wt.phtml?isin=NL24&exid=ETR";)
#
h = r.readlines()
g = open("test.html","w")
g.writelines(h)
g.close()
os.system("test.html")

Thans realy for all ideas!


sincerely 
mark

> --- Ursprüngliche Nachricht ---
> Von: Tim Roberts <[EMAIL PROTECTED]>
> An: python-list@python.org
> Betreff: Re: connect to https unpossible. Please help.
> Datum: Fri, 21 Oct 2005 06:05:45 GMT
> 
> "Mark Delon" <[EMAIL PROTECTED]> wrote:
> >
> >i want to log via python script to https page:
> >
> >'https://brokerjet.ecetra.com/at/'
> >#
> >But it does not work.
> >
> >I am using following code(see below)
> >
> >Has somebody any ideas?
> >How can I get to this https page?
> >Need I to know some infos from "provider"(certificates, etc)?
> >Thank u very much !
> 
> You are trying to set this up to use HTTP BasicAuth authorization, but
> this
> page is not using HTTP authorization.  You can recognize HTTP
> authorization
> by the separate browser window that pops up to ask for your username and
> password.
> 
> In this case, the username and password fields are just ordinary fields on
> a form.  What you need to do is read the HTTP on that page, and figure out
> howfiues for those fields.  In this case, the
> form data goes to
> https://brokerjet.ecetra.com/at/welcome/loginaction.phtml, and you'll need
> to encode 'login' and 'pwd' fields in the POST data.
> 
> However, that isn't the end of your trouble.  That page will almost
> certainly send you a cookie, which you will need to send back with every
> request.
> -- 
> - Tim Roberts, [EMAIL PROTECTED]
>   Providenza & Boekelheide, Inc.
> -- 
> http://mail.python.org/mailman/listinfo/python-list
> 

-- 
Telefonieren Sie schon oder sparen Sie noch?
NEU: GMX Phone_Flat http://www.gmx.net/de/go/telefonie
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python vs Ruby

2005-10-21 Thread Harald Armin Massa
Casey,


> I have heard, but have not been able to verify that if a program is
> about
> 10,000 lines in C++
> it is about
> 5,000 lines in Java
> and it is about
> 3,000 lines in Python (Ruby to?)

BTW: it is normally only 50 lines in Perl. Not that you could read it,
though

Harald

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


finding a number...

2005-10-21 Thread Enrique Palomo Jiménez
After ftp a file from mvs to windows, i find:

is an offset, so up to 2GB, a commercial application drives crazy
this is the result

2147450785|
2147466880|
2147483412|
ÓÕÖZÖ²YÕXÕ|
ÓÕÖZÖÔÓÔÕZ|
ÓÕÖZÖÒ²YÖ0|

could i know what's that?

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


Re: Python extension module segmentation fault

2005-10-21 Thread Robert Kern
Rolf Wester wrote:
> Hi,
> 
> I' trying to make an extension module that passes Numeric arrays. The
> wrapper function is (swig generated and modified by myself):
> 
> static PyObject *_wrap_my_func(PyObject *self, PyObject *args) {
> PyObject * resultobj = 0 ;
> PyObject * obj0 = 0 ;
> PyArrayObject * mat = 0 ;
> 
>   std::cout << __FILE__ << "  " <<  __LINE__ << std::endl;
> if(!PyArg_ParseTuple(args,(char *)"O:my_func",&obj0)) goto fail;
>   std::cout << __FILE__ << "  " <<  __LINE__ <<  "  " << obj0 << 
> std::endl;
>   mat = (PyArrayObject *) PyArray_ContiguousFromObject(obj0,
> PyArray_DOUBLE, 1, 1);
>   std::cout << __FILE__ << "  " <<  __LINE__ <<  "  " << mat << std::endl;
> 
> Py_INCREF(Py_None); resultobj = Py_None;
> return resultobj;
> fail:
> return NULL;
> }
> 
> The shared object is build with:
> 
> g++ -c -g -fPIC -I./  -I/usr/local/include/python2.4
> -I/usr/local/include/python2.4/Numeric  mytest_wrap.cpp -o mytest_wrap.o
> 
> g++ -shared -L/usr/local/lib/python2.4/config/  mytest_wrap.o
> -lpython2.4 -lm   -o _mytest.so
> 
> 
> the Python file reads:
> 
> import _mytest
> from Numeric import *
> mat = ones(100,Float64)
> print _mytest.my_func(mat)
> 
> When running this I get the output:
> 
> mytest_wrap.cpp  1499
> mytest_wrap.cpp  1502  0x402b55e8
> Speicherzugriffsfehler (segmentation fault)

Did you call import_array() in init_mytest()?

-- 
Robert Kern
[EMAIL PROTECTED]

"In the fields of hell where the grass grows high
 Are the graves of dreams allowed to die."
  -- Richard Harter

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


RE: python and outlook

2005-10-21 Thread Tim Golden
[dt]

> Are there any links or sites on how to read outlook mail boxes or
address book?

Easiest thing to probably to automate the Outlook COM object or a MAPI
Session
for CDO access. You can do this easily with the pywin32 extensions.

http://pywin32.sf.net

You can then use pretty much any published example from around the net.

Example (to print the subject of each item in the inbox):


import win32com.client

outlook = win32com.client.gencache.EnsureDispatch
("Outlook.Application")
namespace = outlook.GetNamespace ("MAPI")
inbox = namespace.GetDefaultFolder
(win32com.client.constants.olFolderInbox)
for i in range (inbox.Items.Count):
  message = inbox.Items[i+1]
  print message.Subject


TJG


This e-mail has been scanned for all viruses by Star. The
service is powered by MessageLabs. For more information on a proactive
anti-virus service working around the clock, around the globe, visit:
http://www.star.net.uk

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


Should i pick up Numeric, Numarray or SciPy.core?

2005-10-21 Thread jelle
#No rant intended

I'm not at all confused wether I should learn an one of the advanced
array modules, I'm slightly confused over which I should pick up. I'm
impressed with the efforts of SciPy and Scientific, but since I'm
fairly new to programming & OO, choosing Numarray over Numeric hasnt
been that satisfactory at all, which is not a problem of the quality of
Numarray, but the fact that a lot of modules still heavily realy on
Numeric. Which, with my fragile knowledge in programming is rather
confusing sometimes. Since its seems its far from pragmatic to opt
solely for either one of them. So Scipy.core looks like the ticket for
me here, doesnt it? Before putting an effort into it, I'd like to know
whether this would make sense, certainly since scipy.core is in its
early stages, and documentation isnt available yet (for free that is...
its not clear to me why I should pay for software in its early stages,
when it extents on efforts freely available)

Curious for your opinions, I definitely think the Scipy.core effort is
terrific, but right now I'm wondering whether its a pragmatic choice.

-Jelle

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


Re: Python vs Ruby

2005-10-21 Thread Torsten Bronger
Hallöchen!

"Harald Armin  Massa" <[EMAIL PROTECTED]> writes:

> Casey,
>
>> I have heard, but have not been able to verify that if a program is
>> about
>> 10,000 lines in C++
>> it is about
>> 5,000 lines in Java
>> and it is about
>> 3,000 lines in Python (Ruby to?)
>
> BTW: it is normally only 50 lines in Perl. Not that you could read
> it, though

At least they could form a heart.

Tschö,
Torsten.

-- 
Torsten Bronger, aquisgrana, europa vetusICQ 264-296-646
-- 
http://mail.python.org/mailman/listinfo/python-list


Request to mailing list Lesstif rejected

2005-10-21 Thread lesstif-admin
Your request to the Lesstif mailing list

Posting of your message titled "hello"

has been rejected by the list moderator.  The moderator gave the
following reason for rejecting your request:

"Non-members are not allowed to post messages to this list."

Any questions or comments should be directed to the list administrator
at:

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


Re: Python extension module segmentation fault

2005-10-21 Thread Rolf Wester
Robert Kern wrote:

> 
> 
> Did you call import_array() in init_mytest()?
> 
No I didn't. Thank you very much for your help. Now it works.

With kind regards

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


Re: Should i pick up Numeric, Numarray or SciPy.core?

2005-10-21 Thread Robert Kern
jelle wrote:
> #No rant intended
> 
> I'm not at all confused wether I should learn an one of the advanced
> array modules, I'm slightly confused over which I should pick up. I'm
> impressed with the efforts of SciPy and Scientific, but since I'm
> fairly new to programming & OO, choosing Numarray over Numeric hasnt
> been that satisfactory at all, which is not a problem of the quality of
> Numarray, but the fact that a lot of modules still heavily realy on
> Numeric. Which, with my fragile knowledge in programming is rather
> confusing sometimes. Since its seems its far from pragmatic to opt
> solely for either one of them. So Scipy.core looks like the ticket for
> me here, doesnt it? Before putting an effort into it, I'd like to know
> whether this would make sense, certainly since scipy.core is in its
> early stages, and documentation isnt available yet (for free that is...
> its not clear to me why I should pay for software in its early stages,
> when it extents on efforts freely available)

The software itself is absolutely free. The complete documentation for
scipy_core specifically is available for a fee, but you will get free
updates as the documentation is expanded and as soon as a certain number
of copies have been purchased or a certain amount of time has passed,
the documentation will be made available free of charge. The book does
not extend "on efforts freely available," either; it's entirely new.

However, not much has changed between Numeric and scipy_core, so most of
the Numeric documentation still applies. There is fairly good docstring
coverage in any case.

> Curious for your opinions, I definitely think the Scipy.core effort is
> terrific, but right now I'm wondering whether its a pragmatic choice.

scipy_core is the future. Most of the complete scipy package has been
ported over at the moment.

However, if you need to use other code that depends on Numeric (like
Konrad Hinsen's Scientific), then you can use Numeric for the time being
and port your code to scipy_core using the provided conversion script.
The API on the Python side hasn't changed too dramatically.

-- 
Robert Kern
[EMAIL PROTECTED]

"In the fields of hell where the grass grows high
 Are the graves of dreams allowed to die."
  -- Richard Harter

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


Re: A macro editor

2005-10-21 Thread bruno modulix
Tom Anderson wrote:
> On Thu, 20 Oct 2005, Diez B. Roggisch wrote:
> 
>> So - _I_ think the better user-experience comes froma well-working
>> easy to use REPL to quickly give the scripts a try.
> 
> 
> I'd agree with that. Which is better, a difficult language with lots of
> fancy tools to help you write it, or an easy language?
> 
> I don't know Groovy, but having looked at some examples, it looks like
> jave with a makeover, which, compared to python, sounds like a difficult
> language.
> 
> As for python vs ruby, i can't really offer any insights on the
> languages themselves. Personally, i'd go for python, but that's because
> i know python and not ruby.

I know a bit of Ruby, and my *very humble* opinion is that Python is
easier for beginners - *but* I'm probably (certainly) biased here, so
you'd better find some non-programmers  having learn Ruby in a similar
context and ask them about this (with the buzzword around Rails, you
find such people easily...)

-- 
bruno desthuilliers
python -c "print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for
p in '[EMAIL PROTECTED]'.split('@')])"
-- 
http://mail.python.org/mailman/listinfo/python-list


do cc list from smtplib

2005-10-21 Thread eight02645999
hi
i have email code:

def email(HOST,FROM,TO,SUBJECT,BODY):
import smtplib
import string, sys


body = string.join((
"From: %s" % FROM,
"To: %s" % TO,
"Subject: %s" % SUBJECT,
"",
BODY), "\r\n")

print body

server = smtplib.SMTP(HOST)
server.sendmail(FROM, [TO],body)
server.quit()


is there a way to include CC list for the smtplib module?
thanks

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


Re: do cc list from smtplib

2005-10-21 Thread Tim Williams (gmail)
On 21 Oct 2005 02:34:40 -0700, [EMAIL PROTECTED]
<[EMAIL PROTECTED]>
>
> def email(HOST,FROM,TO,CC,SUBJECT,BODY):
> import smtplib
> import string, sys

> body = string.join((
> "From: %s" % FROM,
> "To: %s" % TO,
> "CC: %s % CC,
> "Subject: %s" % SUBJECT,
> "",
> BODY), "\r\n")
>
> print body
>
> server = smtplib.SMTP(HOST)
> server.sendmail(FROM, [TO]+[CC],body)
> server.quit()
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: do cc list from smtplib

2005-10-21 Thread Steve Holden
Tim Williams (gmail) wrote:
> On 21 Oct 2005 02:34:40 -0700, [EMAIL PROTECTED]
> <[EMAIL PROTECTED]>
> 
>>def email(HOST,FROM,TO,CC,SUBJECT,BODY):
>>import smtplib
>>import string, sys
> 
> 
>>body = string.join((
>>"From: %s" % FROM,
>>"To: %s" % TO,
>>"CC: %s % CC,
>>"Subject: %s" % SUBJECT,
>>"",
>>BODY), "\r\n")
>>
>>print body
>>
>>server = smtplib.SMTP(HOST)
>>server.sendmail(FROM, [TO]+[CC],body)
>>server.quit()

Assuming that TO and CC are single addresses it would be saner to use:

 server.sendmail(FROM, [TO, CC], body)

- in other words, use a two-element list rather than creating it by 
concatenating two one-element lists!

Note that as far as the SMTP protocol is concerned it's the list of 
recipients that gets actions, not the headers in the message.

stating-the-obvious-ly y'rs  - steve
-- 
Steve Holden   +44 150 684 7255  +1 800 494 3119
Holden Web LLC www.holdenweb.com
PyCon TX 2006  www.python.org/pycon/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: do cc list from smtplib

2005-10-21 Thread Tim Williams (gmail)
On 21/10/05, Steve Holden <[EMAIL PROTECTED]> wrote:

>
> Assuming that TO and CC are single addresses it would be saner to use:
>

:)

Assuming that the envelope TOs (inc CCs) are the same as the
Header-TOs and Header-CCs

Actually,  I think this would be safer !

> def email(HOST,FROM,TO,CC, RECIPS, SUBJECT,BODY):
..
..
..
  server.sendmail(FROM,RECIPS,body)

RECIPS = list of SMTP recipients
TO & CC = Text representation of some/all/none of the SMTP recipients
and/or other text

RECIPS should be either a single address as a string *or* a list
containing 1 or more addresses
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: do cc list from smtplib

2005-10-21 Thread Bean

Tim Williams (gmail) wrote:
> On 21 Oct 2005 02:34:40 -0700, [EMAIL PROTECTED]
> <[EMAIL PROTECTED]>
> >
> > def email(HOST,FROM,TO,CC,SUBJECT,BODY):
> > import smtplib
> > import string, sys
>
> > body = string.join((
> > "From: %s" % FROM,
> > "To: %s" % TO,
> > "CC: %s % CC,
> > "Subject: %s" % SUBJECT,
> > "",
> > BODY), "\r\n")
> >
> > print body
> >
> > server = smtplib.SMTP(HOST)
> > server.sendmail(FROM, [TO]+[CC],body)
> > server.quit()

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


Re: How to get a raised exception from other thread

2005-10-21 Thread Peter Hansen
dcrespo wrote:
> Ok, sorry about the above question. I solved it adding this to the main
> thread:
> 
> try:
> SrvrTCP = module.ThreadedTCPServer(ip,port)
> SrvrTCP.start()
> except Exception, description:
> MsgBox(self,"TCPServer
> Error:\n\n"+str(description),title="TCPServer",style=wx.OK |
> wx.ICON_ERROR)
> return
> 
> Peter, thank you very much.

You're quite welcome.  It's nice to be able to provide a "perfect" 
answer, for a change. :-)

One suggestion about the above: "description" is actually the exception 
instance (the object), not just the description.  The except statement 
can take two items after: the exception type(s) to catch and, 
optionally, a name to bind to the exception instance.  But since 
exception objects know how to represent themselves as strings, calling 
str() on it gives you the description you wanted.  Therefore it would be 
more readable/correct to say this:

except Exception, ex:
 MsgBox(. str(ex) ... )

But I'm happy it works either way!

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


Re: classmethods, class variables and subclassing

2005-10-21 Thread Andrew Jaffe
Steve Holden wrote:
> Andrew Jaffe wrote:
> 
>>The problem is that I actually do want to call these methods on the 
>>class itself, before I've made any instances.
>>
> Except you could use staticmethods with an explicit class argument ...

Steve,

Yep, that would work! Thanks.

But it does seem like a bit of a kludge: classmethods seems to be almost 
exactly what you 'ought' to use here (i.e., I really do want to apply 
these methods to the class as an object in its own right).

A

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


Re: Python vs Ruby

2005-10-21 Thread Tom Anderson
On Thu, 20 Oct 2005, Mike Meyer wrote:

> "[EMAIL PROTECTED]" <[EMAIL PROTECTED]> writes:
>
>> other than haskell and SQL, the others are more or less the same to me 
>> so getting familiar with them is not too difficult.
>
> There are actually lots of good "train your brain" type languages. 
> Members of the LISP family, for instance, to learn what you can do with 
> lists, and also for how cool a real macro facility can be. I happen to 
> like Scheme, but that's just me.

I haven't actually done anything much in any LISP, but Scheme definitely 
looks like a winner to me - single namespace, generally cleaned-up 
language and library, etc.

tom

-- 
For one thing at least is almost certain about the future, namely, that very 
much of it will be such as we should call incredible. -- Olaf Stapledon
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Set an environment variable

2005-10-21 Thread Christian
Steve Holden wrote:

> ::
> one.py
> ::
> import os
> os.environ['STEVE'] = "You are the man"
> os.system("python two.py")
> print "Ran one"
> ::
> two.py
> ::
> import os
> print "STEVE is", os.environ['STEVE']
> print "Ran two"
> [EMAIL PROTECTED] tmp]$ python one.py
> STEVE is You are the man
> Ran two
> Ran one
> [EMAIL PROTECTED] tmp]$
> 
> Hope this helps.
> 
> regards
>  Steve

Thanks Steve, you're quite right, you are the man. And thanks to all the 
rest of you for your kind help and patient understanding. I have learned 
quite a lot and is about to consider my self advanced to the status of 
Python newbie.

So here is my final question:
Do I call the .sh script with a .py script like this:

os.system("/path/to/the/script/startupscript.sh")
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: classmethods, class variables and subclassing

2005-10-21 Thread Steve Holden
Andrew Jaffe wrote:
> Steve Holden wrote:
> 
>>Andrew Jaffe wrote:
>>
>>
>>>The problem is that I actually do want to call these methods on the 
>>>class itself, before I've made any instances.
>>>
>>
>>Except you could use staticmethods with an explicit class argument ...
> 
> 
> Steve,
> 
> Yep, that would work! Thanks.
> 
> But it does seem like a bit of a kludge: classmethods seems to be almost 
> exactly what you 'ought' to use here (i.e., I really do want to apply 
> these methods to the class as an object in its own right).
> 
What's the use case?

regards
  Steve
-- 
Steve Holden   +44 150 684 7255  +1 800 494 3119
Holden Web LLC www.holdenweb.com
PyCon TX 2006  www.python.org/pycon/

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


pushing python to multiple windows machines

2005-10-21 Thread [EMAIL PROTECTED]
I am working on a project that requires python to be installed on a
large number of windows servers and was wondering if anyone has found a
method to do this.  I found the article from 2003, but nobody ever
stated that they have found an option for this.

http://groups.google.com/group/comp.lang.python/browse_frm/thread/f42f0813bc271995?tvc=1&q=%22Pushing+Python+to+Windows+workstations%22

-shawn

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


Re: Set an environment variable

2005-10-21 Thread Steve Holden
Christian wrote:
> Steve Holden wrote:
> 
> 
>>::
>>one.py
>>::
>>import os
>>os.environ['STEVE'] = "You are the man"
>>os.system("python two.py")
>>print "Ran one"
>>::
>>two.py
>>::
>>import os
>>print "STEVE is", os.environ['STEVE']
>>print "Ran two"
>>[EMAIL PROTECTED] tmp]$ python one.py
>>STEVE is You are the man
>>Ran two
>>Ran one
>>[EMAIL PROTECTED] tmp]$
>>
>>Hope this helps.
>>
>>regards
>> Steve
> 
> 
> Thanks Steve, you're quite right, you are the man. And thanks to all the 
> rest of you for your kind help and patient understanding. I have learned 
> quite a lot and is about to consider my self advanced to the status of 
> Python newbie.
> 
> So here is my final question:
> Do I call the .sh script with a .py script like this:
> 
> os.system("/path/to/the/script/startupscript.sh")

Time you answered your own questions by trying things at the interactive 
interpreter prompt!

regards
  Steve
-- 
Steve Holden   +44 150 684 7255  +1 800 494 3119
Holden Web LLC www.holdenweb.com
PyCon TX 2006  www.python.org/pycon/

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


Re: TK question

2005-10-21 Thread jepler
In the FileDialog module there are both LoadFileDialog and SaveFileDialog.  Is
the latter what you want?

Jeff


pgptzMbfYw5VI.pgp
Description: PGP signature
-- 
http://mail.python.org/mailman/listinfo/python-list

RE: pushing python to multiple windows machines

2005-10-21 Thread Tim Golden
[EMAIL PROTECTED]

> I am working on a project that requires python to be installed on a
large 
> number of windows servers and was wondering if anyone has found a
method 
> to do this.  I found the article from 2003, but nobody ever stated
that 
> they have found an option for this.

I'm not quite clear whether you're asking this question from a Python
point-of-view (eg running Python from a shared drive) or from a Windows
point-of-view. 

If the former then perhaps have a look at the Moveable Python project:

http://www.voidspace.org.uk/python/movpy/

I admittedly haven't tried it, but since it's designed to run off memory
sticks etc. I imagine running from a shared drive shouldn't be too
difficult.

There are (commercial) products such as LanDesk which facilitate the 
latter, and in any case the Python installation doesn't do anything
especially perverse. If you did want to install on each machine,
perhaps you could get some advice from the Moveable Python people.

TJG


This e-mail has been scanned for all viruses by Star. The
service is powered by MessageLabs. For more information on a proactive
anti-virus service working around the clock, around the globe, visit:
http://www.star.net.uk

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


Re: Python vs Ruby

2005-10-21 Thread Alex Stapleton

On 21 Oct 2005, at 09:31, Harald Armin Massa wrote:

> Casey,
>
>
>
>> I have heard, but have not been able to verify that if a program is
>> about
>> 10,000 lines in C++
>> it is about
>> 5,000 lines in Java
>> and it is about
>> 3,000 lines in Python (Ruby to?)
>>
>
> BTW: it is normally only 50 lines in Perl. Not that you could read it,
> though
>
> Harald
>

Perl is more like a CISC CPU. There are a million different commands.  
Python is more RISC like.
Line count comparisons = pointless.

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


Re: Python vs Ruby

2005-10-21 Thread bruno modulix
Amol Vaidya wrote:
> "Casey Hawthorne" <[EMAIL PROTECTED]> wrote in message 
> news:[EMAIL PROTECTED]
> 
>>What languages do you know already?
>>
>>What computer science concepts do you know?
>>
>>What computer programming concepts do you know?
>>
>>
>>Have you heard of Scheme?
>>
>>
>>Ruby is a bit Perl like -- so if you like Perl, chances are you might
>>like Ruby.

Ruby is a whole lot Smalltalk-like -- so if you like Smalltalk... !-)

>>Python is more like Java.


Err... Python is more like what Java would have been if Java was a smart
 dynamic hi-level object oriented language !-)


>>I have heard, but have not been able to verify that if a program is
>>about
>>10,000 lines in C++
>>it is about
>>5,000 lines in Java
>>and it is about
>>3,000 lines in Python (Ruby to?)

For a whole lot of common tasks (like file IO etc), the Java/Python loc
ratio is between 5/1 and 10/1. Also, not having the dumbest type system
in the world, Python is naturally much more generic than Java, which
saves a lot of boilerplate code. I think that the real numbers would be
much like 5000 lines in Java -> 1000 lines in Python - and probably 5000
-> 500 in some cases.

> 
> I've done a lot of studying on my own, and taken the classes that my 
> high-school offers. I feel that I have a fairly good understanding of Java, 
> and basic OO concepts due to that. 


Err... I wouldn't start another HolyWar, but Java is not that Object
Oriented. 'Class-based' would be more appropriate. Python, while not
being class-based (ie: it doesn't impose that all code goes into a
'class' statement), is much more an OO language than Java, since in
Python *everything* is an object - even functions, classes and modules.
This makes a *big* difference.

So yes, you may have learned some basic 00 concepts with Java (classes,
instances, inheritence and polymorphism), but with Python and/or Ruby,
you will probably realize that there's much more in the OO paradigm than
all the Java world can dream of.


> 
> Well, I'm not sure what you mean by programming concepts. I'm familiar with 
> OO through Java, and procedural programming through C. I'd be more detailed, 
> but I'm not exactly sure what you are asking. Sorry.

patterns, metaclasses, aspects, closures, anonymous functions,
higher-order functions, multiple dispatch, properties (computed
attributes), generators, list expressions... does that ring a bell ?

> I have no idea what Scheme is, but I'll cettainly look it up as soon as I'm 
> done writing this.

Scheme is a Lisp dialect - Lisp being one of the oldest programming
languages, and one of the most modern programming languages. Whatever
the latest overhyped revolutionary new silver bullet buzzword stuff, you
can bet your ass Lisp already had it many years ago.

Now Lisp never managed to make it to the mainstream... It's a language
(well, a familly of languages should I say) that is worth learning, but
probably not until you've become familiar with some Python features and
idioms.

Another language that failed to make it to the mainstream but is worth
giving a try is Smalltalk - the father of OOPLs (Simula being the
GrandFather). BTW, most of Ruby's feature have been happily stolen from
Smalltalk !-)

> I've never given Perl a shot. It was another language I considered learning, 
> but my father's friend told me to go with Python or Ruby.

+1



-- 
bruno desthuilliers
ruby -e "print '[EMAIL PROTECTED]'.split('@').collect{|p|
p.split('.').collect{|w| w.reverse}.join('.')}.join('@')"
python -c "print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for
p in '[EMAIL PROTECTED]'.split('@')])"
-- 
http://mail.python.org/mailman/listinfo/python-list


Embedded Python - Sharing memory among scripts, threads

2005-10-21 Thread adsheehan
Hi,

I have a multi-threaded C++ software app that embeds Python.

When multi-threading (native system threads) it is possible that
multiple instances of a Python script are active.

I have a requirement to 'share' some data values between these script
instances (e.g. counters, file handles etc).

I notice that 'global' variables are NOT visible or shared among these
script instances.

Does Python offer a solution to this ?

What are my options ?


Thanks for helping.

Alan

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


Re: ANN: Beginning Python (Practical Python 2.0)

2005-10-21 Thread Magnus Lie Hetland
In article <[EMAIL PROTECTED]>, Dennis Lee
Bieber wrote:
[snip]
>
> Must be printed on thinner paper... Both run around 600 pages, but
> the older book is a third thicker... 

Heh. Yeah. The new book has more material, too (new chapters, among
other things), so I guess the new layout also has an effect.

-- 
Magnus Lie Hetland"Preparing to stand by."
http://hetland.org-- Microsoft Windows
-- 
http://mail.python.org/mailman/listinfo/python-list


Looking for client+server sample code (httplib and/or urlib)

2005-10-21 Thread Philippe C. Martin
Hi,

Are there such samples/tutorial out there ?

Regards,

Philippe


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


Re: Set an environment variable

2005-10-21 Thread Christian
Steve Holden wrote:

> Time you answered your own questions by trying things at the interactive 
> interpreter prompt!
> 
> regards
>  Steve

Right again, Steve.

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


Re: Python vs Ruby

2005-10-21 Thread Michael Ekstrand
On Friday 21 October 2005 07:07, bruno modulix wrote:
> >>Python is more like Java.
>
> 
> Err... Python is more like what Java would have been if Java was a
> smart dynamic hi-level object oriented language !-)
> 

+1. Python is easily applicable to most of the problem domain of Java, 
but solves problems much more elegantly. It just isn't shipped embedded 
in all leading browsers :-(.

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


Re: ANN: Beginning Python (Practical Python 2.0)

2005-10-21 Thread Kent Johnson
Magnus Lie Hetland wrote:
> I guess it has actually been out for a while -- I just haven't
> received my copies yet... Anyways: My book, "Beginning Python: From
> Novice to Professional" (Apress, 2005) is now out.

Apress is offering a $10 rebate if you purchase the book before October 30. See 
for example
http://www.bookpool.com/sm/159059519X

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


Re: http/urlib pos/get question (newbie)

2005-10-21 Thread Philippe C. Martin
I have found what I needed ... in one of my books :E)

regards,
Philippe


Philippe C. Martin wrote:

> Hi,
> (I am _very_ new to web programming)
> 
> I am writing a client module (browser plugin) and server module (Python
> CGI) that need to exchange information.
> 
> I want the transaction to be intiated when the client accesses the link.
> 
> I need data  to go back and forth between the client and the server (cgi
> script) with no impact on what the browser shows.
> 
> In the end (when I get the above to work), the server will say OK and the
> actual page will appear or NOK and an ERROR page will appear.
> 
> 
> I'm pretty clear (I think) as to what to do on the javascript (client)
> side (XMLHttp) but am not certain if my cgi script must "urlib.open" its
> own link in order to open the pipe on its side (there'll be some HTML
> GET/POST tag I assume but where is the pipe/socket ?)
> 
> Thanks,
> 
> Philippe

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


Re: Looking for client+server sample code (httplib and/or urlib)

2005-10-21 Thread Philippe C. Martin
I have found what I needed ... in one of my books :E)

Philippe


Philippe C. Martin wrote:

> Hi,
> 
> Are there such samples/tutorial out there ?
> 
> Regards,
> 
> Philippe

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


Re: pushing python to multiple windows machines

2005-10-21 Thread [EMAIL PROTECTED]
hey tim -

Thanks for you input.  I'm looking at it from the Windows perspective
of needing to push a python interpreter out to multiple machines.  I'll
check out Moveable Python as you suggested.

thanks
-shawn

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


wanna stop by my homemade glory hole?

2005-10-21 Thread kevin



hi there where are u plz 

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

Re: ANN: Beginning Python (Practical Python 2.0)

2005-10-21 Thread Jaime Wyant
Also, if any of you guys aren't listening to Ron's Python411 podcast,
you're missing out on a quality podcast about Python.  While not
necessarily `hardcore python' material, Ron does touch on various
things happening in the community along with discussion about nifty
python packages / modules that you may have missed.

Its one of my favorite podcasts.  Great job Ron!

jw

On 20 Oct 2005 15:15:26 -0700, [EMAIL PROTECTED]
<[EMAIL PROTECTED]> wrote:
> I found this book at my local Border's this week. It appears to be a
> most excellent book. I own and have read Magnus' earlier book "Pactical
> Python" (which was excellent) but this one is even better. The first
> half of the book covers the language, and then the second half goes
> into depth developing several practical applications. And of course now
> the book is very up to date. While I obviously have not had time to
> really study this book, I believe that anyone looking for an
> introduction to Python would be very hard pressed to find a better
> choice than this book.
>
> Ron Stephens
> Python411 podcast sereis
> http://www.awaretek.com/python/index.html
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>
-- 
http://mail.python.org/mailman/listinfo/python-list


gnuplot stdout & python question

2005-10-21 Thread bwaha
I've posted this question to comp.graphics.apps.gnuplot too but given that
this python group may also comprise a lot of gnuplot users, and is far more
active, I've posted this question here too. My apologies to those who read
this twice. I posted to cgag before I decided to post here with a more
meaningful subject.


Anyone had any success getting stdout from gnuplot on an ms windows system
(XP)? I'm trying to read mouse coordinates using python. This link shows a
basic mechanism implemented in python.

http://www.physik.tu-dresden.de/~baecker/python/gnuplot.html

It is similar to the gnuplot.py code which I understand is unidirectional
only ie. send commands to gnuplot via gnuplot stdin. My hope is that I can
implement the bidirectional interface in gnuplot.py and give it away to
whoever might find it useful. But first, I gotta get it working.

I can't seem to get anything back to a python shell by this method. Hangs in
the function thats supposed to read stdout. Could be something I'm doing
wrong with python but I rather suspect there is something in the way gnuplot
on windows deals with stdout that I'm not understanding.

btw - I'm using gnuplot 4.1 (Oct 10 cvs build), python 2.3

bwaha


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


Re: pushing python to multiple windows machines

2005-10-21 Thread Larry Bates
Do you really need to install the interpreter or do you
want to install a Python application to a bunch of servers?
Using a combination of py2exe and InnoInstaller I push
applications (and services, and COM objects) to lots of
Windows servers just as normal setup.exe files which can
be distributed with lots of tools.

Larry Bates

[EMAIL PROTECTED] wrote:
> hey tim -
> 
> Thanks for you input.  I'm looking at it from the Windows perspective
> of needing to push a python interpreter out to multiple machines.  I'll
> check out Moveable Python as you suggested.
> 
> thanks
> -shawn
> 
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Converting 2bit hex representation to integer ?

2005-10-21 Thread Peter Hansen
Madhusudan Singh wrote:
> I just tried 
> 
> n=str(x)
> print struct.unpack("b",n)
> 
> I get (51,)
> 
> What is the deal with the parenthesis
> and the comma ?

If you really don't know what the parentheses and comma mean in the 
above output, I would suggest that you need to go back a step and walk 
through the Python tutorial before you try to continue on with what you 
are attempting to do.  (Section 5.3 specifically covers your question.) 
  Either that, or read the documentation on struct.unpack() since that 
describes what it returns fairly clearly.

Assuming your input represents a C-style integer (i.e. fixed size) 
rather than a Python long integer (of arbitrary length), you should be 
able to use just struct.unpack('i', mybinarydata)[0] to get the result 
you need...

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


Re: pushing python to multiple windows machines

2005-10-21 Thread Roger Upole
<[EMAIL PROTECTED]> wrote:
>I am working on a project that requires python to be installed on a
> large number of windows servers and was wondering if anyone has found a
> method to do this.  I found the article from 2003, but nobody ever
> stated that they have found an option for this.
>
> http://groups.google.com/group/comp.lang.python/browse_frm/thread/f42f0813bc271995?tvc=1&q=%22Pushing+Python+to+Windows+workstations%22
>
> -shawn
>

You can use WMI to install an Msi installer on a remote machine.
The Win32_Product class has an Install method:

import win32com.client
wmi=win32com.client.gencache.EnsureDispatch('wbemscripting.swbemlocator',0)
s=wmi.ConnectServer('servername')

p=s.Get('win32_product')
inparams=p.Methods_('Install').InParameters
inparams.Properties_('PackageLocation').Value=r'\\someserver\someshare\python-2.4.2.msi'
inparams.Properties_('AllUsers').Value=True

outparams=p.ExecMethod_('Install',inparams)
print outparams.Properties_('ReturnValue')  ## zero on success



 Roger



== Posted via Newsfeeds.Com - Unlimited-Uncensored-Secure Usenet News==
http://www.newsfeeds.com The #1 Newsgroup Service in the World! 120,000+ 
Newsgroups
= East and West-Coast Server Farms - Total Privacy via Encryption =
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python vs Ruby

2005-10-21 Thread Sion Arrowsmith
bruno modulix  <[EMAIL PROTECTED]> wrote:
>> "Casey Hawthorne" <[EMAIL PROTECTED]> wrote in message 
>> news:[EMAIL PROTECTED]
>>>I have heard, but have not been able to verify that if a program is
>>>about
>>>10,000 lines in C++
>>>it is about
>>>5,000 lines in Java
>>>and it is about
>>>3,000 lines in Python (Ruby to?)
>
>For a whole lot of common tasks (like file IO etc), the Java/Python loc
>ratio is between 5/1 and 10/1. Also, not having the dumbest type system
>in the world, Python is naturally much more generic than Java, which
>saves a lot of boilerplate code. I think that the real numbers would be
>much like 5000 lines in Java -> 1000 lines in Python - and probably 5000
>-> 500 in some cases.

I have here a library (it's the client side of a client-server
interface including a pile of class definitions) which has
implementations in pure C++, Java and Python, taking about 3000,
3500 and 1500 loc respectively. And there's an associated module
(with no C++ implementation) that I remember being particular
"impressed" while writing it to find being 3 times as long in Java
as Python despite (a) extensive (and pretty much common) Javadoc/
docstrings and (b) implementing in the Python version a feature
present in the standard Java library (scheduling a thread to run
at specified intervals and time out). Strip the Javadoc/docstrings
out and it's about at that 5:1 ratio.

As for Ruby, looking at some of the comparisons given elsewhere
in this thread, my intuition is that it would be more loc than
Python due to all the explicit end s.

-- 
\S -- [EMAIL PROTECTED] -- http://www.chaos.org.uk/~sion/
  ___  |  "Frankly I have no feelings towards penguins one way or the other"
  \X/  |-- Arthur C. Clarke
   her nu becomeþ se bera eadward ofdun hlæddre heafdes bæce bump bump bump
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: classmethods, class variables and subclassing

2005-10-21 Thread Andrew Jaffe
Steve Holden wrote:
> Andrew Jaffe wrote:
>> Steve Holden wrote:
>>> Andrew Jaffe wrote:
>>>
 The problem is that I actually do want to call these methods on the 
 class itself, before I've made any instances.

>>> Except you could use staticmethods with an explicit class argument ...
>>
>> Yep, that would work! Thanks.
>>
>> But it does seem like a bit of a kludge: classmethods seems to be 
>> almost exactly what you 'ought' to use here (i.e., I really do want to 
>> apply these methods to the class as an object in its own right).
>>
> What's the use case?

Fair question. I hope the following isn't too technical.

I have a class which describes the model for fitting some data, 
encapsulating among other things a bunch of parameters whose values I'd 
like to determine for a given dataset. The base class is a simple model, 
the derived class a slightly more complicated one with an extra parameter.

At present, I instantiate the class with a particular set of values for 
the parameters.

One of the methods in this class is called 'prior', which returns the 
prior probability for the instance's paramters.

However, it turns out there are some 'meta-parameters' which don't 
change between instances, in particular the allowed limits on the 
parameters, beyond which the prior should return 0. Currently these are 
stored as class variables -- so both the base and derived class want to 
be able to act as if these class variables are 'native' to their own 
class -- since in fact the base/derived relationship is in this case 
actually something of an implementation detail. (Currently I've solved 
the problem by explicitly using the base class methods for setting the 
class variables.)

Does this make sense?

Andrew

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


Re: finding a number...

2005-10-21 Thread Martin Blume
"Enrique Palomo Jiménez"
>
> After ftp a file from mvs to windows, i find:
> is an offset, so up to 2GB, a commercial application
> drives crazy
> [...]
>
??? I didn't understand your question, but 2 GB is popular
limit for the maximal size of a file for some filesystems
(e.g. ext2, FAT [???]).

Maybe this helps, otherwise you'd have to reformulate
the question.

HTH. YMMV.
Martin



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


Re: Python vs Ruby

2005-10-21 Thread vdrab
You can tell everything is well in the world of dynamic languages when
someone posts a question with nuclear flame war potential like "python
vs. ruby" and after a while people go off singing hymns about the
beauty of Scheme...

I love this place.
v.

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


win32 process information, using win32 extension

2005-10-21 Thread Java and Swing
i need to get information about the processes running on a windows pc
(98, 2k, xp)

i can get the pid's using, win32process.EnumProcesses()...and I can get
a handle on a process using an id..such as

handle = win32api.OpenProcess(win32con.PROCESS_QUERY_INFORMATION, 0,
pids[0])

..but how can i get the name of the process, path to process, etc.  I
have the win32 extensions (pywin32) on python 2.4.

thanks.

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


Psycopg2 date problems: "Can't adapt"

2005-10-21 Thread Steve Holden
I'm trying to copy data from an Access database to PostgreSQL, as the 
latter now appears to work well in the Windows environment. However I'm 
having trouble with date columns.

The PostgreSQL table receiving the data has the following definition:

CREATE TABLE Lines (
   LinID SERIAL PRIMARY KEY,
   LinDate   TIMESTAMP(0),
   LinQtyINTEGER,
   LinPrdID  INTEGER ,
   LinPrice  NUMERIC(8,2),
   LinInvoice INTEGER)

Here's the problem in a nutshell:

 >>> d

 >>> ocurs.execute("DELETE FROM Lines")
 >>> osql
'INSERT INTO Lines(LinID, LinDate, LinQty, LinPrdID, LinPrice, 
LinInvoice) VALUES(%s, %s, %s, %s, %s, %s)'
 >>> ocurs.execute(osql, (1, d, 1, 1, 12500.0, 88))
Traceback (most recent call last):
   File "", line 1, in 
psycopg.ProgrammingError: can't adapt
 >>> ocurs.execute(osql, (1, None, 1, 1, 12500.0, 88))
 >>>

Since the date value's the only difference between the two, I deduce 
it's causing the problem.

I'd rather not have to manipulate the data (in other words, I'd rather 
just change the definition of the receiving table to avoid the error if 
possible), as the copying operation attempts to be table-independent. It 
currently reads:

for tbl, cols in d.items():
 print "Copying", tbl
 dsql = "DELETE FROM %s" % tbl
 ocurs.execute(dsql)
 isql = "SELECT %s FROM %s" % (", ".join(cols), tbl)
 osql = "INSERT INTO %s(%s) VALUES(%s)" % (
 tbl, ", ".join(cols), ", ".join("%s" for c in cols))
 print isql, '\n', osql
 icurs.execute(isql)
 for row in icurs.fetchall():
 ocurs.execute(osql, row)

Though until I started stepping through the data row by row the last two 
lines were replaced by

 ocurs.executemany(osql, icurs.fetchall())

Who can help me past this little sticking point?

regards
  Steve
-- 
Steve Holden   +44 150 684 7255  +1 800 494 3119
Holden Web LLC www.holdenweb.com
PyCon TX 2006  www.python.org/pycon/

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


RE: win32 process information, using win32 extension

2005-10-21 Thread Tim Golden
[Java and Swing]

> i need to get information about the processes 
> running on a windows pc (98, 2k, xp)

> i can get the pid's using, win32process.EnumProcesses()
> but how can i get the name of the process, path 
> to process, etc.

You can probably do what you want with WMI. You'll have to
make sure to install Microsoft's WMI pack (or whatever it's
called) on the Win98 machines:

http://timgolden.me.uk/python/wmi_cookbook.html#running_processes

TJG


This e-mail has been scanned for all viruses by Star. The
service is powered by MessageLabs. For more information on a proactive
anti-virus service working around the clock, around the globe, visit:
http://www.star.net.uk

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


Re: Psycopg2 date problems: "Can't adapt"

2005-10-21 Thread [EMAIL PROTECTED]
Is "None" a valid value for SQL ? Or should it be NULL ? May be it is
because your input is NULL which is being converted to None in python
but haven't been converted back to NULL on its way out.

Steve Holden wrote:
> I'm trying to copy data from an Access database to PostgreSQL, as the
> latter now appears to work well in the Windows environment. However I'm
> having trouble with date columns.
>
> The PostgreSQL table receiving the data has the following definition:
>
> CREATE TABLE Lines (
>LinID SERIAL PRIMARY KEY,
>LinDate   TIMESTAMP(0),
>LinQtyINTEGER,
>LinPrdID  INTEGER ,
>LinPrice  NUMERIC(8,2),
>LinInvoice INTEGER)
>
> Here's the problem in a nutshell:
>
>  >>> d
> 
>  >>> ocurs.execute("DELETE FROMI Lines")
>  >>> osql
> 'INSERT INTO Lines(LinID, LinDate, LinQty, LinPrdID, LinPrice,
> LinInvoice) VALUES(%s, %s, %s, %s, %s, %s)'
>  >>> ocurs.execute(osql, (1, d, 1, 1, 12500.0, 88))
> Traceback (most recent call last):
>File "", line 1, in 
> psycopg.ProgrammingError: can't adapt
>  >>> ocurs.execute(osql, (1, None, 1, 1, 12500.0, 88))
>  >>>
>
> Since the date value's the only difference between the two, I deduce
> it's causing the problem.
>
> I'd rather not have to manipulate the data (in other words, I'd rather
> just change the definition of the receiving table to avoid the error if
> possible), as the copying operation attempts to be table-independent. It
> currently reads:
>
> for tbl, cols in d.items():
>  print "Copying", tbl
>  dsql = "DELETE FROM %s" % tbl
>  ocurs.execute(dsql)
>  isql = "SELECT %s FROM %s" % (", ".join(cols), tbl)
>  osql = "INSERT INTO %s(%s) VALUES(%s)" % (
>  tbl, ", ".join(cols), ", ".join("%s" for c in cols))
>  print isql, '\n', osql
>  icurs.execute(isql)
>  for row in icurs.fetchall():
>  ocurs.execute(osql, row)
>
> Though until I started stepping through the data row by row the last two
> lines were replaced by
>
>  ocurs.executemany(osql, icurs.fetchall())
>
> Who can help me past this little sticking point?
>
> regards
>   Steve
> --
> Steve Holden   +44 150 684 7255  +1 800 494 3119
> Holden Web LLC www.holdenweb.com
> PyCon TX 2006  www.python.org/pycon/

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


Re: Accessing a dll from Python

2005-10-21 Thread Grant Edwards
On 2005-10-20, dcrespo <[EMAIL PROTECTED]> wrote:

> Can someone give me lights on how can I deal with dlls from python?

Use the ctypes module.

> My main purpose is to get access to a Unitech PT600 Bar Code system. I
> have the dll that works fine through Visual Basic. But I'm migrating to
> Python, so I need a way to use the same dll, or a C library.

ctypes can call dll functions using either C or Pascal calling
conventsions.

> I tried to access a dll created by myself on Visual Basic. The
> dll just have one function. It works perfect when using it on
> a VB project just including it in the references
> configuration. But I can't access it from python. I tried the
> ctypes module.

ctypes has always worked for me.

Sorry, I've no clue about anything VB-related unless it's
Victoria Bitter.

-- 
Grant Edwards   grante Yow!  I have a VISION! It's
  at   a RANCID double-FISHWICH on
   visi.coman ENRICHED BUN!!
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Set an environment variable

2005-10-21 Thread Grant Edwards
On 2005-10-21, Christian <[EMAIL PROTECTED]> wrote:
>> 
>> The closest thing you can do is that:
>> 
>> -myScript.py--
>> print 'export MY_VARIABLE=value'
>> --
>> 
>> -myScript.sh--
>> python myScript.py > /tmp/chgvars.sh
>> . /tmp/chgvars.sh
>> --

Bullshit.  Are people being intentionally misleading??

> Can I write a .py script that calls a .sh script that executes the 
> export command and then calls another .py script (and how would the 
> first .py script look)?

Good grief, that's ugly.  Just use os.putenv().

> That would be much more what is my basic problem.

And even Google knows the correct answer

http://www.google.com/search?hl=en&lr=&q=python+set+environment+variable

Follow the first hit.

-- 
Grant Edwards   grante Yow!  TONY RANDALL! Is YOUR
  at   life a PATIO of FUN??
   visi.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: python and outlook

2005-10-21 Thread skip

dt> Are there any links or sites on how to read outlook mail boxes or
dt> address book?

Check the Outlook plugin code in SpamBayes .

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


Compile C program -> .pyc file

2005-10-21 Thread Ernesto
Is there a way to compile a C program into a .pyc file that has the
same behavior as the compiled C program?

Thanks!

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


Re: Accessing a dll from Python

2005-10-21 Thread Simon Brunning
On 21/10/05, Grant Edwards <[EMAIL PROTECTED]> wrote:
> Sorry, I've no clue about anything VB-related unless it's
> Victoria Bitter.

+1 QOTW.

--
Cheers,
Simon B,
[EMAIL PROTECTED],
http://www.brunningonline.net/simon/blog/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Execute C code through Python

2005-10-21 Thread Ernesto
Thanks.  Can anyone provide an example of using *subprocess* to run
helloWorld.C through the python interpreter.

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


Re: classmethods, class variables and subclassing

2005-10-21 Thread Steve Holden
Andrew Jaffe wrote:
> Steve Holden wrote:
> 
>>Andrew Jaffe wrote:
>>
>>>Steve Holden wrote:
>>>
Andrew Jaffe wrote:


>The problem is that I actually do want to call these methods on the 
>class itself, before I've made any instances.
>

Except you could use staticmethods with an explicit class argument ...
>>>
>>>Yep, that would work! Thanks.
>>>
>>>But it does seem like a bit of a kludge: classmethods seems to be 
>>>almost exactly what you 'ought' to use here (i.e., I really do want to 
>>>apply these methods to the class as an object in its own right).
>>>
>>
>>What's the use case?
> 
> 
> Fair question. I hope the following isn't too technical.
> 
> I have a class which describes the model for fitting some data, 
> encapsulating among other things a bunch of parameters whose values I'd 
> like to determine for a given dataset. The base class is a simple model, 
> the derived class a slightly more complicated one with an extra parameter.
> 
> At present, I instantiate the class with a particular set of values for 
> the parameters.
> 
> One of the methods in this class is called 'prior', which returns the 
> prior probability for the instance's paramters.
> 
> However, it turns out there are some 'meta-parameters' which don't 
> change between instances, in particular the allowed limits on the 
> parameters, beyond which the prior should return 0. Currently these are 
> stored as class variables -- so both the base and derived class want to 
> be able to act as if these class variables are 'native' to their own 
> class -- since in fact the base/derived relationship is in this case 
> actually something of an implementation detail. (Currently I've solved 
> the problem by explicitly using the base class methods for setting the 
> class variables.)
> 
> Does this make sense?
> 

I think so. It's not normal adive, but it sounds like a metaclass might 
be what you need here.

regards
  Steve
-- 
Steve Holden   +44 150 684 7255  +1 800 494 3119
Holden Web LLC www.holdenweb.com
PyCon TX 2006  www.python.org/pycon/

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


HELP! py2exe error - No module named decimal

2005-10-21 Thread Chris
I've just completed a project using the following (Windows XP, python 
2.4.1, wxpython 2.6, and pymssql 0.7.3). The program runs great, but 
after I convert it to an exe (required for this project), it gives me 
the following error when I try to run it.

Traceback (most recent call last):
  File "EstUpdate.py", line 6, in ?
  File "frmSplash.pyc", line 9, in ?
  File "pymssql.pyc", line 23, in ?
  File "_mssql.pyc", line 9, in ?
  File "_mssql.pyc", line 7, in __load
ImportError: No module named decimal

However, when I look in c:\python24\lib on the machine which ran py2exe, 
I see decimal.py and decimal.pyc.

Can someone please help with this? I'm supposed to start testing the 
program today and I can't seem to move past this first step.

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


Re: Compile C program -> .pyc file

2005-10-21 Thread Steve Holden
Ernesto wrote:
> Is there a way to compile a C program into a .pyc file that has the
> same behavior as the compiled C program?
> 
> Thanks!
> 
Here's a start:

http://codespeak.net/pipermail/pypy-dev/2003q1/000198.html

regards
  Steve
-- 
Steve Holden   +44 150 684 7255  +1 800 494 3119
Holden Web LLC www.holdenweb.com
PyCon TX 2006  www.python.org/pycon/

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


Re: Psycopg2 date problems: "Can't adapt"

2005-10-21 Thread Steve Holden
[EMAIL PROTECTED] wrote:
> Steve Holden wrote:
> 
>>I'm trying to copy data from an Access database to PostgreSQL, as the
>>latter now appears to work well in the Windows environment. However I'm
>>having trouble with date columns.
>>
>>The PostgreSQL table receiving the data has the following definition:
>>
>>CREATE TABLE Lines (
>>   LinID SERIAL PRIMARY KEY,
>>   LinDate   TIMESTAMP(0),
>>   LinQtyINTEGER,
>>   LinPrdID  INTEGER ,
>>   LinPrice  NUMERIC(8,2),
>>   LinInvoice INTEGER)
>>
>>Here's the problem in a nutshell:
>>
>> >>> d
>>
>> >>> ocurs.execute("DELETE FROMI Lines")
>> >>> osql
>>'INSERT INTO Lines(LinID, LinDate, LinQty, LinPrdID, LinPrice,
>>LinInvoice) VALUES(%s, %s, %s, %s, %s, %s)'
>> >>> ocurs.execute(osql, (1, d, 1, 1, 12500.0, 88))
>>Traceback (most recent call last):
>>   File "", line 1, in 
>>psycopg.ProgrammingError: can't adapt
>> >>> ocurs.execute(osql, (1, None, 1, 1, 12500.0, 88))
>> >>>
>>
>>Since the date value's the only difference between the two, I deduce
>>it's causing the problem.
>>
[...]
>>
 > Is "None" a valid value for SQL ? Or should it be NULL ? May be it is
 > because your input is NULL which is being converted to None in python
 > but haven't been converted back to NULL on its way out.
 >
Python's None is the way you communicate null values through the query 
parameterisation mechanism. You will observe that the statement with the 
None value for the date field runs fine, and the error occurs when I 
provide an actual date object.

regards
  Steve
-- 
Steve Holden   +44 150 684 7255  +1 800 494 3119
Holden Web LLC www.holdenweb.com
PyCon TX 2006  www.python.org/pycon/

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


RE: get a copy of a string leaving original intact

2005-10-21 Thread Bell, Kevin
I ended up slicing my string into a new one, rather than trying to have
a copy of the string to alter in one case, or leave intact in another
case.

Thanks for the pointer on concatenating paths!




-Original Message-
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] On Behalf
Of Fredrik Lundh
Sent: Friday, October 21, 2005 2:10 AM
To: python-list@python.org
Subject: Re: get a copy of a string leaving original intact

"Bell, Kevin" wrote:

> I'm having trouble with something that seems like it should be simple.
>
> I need to copy a file, say "abc-1.tif" to another directory, but if
it's
> in there already, I need to transfer it named "abc-2.tif" but I'm
going
> about it all wrong.
>
> Here's what doesn't work: (I'll add the copy stuff from shutil after
> figuring out the basic string manipulation.)

define "doesn't work".

> import os
>
> source = r"C:\Source"
> target = r"P:\Target"
>
> files = os.listdir(source)
>
> for f in files:
> if os.path.isfile(target + "\\" + f):  # if it already exists
> print f + " exists"
> s = f  # i'd like a copy to
> alter
> s = s.replace("-1", "-2")
> print "Altered it to be " + s
> print source + "\\" + s, target + "\\" + s

did you mean

print source + "\\" + f, target + "\\" + s

?

> else:
> print f + " IS NOT THERE YET"
> print source + "\\" + f, target + "\\" + f  # use the original
>
> -- 
> http://mail.python.org/mailman/listinfo/python-list

btw, note that

source + "\\" + f

is better written as

os.path.join(source, f)

e.g.

for f in os.listdir(source):
sourcefile = os.path.join(source, f)
targetfile = os.path.join(target, f)
if os.path.isfile(targetfile):
targetfile = os.path.join(target, f.replace("-1", "-2"))
print "copy", sourcefile, "to", targetfile
shutil.copy(sourcefile, targetfile)





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


Re: classmethods, class variables and subclassing

2005-10-21 Thread Steve Holden
Steve Holden wrote:
[...]
> 
> I think so. It's not normal adive, but it sounds like a metaclass might 
> be what you need here.
> 
^adive^advice^

spell-me-own-name-wrong-next-ly y'rs  - evest
-- 
Steve Holden   +44 150 684 7255  +1 800 494 3119
Holden Web LLC www.holdenweb.com
PyCon TX 2006  www.python.org/pycon/

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


Re: Execute C code through Python

2005-10-21 Thread Fredrik Lundh
"Ernesto" wrote:

> Thanks.  Can anyone provide an example of using *subprocess* to run
> helloWorld.C through the python interpreter.

compile helloWorld, and run:

import subprocess
subprocess.call("helloWorld")

(any special reason why you couldn't figure this out yourself, given the
example provided by gsteff ?)

 



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


Re: Compile C program -> .pyc file

2005-10-21 Thread Fredrik Lundh
"Ernesto" wrote:

> Is there a way to compile a C program into a .pyc file that has the
> same behavior as the compiled C program?

unless you find a C->Python compiler, no.  PYC files contain Python bytecode,
C compilers usually generate native code for a given machine platform.

 



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


Re: Compile C program -> .pyc file

2005-10-21 Thread Ernesto

Fredrik Lundh wrote:
> "Ernesto" wrote:
>
> > Is there a way to compile a C program into a .pyc file that has the
> > same behavior as the compiled C program?
>
> unless you find a C->Python compiler, no.  PYC files contain Python bytecode,
> C compilers usually generate native code for a given machine platform.
>
> 


Yeah, I know it can't really be done in ONE step, but I was hoping it
was possible in 'n' steps.

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


Re: Compile C program -> .pyc file

2005-10-21 Thread Fredrik Lundh
Steve Holden wrote:

> Here's a start:
>
> http://codespeak.net/pipermail/pypy-dev/2003q1/000198.html

if anyone could turn ideas that only exist in Christian's brain into working 
systems,
the world would look a lot different.

 



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


coloring a complex number

2005-10-21 Thread Arthur
Spending the morning avoiding responsibilities, and seeing what it would
take to color some complex numbers.

class color_complex(complex):
 def  __init__(self,*args,**kws):
 complex.__init__(*args)
 self.color=kws.get('color', 'BLUE')

>>> a=color_complex(1,7)
>>> print a
(1+7j)  #good so far
>>> a=color_complex(1,7,color='BLUE') 
Traceback (most recent call last):
  File "", line 1, in -toplevel-
a=color_complex(1,7,color='BLUE')
TypeError: 'color' is an invalid keyword argument for this function

No good... it seems that I am actually subclassing the built_in function
'complex' when I am hoping to have been subclassing the built_in numeric
type - complex.

but some googling sends me to lib/test/test_descr.py

where there a working subclass of complex more in
accordance with my intentions.

class color_complex(complex):
def __new__(cls,*args,**kws):
result = complex.__new__(cls, *args)
result.color = kws.get('color', 'BLUE')
return result

>>> a=color_complex(1,7,color='BLUE')
>>> print a
(1+7j)
>>> print a.color
BLUE

which is very good.

But on the chance that I end up pursuing this road, it would be good if
I understood what I just did. It would certainly help with my
documentation  ;)

Assistance appreciated.

NOTE:

The importance of the asset of the depth and breadth of Python archives
-  for learning (and teaching) and real world production - should not be
underestimated, IMO. I could be confident if there was an answer to
getting the functionality I was looking for as above, it would be found
easily enough by a google search.  It is only with the major
technologies that one can hope to pose a question of almost any kind to
google and get the kind of relevant hits one gets when doing a Python
related search.  Python is certainly a major technology, in that
respect.  As these archives serve as an extension to the documentation,
the body of Python documentation is beyond any  normal expectation.

True, this asset is generally better for answers than explanations.

I got the answer I needed.  Pursuing here some explanation of that answer.

Art


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


Re: Execute C code through Python

2005-10-21 Thread Grant Edwards
On 2005-10-21, Ernesto <[EMAIL PROTECTED]> wrote:

> Thanks.  Can anyone provide an example of using *subprocess* to run
> helloWorld.C through the python interpreter.

No.  You can't run a .C file.  You can run a .exe file (I'm
guessing you're using Windows based on the question).


-- 
Grant Edwards   grante Yow!  Am I accompanied by
  at   a PARENT or GUARDIAN?
   visi.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: HELP! py2exe error - No module named decimal

2005-10-21 Thread Larry Bates
FYI there is a separate newsgroup for py2exe at
gmane.comp.python.py2exe.  You may want to post
there also.

Just as a suggestion, put an import decimal at
the top of your program.  It looks like _mssql
might be doing dynamic imports in __load method
which will "confuse" py2exe because it can't
know about dynamic imports which happen at
runtime.

-Larry Bates

Chris wrote:
> I've just completed a project using the following (Windows XP, python 
> 2.4.1, wxpython 2.6, and pymssql 0.7.3). The program runs great, but 
> after I convert it to an exe (required for this project), it gives me 
> the following error when I try to run it.
> 
> Traceback (most recent call last):
>   File "EstUpdate.py", line 6, in ?
>   File "frmSplash.pyc", line 9, in ?
>   File "pymssql.pyc", line 23, in ?
>   File "_mssql.pyc", line 9, in ?
>   File "_mssql.pyc", line 7, in __load
> ImportError: No module named decimal
> 
> However, when I look in c:\python24\lib on the machine which ran py2exe, 
> I see decimal.py and decimal.pyc.
> 
> Can someone please help with this? I'm supposed to start testing the 
> program today and I can't seem to move past this first step.
> 
> Thanks!!
> Chris
-- 
http://mail.python.org/mailman/listinfo/python-list


findwindow by its class name

2005-10-21 Thread James Hu
Hi,

For the simple code:

from wxPython.wx import *
 
class MyApp(wxApp):
def OnInit(self):
frame = wxFrame(NULL, -1, "Hello App")
frame.Show(true)
self.SetTopWindow(frame)
return true
 
app = MyApp(0)
app.MainLoop()

Is there any way to know this windows' class name? I need to find it by
win32gui.FindWindow(classname,None) and send msg from another
application, but not using its title "Hello App".
MyApp is not the classname, for it couldn't be found by
FindWindow("MyApp",None).

Thanks a lot in advance!

James

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


Re: Compile C program -> .pyc file

2005-10-21 Thread Grant Edwards
On 2005-10-21, Fredrik Lundh <[EMAIL PROTECTED]> wrote:
>
>> Is there a way to compile a C program into a .pyc file that
>> has the same behavior as the compiled C program?
>
> unless you find a C->Python compiler, no.

Or a C->Python-byte-code compiler.

> PYC files contain Python bytecode, C compilers usually
> generate native code for a given machine platform.

Generating byte-code for a stack-based virtual machine used to
be fairly popular for Pascal.  [I once typed in from a book a
Pascal compiler in 8080 assembly language that generate
P-code.] Generating Python byte code from Pascal wouldn't be
terribly difficult, but doing so for C would be pretty tough
because you'd have to figure out how to fake all the low-level
pointer shenanigans which C allows (or some would say depends
upon).

-- 
Grant Edwards   grante Yow!  Are we live or
  at   on tape?
   visi.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Execute C code through Python

2005-10-21 Thread Micah Elliott
On Oct 21, Grant Edwards wrote:
> I'm guessing you're using Windows based on the question.

+1 QOTW.

-- 
_ _ ___
|V|icah |- lliott  http://micah.elliott.name  [EMAIL PROTECTED]
" " """
-- 
http://mail.python.org/mailman/listinfo/python-list


ANN: Veusz 0.8 released

2005-10-21 Thread Jeremy Sanders
Veusz 0.8
-
Velvet Ember Under Sky Zenith
-
http://home.gna.org/veusz/
 
Veusz is Copyright (C) 2003-2005 Jeremy Sanders <[EMAIL PROTECTED]>
Licenced under the GPL (version 2 or greater)
 
Veusz is a scientific plotting package written in Python (currently
100% Python). It uses PyQt for display and user-interfaces, and
numarray for handling the numeric data. Veusz is designed to produce
publication-ready Postscript output.
 
Veusz provides a GUI, command line and scripting interface (based on
Python) to its plotting facilities. The plots are built using an
object-based system to provide a consistent interface.
 
Changes from 0.7:
 Please refer to ChangeLog for all the changes.
 Highlights include:
  * Datasets can be linked together with expressions
  * SVG export
  * Edit/Copy/Cut support of widgets
  * Pan image with mouse
  * Click on graph to change settings
  * Lots of UI improvements
 
Features of package:
 * X-Y plots (with errorbars)
 * Images (with colour mappings)
 * Stepped plots (for histograms)
 * Line plots
 * Function plots
 * Fitting functions to data
 * Stacked plots and arrays of plots
 * Plot keys
 * Plot labels
 * LaTeX-like formatting for text
 * EPS output
 * Simple data importing
 * Scripting interface
 * Save/Load plots
 * Dataset manipulation
 * Embed Veusz within other programs
 
To be done:
 * Contour plots
 * UI improvements
 * Import filters (for qdp and other plotting packages, fits, csv)
 
Requirements:
 Python (probably 2.3 or greater required)
   http://www.python.org/
 Qt (free edition)
   http://www.trolltech.com/products/qt/
 PyQt (SIP is required to be installed first)
   http://www.riverbankcomputing.co.uk/pyqt/
   http://www.riverbankcomputing.co.uk/sip/
 numarray
   http://www.stsci.edu/resources/software_hardware/numarray
 Microsoft Core Fonts (recommended)
   http://corefonts.sourceforge.net/
 PyFITS (optional)
   http://www.stsci.edu/resources/software_hardware/pyfits
 
For documentation on using Veusz, see the "Documents" directory. The
manual is in pdf, html and text format (generated from docbook).
 
If you enjoy using Veusz, I would love to hear from you. Please join
the mailing lists at
 
https://gna.org/mail/?group=veusz
 
to discuss new features or if you'd like to contribute code. The
newest code can always be found in CVS.

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


Re: Execute C code through Python

2005-10-21 Thread Grant Edwards
On 2005-10-21, Micah Elliott <[EMAIL PROTECTED]> wrote:
> On Oct 21, Grant Edwards wrote:
>> I'm guessing you're using Windows based on the question.
>
> +1 QOTW.

Yow!  That's two in one day, what do I win?

-- 
Grant Edwards   grante Yow!  I'll take ROAST BEEF
  at   if you're out of LAMB!!
   visi.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Execute C code through Python

2005-10-21 Thread Steve Holden
Grant Edwards wrote:
> On 2005-10-21, Micah Elliott <[EMAIL PROTECTED]> wrote:
> 
>>On Oct 21, Grant Edwards wrote:
>>
>>>I'm guessing you're using Windows based on the question.
>>
>>+1 QOTW.
> 
> 
> Yow!  That's two in one day, what do I win?
> 
If my experience is anything to go by it just means there won't be a 
weekly URL this week :-)

regards
  Steve
-- 
Steve Holden   +44 150 684 7255  +1 800 494 3119
Holden Web LLC www.holdenweb.com
PyCon TX 2006  www.python.org/pycon/

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


Re: DBM scalability

2005-10-21 Thread Paul Rubin
"George Sakkis" <[EMAIL PROTECTED]> writes:
> I'm trying to create a dbm database with around 4.5 million entries
> but the existing dbm modules (dbhash, gdbm) don't seem to cut
> it. What happens is that the more entries are added, the more time
> per new entry is required, so the complexity seems to be much worse
> than linear. Is this to be expected

No, not expected.  See if you're using something like db.keys() which
tries to read all the keys from the db into memory, or anything like that.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: need some advice on x y plot

2005-10-21 Thread nephish
ok, i tried something similar to what you posted.
a little simpler though.
i am running a query on a database and making a list of time, value
pairs
kinda like this
plot_points = ([time, value], [time, value], [time, value])
gnuplot complains that it needs a float for one of the values.
i can plot just the value, and it shows up ( no x value found)

how should i proceed?

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


Binding a variable?

2005-10-21 Thread Paul Dale

Hi everyone,

Is it possible to bind a list member or variable to a variable such that

temp = 5

list = [ temp ]

temp == 6

list

would show

list = [ 6 ]

Thanks in advance?

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


Re: pushing python to multiple windows machines

2005-10-21 Thread [EMAIL PROTECTED]
Thanks Roger & Larry.  Both of your suggestions are very helpful!

-shawn

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


Re: findwindow by its class name

2005-10-21 Thread Steve Holden
James Hu wrote:
> Hi,
> 
> For the simple code:
> 
> from wxPython.wx import *
>  
> class MyApp(wxApp):
> def OnInit(self):
> frame = wxFrame(NULL, -1, "Hello App")
> frame.Show(true)
> self.SetTopWindow(frame)
> return true
>  
> app = MyApp(0)
> app.MainLoop()
> 
> Is there any way to know this windows' class name? I need to find it by
> win32gui.FindWindow(classname,None) and send msg from another
> application, but not using its title "Hello App".
> MyApp is not the classname, for it couldn't be found by
> FindWindow("MyApp",None).
> 
> Thanks a lot in advance!
> 
I'm not saying it can'ty be done (which is a pity for you, because 
that's usually a cue for someone to contradict me) but it's expecting 
quite a lot of win32gui. A wxPython application is not a windows handle, 
and I suspect you will find that the classname you seek isn't visible 
from inside (wx)Python.

regards
  Steve
-- 
Steve Holden   +44 150 684 7255  +1 800 494 3119
Holden Web LLC www.holdenweb.com
PyCon TX 2006  www.python.org/pycon/

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


Help with language, dev tool selection

2005-10-21 Thread vasilijepetkovic
I have a problem that I have to solve programmatically and since HTML
is pretty much the only code I have been exposed to I need an advice on
how to develop the programmatic solution to the problem I have.

In the nutshell, it'd be great if you can give me guidance in terms
of:

1)  What programming language to use
2)  What development tools to use
3)  Tips on how to code the solution

So, here is my challenge:

I have a flat text file, 3 records, each record has two columns,
the columns are tab separated.

The file looks like this (approximately)

Sarajevo431104-133111
Mostar  441242-133421
Zagreb  432322-134423


The first value is a name of a town, and the second value represent
longitude-latitude in degrees, minutes and seconds.

For each record I have to create an html file that will be named as the
name of the town (i.e. Sarajevo.html). The content of the file will be
rather simple; in the first row it will contain the header (i.e.
"This page displays longitude-latitude information") - The second
row will have the following word: "Grad" - and the third row will
contain the name of the city and the fourth row will have the
longitude-latitude info.

The program also needs to prompt me (before it starts spitting the html
pages) and ask what test should be entered in line one (I would than
manually enter "This page displays longitude-latitude information")
and it also need to prompt me about the text that should be entered in
line two (I'd go and manually enter "grad").

I'd greatly appreciate any coment and/or guidance.


Best,

Vasilije Petkovic Vasa

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


Re: Set an environment variable

2005-10-21 Thread Mike Meyer
Grant Edwards <[EMAIL PROTECTED]> writes:

> On 2005-10-21, Christian <[EMAIL PROTECTED]> wrote:
>>> 
>>> The closest thing you can do is that:
>>> 
>>> -myScript.py--
>>> print 'export MY_VARIABLE=value'
>>> --
>>> 
>>> -myScript.sh--
>>> python myScript.py > /tmp/chgvars.sh
>>> . /tmp/chgvars.sh
>>> --
>
> Bullshit.  Are people being intentionally misleading??

No. Are you being intentionally - never mind.

> And even Google knows the correct answer
>
> http://www.google.com/search?hl=en&lr=&q=python+set+environment+variable
>
> Follow the first hit.

The first hit is basically the solution presented above translated
from Unix to Windows: your python script writes the appropriate shell
commands into a file, then you get the command processor to process
that file. The Windows version carries this a step further by wrapping
it all up in a script to make it easy to run, but that's the only real
difference. Maybe the results order has changed since you looked?

Watch the recipe - I may add a Unix/sh solution.

http://www.mired.org/home/mwm/
Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Binding a variable?

2005-10-21 Thread [EMAIL PROTECTED]
I think not. temp is a name, not a variable. I believe temp=5 means it
points to an immutable object 5. temp=6 means now it points to another
immutable object 6. list=[temp] would resolve to whatever object temp
is pointed to at that moment.

You can try temp=[1].

Paul Dale wrote:
> Hi everyone,
>
> Is it possible to bind a list member or variable to a variable such that
>
> temp = 5
>
> list = [ temp ]
>
> temp == 6
>
> list
> 
> would show
> 
> list = [ 6 ]
> 
> Thanks in advance?
> 
> Paul

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


Re: Binding a variable?

2005-10-21 Thread Kent Johnson
Paul Dale wrote:
> 
> Hi everyone,
> 
> Is it possible to bind a list member or variable to a variable such that

No, Python variables don't work that way.
> 
> temp = 5

The name 'temp' is now bound to the integer 5. Think of temp as a pointer to an 
integer object with value 5.
> 
> list = [ temp ]

the name 'list' is bound to a list whose only member is a reference to the 
integer 5
> 
> temp == 6

Ok now temp is bound to a new integer, but the list hasn't changed - it's 
member is still a reference to 5
> 
> list
> 
> would show
> 
> list = [ 6 ]

You have to put a mutable object into the list - something whose state you can 
change. For example this works, because temp and lst[0] are references to the 
same mutable (changeable) list:
 >>> temp = [6]
 >>> lst = [temp]
 >>> lst
[[6]]
 >>> temp[0] = 5
 >>> lst
[[5]]

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


  1   2   3   >