Re: Tip: 'Open IPython here' in Windows context menu

2007-02-27 Thread cyberco
Great! That really helps me, thanks.
2B

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


Re: Interactive os.environ vs. os.environ in script

2007-02-27 Thread Peter Otten
[EMAIL PROTECTED] wrote:

> Is there another possibility of how to solve it just by adding some
> lines in script?

I think you have to wrap your script in a shell script

#!/bin/sh
export LD_LIBRARY_PATH=/path/Linux/rh_linux
python shrink_bs_070226.py

To avoid that you can have the python script invoke itself, e. g.:

#!/usr/bin/env python
import os
if os.environ.get("YADDA") != "whatever":
print "fix environment"
os.environ["YADDA"] = "whatever"
os.system("yadda.py")
raise SystemExit

print "YADDA is now %r" % os.environ["YADDA"]
print "do your real stuff"

Peter

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


Re: Jobs: Lisp and Python programmers wanted in the LA area

2007-02-27 Thread Michele Simionato
On Feb 27, 2:51 am, Dan Bensen <[EMAIL PROTECTED]> wrote:
>  > Tech HR wrote:
>  > easier to train a Java programmer or a Perler on Python than Lisp.Dan 
> Bensen wrote:
>
>  > Are your technical problems simple enough to be solved by Python
>  > trainees?
>
> Aahz wrote:
> > If they're already good programmers, yes.
>
> Sure, but who are these good programmers (coming from Java or Perl)?
> Do you have a list of them?  The employer needs to know how many
> not-so-good programmers they have to interview before they find one
> who's good enough.  It depends on how hard the programming is.

Right, so they should hire Python programmers who know Lisp too. This
is not
so uncommon, we have at least three people here where I work.

 Michele Simionato

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


Python Source Code Beautifier

2007-02-27 Thread Franz Steinhaeusler
Hello, I did not find any reasonable pyhton source code beautifier
program (preferable gui).

Some would ask why? Program it immediatly good.

(BTW: Would be a nice project, if I would have more spare time).

Ich have some foreign source, which are programed in a way
I don't like, so I would like to have a tool, which automatically
processes following options:


Use Spaces, size: 4
convert structs like: if (a > b):   to   if a > b:
fill in spaces, but not in functions between operators:

a+=1 => a += 1
p(t + 1) => p(t+1)

convert:

self.scriptcount = self.scriptcount + 1 => self.scriptcount += 1

from "is" to "==" and "is not" to "!=" (ok a find replace could do that
easily also), but in a program that would be more comfortable.

break long lines (in a reasonable way)

make from:
if len(string) > 0: => if string:
and 
if if len(string) < 1 orr if string == ""  => if not string

detect mixed line ending
detect tabs mixed with space
trim trailing whitespaces.





Is there such a tool around?

Running Pylint or Pycheck automatically afterwards
would be the coronation. :)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Interactive os.environ vs. os.environ in script

2007-02-27 Thread boris . smirnov
On Feb 27, 9:31 am, Peter Otten <[EMAIL PROTECTED]> wrote:
> [EMAIL PROTECTED] wrote:
> > Is there another possibility of how to solve it just by adding some
> > lines in script?
>
> I think you have to wrap your script in a shell script
>
> #!/bin/sh
> export LD_LIBRARY_PATH=/path/Linux/rh_linux
> python shrink_bs_070226.py
>
> To avoid that you can have the python script invoke itself, e. g.:
>
> #!/usr/bin/env python
> import os
> if os.environ.get("YADDA") != "whatever":
> print "fix environment"
> os.environ["YADDA"] = "whatever"
> os.system("yadda.py")
> raise SystemExit
>
> print "YADDA is now %r" % os.environ["YADDA"]
> print "do your real stuff"
>
> Peter

Thanks for the reply.

If I that good understood I did this:
**
import sys, re, glob, shutil
import os


if os.environ["LD_LIBRARY_PATH"].count('/path/Linux/rh_linux') !=1:
   os.environ["LD_LIBRARY_PATH"]=os.environ["LD_LIBRARY_PATH"]+':'+'/
path/Linux/rh_linux'
   os.system("shrink_bs_070226.py")
   raise SystemExit

from qt import *
***

Is that correct. If yes then it not works. If not then, what's wrong?

> python shrink_bs_070226.py

Traceback (most recent call last):
  File "./shrink_bs_070226.py", line 29, in ?
from qt import *
ImportError: No module named qt

Thanks
Boris

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


Re: Is type object an instance or class?

2007-02-27 Thread Peter Otten
JH wrote:

> I found that a type/class are both a subclass and a instance of base
> type "object".
> 
> It conflicts to my understanding that:
> 
> 1.) a type/class object is created from class statement
> 2.) a instance is created by "calling" a class object.
> 
> A object should not be both a class and an instance at the same time.

A class should be an instance. Now what?
 
> Further I found out there is a special type call "type" that is a
> subclass of base type "object". All other types are instances of this
> type.  Even base type "object" is an instance of this special type.
> 
> What is role of this type "type" in object creation?  Could someone
> there straighten this concept a little?

The type of a class is called metaclass. The creation of a class is the same
as an instantiation of its metaclass. You can therefore write

class A(object):
answer = 42
 
as

A = type("A", (object,), dict(answer=42))

So now we know how to make a class from a metaclass, how can we make a
metaclass? The tailbiting answer is that a metaclass is a class, too.

Can you figure out the result of isinstance(type, type)?

Peter


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


Re: How can I disable a device in windows using python

2007-02-27 Thread Duncan Booth
"Phoe6" <[EMAIL PROTECTED]> wrote:

> Hi all,
> I am trying to disable the NIC card (and other cards) enabled in my
> machine to test diagnostics on that card.
> I am trying to disable it programmatic using python. I checked python
> wmi and i could not find ways to disable/enable, (listing is however,
> possible).
> 
> Where should I look for to enable/disable devices in python.
> 
Assuming you mean windows:

If you don't mind doing it by spawning an external program try 
downloading devcon.exe from Microsoft's website 
(http://support.microsoft.com/kb/311272).

Using devcon you can enumerate devices, enable or disable them and a 
variety of other things. For example, on my current machine I can 
disable or enable my wireless card with:

C:\>devcon find *DEV_4222*
PCI\VEN_8086&DEV_4222&SUBSYS_10418086&REV_02\4&214CFA8C&1&00E2: Intel(R) 
PRO/Wireless 3945ABG Network Connection
1 matching device(s) found.

C:\>devcon disable *DEV_4222*
PCI\VEN_8086&DEV_4222&SUBSYS_10418086&REV_02\4&214CFA8C&1&00E2: Disabled
1 device(s) disabled.

C:\>devcon enable *DEV_4222*
PCI\VEN_8086&DEV_4222&SUBSYS_10418086&REV_02\4&214CFA8C&1&00E2: Enabled
1 device(s) enabled.

The most tricky bit is finding the correct id in the first bit, just do 
a wildcard find command and look for something appropriate. The enable 
and disable are exactly the same as the equivalent commands from the 
network connections window or the device manager. Oh, and don't forget 
if you want to use the full id for a device you'll have to escape the & 
characters or quote the argument.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: ArcGIS and Python

2007-02-27 Thread martin . laloux
Try Esri

http://support.esri.com/index.cfm?fa=forums.gateway

or

http://geography.sdsu.edu/People/Pages/jankowski/public_html/web683/lectures683.htm

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


Re: NetUseAdd mystery

2007-02-27 Thread king kikapu
> You need to use level 2 info to pass the username.
> Level 1 is for the old-style share with its own password.
> Also, it should be 'username': instead of just 'user':.
>
>  hth
>Roger

Roger many-many thanks! That was it, i had to put "username" instead
of "user" and 2 instead of 1 at the calling...

Thanks again!

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


installing "pysqlite"

2007-02-27 Thread Nader Emami
I have installed "TurboGears" and I would install 'pysqlite' also. I am 
a user on a Linux machine. If I try to install the 'pysqlite' with 
'easy_install' tool I get the next error message. The error message is 
longer than what I send here.


% easy_install  pysqlite
Searching for pysqlite
Reading http://cheeseshop.python.org/pypi/pysqlite/
Reading http://pysqlite.org/
Reading http://cheeseshop.python.org/pypi/pysqlite/2.3.3
Best match: pysqlite 2.3.3
Downloading 
http://initd.org/pub/software/pysqlite/releases/2.3/2.3.3/pysqlite-2
.3.3.tar.gz
Processing pysqlite-2.3.3.tar.gz
Running pysqlite-2.3.3/setup.py -q bdist_egg --dist-dir 
/tmp/easy_install-71B-Y0
/pysqlite-2.3.3/egg-dist-tmp-Wj2VRc
warning: no files found matching 'doc/*.html'
In file included from src/module.c:24:
src/connection.h:33:21: sqlite3.h: No such file or directory
In file included from src/module.c:24:
src/connection.h:38: error: parse error before "sqlite3"


Could somebody tell me what I have to do to install 'pysqlite'?


With regards,
Nader
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Interactive os.environ vs. os.environ in script

2007-02-27 Thread Peter Otten
[EMAIL PROTECTED] wrote:

> On Feb 27, 9:31 am, Peter Otten <[EMAIL PROTECTED]> wrote:
>> [EMAIL PROTECTED] wrote:
>> > Is there another possibility of how to solve it just by adding some
>> > lines in script?
>>
>> I think you have to wrap your script in a shell script
>>
>> #!/bin/sh
>> export LD_LIBRARY_PATH=/path/Linux/rh_linux
>> python shrink_bs_070226.py
>>
>> To avoid that you can have the python script invoke itself, e. g.:
>>
>> #!/usr/bin/env python
>> import os
>> if os.environ.get("YADDA") != "whatever":
>> print "fix environment"
>> os.environ["YADDA"] = "whatever"
>> os.system("yadda.py")
>> raise SystemExit
>>
>> print "YADDA is now %r" % os.environ["YADDA"]
>> print "do your real stuff"
>>
>> Peter
> 
> Thanks for the reply.
> 
> If I that good understood I did this:
> **
> import sys, re, glob, shutil
> import os
> 
> 
> if os.environ["LD_LIBRARY_PATH"].count('/path/Linux/rh_linux') !=1:
>os.environ["LD_LIBRARY_PATH"]=os.environ["LD_LIBRARY_PATH"]+':'+'/
> path/Linux/rh_linux'
>os.system("shrink_bs_070226.py")
>raise SystemExit
> 
> from qt import *
> ***
> 
> Is that correct. If yes then it not works. If not then, what's wrong?

I don't know. You are not quoting the actual code you are using (from qt
import * is definitely not in line 29, and the #!/path/to/your/python is
missing). Do you have more than one python version installed? then you may
have to put

#!/usr/bin/python2.2

or similar in the first line of your script.

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


Re: JasperServer

2007-02-27 Thread copermine
On Feb 22, 8:22 pm, "batok" <[EMAIL PROTECTED]> wrote:
> JasperServeris a report engine ( java based ).  It has asoap
> interface.  Does anybody has usedJasperserverviaSoap?
>
> An example would be appreciated.

What do you need exactly?

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


Re: Working with C object of python object (pycairo,ctypes)

2007-02-27 Thread AngelBlaZe
Solved my own problem :-)
For future reference here is the solution:

class PycairoContext(Structure):
_fields_ = [("PyObject_HEAD", c_byte * object.__basicsize__),
("ctx", c_void_p),
("base", c_void_p)]


z = PycairoContext.from_address(id(ctx))
print z.ctx

where ctx is the python object
and PycairoContext is the C object of ctx


Full Code : ( simple rsvg / librsvg ctypes wrapper )
--
def WebColour(sCol):
#print sCol
ic = [int(sCol[i:i+2], 16)/255.0 for i in range(1, 7, 2)]
#print ic
return ic

from ctypes import *

l=CDLL('librsvg-2-2.dll')
g=CDLL('libgobject-2.0-0.dll')
print g.g_type_init()


import cairo

WIDTH, HEIGHT = 800, 800

# Setup Cairo
surface = cairo.ImageSurface(cairo.FORMAT_ARGB32, WIDTH, HEIGHT)
ctx = cairo.Context(surface)



error=''
handle1 = l.rsvg_handle_new_from_file('test.svg',error)
print error
print handle1

class PycairoContext(Structure):
_fields_ = [("PyObject_HEAD", c_byte * object.__basicsize__),
("ctx", c_void_p),
("base", c_void_p)]


z = PycairoContext.from_address(id(ctx))
print z.ctx

print '>>',l.rsvg_handle_render_cairo(handle1, z.ctx)


#add some cairo stuff on top
bg = WebColour('#FF')
ctx.set_source_rgb(bg[0],bg[1],bg[2])
# Set thickness of brush
ctx.set_line_width(15)

# Draw out the triangle using absolute coordinates
ctx.move_to(200, 100)
ctx.line_to(300, 300)
ctx.rel_line_to(-200, 0)
ctx.close_path()

# Apply the ink
ctx.stroke()

surface.write_to_png("test.png")

--



AngelBlaZe wrote:
> Can you access the c object of a python object directly? Can this be
> done in ctypes or directly throught python functions without reverting
> to forking the python module?
>
> scanario:
> I have pyctx object that i get in python like this:
>
> pyctx = cairo.Context(surface)
>
> defined in the python extension this:
>
> typedef struct {
> PyObject_HEAD
> cairo_t *ctx;
> PyObject *base; /* base object used to create context, or NULL */
> } PycairoContext;
>
> PyObject *
> PycairoContext_FromContext(cairo_t *ctx, PyTypeObject *type, PyObject
> *base)
> {
> PyObject *o;
>
> assert (ctx != NULL);
>
> if (Pycairo_Check_Status (cairo_status (ctx))) {
>   cairo_destroy (ctx);
>   return NULL;
> }
>
> if (type == NULL)
> type = &PycairoContext_Type;
> o = PycairoContext_Type.tp_alloc (type, 0);
> if (o) {
>   ((PycairoContext *)o)->ctx = ctx;
>   Py_XINCREF(base);
>   ((PycairoContext *)o)->base = base;
> } else {
>   cairo_destroy (ctx);
> }
> return o;
> }
>
> Now my question is:
> Is there any way to access/get a pointer to PycairoContext->ctx from
> python object (pyctx)?
>
> A long shot i know :-)

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


Re: Interactive os.environ vs. os.environ in script

2007-02-27 Thread boris . smirnov
On Feb 27, 10:33 am, Peter Otten <[EMAIL PROTECTED]> wrote:
> [EMAIL PROTECTED] wrote:
> > On Feb 27, 9:31 am, Peter Otten <[EMAIL PROTECTED]> wrote:
> >> [EMAIL PROTECTED] wrote:
> >> > Is there another possibility of how to solve it just by adding some
> >> > lines in script?
>
> >> I think you have to wrap your script in a shell script
>
> >> #!/bin/sh
> >> export LD_LIBRARY_PATH=/path/Linux/rh_linux
> >> python shrink_bs_070226.py
>
> >> To avoid that you can have the python script invoke itself, e. g.:
>
> >> #!/usr/bin/env python
> >> import os
> >> if os.environ.get("YADDA") != "whatever":
> >> print "fix environment"
> >> os.environ["YADDA"] = "whatever"
> >> os.system("yadda.py")
> >> raise SystemExit
>
> >> print "YADDA is now %r" % os.environ["YADDA"]
> >> print "do your real stuff"
>
> >> Peter
>
> > Thanks for the reply.
>
> > If I that good understood I did this:
> > **
> > import sys, re, glob, shutil
> > import os
>
> > if os.environ["LD_LIBRARY_PATH"].count('/path/Linux/rh_linux') !=1:
> >os.environ["LD_LIBRARY_PATH"]=os.environ["LD_LIBRARY_PATH"]+':'+'/
> > path/Linux/rh_linux'
> >os.system("shrink_bs_070226.py")
> >raise SystemExit
>
> > from qt import *
> > ***
>
> > Is that correct. If yes then it not works. If not then, what's wrong?
>
> I don't know. You are not quoting the actual code you are using (from qt
> import * is definitely not in line 29, and the #!/path/to/your/python is
> missing). Do you have more than one python version installed? then you may
> have to put
>
> #!/usr/bin/python2.2
>
> or similar in the first line of your script.
>
> Peter- Hide quoted text -
>
> - Show quoted text -

Probably I understood it not correctly. What did you mean was to put
that code into my python script "shrink_bs_070226.py" and then calls
script itself?

So I took my script "shrink_bs_070226.py" and it starts with:
**
#!/usr/bin/env python
import sys, re, glob, shutil
import os

then I put your code in that script

if os.environ["LD_LIBRARY_PATH"].count('/path/Linux/rh_linux') !=1:
   os.environ["LD_LIBRARY_PATH"]=os.environ["LD_LIBRARY_PATH"]+':'+'/
path/Linux/rh_linux'
   os.system("shrink_bs_070226.py")
   raise SystemExit

and here continues my script:

from qt import *

.
***

Is it correct?

BTW: On lines 3:18 I have comments, script description and
modifications, therefore is "from qt import *" on the line 29



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


gtk.mainquit is deprecated

2007-02-27 Thread awalter1
Hello,
(environment : python 2.4.2, pyGTK, GTK+ 2.6.9 under HPUX 11.11: unix)
On the instruction self.window.destroy(), I get the following
message :
lookup.py:121: GtkDeprecationWarning: gtk.mainquit is deprecated, use
gtk.main_quit instead
self.window.destroy()
But I don't want to quit the application, I need only to close the
window.
My application includes others places where "self.window.destroy()"
instruction is used and the execution is done without warning.
Very strange.
Thank you for your help

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


Re: Interactive os.environ vs. os.environ in script

2007-02-27 Thread Peter Otten
[EMAIL PROTECTED] wrote:

> Probably I understood it not correctly. What did you mean was to put
> that code into my python script "shrink_bs_070226.py" and then calls
> script itself?

Yes.
 
> So I took my script "shrink_bs_070226.py" and it starts with:
> **
> #!/usr/bin/env python
> import sys, re, glob, shutil
> import os
> 
> then I put your code in that script
> 
> if os.environ["LD_LIBRARY_PATH"].count('/path/Linux/rh_linux') !=1:
>os.environ["LD_LIBRARY_PATH"]=os.environ["LD_LIBRARY_PATH"]+':'+'/
> path/Linux/rh_linux'
>os.system("shrink_bs_070226.py")
>raise SystemExit
> 
> and here continues my script:
> 
> from qt import *
> 
> .
> ***
> 
> Is it correct?

Yes.
 
> BTW: On lines 3:18 I have comments, script description and
> modifications, therefore is "from qt import *" on the line 29

The problem must be something else, then.

Peter

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


Re: Lists: Converting Double to Single

2007-02-27 Thread Duncan Booth
Dennis Lee Bieber <[EMAIL PROTECTED]> wrote:

>  Something like (pseudo-code):
> 
> 
> cnt = 0
> for rw in cursor():
>  if cnt:
>   for i,v in enumerate(rw):
>sum[i] += v  #accumulate next row
>  else:
>   sum = rw #initialize to first row
>  cnt += 1
> avg = [ float(v) / cnt for v in sum]
> 
>  Don't know if this is faster than numpy operations, but it
> definitely reduces the amount of memory consumed by that list of
> lists...

A lot of course depends on the input data, and the example given wasn't 
even syntactically valid so I can't tell if he started with integers or 
floats, but if the lists are long and the OP is at all worried about 
accuracy, this code may be a bad idea. Adding up a long list of values 
and then dividing by the number of values is the classic computer 
science example of how to get an inaccurate answer from a floating point 
calculation.

I wouldn't have mentioned it, but since the OP said numpy it might just 
be that he cares about the result. What I really don't understand though 
is why, if he wants the final result in NumPy, he doesn't just use it 
for the calculation?

>>> from numpy import array
>>> lst = [[1, 2, 3, 4, 5], [6, 7, 8, 9, 10]]
>>> array(lst).mean(axis=0)
array([ 3.5,  4.5,  5.5,  6.5,  7.5])

What I haven't tried to figure out is whether, having said all that, 
NumPy's mean is any more accurate than the naive sum and divide 
calculation? So far as I can tell, it isn't any more accurate although 
it does give different results.
-- 
http://mail.python.org/mailman/listinfo/python-list


HTML to dictionary

2007-02-27 Thread Tina I
Hi everyone,

I have a small, probably trivial even, problem. I have the following HTML:
> 
>  METAR:
> 
> ENBR 270920Z 0KT  FEW018 02/M01 Q1004 NOSIG
> 
> 
>  short-TAF:
> 
> ENBR 270800Z 270918 VRB05KT  FEW020 SCT040
> 
> 
>  long-TAF:
> 
> ENBR 271212 VRB05KT  FEW020 BKN030 TEMPO 2012 2000 SNRA VV010 BECMG 2124 
> 15012KT
> 

I need to make this into a dictionary like this:

dictionary = {"METAR:" : "ENBR 270920Z 0KT  FEW018 02/M01 Q1004 
NOSIG" , "short-TAF:" : "ENBR 270800Z 270918 VRB05KT  FEW020 SCT040" 
, "long-Taf:" : "ENBR 271212 VRB05KT  FEW020 BKN030 TEMPO 2012 2000 
SNRA VV010 BECMG 2124 15012KT"}

I have played around with BeautifulSoup but I'm stuck at stripping off 
the tags and chop it up to what I need to put in the dict. If someone 
can offer some hints or example to get me going I would greatly 
appreciate it.

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


Re: HTML to dictionary

2007-02-27 Thread Tina I
Tina I wrote:
> Hi everyone,
> 
> I have a small, probably trivial even, problem. I have the following HTML:
>> 
>>  METAR:
>> 
>> ENBR 270920Z 0KT  FEW018 02/M01 Q1004 NOSIG
>> 
>> 
>>  short-TAF:
>> 
>> ENBR 270800Z 270918 VRB05KT  FEW020 SCT040
>> 
>> 
>>  long-TAF:
>> 
>> ENBR 271212 VRB05KT  FEW020 BKN030 TEMPO 2012 2000 SNRA VV010 
>> BECMG 2124 15012KT
>> 
> 
> I need to make this into a dictionary like this:
> 
> dictionary = {"METAR:" : "ENBR 270920Z 0KT  FEW018 02/M01 Q1004 
> NOSIG" , "short-TAF:" : "ENBR 270800Z 270918 VRB05KT  FEW020 SCT040" 
> , "long-Taf:" : "ENBR 271212 VRB05KT  FEW020 BKN030 TEMPO 2012 2000 
> SNRA VV010 BECMG 2124 15012KT"}
> 
> I have played around with BeautifulSoup but I'm stuck at stripping off 
> the tags and chop it up to what I need to put in the dict. If someone 
> can offer some hints or example to get me going I would greatly 
> appreciate it.
> 
> Thanks!
> Tina
Forgot to mention that the "METAR:", "short-TAF", and "long-TAF" is 
always named as such wheras the line of data ("ENBR 271212 VRB05KT  
FEW020 BKN030 TEMPO 2012 2000 SNRA VV010 ") is dynamic and can be 
anything...

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


spawnl and waitpid

2007-02-27 Thread naima . mans
hello,

I run a python cgi script under Apache...

and while the script is running i want to display a "please wait"
message until the script finish.

I have tried to do this but the "please wait" message appears at the
script end (which is useless at this time! )

here my script:

def get_ret(status):
signal = status & 0xff
if signal == 0:
retcode = status >> 8
else:
retcode = 0
return signal,retcode

pidActuel =  os.spawnl(os.P_NOWAIT,"c:\\python25\
\python.exe","python","Main.py")

if (  get_ret(os.waitpid(pidActuel,0))[1] == 0  ):
 print """ END"""
else:
print """ please wait... """

-

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


Re: spawnl and waitpid

2007-02-27 Thread naima . mans

i forgot ...
thanks for any help :)

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


Re: Pep 3105: the end of print?

2007-02-27 Thread Christophe
Martin v. Löwis a écrit :
> Neil Cerutti schrieb:
>> On 2007-02-23, I V <[EMAIL PROTECTED]> wrote:
>>> While that's true, C++ compiler vendors, for example, take
>>> backwards compatibility significantly less seriously, it seems
>>> to me. 
>> Compiler vendors usually take care of their customers with
>> compiler switches that enable backwards compatibility.
> 
> That's a bold statement, after I V already gave two examples
> (g++ and MSVC 2005) of compilers that broke backwards compatibility
> without providing compiler switches to bring it back. These two
> aren't "minor" compilers.

In C++ land, people are expected to fix their code and not use broken 
compilers in such situations.

They have some kind of moral high ground because they do not break 
compatibility just for that but to be more standards compliant. And the 
fact that all the C++ code I've written with g++ recently compiled 
perfectly on Visual 2005 without a single change ( except fixing new 
warnings ) shows that standard compliance in C++ compilers is a good 
thing to have. That same code had some major and very annoying breakage 
with Visual 6. The fix? Updating that outdated compiler.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: spawnl and waitpid

2007-02-27 Thread Thinker
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

[EMAIL PROTECTED] wrote:
> hello,
>
> I run a python cgi script under Apache...
>
> and while the script is running i want to display a "please wait"
> message until the script finish.
>
> I have tried to do this but the "please wait" message appears at
> the script end (which is useless at this time! )
>
You should flush sys.stdout after you print messages, or
the message will keep in buffer untill buffer is full or process
terminated.


- --
Thinker Li - [EMAIL PROTECTED] [EMAIL PROTECTED]
http://heaven.branda.to/~thinker/GinGin_CGI.py
-BEGIN PGP SIGNATURE-
Version: GnuPG v1.4.6 (FreeBSD)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFF5Afi1LDUVnWfY8gRAgaoAJ9fccAjo00QupE7SRFqgbmOUGZMugCgjvdH
cFoxm+jiZiIpKOfd+fHCt/M=
=9COv
-END PGP SIGNATURE-

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

QPaintDevice: Must construct a QApplication before a QPaintDevice

2007-02-27 Thread boris . smirnov
Hi all,

I have a python script that works without any problem on Windows but
with error:

QPaintDevice: Must construct a QApplication before a QPaintDevice

on Linux.

Where could be the problem?

Thanks.
Boris

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


Re: JasperServer

2007-02-27 Thread Paul Boddie
On 27 Feb, 10:35, "copermine" <[EMAIL PROTECTED]> wrote:
> On Feb 22, 8:22 pm, "batok" <[EMAIL PROTECTED]> wrote:
>
> > JasperServeris a report engine ( java based ).  It has asoap
> > interface.  Does anybody has usedJasperserverviaSoap?
>
> > An example would be appreciated.
>
> What do you need exactly?

I guess the inquirer is looking for some recommendations for a Python
SOAP library that can communicate successfully with JasperServer. I'd
certainly be interested in hearing people's SOAP library
recommendations (for both clients and servers), and it would be even
nicer if someone wrote those recommendations up on the Python Wiki:

http://wiki.python.org/moin/WebServices

Paul

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


Re: QPaintDevice: Must construct a QApplication before a QPaintDevice

2007-02-27 Thread Diez B. Roggisch
[EMAIL PROTECTED] wrote:

> Hi all,
> 
> I have a python script that works without any problem on Windows but
> with error:
> 
> QPaintDevice: Must construct a QApplication before a QPaintDevice
> 
> on Linux.
> 
> Where could be the problem?

This is the problem:

You Must construct a QApplication before a QPaintDevice

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


Re: spawnl and waitpid

2007-02-27 Thread naima . mans
On 27 fév, 11:28, Thinker <[EMAIL PROTECTED]> wrote:
> -BEGIN PGP SIGNED MESSAGE-
> Hash: SHA1
>
> [EMAIL PROTECTED] wrote:
> > hello,
>
> > I run a python cgi script under Apache...
>
> > and while the script is running i want to display a "please wait"
> > message until the script finish.
>
> > I have tried to do this but the "please wait" message appears at
> > the script end (which is useless at this time! )
>
> You should flush sys.stdout after you print messages, or
> the message will keep in buffer untill buffer is full or process
> terminated.
>
> - --
> Thinker Li - [EMAIL PROTECTED] [EMAIL 
> PROTECTED]://heaven.branda.to/~thinker/GinGin_CGI.py
> -BEGIN PGP SIGNATURE-
> Version: GnuPG v1.4.6 (FreeBSD)
> Comment: Using GnuPG with Mozilla -http://enigmail.mozdev.org
>
> iD8DBQFF5Afi1LDUVnWfY8gRAgaoAJ9fccAjo00QupE7SRFqgbmOUGZMugCgjvdH
> cFoxm+jiZiIpKOfd+fHCt/M=
> =9COv
> -END PGP SIGNATURE-

Hello

thanks for answering
i have flush like this but same result .. the server wait until the
end...

pid =  os.spawnl(os.P_NOWAIT,"c:\\python25\
\python.exe","python","Main.py")
sys.stdout.flush()
ret = os.waitpid(pid,0)

if (  ret[1] != 0):
print """ wait %i """ %ret[1]
sys.stdout.flush()
else:
print """ end %i """ %ret[1]
sys.stdout.flush()


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


Re: QPaintDevice: Must construct a QApplication before a QPaintDevice

2007-02-27 Thread boris . smirnov
On Feb 27, 11:46 am, "Diez B. Roggisch" <[EMAIL PROTECTED]> wrote:
> [EMAIL PROTECTED] wrote:
> > Hi all,
>
> > I have a python script that works without any problem on Windows but
> > with error:
>
> > QPaintDevice: Must construct a QApplication before a QPaintDevice
>
> > on Linux.
>
> > Where could be the problem?
>
> This is the problem:
>
> You Must construct a QApplication before a QPaintDevice
>
> Diez

Yes that I can deduce, but why I'm asking is why it's different on
Windows and Linux. Should it not be platform independent?

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


Re: Preallocate? -- potentially brain dead question about performance

2007-02-27 Thread bearophileHUGS
Jan Danielsson:
>...completely avoiding the design issue I raised altogether. Thanks!
> Exactly what I was hoping for! :-)

Another common way to do it, it may be a little slower because that
n,txt is a tuple:

items = set(int(n) for n,txt in mylist)

Bye,
bearophile

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


Re: QPaintDevice: Must construct a QApplication before a QPaintDevice

2007-02-27 Thread Diez B. Roggisch
> 
> Yes that I can deduce, but why I'm asking is why it's different on
> Windows and Linux. Should it not be platform independent?

It should be. I've got no idea why it seems to work on windows but I can say
one thing for sure: that would be an artifact that you shouldn't rely on.
In Qt, you _always_ need a QApplication for anything. So just do as it
requires you to do: first, construct a QApplication. Then things will work.

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


Re: QPaintDevice: Must construct a QApplication before a QPaintDevice

2007-02-27 Thread boris . smirnov
On Feb 27, 11:56 am, "Diez B. Roggisch" <[EMAIL PROTECTED]> wrote:
> > Yes that I can deduce, but why I'm asking is why it's different on
> > Windows and Linux. Should it not be platform independent?
>
> It should be. I've got no idea why it seems to work on windows but I can say
> one thing for sure: that would be an artifact that you shouldn't rely on.
> In Qt, you _always_ need a QApplication for anything. So just do as it
> requires you to do: first, construct a QApplication. Then things will work.
>
> Diez

Hmm, as I see the code, I do construct QApplication as first

if __name__ == '__main__':
  a = QApplication (sys.argv)
  mywidget = Optimizer()
  a.setMainWidget (mywidget)
  mywidget.show()
  Update_StatusLine(mywidget)
  mywidget.setStartconfig()
  a.exec_loop ()

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


Re: gmpy moving to code.google.com

2007-02-27 Thread Daniel Nogradi
Hi Alex,

I did another test, this time with python 2.4 on suse and things are
worse than in the previous case (which was python 2.5 on fedora 3),
ouput of 'python gmp_test.py' follows:


Unit tests for gmpy 1.02 release candidate
on Python 2.4 (#1, Mar 22 2005, 21:42:42)
[GCC 3.3.5 20050117 (prerelease) (SUSE Linux)]
Testing gmpy 1.02 (GMP 4.1.3), default caching (20, 20, -2..11)
gmpy_test_cvr 270 tests, 0 failures
gmpy_test_rnd  26 tests, 0 failures
gmpy_test_mpf 155 tests, 0 failures
gmpy_test_mpq 264 tests, 0 failures
gmpy_test_mpz 376 tests, 0 failures
**
File "/home/nogradi/tmp/gmpy/test/gmpy_test_dec.py", line ?, in
gmpy_test_dec.__test__.elemop
Failed example:
print f+d
Exception raised:
Traceback (most recent call last):
  File "/usr/lib/python2.4/doctest.py", line 1243, in __run
compileflags, 1) in test.globs
  File "", line 1, in ?
print f+d
  File "/usr/lib/python2.4/decimal.py", line 906, in __add__
other = _convert_other(other)
  File "/usr/lib/python2.4/decimal.py", line 2863, in _convert_other
raise TypeError, "You can interact Decimal only with int, long
or Decimal data types."
TypeError: You can interact Decimal only with int, long or Decimal
data types.
**
File "/home/nogradi/tmp/gmpy/test/gmpy_test_dec.py", line ?, in
gmpy_test_dec.__test__.elemop
Failed example:
print d+f
Exception raised:
Traceback (most recent call last):
  File "/usr/lib/python2.4/doctest.py", line 1243, in __run
compileflags, 1) in test.globs
  File "", line 1, in ?
print d+f
  File "/usr/lib/python2.4/decimal.py", line 906, in __add__
other = _convert_other(other)
  File "/usr/lib/python2.4/decimal.py", line 2863, in _convert_other
raise TypeError, "You can interact Decimal only with int, long
or Decimal data types."
TypeError: You can interact Decimal only with int, long or Decimal
data types.
**
File "/home/nogradi/tmp/gmpy/test/gmpy_test_dec.py", line ?, in
gmpy_test_dec.__test__.elemop
Failed example:
print q+d
Exception raised:
Traceback (most recent call last):
  File "/usr/lib/python2.4/doctest.py", line 1243, in __run
compileflags, 1) in test.globs
  File "", line 1, in ?
print q+d
  File "/usr/lib/python2.4/decimal.py", line 906, in __add__
other = _convert_other(other)
  File "/usr/lib/python2.4/decimal.py", line 2863, in _convert_other
raise TypeError, "You can interact Decimal only with int, long
or Decimal data types."
TypeError: You can interact Decimal only with int, long or Decimal
data types.
**
File "/home/nogradi/tmp/gmpy/test/gmpy_test_dec.py", line ?, in
gmpy_test_dec.__test__.elemop
Failed example:
print d+q
Exception raised:
Traceback (most recent call last):
  File "/usr/lib/python2.4/doctest.py", line 1243, in __run
compileflags, 1) in test.globs
  File "", line 1, in ?
print d+q
  File "/usr/lib/python2.4/decimal.py", line 906, in __add__
other = _convert_other(other)
  File "/usr/lib/python2.4/decimal.py", line 2863, in _convert_other
raise TypeError, "You can interact Decimal only with int, long
or Decimal data types."
TypeError: You can interact Decimal only with int, long or Decimal
data types.
**
File "/home/nogradi/tmp/gmpy/test/gmpy_test_dec.py", line ?, in
gmpy_test_dec.__test__.elemop
Failed example:
print z+d
Exception raised:
Traceback (most recent call last):
  File "/usr/lib/python2.4/doctest.py", line 1243, in __run
compileflags, 1) in test.globs
  File "", line 1, in ?
print z+d
  File "/usr/lib/python2.4/decimal.py", line 906, in __add__
other = _convert_other(other)
  File "/usr/lib/python2.4/decimal.py", line 2863, in _convert_other
raise TypeError, "You can interact Decimal only with int, long
or Decimal data types."
TypeError: You can interact Decimal only with int, long or Decimal
data types.
**
File "/home/nogradi/tmp/gmpy/test/gmpy_test_dec.py", line ?, in
gmpy_test_dec.__test__.elemop
Failed example:
print d+z
Exception raised:
Traceback (most recent call last):
  File "/usr/lib/python2.4/doctest.py", line 1243, in __run
compileflags, 1) in test.globs
  File "", line 1, in ?
print d+z
  File "/usr/lib/python2.4/decimal.py", line 906, in __add__
other = _convert_other(other)
  File "/usr/lib/python2.4/decimal.py", line 2863, in _convert_other
raise TypeError, "You can interact Decimal only with int, long
or Decim

Re: newbie question(file-delete trailing comma)

2007-02-27 Thread kavitha thankaian
i get an error when i try to delete in file and rename it as out file,,the 
error says
  "permission denied".
   
  actually i need something like following:
   
  in_file = open('in.txt','w')
for line in in_file:
line.strip().strip(',')
   
  but when i run the above code,i get an error"bad file descriptor"
   
  thanks,,
   
  kavitha
   
  

Mohammad Tayseer <[EMAIL PROTECTED]> wrote:
  kavitha thankaian <[EMAIL PROTECTED]> wrote:
> and i need the output also in the same input.txt

just add

import os
os.remove('in.txt')
os.rename('out.txt', 'in.txt')

-
  Don't be flakey. Get Yahoo! Mail for Mobile and 
always stay connected to friends.-- 
http://mail.python.org/mailman/listinfo/python-list


-
 Here’s a new way to find what you're looking for - Yahoo! Answers -- 
http://mail.python.org/mailman/listinfo/python-list

Re: HTML to dictionary

2007-02-27 Thread bearophileHUGS
Tina I:
> I have a small, probably trivial even, problem. I have the following HTML:

This is a little data munging problem.
If it's a one-shot problem, then you can just load it with a browser,
copy and paste it as text, and then process the lines of the text in a
simple way (splitting lines according to ":", and using the stripped
pairs to feed a dict).

If there are more Html files, or you want to automate things more, you
can use html2text:
http://www.aaronsw.com/2002/html2text/

A little script like this may help you:

from html2text import html2text
txt = html2text(the_html_data)
lines = str(txt).replace("**", "").strip().splitlines()
fields = [[field.strip() for field in line.split(":")] for line in
lines]
print dict(fields)

Note that splitlines() is tricky, if you find some problems, then you
may want a smarter splitter.

Bye,
bearophile

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


Re: HTML to dictionary

2007-02-27 Thread WEINHANDL Herbert
Tina I schrieb:
> Hi everyone,
> 
> I have a small, probably trivial even, problem. I have the following HTML:
>> 
>>  METAR:
>> 
>> ENBR 270920Z 0KT  FEW018 02/M01 Q1004 NOSIG
>> 
...

BeautifulSoup is really fun to work with ;-)

> I have played around with BeautifulSoup but I'm stuck at stripping off 
> the tags and chop it up to what I need to put in the dict. If someone 
> can offer some hints or example to get me going I would greatly 
> appreciate it.
> 
> Thanks!
> Tina

#!/usr/bin/python
# -*- coding: utf-8 -*-

from   BeautifulSoup import BeautifulSoup, Tag, NavigableString

html = """ Title 

 METAR: ENBR 270920Z 0KT  ... 
 short-TAF: ENBR 270800Z 270918 VRB05KT ... 
 long-TAF:  ENBR 271212 VRB05KT   ... 


"""

soup  = BeautifulSoup( html, convertEntities='html' )
bolds = soup.findAll( 'b' )

dict = {}

for b in bolds :
 key = b.next.strip()
 val = b.next.next.strip()
 print 'key=', key
 print 'val=', val, '\n'
 dict[key] = val

print dict

# end 


happy pythoning

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


[Job Posting] EXCITING OPPORTUNITY FOR EXPERIENCED PYTHON DEVELOPER

2007-02-27 Thread Azri Careers
Azri Solutions Pvt Limited ( http://www.azri.biz) provides a
challenging work environment, an open work culture & competitive
remuneration : the right ingredients to facilitate superlative
performance.Vacancies for Experienced PYTHON DEVELOPER are currently
open. Azri is an extremely flexible & sustainable networked enterprise
with presence in Germany, the U.S.A. & India. Our team has intense
hands-on experience in designing, deploying and managing high-volume
Service-Oriented Architectures (SOA) including RDBMS-backed
Webservices. In most cases, we leverage tried and tested open-source
software.

Join our highly motivated and dedicated team to embark upon a
challenging and rewarding career where you get to make decisions,
create great products and in the process, have some fun! We believe in
the concept of continuous learning, taking on responsibilities and
providing growth opportunities for every team member. Our environment
encourages innovation. Ideas are welcome and every individual is
empowered to think, share and take ownership of their ideas and
creations.

MAIL YOUR RESUME TO [EMAIL PROTECTED]

General :
·   Should have developed applications using Open Source systems.
·   Scripting : TCL, PHP, Perl, Python(Mandatory), Ruby.
·   Languages : C, C++ development experience is an added advantage.
·   OS : Linux / Unix, Windows. (Must have Linux / Unix experience).
·   Frameworks : Should have used Open Source languages like PHP / Perl/
Ruby / TCL and frameworks like Drupal / Mojave / Rails / OpenACS.
Job Location : Hyderabad

Candidate Profile :
·   Should enjoy programming.
·   Experience : One to four years' programming experience.
·   Knowledge of Linux, Shell scripting, Web application development,
Quality software development.
·   Excellent conceptual, analytical and programming skills.
·   Should have Application Design experience.
·   Familiarity with Open Source Application Development.
·   Familiarity with Open Source Web Application Frameworks.
·   Participation in open source communities is an added advantage.

SOFTSKILLS :

Good communication and interpersonal skills.


LOCATION : HYDERABAD

MAIL YOUR RESUME TO [EMAIL PROTECTED]

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


Re: spawnl and waitpid

2007-02-27 Thread Thinker
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

[EMAIL PROTECTED] wrote:
> On 27 f憝, 11:28, Thinker <[EMAIL PROTECTED]> wrote:
> [EMAIL PROTECTED] wrote:
 hello, I run a python cgi script under Apache... and while
 the script is running i want to display a "please wait"
 message until the script finish. I have tried to do this but
 the "please wait" message appears at the script end (which is
 useless at this time! )
> You should flush sys.stdout after you print messages, or the
> message will keep in buffer untill buffer is full or process
> terminated.
>

> Hello

> thanks for answering i have flush like this but same result .. the
> server wait until the end...

> pid = os.spawnl(os.P_NOWAIT,"c:\\python25\
> \python.exe","python","Main.py") sys.stdout.flush() ret =
> os.waitpid(pid,0)
Your program will be blocked here until child process being terminated.
You should print your messages before this line.

> if ( ret[1] != 0): print """ wait %i """ %ret[1]
> sys.stdout.flush() else: print """ end %i """ %ret[1]
> sys.stdout.flush()




- --
Thinker Li - [EMAIL PROTECTED] [EMAIL PROTECTED]
http://heaven.branda.to/~thinker/GinGin_CGI.py
-BEGIN PGP SIGNATURE-
Version: GnuPG v1.4.6 (FreeBSD)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFF5BWS1LDUVnWfY8gRAkp8AKCAcTKi/MO6sfkGBBEcMjfpH42O1wCeN14I
0AZ83oVacK0hKik4YC/jfCA=
=3h7d
-END PGP SIGNATURE-

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

Re: HTML to dictionary

2007-02-27 Thread Paul Boddie
On 27 Feb, 11:08, Tina I <[EMAIL PROTECTED]> wrote:
>
> I have a small, probably trivial even, problem. I have the following HTML:
>> 
>>  METAR:
>> 
>> ENBR 270920Z 0KT  FEW018 02/M01 Q1004 NOSIG
>> 
>> 
>>  short-TAF:
>> 
>> ENBR 270800Z 270918 VRB05KT  FEW020 SCT040
>> 
>> 
>>  long-TAF:
>> 
>> ENBR 271212 VRB05KT  FEW020 BKN030 TEMPO 2012 2000 SNRA VV010
>> BECMG 2124 15012KT
>> 

This looks almost like XHTML which means that you might be able to use
a normal XML parser.

> I need to make this into a dictionary like this:
>
> dictionary = {"METAR:" : "ENBR 270920Z 0KT  FEW018 02/M01 Q1004
> NOSIG" , "short-TAF:" : "ENBR 270800Z 270918 VRB05KT  FEW020 SCT040"
> , "long-Taf:" : "ENBR 271212 VRB05KT  FEW020 BKN030 TEMPO 2012 2000
> SNRA VV010 BECMG 2124 15012KT"}

So what you want to do is to find each "b" element, extract the
contents to produce a dictionary key, and then find all following text
nodes up to the "br" element, extracting the contents of those nodes
to produce the corresponding dictionary value.

Now, with a DOM/XPath library, the first part is quite
straightforward. Let's first parse the document, though:

import libxml2dom  # my favourite ;-)
d = libxml2dom.parse(the_file) # add html=1 if it's HTML

Now, let's get the "b" elements providing the keys:

key_elements = d.xpath("//b")

The above will find all "b" elements throughout the document. If
that's too broad a search, you can specify something more narrow. For
example:

key_elements = d.xpath("/html/body/b")

At this point, key_elements should contain a list of nodes, each
corresponding to a "b" element, and you can get the contents of each
element by asking for all the text nodes inside it and joining them
together, stripping the whitespace off each end to make the dictionary
key itself:

def get_key(key_element):
texts = []
# Get all text child nodes, collecting the contents.
for n in key_element.xpath("text()"):
texts.append(n.nodeValue)
# Join them together, removing leading/trailing space.
return "".join(texts).strip()

(Currently, libxml2dom lets you ask an element for its nodeValue,
erroneously returning text inside that element, but I don't want to
promote this as a solution since I may change it at some point.)

The process of getting the dictionary values is a bit more difficult.
What we need to do is to ask for the following siblings of the "b"
element, then to loop over them until we find a "br" element. The
dictionary value is then obtained from the discovered text fragments
by joining them together and stripping whitespace from the ends:

def get_value(key_element):
texts = []
# Loop over nodes following the element...
for n in key_element.xpath("following-sibling::node()"):
# Stop looping if we find a "br" element.
if n.nodeType == n.ELEMENT_NODE and n.localName == "br":
break
# Otherwise get the (assumed) text content.
texts.append(n.nodeValue)
# Join the texts and remove leading/trailing space.
return "".join(texts).strip()

So, putting this together, you should get something like this:

dictionary = {}
for key_element in key_elements:
dictionary[get_key(key_element)] = get_value(key_element)

As always with HTML processing, your mileage may vary with such an
approach, but I hope this is helpful. You should also be able to use
something like 4Suite or PyXML with the above code, albeit possibly
slightly modified.

Paul

P.S. Hopefully, Google Groups won't wrap the code badly. Whatever
happened to the preview option, Google?

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


Job Ad: Full-time Python software developer, Wimbledon, London, England

2007-02-27 Thread John J. Lee
`ReportLab `_ (Wimbledon, London, England)


**Job Description**: ReportLab develop enterprise reporting and
document generation solutions using cutting-edge Python technology,
and have a growing business with an excellent blue chip customer base.
You may also know us from our open source PDF and graphics library...

We are looking for a full-time Python software developer for immediate
start.

We are now developing a new generation of applications to publish PDF
on demand for specific vertical markets in the travel and financial
services industries using our own core products.  These involve
flexible admin interfaces to let customers enter and approve data
prior to publishing with our own PDF products.  We are making use of
the very latest and best ideas in web development to help create value
for our customers and a scalable business model for ourselves.

There will be opportunities for travel to exotic locations to visit
travel industry customers.

We're looking for a good all-rounder to join our team and work on
this, as well as many other projects.  The ideal candidate will either
be a **graduate or have up to 3 years experience** and will have the
following skills:

 - Python programming - or enough evidence of skill elsewhere to
   persuade us you can learn it quickly

 - Good analysis skills - the ability to listen to customers,
   figure out where the value lies, and help decide what to build
   in the first place

 - Understanding of web frameworks, databases, XML.  Django
   experience is a plus

 - Know CSS and HTML (an eye for visual design is a plus)

 - Know JavaScript beyond the usual form validation (AJAX a plus)

 - Have the common sense to know when coding is NOT the answer

You must have good written English, good aptitude for programming, and
an ability to Get Things Done.  You must be eligible to work in the
UK, and have a passport allowing travel to most world locations.
Driving license is also an advantage.

You will get responsibilities which are not possible in large
companies including a chance to work with the latest and best
technologies; to see substantial, cutting-edge projects from
commencement to delivery with world class clients; and to help design
and roll out entire software services with fantastic upside potential.

**What Python is used for**: Just about everything.

* **Contact**: Alisa Pasic
* **E-mail contact**: [EMAIL PROTECTED]
* **Web**: http://www.reportlab.com/careers.html


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


Re: QPaintDevice: Must construct a QApplication before a QPaintDevice

2007-02-27 Thread Diez B. Roggisch
[EMAIL PROTECTED] wrote:

> On Feb 27, 11:56 am, "Diez B. Roggisch" <[EMAIL PROTECTED]> wrote:
>> > Yes that I can deduce, but why I'm asking is why it's different on
>> > Windows and Linux. Should it not be platform independent?
>>
>> It should be. I've got no idea why it seems to work on windows but I can
>> say one thing for sure: that would be an artifact that you shouldn't rely
>> on. In Qt, you _always_ need a QApplication for anything. So just do as
>> it requires you to do: first, construct a QApplication. Then things will
>> work.
>>
>> Diez
> 
> Hmm, as I see the code, I do construct QApplication as first
> 
> if __name__ == '__main__':
>   a = QApplication (sys.argv)
>   mywidget = Optimizer()
>   a.setMainWidget (mywidget)
>   mywidget.show()
>   Update_StatusLine(mywidget)
>   mywidget.setStartconfig()
>   a.exec_loop ()

I don't see any QPaintDevice here. Where does that come from? You need to
give more information, a stack trace and a reduced example exhibiting the
behaviour.

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


Re: what the heck is going on here?

2007-02-27 Thread Peter Otten
[EMAIL PROTECTED] wrote:

> I found the following ways to generate permutations on the ASPN:
> Python Cookbook page.
> 
> SLOW (two defs):
> 
> def xcombinations(items,n):
> if n == 0: yield[]
> else:
> for  i in xrange(len(items)):
> for cc in xcombinations(items[:i]+items[i+1:],n-1):
> yield [items[i]]+cc
> 
> def xpermutations(items):
>   return xcombinations(items,len(items))
> 
> FAST:
> 
> def permutations(L):
> if len(L) <= 1:
> yield L
> else:
> a = [L.pop(0)]
> for p in permutations(L):
> for i in range(len(p)+1):
> yield p[:i] + a + p[i:]
> 
> The author of the FAST claimed his method was faster, which I wanted
> to test.  I ran the test as follows:
> 
> import time
> name = list('python')
> 
> faster = time.clock()
> for x in range(1):
> map(''.join,list(permutations(name)))
> total1 = time.clock() - faster
> print "Total time for faster: ", total1
> 
> xperm_start = time.clock()
> for x in range(1):
> map(''.join,list(xpermutations(name)))
> total2 = time.clock() - xperm_start
> print "Total time for xperm: ", total2
> 
> If you run these tests in the order above, FAST takes about a .1
> seconds and slow takes about .17 seconds.  BUT if you reverse the
> order of the test, SLOW takes almost 10 seconds and FAST is about the
> same!  What's more, if you take map, join and list out of the tests
> (there's no reason for them to be there anyway) the order doesn't
> matter any more.  Without map/join/list, SLOW and FAST are almost
> indistinguishable at 10K loops.  What's going on? ( This was done
> in Python2.4 )

permutations() modifies its argument. Try

items = ["a", "b", "c"]
for p in permutations(items): 
   pass
print items

to see why all measurements after the first pass of permutations() are
bogus. Then modify your code to have permutations() operate on copies of
the 'name' list.

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


Re: installing "pysqlite"

2007-02-27 Thread Paul Boddie
On 27 Feb, 10:31, Nader Emami <[EMAIL PROTECTED]> wrote:
> I have installed "TurboGears" and I would install 'pysqlite' also. I am
> a user on a Linux machine. If I try to install the 'pysqlite' with
> 'easy_install' tool I get the next error message. The error message is
> longer than what I send here.

[...]

> src/connection.h:33:21: sqlite3.h: No such file or directory

[...]

> Could somebody tell me what I have to do to install 'pysqlite'?

Install SQLite, perhaps? If the pysqlite build process can't find
sqlite3.h then you either don't have SQLite installed, or you don't
have the headers for SQLite installed. I'd recommend that you check
your installed packages for the SQLite libraries (eg. libsqlite3-0 on
Ubuntu) and/or the user interface (eg. sqlite3) and for the
development package (eg. libsqlite3-dev).

If you can't install the packages, install SQLite from source (see
http://www.sqlite.org/) and try and persuade pysqlite to use your own
SQLite installation - there's a setup.cfg file in the pysqlite
distribution which may need to be changed to achieve this, but I don't
know how that interacts with setuptools.

Paul

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


Re: Help on object scope?

2007-02-27 Thread bmaron2
On Feb 26, 1:16 pm, Dennis Lee Bieber <[EMAIL PROTECTED]> wrote:
> On Mon, 26 Feb 2007 07:54:12 +0200, "Hendrik van Rooyen"
> <[EMAIL PROTECTED]> declaimed the following in comp.lang.python:
>
>
>
> > from param import *
>
> "from <> import *" (or any "from <> import ..." variant) is NOT the
> best thing to use.
>
> Any rebinding to an imported name breaks the linkage to the import
> module.
>
> --
> WulfraedDennis Lee Bieber   KD6MOG
> [EMAIL PROTECTED] [EMAIL PROTECTED]
> HTTP://wlfraed.home.netcom.com/
> (Bestiaria Support Staff:   [EMAIL PROTECTED])
> HTTP://www.bestiaria.com/

Thank you all for the advice.

The suggestion Dennis made about using a 3rd, "common" module to hold
global names seemed to be the best idea. The only problem is now I
have to type common.r.t instead of just r.t. If I put common in the /
lib directory, it is even worse and I have to type lib.common.r.t. I
like that it is explicit and perhaps this is the Python way, but it is
annoying and produces ugly code to see all those fully-qualified names
when all I'd really like to use is r.t throughout the program.

Is there a way to import lib.common but then re-bind its attributes to
the local space without breaking the linkage?


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


Re: Python Source Code Beautifier

2007-02-27 Thread Neil Hodgson
Franz Steinhaeusler:

> Hello, I did not find any reasonable pyhton source code beautifier
> program (preferable gui).
> ...
> convert:
> ...
> from "is" to "==" and "is not" to "!=" (ok a find replace could do that
> easily also), but in a program that would be more comfortable.

   That's an unsafe conversion. I don't think it is possible for a
reasonable program to determine statically that "is" is equivalent to
"==" except for trivial pieces of code.

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


Re: Odd import behavior

2007-02-27 Thread Facundo Batista
Gregory Piñero wrote:

> I didn't realize Python behaved like this.  Is there an FAQ I can read on 
> this?

I'll explain step by step:


> FILE module1.py:
> VAR1='HI'
>
> FILE MAIN.py:
> from module1 import *
> import module1

Here you have, in your module scope, a name 'VAR1' that points to "HI"
and a name 'module1' that points to a module where you have a name
'VAR1' that points to "HI" (and that's why you have to use two names
"import.VAR1")


> print VAR1
> print module1.VAR1

This prints "HI" (VAR1 pointed to it), and "HI" (VAR1, inside module1,
pointed to it).


> VAR1='bye'

This rebinds the name "VAR1" in this module scope. Now it points to
"bye", not pointing anymore to the (still living) string "HI". Take note
that you're not changing the value in memory, you're pointing to another
place.


> print VAR1
> print module1.VAR1

This prints "bye" (VAR1 now is pointing to it), and "HI" (VAR1, inside
module1, still is pointing to it).


> It seems to use module1.VAR1 for VAR1 until I assign something to VAR1
> in which case they become seperate.

You do not assign something to VAR1, you rebind the name to point a new
object in memory.

For further detail in the explanation, you can check this very, *very*
good paper (it's small and fun):

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

Regards.

-- 
.   Facundo
.
Blog: http://www.taniquetil.com.ar/plog/
PyAr: http://www.python.org/ar/



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


Python, Embedded linux and web development

2007-02-27 Thread Tzury
Regarding the platform described below, can anyone suggest from his
experience what would be the best library choice to develop the
following application.

a) application that deals with data transformed via TCP sockets.
b) reading and writing to and from sqlite3 (include Unicode
manipulations).
c) small web application that will be used as front end to configure
the system (flat files and sqlite3 db are the back-end).

Our platform is base on the Intel PXA270 processor (XSCALE family,
which is ARM compatible) running at 312MHz.

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


Re: Bypassing __setattr__ for changing special attributes

2007-02-27 Thread Facundo Batista
Ziga Seilnacht wrote:


 object.__setattr__(f, '__class__', Bar)
 f.__class__ is Bar
> True

Interesting, but... why I must do this? And, I must *always* do this?

With Foo and Bar like the OP coded (just two new style classes, f is
instance of Foo), see this:

>>> f
<__main__.Foo object at 0xb7d1280c>
>>> setattr(f, '__class__', Bar)
>>> f
<__main__.Foo object at 0xb7d1280c>


Ok, didn't work, try your way:

>>> object.__setattr__(f, '__class__', Bar)
>>> f
<__main__.Bar object at 0xb7d1280c>


Wow! Ok, but getting back to Foo, with the *former* method:

>>> setattr(f, '__class__', Foo)
>>> f
<__main__.Foo object at 0xb7d1280c>


I can't explain this to myself, :(

Regards,

-- 
.   Facundo
.
Blog: http://www.taniquetil.com.ar/plog/
PyAr: http://www.python.org/ar/



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


Is there a technic to avoid this bug

2007-02-27 Thread hg
Hi,

In C/C++ I got used to  write an expression like so:

#define TEST 0

if (TEST == value) 
{

}

in order to avoid the usual bug:
if (value = TEST)
{

}

In a relatively similar domain, I spent a few hours find this bug:

value == self.Get_Value()
if value == WHATEVER:
   do this

instead of
value = self.Get_Value()
if value == WHATEVER:
   do this

Is there a way to avoid such a bug with some type of construct ?

Thanks,
hg


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


Re: Python, Embedded linux and web development

2007-02-27 Thread Paul Boddie
On 27 Feb, 13:12, "Tzury" <[EMAIL PROTECTED]> wrote:
>
> c) small web application that will be used as front end to configure
> the system (flat files and sqlite3 db are the back-end).
>
> Our platform is base on the Intel PXA270 processor (XSCALE family,
> which is ARM compatible) running at 312MHz.

You might want to read this article which got mentioned fairly
recently either on comp.lang.python or on some blog or other:

http://www.linuxdevices.com/articles/AT5550934609.html

Paul

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


Curses sorely lacking an event loop?

2007-02-27 Thread James Stroud
Hello,

Is curses really lacking an event loop? Do I have to write my own? I 
infer from the docs that this is the case. For example, I want the 
screen to be updated with resize but I find myself waiting for getch() 
if I want user input, and so the screen must remain ugly until the user 
presses a key. What am I missing?

Also, does anyone have boilerplate for handling mouse events? getmouse() 
returns an "ERR" of no particular description and also appears to 
require a preceding getch() and hence does not seem to be wired at all 
for clicks, although allusion to clicks is found in the descriptions for 
mouseinterval() and mousemask().

Here is the error message for getmouse() in case anyone wants details: 
"_curses.error: getmouse() returned ERR". This is much less informative 
than one might hope.

Thanks in advance for any help.

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


Re: ANN: PyDSTool now compatible with numpy 1.0.1, scipy 0.5.2 and 64-bit CPUs.

2007-02-27 Thread [EMAIL PROTECTED]
On Feb 20, 4:16 pm, Stef Mientki <[EMAIL PROTECTED]>
wrote:
> Sounds GREAT !
> thank you !
> I just took a quick look,
> the comparison to SimuLink looks good,
> now if someone could make a comparison with Modelica;-)
>
> cheers,
> Stef Mientki

As far as I can tell, PyDSTool provides some basic symbolic math
capabilities sufficient to formulate systems of equations that can
then be simulated.  The symbolic capability seems to be mainly to
allow for analytical Jacobian calculation (presumably for backward
differentiation algorithms, etc).  Someone feel free to correct me if
I'm wrong.

This is all quite useful and it is implicitly included in Modelica but
may important aspects of Modelica are missing.  For example, Modelica
includes inheritance (to facilitate reuse), polymorphism (to
substitute one implementation of a component for another), a strong
types system (to ensure safety and robustness), a meta-data
infrastructure including standardized metadata for documentation and
graphical representation, connectors to define interactions between
components, an expansive standard library and support for numerous
modeling formalisms both continuous, discrete and mixed systems of
DAEs (e.g. block diagrams, acausal modeling, state charts, petri
nets, ...).

My sense is that perhaps PyDSTool is attempting to leverage some of
these aspects directly from Python (e.g. inheritance).  I am a fan of
both Python and Modelica but when it comes to the kind of modeling
work I do I prefer the more "static" approach to type checking that
Modelica uses (of course that is just a personal preference).

--
Mike

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


Re: finding out the precision of floats

2007-02-27 Thread Facundo Batista
Arnaud Delobelle wrote:


> (and I don't want the standard Decimal class :)

Why?


-- 
.   Facundo
.
Blog: http://www.taniquetil.com.ar/plog/
PyAr: http://www.python.org/ar/


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


Re: installing "pysqlite"

2007-02-27 Thread Nader
On Feb 27, 12:44 pm, "Paul Boddie" <[EMAIL PROTECTED]> wrote:
> On 27 Feb, 10:31, Nader Emami <[EMAIL PROTECTED]> wrote:
>
> > I have installed "TurboGears" and I would install 'pysqlite' also. I am
> > a user on a Linux machine. If I try to install the 'pysqlite' with
> > 'easy_install' tool I get the next error message. The error message is
> > longer than what I send here.
>
> [...]
>
> > src/connection.h:33:21: sqlite3.h: No such file or directory
>
> [...]
>
> > Could somebody tell me what I have to do to install 'pysqlite'?
>
> Install SQLite, perhaps? If the pysqlite build process can't find
> sqlite3.h then you either don't have SQLite installed, or you don't
> have the headers for SQLite installed. I'd recommend that you check
> your installed packages for the SQLite libraries (eg. libsqlite3-0 on
> Ubuntu) and/or the user interface (eg. sqlite3) and for the
> development package (eg. libsqlite3-dev).
>
> If you can't install the packages, install SQLite from source 
> (seehttp://www.sqlite.org/) and try and persuade pysqlite to use your own
> SQLite installation - there's a setup.cfg file in the pysqlite
> distribution which may need to be changed to achieve this, but I don't
> know how that interacts with setuptools.
>
> Paul

Thank for your reaction. I don't know also how the interaction sith
'easy_install' is. I think that I have to install 'pysqlite' from
source code also, because i can change ther the 'setup.cfg' file and I
can give there where the 'libsqlie3' is.

Nader

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


Re: Is there a technic to avoid this bug

2007-02-27 Thread Diez B. Roggisch
hg wrote:

> Hi,
> 
> In C/C++ I got used to  write an expression like so:
> 
> #define TEST 0
> 
> if (TEST == value)
> {
> 
> }
> 
> in order to avoid the usual bug:
> if (value = TEST)
> {
> 
> }
> 
> In a relatively similar domain, I spent a few hours find this bug:
> 
> value == self.Get_Value()
> if value == WHATEVER:
>do this
> 
> instead of
> value = self.Get_Value()
> if value == WHATEVER:
>do this
> 
> Is there a way to avoid such a bug with some type of construct ?

No. In a language inherent with sideeffects, there is nothing that should
force you to not write that.

However, it might be that either pychecker or pylint will give you a warning
for such statements.

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


Re: Is type object an instance or class?

2007-02-27 Thread René Fleschenberg
Hi

The article you read at
http://www.cafepy.com/article/python_types_and_objects is really good,
and the most comprehensive one I know about Python's object system. I
recommend that you read it as many times as you need to understand it.
It can be confusing -- just don't give up ;)

I will try to give some answers to your questions. Note that I assume we
are only speaking of new-style classes. Old-style classes are different,
but pretty uninteresting since there is little reason to use them in new
code.

Another note: As far as this stuff in Python is concerened, "type" and
"class" are, to my knowledge, basically just two different names for the
same thing.

JH schrieb:
> Hi
> http://www.cafepy.com/article/python_types_and_objects/
> I found that a type/class are both a subclass and a instance of base
> type "object".
> 
> It conflicts to my understanding that:
> 
> 1.) a type/class object is created from class statement
> 2.) a instance is created by "calling" a class object.

Why? I see no conflict here.

> A object should not be both a class and an instance at the same time.

It should.

1) Everything is an object.
2) Every object is an instance of a class.

>From this, it logically follows that every class should also be an
instance of a class. Classes are objects, and objects are instances of
classes.

> Further I found out there is a special type call "type" that is a
> subclass of base type "object". All other types are instances of this
> type.  Even base type "object" is an instance of this special type.
> 
> What is role of this type "type" in object creation?  Could someone
> there straighten this concept a little?

I) object' is the root of the inheritance hierarchy. All classes inherit
from 'object'. 'object' is its own baseclass. Also, all objects are
instances of 'object'.

II) 'type' is the root of the type hierarchy. All types (i.e. classes)
are subtypes of 'type'. 'type' is its own type.
Because 'type' also is, like everything else, an object, it is an
instance of 'object' (see I). Because it is a type object (a class), it
also is a subclass of 'object' (again, see I).

Objects are created by instantiating their class/type. Classes (also
called "type objects") are usually created by instantiating 'type'.

The object you instantiate to get a class is called that class'
"metaclass". One can just as well call it that class' type.

Unless you specify something else, the metaclass is 'type'. Sometimes it
can be useful to not use the default 'type' as a metaclass, but a class
that inherits from 'type'.

class A(type):
# Custom code here.
pass

class B(object):
__metaclass__ = A

type(B)# A. We overrode the metaclass.
type(type(B))  # 'type'. The default metaclass.


> For example (Python2.5):
> 
 issubclass(int, object)
> True

All classes are subclasses of 'object'. 'int' is a class, so it is a
subclass of 'object'.

 isinstance(int, object)
> True

All objects are instances of 'object', and 'int' is an object.

 print type(int)
> 

'type' is the default type for classes (the "metaclass"). In the case of
'int', that default was not changed.

 isinstance(int, type)
> True

Since all classes are subclasses of 'object' and 'object' is an instance
of 'type', all classes are instances of 'type'.

 issubclass(int, type)
> False

No reason why it should be. It could be, but it does not have to.

 issubclass(type, object)
> True

'type' is a class, all classes are subclasses of 'object'.

 isinstance(type, object)
> True

'type' is an object, all objects are instances of 'object'.

 isinstance(object, type)
> True

'object' is a class, all classes are instances of 'type'.


Hope this helps ;)

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


Re: newbie question(file-delete trailing comma)

2007-02-27 Thread Mikael Olofsson
kavitha thankaian wrote:
> i get an error when i try to delete in file and rename it as out 
> file,,the error says
> "permission denied".

Perhaps you should give us both the exact code you are running and the
complete traceback of the error. That could make things easier. There
can be numerous reasons for "permission denied".

> actually i need something like following:
>  
> in_file = open('in.txt','w')
> for line in in_file:
> line.strip().strip(',')
>  
> but when i run the above code,i get an error"bad file descriptor"

Of course you do! You are opening the file for writing, but your code
attempts to read the file. Probably, you think that the code would
change the lines in the file itself, which it does not, even if it would
be possible to read from a file opened for writing.

What's wrong with the code that Mohammad posted? Note that you might
need to close out_file in his code.

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


Re: Curses sorely lacking an event loop?

2007-02-27 Thread Michael Zawrotny
On Tue, 27 Feb 2007 12:27:17 GMT, James Stroud wrote:
> 
>  Is curses really lacking an event loop? Do I have to write my own? I 
>  infer from the docs that this is the case. For example, I want the 
>  screen to be updated with resize but I find myself waiting for getch() 
>  if I want user input, and so the screen must remain ugly until the user 
>  presses a key. What am I missing?

I'm not a curses expert, but I can answer this part.  When the screen
is resized, SIGWINCH is sent to the process.  You can use the normal
signal handling apparatus to install a handler that updates the screen
when that signal arrives.


Mike

-- 
Michael Zawrotny
Institute of Molecular Biophysics
Florida State University| email:  [EMAIL PROTECTED]
Tallahassee, FL 32306-4380  | phone:  (850) 644-0069
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Curses sorely lacking an event loop?

2007-02-27 Thread Michele Simionato
On Feb 27, 1:27 pm, James Stroud <[EMAIL PROTECTED]> wrote:
> Hello,
>
> Is curses really lacking an event loop? Do I have to write my own? I
> infer from the docs that this is the case. For example, I want the
> screen to be updated with resize but I find myself waiting for getch()
> if I want user input, and so the screen must remain ugly until the user
> presses a key. What am I missing?
>
> Also, does anyone have boilerplate for handling mouse events? getmouse()
> returns an "ERR" of no particular description and also appears to
> require a preceding getch() and hence does not seem to be wired at all
> for clicks, although allusion to clicks is found in the descriptions for
> mouseinterval() and mousemask().
>
> Here is the error message for getmouse() in case anyone wants details:
> "_curses.error: getmouse() returned ERR". This is much less informative
> than one might hope.
>
> Thanks in advance for any help.
>
> James

Did you check Urwid? http://excess.org/urwid

 Michele Simionato

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


Re: spawnl and waitpid

2007-02-27 Thread naima . mans
On 27 fév, 12:27, Thinker <[EMAIL PROTECTED]> wrote:
> -BEGIN PGP SIGNED MESSAGE-
> Hash: SHA1
>
>
>
>
>
> [EMAIL PROTECTED] wrote:
> > On 27 f憝, 11:28, Thinker <[EMAIL PROTECTED]> wrote:
> > [EMAIL PROTECTED] wrote:
>  hello, I run a python cgi script under Apache... and while
>  the script is running i want to display a "please wait"
>  message until the script finish. I have tried to do this but
>  the "please wait" message appears at the script end (which is
>  useless at this time! )
> > You should flush sys.stdout after you print messages, or the
> > message will keep in buffer untill buffer is full or process
> > terminated.
>
> > Hello
> > thanks for answering i have flush like this but same result .. the
> > server wait until the end...
> > pid = os.spawnl(os.P_NOWAIT,"c:\\python25\
> > \python.exe","python","Main.py") sys.stdout.flush() ret =
> > os.waitpid(pid,0)
>
> Your program will be blocked here until child process being terminated.
> You should print your messages before this line.
>
> > if ( ret[1] != 0): print """ wait %i """ %ret[1]
> > sys.stdout.flush() else: print """ end %i """ %ret[1]
> > sys.stdout.flush()
>
> - --
> Thinker Li - [EMAIL PROTECTED] [EMAIL 
> PROTECTED]://heaven.branda.to/~thinker/GinGin_CGI.py
> -BEGIN PGP SIGNATURE-
> Version: GnuPG v1.4.6 (FreeBSD)
> Comment: Using GnuPG with Mozilla -http://enigmail.mozdev.org
>
> iD8DBQFF5BWS1LDUVnWfY8gRAkp8AKCAcTKi/MO6sfkGBBEcMjfpH42O1wCeN14I
> 0AZ83oVacK0hKik4YC/jfCA=
> =3h7d
> -END PGP SIGNATURE-- Masquer le texte des messages précédents -
>
> - Afficher le texte des messages précédents -

thanks again

i have tried as you said (cf bellow) and same result...
is there any link which explain how a server Web read script and send
the answer ?

-
pid =  os.spawnl(os.P_NOWAIT,"c:\\python25\
\python.exe","python","Main.py")
ret = os.waitpid(pid,0)
print """please wait """
sys.stdout.flush()
   # retourne le process id
if (  ret[1] != 0):
print """ wait %i """ %ret[1]
sys.stdout.flush()
else:
 print """ end %i """ %ret[1]
 sys.stdout.flush()
---
thanks

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

Calling Python Web Services from C#

2007-02-27 Thread jvframework
I have a C# .NET cliente calling a Python web services. I pass two
string values to web service and I wanna receive a string from the
method.

But, the server side receive my string values and the client side only
display a empty string ("").

I generate a C# Proxy class from the python web services WSDL with
wsdl.exe tool.

Any idea about this problem?

Regards.

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


Re: Calling Python Web Services from C#

2007-02-27 Thread Diez B. Roggisch
[EMAIL PROTECTED] wrote:

> I have a C# .NET cliente calling a Python web services. I pass two
> string values to web service and I wanna receive a string from the
> method.
> 
> But, the server side receive my string values and the client side only
> display a empty string ("").
> 
> I generate a C# Proxy class from the python web services WSDL with
> wsdl.exe tool.
> 
> Any idea about this problem?

Not until you provide some more detail. Read this on how to do so properly:

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


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


pyHook or SetWindowsHookEx

2007-02-27 Thread abcd
I am having trouble with pyHook on python 2.4.1.  Basically I have a
python app that uses pyHook to capture keyboard events and write them
straight to a file.  The application is running as a service on a
windows machine.  If I am at that windows machine the application
works just fine, logging my keystrokes.  However, if I use Remote
Desktop to connect to the machine and open up say Notepad it doesn't
capture the keystrokes.  Is this a problem with pyHook?  or is it he
way Windows handles the events?

Is there a way to setup my own hook without pyHook using just python?
i think the function I am interested in is SetWindowsHookEx.

Thanks in advance.

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


Re: finding out the precision of floats

2007-02-27 Thread Bart Ogryczak
On Feb 27, 1:36 pm, Facundo Batista <[EMAIL PROTECTED]> wrote:
> Arnaud Delobelle wrote:
> > (and I don't want the standard Decimal class :)
>
> Why?

Why should you? It only gives you 28 significant digits, while 64-bit
float (as in 32-bit version of Python) gives you 53 significant
digits. Also note, that on x86 FPU uses 80-bit registers. An then
Decimal executes over 1500 times slower.

>>> from timeit import Timer
>>> t1 = Timer('(1.0/3.0)*3.0 - 1.0')
>>> t2 = Timer('(Decimal(1)/Decimal(3))*Decimal(3)-Decimal(1)',
'from decimal import Decimal')
>>> t2.timeit()/t1.timeit()
1621.7838879255889

If that's not enough to forget about Decimal, take a look at this:

>>> (Decimal(1)/Decimal(3))*Decimal(3) == Decimal(1)
False
>>> ((1.0/3.0)*3.0) == 1.0
True





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


os.system and quoted strings

2007-02-27 Thread svata
Hello,

as I'm new to python I've stumbled accros os.system and its not very
well documented usage.

I use Win XP Pro and Python 2.5.

Here is the code snippet:

--

import time
import os

dir = "C:\\Documents and Settings\\somepath\\"
fileName = time.strftime("%d%m%Y")
os.system('gvim dir+fileName+".txt"')

---

The problem is that concatenated variable dir+fileName doesn't get
expanded as expected.

Is there anything I omitted?

svata

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


Re: Jobs: Lisp and Python programmers wanted in the LA area

2007-02-27 Thread Wade Humeniuk
Tech HR wrote:
> In article <[EMAIL PROTECTED]>,
>  [EMAIL PROTECTED] wrote:
> 
>> On Feb 26, 6:32 am, Tech HR <[EMAIL PROTECTED]> wrote:
>>> Our
>>> website is currently a LAMP appication with P=Python. We are looking for
>>> bright motivated people who know or are willing to learn Python and/or
>>> Linux, Apache and MySQL system administration skills. (And if you want
>>> to convince us that we should switch over to Postgres, we're willing to
>>> listen.)
>> This is more out of curiosity, but does it mean that you wouldn't be
>> willing to listen about a switch from Python to Lisp?
> 
> No, it doesn't mean that.  In fact, there is a significant faction in 
> the technical staff (including the CTO) who would like nothing better 
> than to be able to use Lisp instead of Python.

Who is the CTO?

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


Re: Is there a technic to avoid this bug

2007-02-27 Thread Michele Simionato
On Feb 27, 1:49 pm, "Diez B. Roggisch" <[EMAIL PROTECTED]> wrote:
> However, it might be that either pychecker or pylint will give you a warning
> for such statements.

Yep, pychecker gives a warning "Statement appears to have no effect"

   Michele Simionato

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


Re: os.system and quoted strings

2007-02-27 Thread Sriram
Hello svata,
It is always better to compose your string before you send it as a
command.

try printing your command string out like this :
print 'gvim dir+fileName+".txt". You'll see what the problem is.

One possible solution is to compose your command string in the
following manner:
cmd = "gvim %s%s.txt" %(dir, fileName)
and simply call os.system with cmd.
os.system(cmd)

Here is a little more detail on string format specifiers
http://docs.python.org/lib/typesseq-strings.html

HTH
Sriram

On Feb 27, 7:24 am, "svata" <[EMAIL PROTECTED]> wrote:
> Hello,
>
> as I'm new to python I've stumbled accros os.system and its not very
> well documented usage.
>
> I use Win XP Pro and Python 2.5.
>
> Here is the code snippet:
>
> --
>
> import time
> import os
>
> dir = "C:\\Documents and Settings\\somepath\\"
> fileName = time.strftime("%d%m%Y")
> os.system('gvim dir+fileName+".txt"')
>
> ---
>
> The problem is that concatenated variable dir+fileName doesn't get
> expanded as expected.
>
> Is there anything I omitted?
>
> svata


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


Re: os.system and quoted strings

2007-02-27 Thread Sick Monkey

Do you mean:


import time, os
dir = "C:\\Documents and Settings\\somepath\\"
fileName = time.strftime("%d%m%Y")
finalname = "%s%s.txt" % (dir,fileName)
print finalname

C:\Documents and Settings\somepath\27022007.txt


On 27 Feb 2007 06:24:41 -0800, svata <[EMAIL PROTECTED]> wrote:


Hello,

as I'm new to python I've stumbled accros os.system and its not very
well documented usage.

I use Win XP Pro and Python 2.5.

Here is the code snippet:


--

import time
import os

dir = "C:\\Documents and Settings\\somepath\\"
fileName = time.strftime("%d%m%Y")
os.system('gvim dir+fileName+".txt"')


---

The problem is that concatenated variable dir+fileName doesn't get
expanded as expected.

Is there anything I omitted?

svata

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

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

Re: Is there a technic to avoid this bug

2007-02-27 Thread hg
Michele Simionato wrote:

> pychecker

Thanks all ... pydev extension does not however ... will have to install
pychecker also.

hg

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


Re: os.system and quoted strings

2007-02-27 Thread zefciu
svata wrote:
> Hello,
> 
> as I'm new to python I've stumbled accros os.system and its not very
> well documented usage.
> 
> I use Win XP Pro and Python 2.5.
> 
> Here is the code snippet:
> 
> --
> 
> import time
> import os
> 
> dir = "C:\\Documents and Settings\\somepath\\"
> fileName = time.strftime("%d%m%Y")
> os.system('gvim dir+fileName+".txt"')
> 
> ---
> 
> The problem is that concatenated variable dir+fileName doesn't get
> expanded as expected.
> 
> Is there anything I omitted?
> 
> svata
> 

The way you write it, Python has no idea that dir and fileName are
variables, not literal parts of the string.  You should put those names
outside the quotation marks, or better us the % format operator as
Sriram showed
you, or even better use os.path module.  Here is the reference:
http://docs.python.org/lib/module-os.path.html

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


Re: Lists: Converting Double to Single

2007-02-27 Thread Steven D'Aprano
On Tue, 27 Feb 2007 10:06:29 +, Duncan Booth wrote:

> Adding up a long list of values 
> and then dividing by the number of values is the classic computer 
> science example of how to get an inaccurate answer from a floating point 
> calculation.

I'm not entirely ignorant when it comes to computational mathematics, but
I must admit this is a new one to me.

If the values vary greatly in magnitude, you probably want to add them
from smallest to biggest; other than that, how else can you calculate the
mean?

The only alternative I thought of was to divide each value by the count
before summing, but that would be horribly inaccurate.

Or would it?

>>> def mean1(*args):
... return sum(args)/len(args)
...
>>> def mean2(*args):
... n = len(args)
... return sum([x/n for x in args])
...
>>> L = range(25, 597)  # 572 values
>>> L = [x/3.3 for x in L]
>>>
>>> mean1(*L)
94.090909090909108
>>> mean2(*L)
94.090909090909108

The first calculation has 571 additions and one division; the second
calculation has 571 additions and 572 divisions, but they both give the
same result to 15 decimal places.



-- 
Steven.

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


Re: Jobs: Lisp and Python programmers wanted in the LA area

2007-02-27 Thread dixkey

> Who is the CTO?
>
> Wade

Don't you people have Google in your villag^W universe?

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


Re: installing "pysqlite"

2007-02-27 Thread Diez B. Roggisch
Nader wrote:

> On Feb 27, 12:44 pm, "Paul Boddie" <[EMAIL PROTECTED]> wrote:
>> On 27 Feb, 10:31, Nader Emami <[EMAIL PROTECTED]> wrote:
>>
>> > I have installed "TurboGears" and I would install 'pysqlite' also. I am
>> > a user on a Linux machine. If I try to install the 'pysqlite' with
>> > 'easy_install' tool I get the next error message. The error message is
>> > longer than what I send here.
>>
>> [...]
>>
>> > src/connection.h:33:21: sqlite3.h: No such file or directory
>>
>> [...]
>>
>> > Could somebody tell me what I have to do to install 'pysqlite'?
>>
>> Install SQLite, perhaps? If the pysqlite build process can't find
>> sqlite3.h then you either don't have SQLite installed, or you don't
>> have the headers for SQLite installed. I'd recommend that you check
>> your installed packages for the SQLite libraries (eg. libsqlite3-0 on
>> Ubuntu) and/or the user interface (eg. sqlite3) and for the
>> development package (eg. libsqlite3-dev).
>>
>> If you can't install the packages, install SQLite from source
>> (seehttp://www.sqlite.org/) and try and persuade pysqlite to use your own
>> SQLite installation - there's a setup.cfg file in the pysqlite
>> distribution which may need to be changed to achieve this, but I don't
>> know how that interacts with setuptools.
>>
>> Paul
> 
> Thank for your reaction. I don't know also how the interaction sith
> 'easy_install' is. I think that I have to install 'pysqlite' from
> source code also, because i can change ther the 'setup.cfg' file and I
> can give there where the 'libsqlie3' is.

I think you are ok with easyinstall here. But as Paul said - you need the
sqlite3-headers. Usually, these are in a package called sqlite3-dev or
something.

However, if you happen to have a decent distribution (read: debian-based),
you should be able to install pysqlite2 as a package itself - no need to
easy_install it.


Diez
 

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


Re: installing "pysqlite"

2007-02-27 Thread Paul Boddie
On 27 Feb, 13:35, "Nader" <[EMAIL PROTECTED]> wrote:
>
> Thank for your reaction. I don't know also how the interaction sith
> 'easy_install' is. I think that I have to install 'pysqlite' from
> source code also, because i can change ther the 'setup.cfg' file and I
> can give there where the 'libsqlie3' is.

What I did was to go to the pysqlite site (http://www.initd.org/
tracker/pysqlite/wiki/pysqlite), download the sources for the latest
version, then change the setup.cfg file so that include_dirs refers to
the place where the SQLite headers (eg. sqlite.h) were installed, and
that library_dirs refers to the place where the SQLite libraries were
installed. For example:

include_dirs=/opt/sqlite/usr/include
library_dirs=/opt/sqlite/usr/lib

(You'd get the above if you configured SQLite to install into /opt/
sqlite/usr.)

Then, just do the usual build:

python setup.py build

And install with a prefix:

python setup.py install --prefix=/opt/pysqlite/usr

Since you seem to be installing things in non-root-controlled places,
I imagine you're familiar with specifying things like the --prefix
above, as well as setting up your PYTHONPATH afterwards.

Paul

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


Re: Python Source Code Beautifier

2007-02-27 Thread Chuck Rhode
Franz Steinhaeusler wrote this on Tue, 27 Feb 2007 09:45:42 +0100.  My
reply is below.

> Hello, I did not find any reasonable pyhton source code beautifier
> program (preferable gui).

-snip-

> Is there such a tool around?

Why, yes!  Yes, there is:

o http://lacusveris.com/PythonTidy/PythonTidy.python

It doesn't have a graphical user interface, and it doesn't do
everything you want, and it isn't reasonable (It's of an unreasonable
size.), but it is a beginning.

For future reference, look in:

o http://cheeseshop.python.org/pypi

... under "reformat."

-- 
.. Chuck Rhode, Sheboygan, WI, USA
.. Weather:  http://LacusVeris.com/WX
.. 26° — Wind WNW 5 mph — Sky overcast. Mist.
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: os.system and quoted strings

2007-02-27 Thread Steven D'Aprano
On Tue, 27 Feb 2007 06:24:41 -0800, svata wrote:

> Hello,
> 
> as I'm new to python I've stumbled accros os.system and its not very
> well documented usage.

Documentation seems pretty good to me.

system(...)
system(command) -> exit_status

Execute the command (a string) in a subshell.

What more did you want to see?

> I use Win XP Pro and Python 2.5.
> 
> Here is the code snippet:
> 
> --
> 
> import time
> import os
> 
> dir = "C:\\Documents and Settings\\somepath\\"

I believe that Windows will accept forward slashes as directory
separators, so you can write that as:

dir = "C:/Documents and Settings/somepath/"


> fileName = time.strftime("%d%m%Y")
> os.system('gvim dir+fileName+".txt"')

This will execute the command 

gvim dir+fileName+".txt"

exactly as you typed it. I assume you don't have a file called
dir+fileName+".txt"


> The problem is that concatenated variable dir+fileName doesn't get
> expanded as expected.

Why would you expect them to be expanded? Does the documentation of
os.system say that the command string will be expanded before it is passed
to the subshell?


> Is there anything I omitted?

dir = "C:/Documents and Settings/somepath/"
fileName = time.strftime("%d%m%Y")
fileName = dir + fileName + ".txt"
os.system('gvim %s' % fileName)

That builds the command string correctly before passing it to a subshell.


-- 
Steven

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


book for a starter

2007-02-27 Thread Wensui Liu
Good morning, all,

I just start learning python and have a question regarding books for a
newbie like me.
If you are only allowed to buy 1 python book, which one will you pick? ^_^.

Thank you so much!
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: os.system and quoted strings

2007-02-27 Thread svata
On Feb 27, 2:36 pm, "Sriram" <[EMAIL PROTECTED]> wrote:
> Hello svata,
> It is always better to compose your string before you send it as a
> command.
>
> try printing your command string out like this :
> print 'gvim dir+fileName+".txt". You'll see what the problem is.
>
> One possible solution is to compose your command string in the
> following manner:
> cmd = "gvim %s%s.txt" %(dir, fileName)
> and simply call os.system with cmd.
> os.system(cmd)
>
> Here is a little more detail on string format 
> specifiershttp://docs.python.org/lib/typesseq-strings.html
>
> HTH
> Sriram
>
> On Feb 27, 7:24 am, "svata" <[EMAIL PROTECTED]> wrote:
>
> > Hello,
>
> > as I'm new to python I've stumbled accros os.system and its not very
> > well documented usage.
>
> > I use Win XP Pro and Python 2.5.
>
> > Here is the code snippet:
>
> > --
>
> > import time
> > import os
>
> > dir = "C:\\Documents and Settings\\somepath\\"
> > fileName = time.strftime("%d%m%Y")
> > os.system('gvim dir+fileName+".txt"')
>
> > ---
>
> > The problem is that concatenated variable dir+fileName doesn't get
> > expanded as expected.
>
> > Is there anything I omitted?
>
> > svata

Thank you for prompt reply. I should be more concise with strings, I
think :)

svata

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


Re: gmpy moving to code.google.com

2007-02-27 Thread Alex Martelli

On Feb 27, 2007, at 2:59 AM, Daniel Nogradi wrote:

> Hi Alex,
>
> I did another test, this time with python 2.4 on suse and things are
> worse than in the previous case (which was python 2.5 on fedora 3),
> ouput of 'python gmp_test.py' follows:

Interesting!  gmpy interacts with decimal.Decimal by "monkey- 
patching" that class on the fly; clearly the monkey-patching isn't  
working with 2.4 on SuSE, so all the addition attempts are failing  
(all 6 of them).

So the issue is finding out why this strategy is failing there, while  
succeeding on other Linux distros, Mac, and Windows.

To that end, I have added a feature in the latest svn trunk (revision  
11) to set gmpy's own options.debug flag from an environment variable  
named GMPY_DEBUG at startup (if that environment variable is set).

If you could please svn up and rebuild, then running with GMPY_DEBUG  
set in the environment should give something like:

brain:~/gmpy alex$ GMPY_DEBUG=1 python -c 'import gmpy' 2>&1 | tail -5
mp_allocate( 4->8 )
mp_allocate( 4->8 ) ->0x60b8b0
gmpy_module at 0x63390
gmpy_module imported decimal OK
gmpy_module tweaked decimal OK

This is the expected behavior when module decimal is present, while,  
when it's absent, you should see something like:

brain:~/gmpy alex$ GMPY_DEBUG=1 python2.3 -c 'import gmpy' 2>&1 |  
tail -5
Initing new not in zcache
mp_allocate( 4->8 )
mp_allocate( 4->8 ) ->0x3017d0
gmpy_module at 0x6de70
gmpy_module could not import decimal

In each case, what matters is the last line or two after "gmpy_module  
at" -- the rest of the copious debugging output is irrelevant here.

Module decimal is expected to be present from 2.4 forward (though it  
could also be explicitly installed on 2.3).  However, from the test  
failures you report, it looks like SuSE's 2.4 does not have decimal  
available for importing when gmpy is starting up -- so I'd like to  
confirm that first.

If it's confirmed, it will be interesting to discover how this  
happens (but that requires a SuSE installation, which I don't have)  
and secondarily what is gmpy to do about it -- maybe offer a warning  
on startup when module decimal is unexpectedly not importable but  
then skip the relevant unittests in that case?  (Note that the tests  
ARE already skipped if module decimal is not importable _at test  
time_ -- what's really weird is that apparently on SuSE decimal CAN  
be imported by the tests but CANNOT be imported earlier while gmpy is  
loading, which is truly puzzling).

I'd appreciate reports about this behavior on as many Python/Linux  
installations as possible -- yours, of course (to check my guess that  
the problem is that decimal can't be imported while gmpy is loading),  
but also others' (to see how widespread the problem is, etc, etc).

Thanks again for reporting this, and thanks in advance to anybody  
who'll lend a hand in tracking down this little strangeness!!!


Alex

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


Re: installing "pysqlite"

2007-02-27 Thread Nader Emami
Paul Boddie wrote:
> On 27 Feb, 13:35, "Nader" <[EMAIL PROTECTED]> wrote:
>> Thank for your reaction. I don't know also how the interaction sith
>> 'easy_install' is. I think that I have to install 'pysqlite' from
>> source code also, because i can change ther the 'setup.cfg' file and I
>> can give there where the 'libsqlie3' is.
> 
> What I did was to go to the pysqlite site (http://www.initd.org/
> tracker/pysqlite/wiki/pysqlite), download the sources for the latest
> version, then change the setup.cfg file so that include_dirs refers to
> the place where the SQLite headers (eg. sqlite.h) were installed, and
> that library_dirs refers to the place where the SQLite libraries were
> installed. For example:
> 
> include_dirs=/opt/sqlite/usr/include
> library_dirs=/opt/sqlite/usr/lib
> 
> (You'd get the above if you configured SQLite to install into /opt/
> sqlite/usr.)
> 
> Then, just do the usual build:
> 
> python setup.py build
> 
> And install with a prefix:
> 
> python setup.py install --prefix=/opt/pysqlite/usr
> 
> Since you seem to be installing things in non-root-controlled places,
> I imagine you're familiar with specifying things like the --prefix
> above, as well as setting up your PYTHONPATH afterwards.
> 
> Paul
> 
I have first installed "sqlite" and then I have configure the 
"setup.cfg" file of "pysqlite" package. I had to do two things in
'pysqlite' directory:
1- python setup.py build
2- python setup.py install

It has done without any error. I suppose that the installation is well 
done, but I haven't yet test whether I can import the 'pysqlite' module 
in python. But how you mean about "PYTHONPATH"? If I do "echo 
$PYTHONPAT" i get an empty string. That meant that I don't have any 
"PYTHONPATH". How can I assign a correct "path" to this variable?

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


Re: book for a starter

2007-02-27 Thread Sick Monkey

I personally would get "Programming Python, Third Edition "
http://www.oreilly.com/catalog/python3/



On 2/27/07, Wensui Liu <[EMAIL PROTECTED]> wrote:


Good morning, all,

I just start learning python and have a question regarding books for a
newbie like me.
If you are only allowed to buy 1 python book, which one will you pick?
^_^.

Thank you so much!
--
http://mail.python.org/mailman/listinfo/python-list

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

Re: How to use cmp() function to compare 2 files?

2007-02-27 Thread samuel . y . l . cheung
On Feb 27, 12:07 am, Marc 'BlackJack' Rintsch <[EMAIL PROTECTED]> wrote:
> In <[EMAIL PROTECTED]>, [EMAIL PROTECTED]
> wrote:
>
> >   File "./scripts/regressionTest.py", line 30, in getSnapShot
> > if (difflib.context_diff(f1.readlines(), f2.readlines()).len() ==
> > 0):
> >  # no difference
> > else:
> >  # files are different
> > AttributeError: 'generator' object has no attribute 'len'
>
> > Can you please help?
>
> The function returns a generator/iterator over the differences which has
> no `len()` method.  If you just want to know if two files are equal or not
> use `filecmp.cmp()`.  Read the docs about the `shallow` argument of that
> function.
>
> Ciao,
> Marc 'BlackJack' Rintsch

Thanks. I use that before, it does not work for me, since it always
return 1, regardless if the file content of 2 files are different or
not.


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


Re: Checking for EOF in stream

2007-02-27 Thread kousue
On Feb 19, 6:58 pm, GiBo <[EMAIL PROTECTED]> wrote:
> Hi!
>
> Classic situation - I have to process an input stream of unknown length
> until a I reach its end (EOF, End Of File). How do I check for EOF? The
> input stream can be anything from opened file through sys.stdin to a
> network socket. And it's binary and potentially huge (gigabytes), thus
> "for line in stream.readlines()" isn't really a way to go.

Could you use xreadlines()? It's a lazily-evaluated stream reader.

> For now I have roughly:
>
> stream = sys.stdin
> while True:
> data = stream.read(1024)
> process_data(data)
> if len(data) < 1024: ## (*)
> break
>
> I smell a fragile point at (*) because as far as I know e.g. network
> sockets streams may return less data than requested even when the socket
> is still open.

Well it depends on a lot of things. Is the stream blocking or non-
blocking (on sockets and some other sorts of streams, you can pick
this yourself)? What are the underlying semantics (reliable-and-
blocking TCP or dropping-and-unordered-UDP)? Unfortunately, you really
need to just know what you're working with (and there's really no
better solution; trying to hide the underlying semantics under a
proscribed overlaid set of semantics can only lead to badness in the
long run).

> I'd better like something like:
>
> while not stream.eof():
> ...
>
> but there is not eof() method :-(
>
> This is probably a trivial problem but I haven't found a decent solution.

For your case, it's not so hard:
http://pyref.infogami.com/EOFError says "read() and readline() methods
of file objects return an empty string when they hit EOF." so you
should assume that if something is claiming to be a file-like object
that it will work this way.

> Any hints?

So:
stream = sys.stdin
while True:
data = stream.read(1024)
if data=="":
break
process_data(data)

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


Re: book for a starter

2007-02-27 Thread abcd
I'd pick, Dive Into Python (http://www.diveintopython.org/) you
can read it online for FREE!

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


Re: installing "pysqlite"

2007-02-27 Thread Paul Boddie
On 27 Feb, 16:34, Nader Emami <[EMAIL PROTECTED]> wrote:
>
> I have first installed "sqlite" and then I have configure the
> "setup.cfg" file of "pysqlite" package. I had to do two things in
> 'pysqlite' directory:
> 1- python setup.py build
> 2- python setup.py install
>
> It has done without any error. I suppose that the installation is well
> done, but I haven't yet test whether I can import the 'pysqlite' module
> in python. But how you mean about "PYTHONPATH"? If I do "echo
> $PYTHONPAT" i get an empty string. That meant that I don't have any
> "PYTHONPATH". How can I assign a correct "path" to this variable?

I was getting ahead of myself and forgot that you may have a version
of Python that you installed yourself from source. If so, "python
setup.py install" (without specifying --prefix) should put the package
in the right place so that you don't have to worry about PYTHONPATH.

Just try and "import pysqlite2", then see if it worked or not.

Paul

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


Re: Help on object scope?

2007-02-27 Thread Jussi Salmela
[EMAIL PROTECTED] kirjoitti:
> 

> global names seemed to be the best idea. The only problem is now I
> have to type common.r.t instead of just r.t. If I put common in the /
> lib directory, it is even worse and I have to type lib.common.r.t. I
> like that it is explicit and perhaps this is the Python way, but it is
> annoying and produces ugly code to see all those fully-qualified names
> when all I'd really like to use is r.t throughout the program.
> 
> Is there a way to import lib.common but then re-bind its attributes to
> the local space without breaking the linkage?
> 
> 

See section "6.12 The import statement" in the "Python Reference 
Manual". (Hint the part "as name" is what you want)

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


Re: book for a starter

2007-02-27 Thread king kikapu
Me, i bought this
http://www.amazon.com/Core-Python-Programming-2nd/dp/0132269937/sr=8-1/qid=1172592163/ref=pd_bbs_sr_1/105-9302229-1138834?ie=UTF8&s=books
and i really think it is a great book for learning Python.
It refers to the latest Python version (2.5) and covers a lot of
things, besides the language.

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


Re: book for a starter

2007-02-27 Thread David Brochu

From: "Wensui Liu" <[EMAIL PROTECTED]>
To: [email protected]
Date: Tue, 27 Feb 2007 10:09:57 -0500
Subject: book for a starter
Good morning, all,

[I just start learning python and have a question regarding books for a
newbie like me.
If you are only allowed to buy 1 python book, which one will you pick? ^_^.

Thank you so much!]

- If your new to programming I would recommend reading Learning Python
(O'Reilly). Along with that the tutorial by Guido on the Python website is a
good foundation. If you have programming experience I would recommend Dive
Into Python.

Either way you probably should have Learning Python and/or Programming
Python on your bookshelf for reference if you are going to really program
using Python.
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: How to use cmp() function to compare 2 files?

2007-02-27 Thread Jussi Salmela
[EMAIL PROTECTED] kirjoitti:
> On Feb 27, 12:07 am, Marc 'BlackJack' Rintsch <[EMAIL PROTECTED]> wrote:
>> In <[EMAIL PROTECTED]>, [EMAIL PROTECTED]
>> wrote:
>>
>>>   File "./scripts/regressionTest.py", line 30, in getSnapShot
>>> if (difflib.context_diff(f1.readlines(), f2.readlines()).len() ==
>>> 0):
>>>  # no difference
>>> else:
>>>  # files are different
>>> AttributeError: 'generator' object has no attribute 'len'
>>> Can you please help?
>> The function returns a generator/iterator over the differences which has
>> no `len()` method.  If you just want to know if two files are equal or not
>> use `filecmp.cmp()`.  Read the docs about the `shallow` argument of that
>> function.
>>
>> Ciao,
>> Marc 'BlackJack' Rintsch
> 
> Thanks. I use that before, it does not work for me, since it always
> return 1, regardless if the file content of 2 files are different or
> not.
> 
> 

I think you are mixing cmp and filecmp.cmp. They are two different beasts.

Cheers,
Jussi
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: gtk.mainquit is deprecated

2007-02-27 Thread Alan Franzoni
Il 27 Feb 2007 01:56:33 -0800, awalter1 ha scritto:

> But I don't want to quit the application, I need only to close the
> window.
> My application includes others places where "self.window.destroy()"
> instruction is used and the execution is done without warning.
> Very strange.

But does then the application end, as if gtk.main_quit() were called? If
it's the case, it's very likely you connected the 'destroy' signal on that
very window and you set gtk.mainquit() as the callback.

-- 
Alan Franzoni <[EMAIL PROTECTED]>
-
Togli .xyz dalla mia email per contattarmi.
Remove .xyz from my address in order to contact me.
-
GPG Key Fingerprint (Key ID = FE068F3E):
5C77 9DC3 BD5B 3A28 E7BC 921A 0255 42AA FE06 8F3E 
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Help on object scope?

2007-02-27 Thread Bart Ogryczak
On Feb 25, 10:25 pm, [EMAIL PROTECTED] wrote:
> Hello everybody,
>
> I have a (hopefully) simple question about scoping in python. I have a
> program written as a package, with two files of interest. The two
> files are /p.py and /lib/q.py
>
> My file p.py looks like this:
>
> ---
>
> from lib import q
>
> def main():
>   global r
>   r = q.object1()
>   s = q.object2()
>
> if __name__ == "__main__":
>   main()
>
> ---
>
> My file q.py in the subdirectory lib looks like this:
>
> class object1:
>   t = 3
>
> class object2:
>   print r.t

"Globals" are only global within the module they are defined in.
Change "global r" to "import __main__; __main__.r = r", and in q.py
add "from __main__ import r".



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


Re: Lists: Converting Double to Single

2007-02-27 Thread Neil Cerutti
On 2007-02-27, Steven D'Aprano <[EMAIL PROTECTED]> wrote:
> On Tue, 27 Feb 2007 10:06:29 +, Duncan Booth wrote:
>> Adding up a long list of values and then dividing by the
>> number of values is the classic computer science example of
>> how to get an inaccurate answer from a floating point
>> calculation.
>
> I'm not entirely ignorant when it comes to computational
> mathematics, but I must admit this is a new one to me.
>
> If the values vary greatly in magnitude, you probably want to add them
> from smallest to biggest; other than that, how else can you calculate the
> mean?
>
> The only alternative I thought of was to divide each value by the count
> before summing, but that would be horribly inaccurate.
>
> Or would it?
>
 def mean1(*args):
> ... return sum(args)/len(args)
> ...
 def mean2(*args):
> ... n = len(args)
> ... return sum([x/n for x in args])
> ...
 L = range(25, 597)  # 572 values
 L = [x/3.3 for x in L]

 mean1(*L)
> 94.090909090909108
 mean2(*L)
> 94.090909090909108
>
> The first calculation has 571 additions and one division; the
> second calculation has 571 additions and 572 divisions, but
> they both give the same result to 15 decimal places.

How about this?

>>> L = range(5, 10)
>>> L = [pow(2, -x) for x in L]
>>> "%40.40f" % mean1(*L)
'0.012109375000'
>>> "%40.40f" % mean2(*L)
'0.012109375200'

Offhand, I think the first is "righter". Weird!

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


Re: Python, Embedded linux and web development

2007-02-27 Thread [EMAIL PROTECTED]
On 27 fév, 13:27, "Paul Boddie" <[EMAIL PROTECTED]> wrote:
> On 27 Feb, 13:12, "Tzury" <[EMAIL PROTECTED]> wrote:
>
>
>
> > c) small web application that will be used as front end to configure
> > the system (flat files and sqlite3 db are the back-end).
>
> > Our platform is base on the Intel PXA270 processor (XSCALE family,
> > which is ARM compatible) running at 312MHz.
>
> You might want to read this article which got mentioned fairly
> recently either on comp.lang.python or on some blog or other:
>
> http://www.linuxdevices.com/articles/AT5550934609.html
>

Don't know for sure if it's relevant, but this might be of interest
too:
http://william-os4y.livejournal.com/2924.html



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


Re: Python Source Code Beautifier

2007-02-27 Thread Alan Franzoni
Il Tue, 27 Feb 2007 09:45:42 +0100, Franz Steinhaeusler ha scritto:

> Hello, I did not find any reasonable pyhton source code beautifier
> program (preferable gui).

Well, most of the things you ask should be written as such, not written and
then beautified!

> Use Spaces, size: 4

Your editor should support this.

> convert structs like: if (a > b):   to   if a > b:

Well... that's a matter of fact, not just style. Sometimes parentheses help
the reading; if a,b are not just plain names but somewhat complex
instructions, parentheses should stay.

> fill in spaces, but not in functions between operators:
> 
> a+=1 => a += 1
> p(t + 1) => p(t+1)

Code should be written this way.

> self.scriptcount = self.scriptcount + 1 => self.scriptcount += 1

the += operator is syntactic sugar just to save time... if one doesn't use
it I don't think it's a matter of beauty.
> 
> from "is" to "==" and "is not" to "!=" (ok a find replace could do that
> easily also), but in a program that would be more comfortable.

what? No, I think you're missing the difference between 'is' and '=='. You
could say it the other way for None, True, False, e.g. if there's a 'a ==
None' it could be safely converted to 'a is None', but again: this should
be done while writing the code.

> break long lines (in a reasonable way)

well... this could be useful sometimes, but again... 'reason' is usually
something human beings should employ, and shouldn't be 'outsourced' to
computer programs.

> make from:
> if len(string) > 0: => if string:
> and 
> if if len(string) < 1 orr if string == ""  => if not string

That's impossibile! Python is dynamically typed! How could the 'beautifier'
understand what the 'string' name is bound to? It could be whatever object!

> detect mixed line ending
> detect tabs mixed with space
> trim trailing whitespaces.

Those are editor tasks.

Get a good Editor or IDE. You haven't told us what OS are you on. If you're
on Windows, UltraEdit can do most of the things you'd like. And don't rely
on a software to correct human behaviours ^_^.

-- 
Alan Franzoni <[EMAIL PROTECTED]>
-
Togli .xyz dalla mia email per contattarmi.
Remove .xyz from my address in order to contact me.
-
GPG Key Fingerprint (Key ID = FE068F3E):
5C77 9DC3 BD5B 3A28 E7BC 921A 0255 42AA FE06 8F3E 
-- 
http://mail.python.org/mailman/listinfo/python-list


MI5 Persecution: Stand up for Free Speech 14/8/95 (363)

2007-02-27 Thread MI5Victim
From: [EMAIL PROTECTED] (Richard Ingram)
Newsgroups: uk.misc
Date: Mon Aug 14 10:08:32 1995

Some cencorship loving bore wrote :

> In article <[EMAIL PROTECTED]> [EMAIL PROTECTED] (Gareth Evans) writes:
>
>   His sysadmin is also next to useless, and has not replied to my request or
>   even acknowledged it. Maybe this person *is* a sysadmin?
>
> He's not. It seems the public access site he uses has got no proper
> management over its users. Here's a copy of a reply I got from a
> complaint I made. [After returning every one of Corley's postings to

[snip a large pile of winging complaining drivel]

Geez what a bunch of tossers you all are - you don't like someones postings so
you try and get him evicted from the net, why not just use a kill file - you 
DONT have to read his posts/threads now do you ?

Why is it the net is getting populated by the biggest bunch of self absorbed 
little Hitlers ? You don't like someones posts so you bloody complain or mail 
bomb them - grow up you bunch of fucking sad gits !

Richard.

363

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


Re: gmpy moving to code.google.com

2007-02-27 Thread Daniel Nogradi
> > Hi Alex,
> >
> > I did another test, this time with python 2.4 on suse and things are
> > worse than in the previous case (which was python 2.5 on fedora 3),
> > ouput of 'python gmp_test.py' follows:
>
> Interesting!  gmpy interacts with decimal.Decimal by "monkey-
> patching" that class on the fly; clearly the monkey-patching isn't
> working with 2.4 on SuSE, so all the addition attempts are failing
> (all 6 of them).
>
> So the issue is finding out why this strategy is failing there, while
> succeeding on other Linux distros, Mac, and Windows.
>
> To that end, I have added a feature in the latest svn trunk (revision
> 11) to set gmpy's own options.debug flag from an environment variable
> named GMPY_DEBUG at startup (if that environment variable is set).
>
> If you could please svn up and rebuild, then running with GMPY_DEBUG
> set in the environment should give something like:
>
> brain:~/gmpy alex$ GMPY_DEBUG=1 python -c 'import gmpy' 2>&1 | tail -5
> mp_allocate( 4->8 )
> mp_allocate( 4->8 ) ->0x60b8b0
> gmpy_module at 0x63390
> gmpy_module imported decimal OK
> gmpy_module tweaked decimal OK
>
> This is the expected behavior when module decimal is present, while,
> when it's absent, you should see something like:
>
> brain:~/gmpy alex$ GMPY_DEBUG=1 python2.3 -c 'import gmpy' 2>&1 |
> tail -5
> Initing new not in zcache
> mp_allocate( 4->8 )
> mp_allocate( 4->8 ) ->0x3017d0
> gmpy_module at 0x6de70
> gmpy_module could not import decimal
>
> In each case, what matters is the last line or two after "gmpy_module
> at" -- the rest of the copious debugging output is irrelevant here.
>
> Module decimal is expected to be present from 2.4 forward (though it
> could also be explicitly installed on 2.3).  However, from the test
> failures you report, it looks like SuSE's 2.4 does not have decimal
> available for importing when gmpy is starting up -- so I'd like to
> confirm that first.
>
> If it's confirmed, it will be interesting to discover how this
> happens (but that requires a SuSE installation, which I don't have)
> and secondarily what is gmpy to do about it -- maybe offer a warning
> on startup when module decimal is unexpectedly not importable but
> then skip the relevant unittests in that case?  (Note that the tests
> ARE already skipped if module decimal is not importable _at test
> time_ -- what's really weird is that apparently on SuSE decimal CAN
> be imported by the tests but CANNOT be imported earlier while gmpy is
> loading, which is truly puzzling).
>
> I'd appreciate reports about this behavior on as many Python/Linux
> installations as possible -- yours, of course (to check my guess that
> the problem is that decimal can't be imported while gmpy is loading),
> but also others' (to see how widespread the problem is, etc, etc).
>
> Thanks again for reporting this, and thanks in advance to anybody
> who'll lend a hand in tracking down this little strangeness!!!

Okay, here is a summary. The notation is:

platform version python version debug unittest

where debug will be either 'pass' or 'fail' if that particular
platform and python version passes or fails the GMPY_DEBUG=1
importing/tweaking test. Unittest will also be 'pass' or 'fail' if the
full unittesting passes or fails respectively.

Fedora 3 python 2.5passpass
Fedora 3 python 2.4passfail
Fedora 3 python 2.3.4 fail   pass
Suse 9.3 python 2.4passfail
Suse 10 python 2.4.1  passpass
Suse 10.2(64bit) python 2.5 passfail

The output from each test is zipped and you can grab it from here:
http://lorentz.leidenuniv.nl/~nogradi/gmpy_test.zip

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


Re: Python Source Code Beautifier

2007-02-27 Thread Michael Spencer
Franz Steinhaeusler wrote:
> Use Spaces, size: 4
 > detect mixed line ending
 > detect tabs mixed with space
 > trim trailing whitespaces.

look at: tools/scripts/reindent.py

> convert structs like: if (a > b):   to   if a > b:
> fill in spaces, but not in functions between operators:
> 
> a+=1 => a += 1
> p(t + 1) => p(t+1)
> 
an ast pretty printer could do this sort of thing.  I saw someone post about 
one 
on this list a couple of years ago, but can't quickly turn up the link.


> 
> from "is" to "==" and "is not" to "!=" (ok a find replace could do that
> easily also), but in a program that would be more comfortable.

careful!
  >>> (1,2,3) == (1,2,3)
  True
  >>> (1,2,3) is (1,2,3)
  False
  >>>

Michael

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


Re: HTML to dictionary

2007-02-27 Thread Nikita the Spider
In article <[EMAIL PROTECTED]>,
 Tina I <[EMAIL PROTECTED]> wrote:

> Hi everyone,
> 
> I have a small, probably trivial even, problem. I have the following HTML:
> > 
> >  METAR:
> > 
> > ENBR 270920Z 0KT  FEW018 02/M01 Q1004 NOSIG
> > 
> > 
> >  short-TAF:
> > 
> > ENBR 270800Z 270918 VRB05KT  FEW020 SCT040
> > 
> > 
> >  long-TAF:
> > 
> > ENBR 271212 VRB05KT  FEW020 BKN030 TEMPO 2012 2000 SNRA VV010 BECMG 
> > 2124 15012KT
> > 
> 
> I need to make this into a dictionary like this:
> 
> dictionary = {"METAR:" : "ENBR 270920Z 0KT  FEW018 02/M01 Q1004 
> NOSIG" , "short-TAF:" : "ENBR 270800Z 270918 VRB05KT  FEW020 SCT040" 
> , "long-Taf:" : "ENBR 271212 VRB05KT  FEW020 BKN030 TEMPO 2012 2000 
> SNRA VV010 BECMG 2124 15012KT"}

Tina,
In addition to Beautiful Soup which others have mentioned, Connelly 
Barnes' HTMLData module will take (X)HTML and convert it into a 
dictionary for you:
http://oregonstate.edu/~barnesc/htmldata/

THe dictionary won't have the exact format you want, but I think it 
would be fairly easy for you to convert to what you're looking for.

I use HTMLData a lot. Beautiful Soup is great for parsing iteratively, 
but if I just want to throw some HTML at a function and get data back, 
HTMLData is my tool of choice.

Good luck with whatever you choose

-- 
Philip
http://NikitaTheSpider.com/
Whole-site HTML validation, link checking and more
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: spawnl and waitpid

2007-02-27 Thread Thinker
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

[EMAIL PROTECTED] wrote:
> i have tried as you said (cf bellow) and same result... is there
> any link which explain how a server Web read script and send the
> answer ?
> -
> pid = os.spawnl(os.P_NOWAIT,"c:\\python25\
> \python.exe","python","Main.py")

print 'please wait...'

> ret = os.waitpid(pid,0)

You have missed my idea.
Since os.waitpid will be blocked, you should print your message before
calling os.waitpid().


- --
Thinker Li - [EMAIL PROTECTED] [EMAIL PROTECTED]
http://heaven.branda.to/~thinker/GinGin_CGI.py

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

iD8DBQFF5HA61LDUVnWfY8gRAu8sAJ4n1dogsw7RzTxH8Ke3xnNX6gXnRQCeMOKf
/dsGHttcJc/KGpx414I7rxw=
=E3o7
-END PGP SIGNATURE-

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

Re: book for a starter

2007-02-27 Thread Bjoern Schliessmann
Wensui Liu wrote:

> I just start learning python and have a question regarding books
> for a newbie like me.

http://wiki.python.org/moin/IntroductoryBooks

> If you are only allowed to buy 1 python book, which one will you
> pick? ^_^.

I'd pick a reference. YMMV.

Regards,


Björn (having been allowed to buy more than one Python book)

-- 
BOFH excuse #314:

You need to upgrade your VESA local bus to a MasterCard local bus.

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


  1   2   3   >