Pyastro

2007-02-28 Thread l
Where can I find the code...
I have checked starship, "the vaults" and googled for a long time. either 
they point to starshup(wiki) where it doesn't exists, or to dead links.
Any help would be much appreciated.

TIA 


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


Re: QPaintDevice: Must construct a QApplication before a QPaintDevice

2007-02-28 Thread boris . smirnov
On Feb 28, 8:56 am, Phil Thompson <[EMAIL PROTECTED]>
wrote:
> On Tuesday 27 February 2007 11:09 pm, shredwheat wrote:
>
> > When your programs stops with the error, it should also be printing a
> > stack trace. This is a list of all the functions that have been called
> > when Python had the problem.
>
> > You shouldn't have to do anything extra to get the stack trace.
>
> The error is raised in Qt and aborts immediately. It never gets back to Python
> to generate a trace.
>
> He needs to produce a short and complete test which demonstrates the problem,
> then we can point out where the QPaintDevice is being created.
>
> Phil

OK, but before I do a complete test, could anybody tell/explain me why
the same file is working on Windows?
Did anybody already meet with something similar Win vs. Linux?

b.

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


Re: gtk.mainquit is deprecated

2007-02-28 Thread awalter1
Thank you
You're right. a connection was made between "destroy" and
gtk.main_quit (a bad cut and paste from an old application).

On 27 fév, 17:25, Alan Franzoni
<[EMAIL PROTECTED]> wrote:
> 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: newbie question(file-delete trailing comma)

2007-02-28 Thread kavitha thankaian
ok,,,
  my script writes a dictionary to a file.but i need only the values from the 
dictionary which should be sepearted by a comma,,,so i did as following:
   
   
  some=getAllData()-->dictionary
f=open("test.txt", "w")
  for value in some.values():
f.writelines('\%s\,' % value )>strings seperated by comma
   
  when i execute the above code,my test.txt file has the following:
   
  a,b,c,d,
   
  now i need to delete the comma at the end,,,this is my problem,,,
   
  kavitha
  
 
   
   
   
  
Mikael Olofsson <[EMAIL PROTECTED]> wrote:
  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



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

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

2007-02-28 Thread Phoe6
On Feb 27, 2:21 pm, Duncan Booth <[EMAIL PROTECTED]> wrote:

> > Hi all,
> > 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).

Thanks for the reply, this is very helpful.

Thanks,
Senthil

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


Re: database without installation again

2007-02-28 Thread Andrzej S.
[EMAIL PROTECTED] wrote:
> MySQL is a server software. You cannot just drop some files and expect
> the whole thing to work.

Yes, sure. There is mySQL server installed. I can access it from php.


>> I think, the
>> best solution would be db stored in binary file with interface in based on
>> standard Python library, but is there anything like that??
> 
> SQLite ? Gadfly ?

How can I install them? Is it so simple as uploading module files to 
cgi-bin directory? Metakit (http://www.equi4.com/metakit/python.html) 
database works this way, but i haven't tested it yet.

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


Cover up attempt

2007-02-28 Thread Jennifer Crosby
http://toiletseatcoverup.blogspot.com/ - Yahoo ads not performing well? 
Publisher profits in the toilet? Join the best affiliate program known to man. 

Jennifer Crosby very hot but is she single?

Ya its no two man race to a one man shit show this time dear.






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


Re: QPaintDevice: Must construct a QApplication before a QPaintDevice

2007-02-28 Thread boris . smirnov
On Feb 28, 9:07 am, [EMAIL PROTECTED] wrote:
> On Feb 28, 8:56 am, Phil Thompson <[EMAIL PROTECTED]>
> wrote:
>
> > On Tuesday 27 February 2007 11:09 pm, shredwheat wrote:
>
> > > When your programs stops with the error, it should also be printing a
> > > stack trace. This is a list of all the functions that have been called
> > > when Python had the problem.
>
> > > You shouldn't have to do anything extra to get the stack trace.
>
> > The error is raised in Qt and aborts immediately. It never gets back to 
> > Python
> > to generate a trace.
>
> > He needs to produce a short and complete test which demonstrates the 
> > problem,
> > then we can point out where the QPaintDevice is being created.
>
> > Phil
>
> OK, but before I do a complete test, could anybody tell/explain me why
> the same file is working on Windows?
> Did anybody already meet with something similar Win vs. Linux?
>
> b.

Here is my simple script:

import sys
from qt import *
class Optimizer(QWidget):
   def __init__(self, parent = 0):
  QWidget.__init__(self)
  QGridLayout(self)
if __name__ == '__main__':
   a = QApplication (sys.argv)
   mywidget = Optimizer()
   a.exec_loop()

This produces this:
> python qt_script_bs_070228.py
QPaintDevice: Must construct a QApplication before a QPaintDevice

Any suggestions here?
Thanks



BTW: One question:
when I use "import qt" instead of "from qt import *" I get this error:
Traceback (most recent call last):
  File "mscarideidtool_bs_070228.py", line 4, in ?
class Optimizer(QWidget):
NameError: name 'QWidget' is not defined

What is the difference between "import qt" and "from qt import *" ? I
thought that these are the same.

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


Re: spawnl and waitpid

2007-02-28 Thread naima . mans
On 27 fév, 19:31, Dennis Lee Bieber <[EMAIL PROTECTED]> wrote:
> On 27 Feb 2007 05:39:51 -0800, [EMAIL PROTECTED] declaimed the
> following in comp.lang.python:
>
>
>
> > On 27 fév, 12:27, Thinker <[EMAIL PROTECTED]> wrote:
> > > -BEGIN PGP SIGNED MESSAGE-
> 
>
> > > Your program will be blocked here until child process being terminated.
> > > You should print your messages before this line.
>
> > i have tried as you said (cf bellow) and same result...
>
> No, you did NOT do as was suggested (unless you misunderstood which
> line "before this" meant.
>
> > 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)
>
> As soon as you execute os.waitpid(), your script WAITS. NOTHING
> after that point will happen until the process you are waiting on exits.
>
> > 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()
>
> pid = os.spawnl(os.P_NOWAIT,
> "c:\\python25\\python.exe",
> "python",
> "Main.py")#apparently a Windows OS
> print "Please wait ..."
> sys.stdout.flush()
> ret = os.waitpid(pid, 0)
>
> if ret[1]:
> print "Non-zero exit code: %s %s" % (ret[1], ret[0])
> else:
> print "Successful exit"
> sys.stdout.flush()
>
> {I'm presuming a 0 return code means success... VMS used 1 for success
> and 0 for failure [actually, odd numbers were informational status, even
> numbers were error status]}
>
> > ---
> > thanks
>
> --
> WulfraedDennis Lee Bieber   KD6MOG
> [EMAIL PROTECTED]  [EMAIL PROTECTED]
> HTTP://wlfraed.home.netcom.com/
> (Bestiaria Support Staff:   [EMAIL PROTECTED])
> HTTP://www.bestiaria.com/

hello

thanks a lot..

sorry for misunderstanding, my english isn't good (i'm french).

i have tried like this:
--
#! C:/Python25/python.exe
# -*- coding: cp1252 -*-


import cgitb; cgitb.enable()
import os,sys

print "Content-Type: text/html"
print

pid =  os.spawnl(os.P_NOWAIT,"c:\\python25\
\python.exe","python","Main.py")
print "please wait.."
sys.stdout.flush()
ret = os.waitpid(pid,0)
   # retourne le process id
if ret[1]:
print "Non-zero exit code: %s %s" % (ret[1], ret[0])
else:
print "Successful exit"
sys.stdout.flush()


and the result:

At the end of the script execution it write:
==  please wait.. Successful exit

The browser doesn't let the script executing on background to write
the message at once.. it waits the end.


what happend?

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


Re: Lists: Converting Double to Single

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

>  For floating point, smallest magnitude to largest IS the most
> precise.
> 
>  Pretend you only have 2 significant digits of precision...
> 
>  10 + 0.4 + 0.4 + 0.4 => 10
> 
>  0.4 + 0.4 + 0.4 + 10 => 11

and if you try the way I suggested then initial input order doesn't 
matter:

   (10 + 0.4) = 10, (0.4 + 0.4) = 0.8, (10 + 0.8) = 11
   (0.4 + 0.4) = 0.8, (10 + 0.4) = 10, (0.8 + 10) = 11


Pretend you ran the example code I posted. Specifically the bit where 
the output is:

all the same
builtin sum  100.016732
pairwise sum 100.1

It isn't so much the order of the initial values that matters 
(especially if the values are all similar). What *really* matters is 
keeping the magnitude of the intermediate results as small as possible. 

Summing in pairs ensures that you keep the precision as long as 
possible. The order of the initial values is less important than this 
(although it does still have a minor effect). For a solution which works 
with a sequence of unknown length and doesn't require lookahead I don't 
think you can do much better than that.

BTW, in case someone thinks my example numbers are a bit too weird you 
can show the same problem averaging a list of 10 digit floating point 
numbers with exact representations:

v = [99.] * 1000
print "builtin sum ", (sum(v)/len(v))
print "pairwise sum", (sumpairs(v)/len(v))


gives:
builtin sum  99.91
pairwise sum 99.0

In both cases the total is large enough to go beyond the range of 
integers that can be expressed exactly in floating point and as soon as 
that happens the builtin sum loses precision on every subsequent 
addition. pairwise summation only loses precision on a very few of the 
additions.

P.S. Apologies for the sloppy coding in the sumpairs function. It should 
of course do the final addition manually otherwise it is going to give 
odd results summing lists or strings or anything else where the order 
matters. Revised version:

def sumpairs(seq):
tmp = []
for i,v in enumerate(seq):
if i&1:
tmp[-1] += v
i = i + 1
n = i & -i
while n > 2:
t = tmp.pop(-1)
tmp[-1] = tmp[-1] + t
n >>= 1
else:
tmp.append(v)

while len(tmp) > 1:
t = tmp.pop(-1)
tmp[-1] = tmp[-1] + t
return tmp[0]


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


Re: QPaintDevice: Must construct a QApplication before a QPaintDevice

2007-02-28 Thread Phil Thompson
On Wednesday 28 February 2007 9:00 am, [EMAIL PROTECTED] wrote:
> On Feb 28, 9:07 am, [EMAIL PROTECTED] wrote:
> > On Feb 28, 8:56 am, Phil Thompson <[EMAIL PROTECTED]>
> >
> > wrote:
> > > On Tuesday 27 February 2007 11:09 pm, shredwheat wrote:
> > > > When your programs stops with the error, it should also be printing a
> > > > stack trace. This is a list of all the functions that have been
> > > > called when Python had the problem.
> > > >
> > > > You shouldn't have to do anything extra to get the stack trace.
> > >
> > > The error is raised in Qt and aborts immediately. It never gets back to
> > > Python to generate a trace.
> > >
> > > He needs to produce a short and complete test which demonstrates the
> > > problem, then we can point out where the QPaintDevice is being created.
> > >
> > > Phil
> >
> > OK, but before I do a complete test, could anybody tell/explain me why
> > the same file is working on Windows?
> > Did anybody already meet with something similar Win vs. Linux?
> >
> > b.
>
> Here is my simple script:
>
> import sys
> from qt import *
> class Optimizer(QWidget):
>def __init__(self, parent = 0):
>   QWidget.__init__(self)
>   QGridLayout(self)
> if __name__ == '__main__':
>a = QApplication (sys.argv)
>mywidget = Optimizer()
>a.exec_loop()
>
> This produces this:
> > python qt_script_bs_070228.py
>
> QPaintDevice: Must construct a QApplication before a QPaintDevice
>
> Any suggestions here?

It works fine for me.

> Thanks
>
>
>
> BTW: One question:
> when I use "import qt" instead of "from qt import *" I get this error:
> Traceback (most recent call last):
>   File "mscarideidtool_bs_070228.py", line 4, in ?
> class Optimizer(QWidget):
> NameError: name 'QWidget' is not defined
>
> What is the difference between "import qt" and "from qt import *" ? I
> thought that these are the same.

The first creates a new namespace called "qt" and imports the module's objects 
into it. To reference those objects you have to include the namespace name.

The second imports the module's objects into the current namespace.

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


Re: Installing java2python (Newbie)

2007-02-28 Thread John Machin
On Feb 28, 4:27 pm, "[EMAIL PROTECTED]" <[EMAIL PROTECTED]>
wrote:
> > Hi Jeremy, that's the problem I'm having. Where should I type that "
> > python setup.py install" ? Once again I'm using Windows system and not
> > Unix. Should I move the file to a specific folder under Python 2.5 and
> > then type  " python setup.py install" in IDLE or Command Line window?
> > I get the error "SyntaxError: invalid syntax" with the word "setup"
>
> hi andy,
>
> you want to run the windows command prompt, which is called "cmd.exe"
> in windows xp.  press the "start menu", then select "run", then type
> "cmd.exe" without the quotes.
>

Hi Troy, Windows users don't really "want" to do that. They'd prefer
to download a Windows installer, and "double-click on it".

http://docs.python.org/dist/postinstallation-script.html

This might save some wear'n'tear on their nervous systems, and
yours :-)

HTH,
John


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


using telnetlib

2007-02-28 Thread Phoe6
Hi All,
I am trying to use the telnetlib module.

Manually when I do
telnet 172.31.128.244
I get:

Login: (I type root)
Password: ( I type Password)
And it enters to the Telnet Session:
[root]#

Now, I am trying to use telnetlib module
>>> import telnetlib
>>> tn = telnetlib.Telnet("172.31.128.244")
>>> tn.read_until("Login: ")
'\r\nLogin: '
>>> tn.write("root\n:")
>>>tn.read_until("Password: ")

Cursor stays over here forever!. Delays are not working. I tried all
the codes mentioned n c.l.p, but i have not yet been able to get
telnetlib working.
Any suggestions as how to troubleshoot and resolve this issue?

Thanks,
Senthil

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


Re: QPaintDevice: Must construct a QApplication before a QPaintDevice

2007-02-28 Thread boris . smirnov
On Feb 28, 10:22 am, Phil Thompson <[EMAIL PROTECTED]>
wrote:
> On Wednesday 28 February 2007 9:00 am, [EMAIL PROTECTED] wrote:
>
>
>
>
>
> > On Feb 28, 9:07 am, [EMAIL PROTECTED] wrote:
> > > On Feb 28, 8:56 am, Phil Thompson <[EMAIL PROTECTED]>
>
> > > wrote:
> > > > On Tuesday 27 February 2007 11:09 pm, shredwheat wrote:
> > > > > When your programs stops with the error, it should also be printing a
> > > > > stack trace. This is a list of all the functions that have been
> > > > > called when Python had the problem.
>
> > > > > You shouldn't have to do anything extra to get the stack trace.
>
> > > > The error is raised in Qt and aborts immediately. It never gets back to
> > > > Python to generate a trace.
>
> > > > He needs to produce a short and complete test which demonstrates the
> > > > problem, then we can point out where the QPaintDevice is being created.
>
> > > > Phil
>
> > > OK, but before I do a complete test, could anybody tell/explain me why
> > > the same file is working on Windows?
> > > Did anybody already meet with something similar Win vs. Linux?
>
> > > b.
>
> > Here is my simple script:
>
> > import sys
> > from qt import *
> > class Optimizer(QWidget):
> >def __init__(self, parent = 0):
> >   QWidget.__init__(self)
> >   QGridLayout(self)
> > if __name__ == '__main__':
> >a = QApplication (sys.argv)
> >mywidget = Optimizer()
> >a.exec_loop()
>
> > This produces this:
> > > python qt_script_bs_070228.py
>
> > QPaintDevice: Must construct a QApplication before a QPaintDevice
>
> > Any suggestions here?
>
> It works fine for me.
>
> > Thanks
>
> > BTW: One question:
> > when I use "import qt" instead of "from qt import *" I get this error:
> > Traceback (most recent call last):
> >   File "mscarideidtool_bs_070228.py", line 4, in ?
> > class Optimizer(QWidget):
> > NameError: name 'QWidget' is not defined
>
> > What is the difference between "import qt" and "from qt import *" ? I
> > thought that these are the same.
>
> The first creates a new namespace called "qt" and imports the module's objects
> into it. To reference those objects you have to include the namespace name.
>
> The second imports the module's objects into the current namespace.
>
> Phil- Hide quoted text -
>
> - Show quoted text -

OK, I have to apologize because I didn't mention that I use python
version 2.2.1, could it be the problem here? Bugs or something? I have
to use this version since it was delivered with a software that we use
here.

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


Re: Installing java2python (Newbie)

2007-02-28 Thread Troy Melhase
> Hi Troy, Windows users don't really "want" to do that. They'd prefer
> to download a Windows installer, and "double-click on it".

Hi John,

Understood and agreed.  I was thinking about Andy's problem, and I
realized that many users would benefit from a gui to do side-by-side
translation.  If I ever have the time, I could write one I think.

 > This might save some wear'n'tear on their nervous systems, and
> yours :-)

Like so many projects, it works for me the way it is -- I'm driving
j2py via makefiles, and a gui just isn't something I need.  But of
course patches are welcome -- even gui ones!
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: newbie question(file-delete trailing comma)

2007-02-28 Thread Mikael Olofsson
kavitha thankaian wrote:
> my script writes a dictionary to a file.but i need only the values 
> from the dictionary which should be sepearted by a comma,,,so i did as 
> following:
> [snip code that generates the incorrect original file]
> when i execute the above code,my test.txt file has the following:
> a,b,c,d,
> now i need to delete the comma at the end,,,this is my problem,,,

This is the first time you mention that you have control over the 
generation of the original file. Then I suggest that you fix the problem 
before generating the file. For instance, consider the following 
interactive session.

 >>> some={1:'a',2:7,3:'c',4:'d'}
 >>> some
{1: 'a', 2: 7, 3: 'c', 4: 'd'}
 >>> some.values()
['a', 7, 'c', 'd']
 >>> [str(x) for x in some.values()]
['a', '7', 'c', 'd']
 >>> ','.join([str(x) for x in some.values()])
'a,7,c,d'

Then write that to your file instead.

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


msvcr71.dll

2007-02-28 Thread Konte
Are there news about the impossibility of redistributing msvcr71.ddl 
with own stand-alone application written in python for who doesn't have 
MSVC7 license?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: QPaintDevice: Must construct a QApplication before a QPaintDevice

2007-02-28 Thread Phil Thompson
On Wednesday 28 February 2007 9:26 am, [EMAIL PROTECTED] wrote:
> On Feb 28, 10:22 am, Phil Thompson <[EMAIL PROTECTED]>
>
> wrote:
> > On Wednesday 28 February 2007 9:00 am, [EMAIL PROTECTED] wrote:
> > > On Feb 28, 9:07 am, [EMAIL PROTECTED] wrote:
> > > > On Feb 28, 8:56 am, Phil Thompson <[EMAIL PROTECTED]>
> > > >
> > > > wrote:
> > > > > On Tuesday 27 February 2007 11:09 pm, shredwheat wrote:
> > > > > > When your programs stops with the error, it should also be
> > > > > > printing a stack trace. This is a list of all the functions that
> > > > > > have been called when Python had the problem.
> > > > > >
> > > > > > You shouldn't have to do anything extra to get the stack trace.
> > > > >
> > > > > The error is raised in Qt and aborts immediately. It never gets
> > > > > back to Python to generate a trace.
> > > > >
> > > > > He needs to produce a short and complete test which demonstrates
> > > > > the problem, then we can point out where the QPaintDevice is being
> > > > > created.
> > > > >
> > > > > Phil
> > > >
> > > > OK, but before I do a complete test, could anybody tell/explain me
> > > > why the same file is working on Windows?
> > > > Did anybody already meet with something similar Win vs. Linux?
> > > >
> > > > b.
> > >
> > > Here is my simple script:
> > >
> > > import sys
> > > from qt import *
> > > class Optimizer(QWidget):
> > >def __init__(self, parent = 0):
> > >   QWidget.__init__(self)
> > >   QGridLayout(self)
> > > if __name__ == '__main__':
> > >a = QApplication (sys.argv)
> > >mywidget = Optimizer()
> > >a.exec_loop()
> > >
> > > This produces this:
> > > > python qt_script_bs_070228.py
> > >
> > > QPaintDevice: Must construct a QApplication before a QPaintDevice
> > >
> > > Any suggestions here?
> >
> > It works fine for me.
> >
> > > Thanks
> > >
> > > BTW: One question:
> > > when I use "import qt" instead of "from qt import *" I get this error:
> > > Traceback (most recent call last):
> > >   File "mscarideidtool_bs_070228.py", line 4, in ?
> > > class Optimizer(QWidget):
> > > NameError: name 'QWidget' is not defined
> > >
> > > What is the difference between "import qt" and "from qt import *" ? I
> > > thought that these are the same.
> >
> > The first creates a new namespace called "qt" and imports the module's
> > objects into it. To reference those objects you have to include the
> > namespace name.
> >
> > The second imports the module's objects into the current namespace.
> >
> > Phil- Hide quoted text -
> >
> > - Show quoted text -
>
> OK, I have to apologize because I didn't mention that I use python
> version 2.2.1, could it be the problem here? Bugs or something? I have
> to use this version since it was delivered with a software that we use
> here.

So what versions of Qt, PyQt and SIP are you using? Were these included with 
the software you are using? If so, what is that software?

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


Re: newbie question(file-delete trailing comma)

2007-02-28 Thread kavitha thankaian

  Thanks Sanket,,,
  But still doesnt solve my problem,,,
  now my file contains:
   
  aa,ba,b,ca,b,c, and so on,,,
  the comma at the end is deleted,,,but the file contains some junk values,,,
   
  kavitha

sanket kathalkar <[EMAIL PROTECTED]> wrote:
  Solution to this problem is:
---
some=getAllData()-->dictionary
tmpstr=""
f=open("test.txt", "w")
for value in some.values():
tmpstr+= '\%s\,' % value
f.writelines(tmpstr.strip(","))>strings seperated by comma
---

Thanks
sanket


kavitha thankaian wrote:
> ok,,,
> my script writes a dictionary to a file.but i need only the values 
> from the dictionary which should be sepearted by a comma,,,so i did as 
> following:
> some=getAllData()-->dictionary
> f=open("test.txt", "w")
> for value in some.values():
> f.writelines('\%s\,' % value )>strings seperated by comma
> when i execute the above code,my test.txt file has the following:
> a,b,c,d,
> now i need to delete the comma at the end,,,this is my problem,,,
> kavitha
>
>
> */Mikael Olofsson /* wrote:
>
> 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
>
>
> 
> Here’s a new way to find what you're looking for - Yahoo! Answers 
> 




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

Three days left for Zope3 boot camp registration

2007-02-28 Thread Chris Calloway
Registration ends Friday:

http://trizpug.org/boot-camp/camp5

-- 
Sincerely,

Chris Calloway
http://www.seacoos.org
office: 332 Chapman Hall   phone: (919) 962-4323
mail: Campus Box #3300, UNC-CH, Chapel Hill, NC 27599



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


msvcr71.dll

2007-02-28 Thread Konte
Are there news about the impossibility of redistributing msvcr71.dll 
with own stand-alone application written in python, without having MSVC7 
license?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: spawnl and waitpid

2007-02-28 Thread naima . mans
On 28 fév, 10:13, [EMAIL PROTECTED] wrote:
> On 27 fév, 19:31, Dennis Lee Bieber <[EMAIL PROTECTED]> wrote:
>
>
>
>
>
> > On 27 Feb 2007 05:39:51 -0800, [EMAIL PROTECTED] declaimed the
> > following in comp.lang.python:
>
> > > On 27 fév, 12:27, Thinker <[EMAIL PROTECTED]> wrote:
> > > > -BEGIN PGP SIGNED MESSAGE-
> > 
>
> > > > Your program will be blocked here until child process being terminated.
> > > > You should print your messages before this line.
>
> > > i have tried as you said (cf bellow) and same result...
>
> > No, you did NOT do as was suggested (unless you misunderstood which
> > line "before this" meant.
>
> > > 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)
>
> > As soon as you execute os.waitpid(), your script WAITS. NOTHING
> > after that point will happen until the process you are waiting on exits.
>
> > > 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()
>
> > pid = os.spawnl(os.P_NOWAIT,
> > "c:\\python25\\python.exe",
> > "python",
> > "Main.py")#apparently a Windows 
> > OS
> > print "Please wait ..."
> > sys.stdout.flush()
> > ret = os.waitpid(pid, 0)
>
> > if ret[1]:
> > print "Non-zero exit code: %s %s" % (ret[1], ret[0])
> > else:
> > print "Successful exit"
> > sys.stdout.flush()
>
> > {I'm presuming a 0 return code means success... VMS used 1 for success
> > and 0 for failure [actually, odd numbers were informational status, even
> > numbers were error status]}
>
> > > ---
> > > thanks
>
> > --
> > WulfraedDennis Lee Bieber   KD6MOG
> > [EMAIL PROTECTED]  [EMAIL PROTECTED]
> > HTTP://wlfraed.home.netcom.com/
> > (Bestiaria Support Staff:   [EMAIL PROTECTED])
> > HTTP://www.bestiaria.com/
>
> hello
>
> thanks a lot..
>
> sorry for misunderstanding, my english isn't good (i'm french).
>
> i have tried like this:
> --
> #! C:/Python25/python.exe
> # -*- coding: cp1252 -*-
>
> import cgitb; cgitb.enable()
> import os,sys
>
> print "Content-Type: text/html"
> print
>
> pid =  os.spawnl(os.P_NOWAIT,"c:\\python25\
> \python.exe","python","Main.py")
> print "please wait.."
> sys.stdout.flush()
> ret = os.waitpid(pid,0)
># retourne le process id
> if ret[1]:
> print "Non-zero exit code: %s %s" % (ret[1], ret[0])
> else:
> print "Successful exit"
> sys.stdout.flush()
> 
>
> and the result:
>
> At the end of the script execution it write:
> ==  please wait.. Successful exit
>
> The browser doesn't let the script executing on background to write
> the message at once.. it waits the end.
>
> what happend?- Masquer le texte des messages précédents -
>
> - Afficher le texte des messages précédents -

re hello

perhaps there is a link with the script being called..
as there is a function which use stdout:
here it is

def erreur_ccm(cmd):
try:
child_stdin, child_stdout, child_stderr =os.popen3(cmd)
stderr=child_stderr.read()
stdout=child_stdout.read()
if stderr == "":
retour = stdout
else :
retour = 0
except OSError, e:
child_stdin.close()
child_stdout.close()
child_stderr.close()

return retour
--

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


Re: QPaintDevice: Must construct a QApplication before a QPaintDevice

2007-02-28 Thread boris . smirnov
On Feb 28, 10:45 am, Phil Thompson <[EMAIL PROTECTED]>
wrote:
> On Wednesday 28 February 2007 9:26 am, [EMAIL PROTECTED] wrote:
>
>
>
>
>
> > On Feb 28, 10:22 am, Phil Thompson <[EMAIL PROTECTED]>
>
> > wrote:
> > > On Wednesday 28 February 2007 9:00 am, [EMAIL PROTECTED] wrote:
> > > > On Feb 28, 9:07 am, [EMAIL PROTECTED] wrote:
> > > > > On Feb 28, 8:56 am, Phil Thompson <[EMAIL PROTECTED]>
>
> > > > > wrote:
> > > > > > On Tuesday 27 February 2007 11:09 pm, shredwheat wrote:
> > > > > > > When your programs stops with the error, it should also be
> > > > > > > printing a stack trace. This is a list of all the functions that
> > > > > > > have been called when Python had the problem.
>
> > > > > > > You shouldn't have to do anything extra to get the stack trace.
>
> > > > > > The error is raised in Qt and aborts immediately. It never gets
> > > > > > back to Python to generate a trace.
>
> > > > > > He needs to produce a short and complete test which demonstrates
> > > > > > the problem, then we can point out where the QPaintDevice is being
> > > > > > created.
>
> > > > > > Phil
>
> > > > > OK, but before I do a complete test, could anybody tell/explain me
> > > > > why the same file is working on Windows?
> > > > > Did anybody already meet with something similar Win vs. Linux?
>
> > > > > b.
>
> > > > Here is my simple script:
>
> > > > import sys
> > > > from qt import *
> > > > class Optimizer(QWidget):
> > > >def __init__(self, parent = 0):
> > > >   QWidget.__init__(self)
> > > >   QGridLayout(self)
> > > > if __name__ == '__main__':
> > > >a = QApplication (sys.argv)
> > > >mywidget = Optimizer()
> > > >a.exec_loop()
>
> > > > This produces this:
> > > > > python qt_script_bs_070228.py
>
> > > > QPaintDevice: Must construct a QApplication before a QPaintDevice
>
> > > > Any suggestions here?
>
> > > It works fine for me.
>
> > > > Thanks
>
> > > > BTW: One question:
> > > > when I use "import qt" instead of "from qt import *" I get this error:
> > > > Traceback (most recent call last):
> > > >   File "mscarideidtool_bs_070228.py", line 4, in ?
> > > > class Optimizer(QWidget):
> > > > NameError: name 'QWidget' is not defined
>
> > > > What is the difference between "import qt" and "from qt import *" ? I
> > > > thought that these are the same.
>
> > > The first creates a new namespace called "qt" and imports the module's
> > > objects into it. To reference those objects you have to include the
> > > namespace name.
>
> > > The second imports the module's objects into the current namespace.
>
> > > Phil- Hide quoted text -
>
> > > - Show quoted text -
>
> > OK, I have to apologize because I didn't mention that I use python
> > version 2.2.1, could it be the problem here? Bugs or something? I have
> > to use this version since it was delivered with a software that we use
> > here.
>
> So what versions of Qt, PyQt and SIP are you using? Were these included with
> the software you are using? If so, what is that software?
>
> Phil- Hide quoted text -
>
> - Show quoted text -

Stupid question but how can I find out what are the versions of those?
I only found qt.py file and there was this:
# Generated by SIP 3.3 (build 25) on Fri Jul 26 12:44:13 2002
The version of PyQt and SIP can't find out, but there is a directory
PyQt wit .pyc files and SIP.h file.

The sofware is MSC.ADAMS from msc.software

b.

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


Re: Python, SOAP & SSL

2007-02-28 Thread Simon Brunning
On 2/28/07, Barker, CJ <[EMAIL PROTECTED]> wrote:
> Was this ever solved?

You might get more feedback about this on the Python web services list
at .

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


Re: Installing java2python (Newbie)

2007-02-28 Thread John Machin
On Feb 28, 8:33 pm, "Troy Melhase" <[EMAIL PROTECTED]> wrote:
> > Hi Troy, Windows users don't really "want" to do that. They'd prefer
> > to download a Windows installer, and "double-click on it".
>
> Hi John,
>
> Understood and agreed.  I was thinking about Andy's problem, and I
> realized that many users would benefit from a gui to do side-by-side
> translation.  If I ever have the time, I could write one I think.
>
>  > This might save some wear'n'tear on their nervous systems, and
>
> > yours :-)
>
> Like so many projects, it works for me the way it is -- I'm driving
> j2py via makefiles, and a gui just isn't something I need.  But of
> course patches are welcome -- even gui ones!

Did you think I was suggesting that you write a GUI version of
java2python? Please carefully (re)?read the documentation link that I
gave you. The idea is that with a simple variation of your setup.py
build comamnd, you create a Windows installer for your existing
package, and make it available for download. Then, all the Windows
user has to do is to double-click on it, and it guides them through
the installation. This would save wear'n'tear on you having to try to
explain to some newbie Windows user how to install your package.

HTH take 2,
John

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


Re: msvcr71.dll

2007-02-28 Thread Simon Brunning
On 2/28/07, Konte <[EMAIL PROTECTED]> wrote:
> Are there news about the impossibility of redistributing msvcr71.ddl
> with own stand-alone application written in python for who doesn't have
> MSVC7 license?

Last I heard the consensus was that it's OK to distribute msvcr71.ddl.
But IANAL, and neither is anyone else that I've heard discussing the
matter.

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


Re: spawnl and waitpid

2007-02-28 Thread naima . mans
On 27 fév, 19:32, Thinker <[EMAIL PROTECTED]> wrote:
> -BEGIN PGP SIGNED MESSAGE-
> Hash: SHA1
>
> [EMAIL PROTECTED] wrote:
> > On 27 f憝, 18:54, Thinker <[EMAIL PROTECTED]> wrote:
> > hello
> > ha ok...
> > i tried this one and the browser don't write the message at once...
> > I have alos tried with thread and have the same result... :(
>
> Does child-process terminate it-self in a very short time ?
> It can be a race condition, here.
> You can try to sleep for a while in child-process to make sure parent
> being executed. Parent process may not schedule to run immediately
> after spawn. And, you can print some thing before os.spawnl() to make
> sure that message can be delivered successfully.
>
> - --
> 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
>
> iD8DBQFF5Hkp1LDUVnWfY8gRAtDdAKCKy8/ap5VJvZV14nhSCWYfLZdyYACffJ+Y
> 0sHMgyaQBmsOMwq/rxEvm1Q=
> =qjTU
> -END PGP SIGNATURE-

hello

oki, i have test a simple script that only wait...
when i tun the script without the server it write on 2 time which is
normal:

Content-Type: text/html
wait
The main program continues to run in foreground.
(((then after 5 second ))]]]
Fin background
Main program waited until background was done.
==

BUT when i call it under the server web it write after 5 second all
the message in 1 time :
===
wait The main program continues to run in foreground. Fin background
Main program waited until background was done.
===

---THE SCRIPT ---
import cgitb; cgitb.enable()
import os,sys
import threading, zipfile,time,Main

print "Content-Type: text/html"
print
print "wait"
sys.stdout.flush()

class AsyncZip(threading.Thread):
def __init__(self, infile):
threading.Thread.__init__(self)
self.infile = infile
def run(self):
time.sleep(5.0)
print 'Fin background'

background = AsyncZip('Main.py')
background.start()
print 'The main program continues to run in foreground.'
sys.stdout.flush()
background.join()# Wait for background task to finish
print 'Main program waited until background was done.'
sys.stdout.flush()
---

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

Re: os.system and quoted strings

2007-02-28 Thread Duncan Booth
"Dan Bishop" <[EMAIL PROTECTED]> wrote:

> Windows system calls treat / and \ interchangeably, but the command
> prompt insists on backslashes.

No. Commands built-in to the command prompt and certain other programs 
(mostly but not exclusively from Microsoft) insist on backslashes. Most 
programs, especially those originating from the unixverse, will accept 
backslashes and forward slashes interchangeably from the command prompt. 
Even a lot of Microsoft's own programs are happy to accept backslashed 
command line arguments.

If in doubt just call os.path.normpath() on a path string before using it.
Also it is usually worth putting command line arguments inside " marks to 
avoid problems with spaces or other special characters in path names.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Installing java2python (Newbie)

2007-02-28 Thread Troy Melhase
> Did you think I was suggesting that you write a GUI version of
> java2python? Please carefully (re)?read the documentation link that I
> gave you. The idea is that with a simple variation of your setup.py
> build comamnd, you create a Windows installer for your existing
> package, and make it available for download. Then, all the Windows
> user has to do is to double-click on it, and it guides them through
> the installation. This would save wear'n'tear on you having to try to
> explain to some newbie Windows user how to install your package.

You're right, and what I didn't communicate was the thought process
that was between "users need an installer" and "users need a gui".  I
jumped to the end and only typed that.  Sorry for any confusion.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Installing java2python (Newbie)

2007-02-28 Thread John Machin
On Feb 28, 9:39 pm, "Troy Melhase" <[EMAIL PROTECTED]> wrote:
> > Did you think I was suggesting that you write a GUI version of
> > java2python? Please carefully (re)?read the documentation link that I
> > gave you. The idea is that with a simple variation of your setup.py
> > build comamnd, you create a Windows installer for your existing
> > package, and make it available for download. Then, all the Windows
> > user has to do is to double-click on it, and it guides them through
> > the installation. This would save wear'n'tear on you having to try to
> > explain to some newbie Windows user how to install your package.
>
> You're right, and what I didn't communicate was the thought process
> that was between "users need an installer" and "users need a gui".  I
> jumped to the end and only typed that.  Sorry for any confusion.

I doubt that users need a GUI (but TMMV of course).

No need to say sorry -- I wasn't confused :-)
Cheers,
john

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


random textimage

2007-02-28 Thread gert
import string
import random
import PIL
from PIL import Image, ImageFont, ImageDraw
from PIL import ImageEnhance, ImageOps, ImageStat
from StringIO import StringIO
import os

pwd = os.path.dirname(os.path.abspath(__file__))
fpath=os.path.join(pwd,'img.ttf')
iname=os.path.join(pwd,'pass.jpg')

def gen():
text = str(random.randint(0,1000))
im = Image.new("RGB", (125, 34), "#fff")
ttf = ImageFont.truetype(fpath, 16)
draw = ImageDraw.Draw(im)
draw.text((10,10), text, font=ttf, fill="green")
img = StringIO()
im.save(img, "JPEG")
f = open(iname)
f.write(im)
f.close()
return text

if __name__ == "__main__":
print gen()

[EMAIL PROTECTED]:~/Desktop/svn/xhtml$ python2.5 textimg.py
Traceback (most recent call last):
  File "textimg.py", line 27, in 
print gen()
  File "textimg.py", line 22, in gen
f.write(im)
TypeError: argument 1 must be string or read-only character buffer,
not instance
[EMAIL PROTECTED]:~/Desktop/svn/xhtml$

i am stuck anybody can help me ?

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


py2exe, library.zip and python.exe

2007-02-28 Thread Martin Evans
I have converted a Python script using py2exe and have it set to not bundle 
or compress. The result is my exe and all the support files including 
library.zip (exactly as planned - nice job py2exe).

Question:  My py2exe application needs to be able to execute extra copies of 
python.exe. I have placed python.exe in the same directory. It obviously 
picks up the main python24.dll but how can I configure things so that it 
would use the same library.zip for all the library files?  This would save 
me having two sets of files.

(The py2exe application happens to be a twisted server app running as a 
service which has the ability to launch python scripts as a logged on user)

Thanks,  Martin.


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


Re: installing "pysqlite"

2007-02-28 Thread Nader Emami
Paul Boddie 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 (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
> 
Hello,

I am back with another problem. I suppose that I can tell it!
I have installed both, 'sqlite' and 'pysqlite' without any problem. But 
If I try to test whether the 'pysqlite' interface works, I get the next 
error message:

 >>>from pysqlite2 import dbapi2 as sqlite
Traceback (most recent call last):
   File "", line 1, in ?
   File 
"/usr/people/emami/lib/python2.4/site-packages/pysqlite2/dbapi2.py", 
line 27, in ?
 from pysqlite2._sqlite import *
ImportError: 
/usr/people/emami/lib/python2.4/site-packages/pysqlite2/_sqlite.so: 
undefined symbol: sqlite3_set_authorizer

I don't understand it. Could you tell me how I can solve this last 
point? I hope so!

With regards,

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


Re: random textimage

2007-02-28 Thread James Stroud
gert wrote:
> import string
> import random
> import PIL
> from PIL import Image, ImageFont, ImageDraw
> from PIL import ImageEnhance, ImageOps, ImageStat
> from StringIO import StringIO
> import os
> 
> pwd = os.path.dirname(os.path.abspath(__file__))
> fpath=os.path.join(pwd,'img.ttf')
> iname=os.path.join(pwd,'pass.jpg')
> 
> def gen():
> text = str(random.randint(0,1000))
> im = Image.new("RGB", (125, 34), "#fff")
> ttf = ImageFont.truetype(fpath, 16)
> draw = ImageDraw.Draw(im)
> draw.text((10,10), text, font=ttf, fill="green")
> img = StringIO()
> im.save(img, "JPEG")
> f = open(iname)
> f.write(im)
> f.close()
> return text
> 
> if __name__ == "__main__":
> print gen()
> 
> [EMAIL PROTECTED]:~/Desktop/svn/xhtml$ python2.5 textimg.py
> Traceback (most recent call last):
>   File "textimg.py", line 27, in 
> print gen()
>   File "textimg.py", line 22, in gen
> f.write(im)
> TypeError: argument 1 must be string or read-only character buffer,
> not instance
> [EMAIL PROTECTED]:~/Desktop/svn/xhtml$
> 
> i am stuck anybody can help me ?
> 

Are you sure you don't want f.write(img) ?

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


Re: using telnetlib

2007-02-28 Thread Bjoern Schliessmann
Phoe6 wrote:

 import telnetlib
 tn = telnetlib.Telnet("172.31.128.244")
 tn.read_until("Login: ")
> '\r\nLogin: '
 tn.write("root\n:")
   ^^^

With telnet, use "\r\n" for line breaks at *all* times to be on the
safe side. Also, what's the ":" at the end for?
Regards,


Björn

-- 
BOFH excuse #88:

Boss' kid fucked up the machine

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


Re: Curses sorely lacking an event loop?

2007-02-28 Thread James Stroud
Michele Simionato wrote:
> 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
> 

Perfect. Just what I was looking for.

Thank you.

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


Re: Curses sorely lacking an event loop?

2007-02-28 Thread James Stroud
Michael Zawrotny wrote:
> 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
> 

Thank you. This is good to know.

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


Re: newbie question(file-delete trailing comma)

2007-02-28 Thread kavitha thankaian
thanks,,
  now i have one more problem,,,
  the strings should be seperated in an order,,,
  some={1:'a', 2:7, 3:'c', 4:'d'}
  i need the output to be a,c,d,7
   
  before my code was:
  field_order = [1,3,4,2]
for field in field_order:
f.writelines('\"%s\",' % someprt[field] )
   
  do you have an idea now how should it look like???
   
   
  

Mikael Olofsson <[EMAIL PROTECTED]> wrote:
  kavitha thankaian wrote:
> my script writes a dictionary to a file.but i need only the values 
> from the dictionary which should be sepearted by a comma,,,so i did as 
> following:
> [snip code that generates the incorrect original file]
> when i execute the above code,my test.txt file has the following:
> a,b,c,d,
> now i need to delete the comma at the end,,,this is my problem,,,

This is the first time you mention that you have control over the 
generation of the original file. Then I suggest that you fix the problem 
before generating the file. For instance, consider the following 
interactive session.

>>> some={1:'a',2:7,3:'c',4:'d'}
>>> some
{1: 'a', 2: 7, 3: 'c', 4: 'd'}
>>> some.values()
['a', 7, 'c', 'd']
>>> [str(x) for x in some.values()]
['a', '7', 'c', 'd']
>>> ','.join([str(x) for x in some.values()])
'a,7,c,d'

Then write that to your file instead.

/MiO
-- 
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: py2exe, library.zip and python.exe

2007-02-28 Thread Thomas Heller
Martin Evans schrieb:
> I have converted a Python script using py2exe and have it set to not bundle 
> or compress. The result is my exe and all the support files including 
> library.zip (exactly as planned - nice job py2exe).
> 
> Question:  My py2exe application needs to be able to execute extra copies of 
> python.exe. I have placed python.exe in the same directory. It obviously 
> picks up the main python24.dll but how can I configure things so that it 
> would use the same library.zip for all the library files?  This would save 
> me having two sets of files.
> 
> (The py2exe application happens to be a twisted server app running as a 
> service which has the ability to launch python scripts as a logged on user)
> 
> Thanks,  Martin.
> 
> 
You have to put library.zip on sys.path.  Maybe you could create a site.py file
in that directory which can do this, I assume the python.exe will try to load 
that.

There may be other possibilities as well.

Thomas

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


Re: finding out the precision of floats

2007-02-28 Thread Bart Ogryczak
On Feb 27, 7:58 pm, "Arnaud Delobelle" <[EMAIL PROTECTED]> wrote:
> On 27 Feb, 14:09, "Bart Ogryczak" <[EMAIL PROTECTED]> wrote:
>
> > 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.
>
> Actually 28 significant digits is the default, it can be set to
> anything you like.  Moreover 53 significant bits (as this is what 53
> counts) is about 16 decimal digits.

My mistake.

> > >>> 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
>
> Yes. The internal representation of a Decimal is a tuple of one-digit
> strings!
> This is one of the reasons (by no means the main) why I decided to
> write my own class.

Why not GMP?

> > 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
>
> OTOH float is not the panacea:

My point is, that neither is Decimal. It doesn't solve the problem,
creating additional problem with efficiency.

> >>> 0.1+0.1+0.1==0.3
> False
> >>> 3*0.1==0.3
>
> False
>
> Decimals will behave better in this case.

Decimal will work fine as long as you deal only with decimal numbers
and the most basic arithmetic. Any rational number with base that is
not power of 10, or any irrational number won't have an exact
representation. So as long as you're dealing with something like
invoices, Decimal does just fine. When you start real calculations,
not only scientific, but even financial ones[1], it doesn't do any
better then binary float, and it's bloody slow.

[1] eg. consider calculating interests rate, which often is defined as
math.pow(anualRate,days/365.0). It's not rational number (unless days
happen to be mutliple of 365), therefore has no exact representation.
BTW, math.* functions do not return Decimals.


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


Re: random textimage

2007-02-28 Thread gert
On Feb 28, 12:13 pm, James Stroud <[EMAIL PROTECTED]> wrote:
> gert wrote:
> > [EMAIL PROTECTED]:~/Desktop/svn/xhtml$ python2.5 textimg.py
> > Traceback (most recent call last):
> >   File "textimg.py", line 27, in 
> > print gen()
> >   File "textimg.py", line 22, in gen
> > f.write(im)
> > TypeError: argument 1 must be string or read-only character buffer,
> > not instance
> > [EMAIL PROTECTED]:~/Desktop/svn/xhtml$
>
> > i am stuck anybody can help me ?
>
> Are you sure you don't want f.write(img) ?
>
> James

no this seems to work lol :)

import ImageFont, ImageDraw, Image

def gen(text):
image_file = "test.jpg"
image = Image.open(image_file)
font = "font.ttf"
draw = ImageDraw.Draw(image)
font = ImageFont.truetype(font, 12)
draw.text((1, 1), text,font=font)
image.save("temp.jpg")

if __name__ == "__main__":
import random
print gen(str(random.randint(0,1000)))

The next problem would be that i need this to work  in cherrypy because if two persons login at the
same time the first user get to see the second user textimage DOH!

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


Re: installing "pysqlite"

2007-02-28 Thread Paul Boddie
On 28 Feb, 12:07, Nader Emami <[EMAIL PROTECTED]> wrote:
>
> I am back with another problem. I suppose that I can tell it!
> I have installed both, 'sqlite' and 'pysqlite' without any problem. But
> If I try to test whether the 'pysqlite' interface works, I get the next
> error message:

[...]

> /usr/people/emami/lib/python2.4/site-packages/pysqlite2/_sqlite.so:
> undefined symbol: sqlite3_set_authorizer
>
> I don't understand it. Could you tell me how I can solve this last
> point? I hope so!

It looks like Python (although it's really the dynamic linker) can't
locate the SQLite libraries. If you have installed SQLite into a non-
standard place, which I'm guessing is the case, then you will need to
set your LD_LIBRARY_PATH environment variable to refer to the
directory where the libraries were installed.

So, if you installed SQLite into /usr/people/emami and you see files
like libsqlite3.so in /usr/people/emami/lib, then you need to change
your LD_LIBRARY_PATH as follows:

export LD_LIBRARY_PATH=${LD_LIBRARY_PATH}:/usr/people/emami/lib

(The actual directory should be the same as the one you specified for
library_dirs in the setup.cfg file for pysqlite.)

If you're not using bash as your shell, the syntax for the command may
be different. Don't forget to add this command to your shell
configuration file (eg. .bashrc) so that your system remembers this
information.

Paul

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


Re: py2exe, library.zip and python.exe

2007-02-28 Thread Matthias Vodel
Hey,

[Offtopic:] Use PyInstaller...very easy to use - better than py2exe!!

see here:

http://pyinstaller.hpcf.upr.edu/cgi-bin/trac.cgi

Bye,

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


Re: Running Python scripts from BASH

2007-02-28 Thread Hendrik van Rooyen
"Ishpeck" <[EMAIL PROTECTED]> wrote:

8<--- a bash problem -

If it were Python, the advice would have been to use the 
print statement to figure out what the content of the 
variables were.

As it is Bash, you may have to stoop to something like
echo to see what is in $i...

hth - Hendrik

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


Creating arrays (builtin) in C Extensions

2007-02-28 Thread iwl
Hello,

there is an builtin documented array module in phyton,
but no documentation how such an array can be
created in C-Extension functions.
So I have to use Lists at time, but this is I think
inefficient with large data sets.

Is there some interface aviable which I can link to my
Programm without any change to standard python?

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


Re: book for a starter

2007-02-28 Thread Ramon Diaz-Uriarte
On 2/27/07, Wensui Liu <[EMAIL PROTECTED]> wrote:
> Thank you all for your wonderful suggestion and advice.
>
> Have a great evening!
>
> wensui
>
> On 27 Feb 2007 12:08:46 -0800, RickMuller <[EMAIL PROTECTED]> wrote:
> > On Feb 27, 12:08 pm, "Sriram" <[EMAIL PROTECTED]> wrote:
> > > Hi,
> > >
> > > If you have experience programming, just read the online tutorial 
> > > athttp://docs.python.org/tut/tut.html
> > >
> >
> > Seconded. It really is a wonderful introduction to Python. Once you've
> > digested that, the Python Library Reference in the docs is your best
> > friend. The nice thing about getting familiar with the official python
> > documentation is that it's always available to you.
> >
> > --
> > http://mail.python.org/mailman/listinfo/python-list
> >
>


WenSui, from the R list I think you are not a novice programmer. I'd
recommend Python in a Nutshell. Note there is a recent edition that
covers Python 2.5.

(I actually use almost exclusively Nuthsell --- and the pocket
reference which is small and inexpensive and i carry on my backpack
all the time).

Best,

R.


>
> --
> WenSui Liu
> A lousy statistician who happens to know a little programming
> (http://spaces.msn.com/statcompute/blog)
> --
> http://mail.python.org/mailman/listinfo/python-list
>


-- 
Ramon Diaz-Uriarte
Statistical Computing Team
Structural Biology and Biocomputing Programme
Spanish National Cancer Centre (CNIO)
http://ligarto.org/rdiaz
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: design question: no new attributes

2007-02-28 Thread Alan Isaac
Ben Finney writes:
> Really, though, adding attributes to an instance is a normal thing to
> do in Python, and you've not yet shown why you want that normal
> functionality to be special-cased here.


I accept your earlier point that if an interface changes
one can just trap use of the old interface.  But I remain
interested in preventing dynamic attribute creation in
particular cases.

I have not tried to argue that dynamic attribute creation
can be dangerous for a couple reasons.
- There is no reason to expect this list to be receptive.
- I do not have the experience to make a general argument.
- I do not always find it a problem, but only in certain situations.

However I will observe that
- entire languages are structured on the premise that dynamic
attribute creation can be hazardous
- debuggers watch out for dynamic attribute creation, which
tells us it is a common source of bugs
- I sincerely doubt that anyone who has written more than
a couple scripts in Python has never accidentally created an
attribute dynamically while intending to assign to an existing
attribute.

I know the response: write good unit tests.  OK, but right now
I am writing code where this restriction will serve as a reasonable
error check, and the design I offered allows very easy removal
of the restriction in the future. Say, once I have written adequate
unit tests.

Alan


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


Re: using telnetlib

2007-02-28 Thread Phoe6
On Feb 28, 4:15 pm, Bjoern Schliessmann  wrote:
> Phoe6 wrote:
>  import telnetlib
>  tn = telnetlib.Telnet("172.31.128.244")
>  tn.read_until("Login: ")
> > '\r\nLogin: '
>  tn.write("root\n:")
>
>^^^
>
> With telnet, use "\r\n" for line breaks at *all* times to be on the
> safe side.

Thanks a lot, Björn.
That did help and solved my problem. ":" after \n was just a typo.

--
Senthil

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


pyopengl vs directpython

2007-02-28 Thread Gigs_
can someone tell me which is better for making 3d game in python. 
something like tennis simulation


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


Re: py2exe, library.zip and python.exe

2007-02-28 Thread Martin Evans
"Thomas Heller" <[EMAIL PROTECTED]> wrote in message 
news:[EMAIL PROTECTED]
> Martin Evans schrieb:
>> I have converted a Python script using py2exe and have it set to not 
>> bundle
>> or compress. The result is my exe and all the support files including
>> library.zip (exactly as planned - nice job py2exe).
>>
>> Question:  My py2exe application needs to be able to execute extra copies 
>> of
>> python.exe. I have placed python.exe in the same directory. It obviously
>> picks up the main python24.dll but how can I configure things so that it
>> would use the same library.zip for all the library files?  This would 
>> save
>> me having two sets of files.
>>
>> (The py2exe application happens to be a twisted server app running as a
>> service which has the ability to launch python scripts as a logged on 
>> user)
>>
>> Thanks,  Martin.
>>
>>
> You have to put library.zip on sys.path.  Maybe you could create a site.py 
> file
> in that directory which can do this, I assume the python.exe will try to 
> load that.
>
> There may be other possibilities as well.
>
> Thomas
>

Many thanks for the tip, it got me thinking. When python.exe is loaded, 
sys.path already had python24.zip in it so changing the specified library in 
py2exe from the default libary.zip to python24.zip solved it!

Martin


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


Re: Creating arrays (builtin) in C Extensions

2007-02-28 Thread Duncan Booth
"iwl" <[EMAIL PROTECTED]> wrote:

> there is an builtin documented array module in phyton,
> but no documentation how such an array can be
> created in C-Extension functions.

I would guess you create an array from C the same way you create any other 
Python objects. So call PyImport_ImportModule to get the array module, get 
its 'array' attribute with PyObject_GetAttrString then call PyObject_New to 
create your array.

There is documentation on how to set the data in the array. See 
http://docs.python.org/api/bufferObjects.html
-- 
http://mail.python.org/mailman/listinfo/python-list


cPickle EOF Error

2007-02-28 Thread Roopesh
I am trying to write xml files which are inside a zip file into the
database.

In the zipfile module the function read returns bytes. What I did was
to make a blob out of the returned bytes and write it to the
database(for this I used cPickle). I also used _mysql's escape_string
which escapes some characters (without this the file content was not
getting written).  But once we try to unpickle the content, an EOF
error is getting thrown. When I tried putting the content(xml in
database) to a file without unpickling then the xml file with escape
characters gets printed.

My code is as follows :

def import_cards():
try :
conn =
MySQLdb.connect(host="localhost",port=3306,user="roopesh",passwd="pass",db="mydbs")

cursor = conn.cursor()

cursor.execute("CREATE TABLE card (serial_no int(10),
id varchar(50), data blob, used char(1), ip varchar(20),
date_downloaded datetime)")

z = zipfile.ZipFile('/home/roopesh/public_html/
cards.zip', 'r')

sql = "INSERT INTO card (serial_no, id, data, used)
values (%s, %s, %s, %s)"


for filename in z.namelist() :
bytes = z.read(filename)
data = cPickle.dumps(bytes, 2)
#print data
cursor.execute(sql, (1, filename ,
_mysql.escape_string(data), 'n'))

sql = "SELECT serial_no, id, data, used FROM card"

cursor.execute(sql)
for serial_no, id, data, used in cursor.fetchall() :
print serial_no, id,
cPickle.loads(data.tostring())
#f = open(id ,'wb')
#f.write(data.tostring())
finally :
cursor.execute("DROP TABLE card")
conn.close()

return True

The output is :

[EMAIL PROTECTED]:~/public_html$ python cardManagement.py
1 cards/passcard1.xml
Traceback (most recent call last):
  File "cardManagement.py", line 136, in ?
import_cards()
  File "cardManagement.py", line 28, in import_cards
print serial_no, id, cPickle.loads(data.tostring())
EOFError

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


Re: f2py and Fortran90 gfortran_filename error

2007-02-28 Thread Tyler
On Feb 28, 12:40 am, Robert Kern <[EMAIL PROTECTED]> wrote:
> Tyler wrote:
> > Hello All:
>
> > Since my last post I have attempted to use the f2py program which
> > comes with numpy.
>
> It's better to ask these questions on numpy-discussion, instead. There are 
> more
> f2py users per capita there.
>
>  http://www.scipy.org/Mailing_Lists
>
>
>
> > I am able to create a .so file fine;
> > however, when I import it into Python, I receive the following
> > message:
>
>  import matsolve2
> > Traceback (most recent call last):
> >   File "", line 1, in ?
> > ImportError: ./matsolve2.so: undefined symbol: _gfortran_filename
>
> > The steps I used to create the matsolve2.so file are as follows:
>
> > (1) Created a Fortran90 program matsolve.f90
>
> > Note: The program compiles fine and prints the proper output for the
> > simple matrix specified. I have also attached below the file
> > matsolve.f90 if it helps at all.
>
> > (2) f2py matsolve.f90 -m matsolve2 -h matsolve2.pyf
> > (3) f2py -c matsolve2.pyf --f90exec=/usr/bin/gfortran matsolve.f90
>
> > Note: I had to specify the f90 path as f2py did not automatically find
> > it.
>
> You want to specify the *kind* of Fortran compiler such that f2py knows what
> compile/link flags to use. Only use the --f90exec option to inform f2py that 
> the
> actual executable is named something odd or is in an unexpected place, like
> /opt/gfortran/bin/gfortran-4.3, for example. The correct option to use is
>
>   --fcompiler=gnu95
>
> --
> Robert Kern
>
> "I have come to believe that the whole world is an enigma, a harmless enigma
>  that is made terrible by our own mad attempt to interpret it as though it had
>  an underlying truth."
>   -- Umberto Eco


Hi Robert:

Thanks for the advice and I'll try posting to the mailing list you
mentioned. For what it's worth, the option, --fcompiler=gnu95 yileds
the following error in the second calling of f2py:

error: don't know how to compile Fortran code on platform 'posix' with
'gnu95' compiler. Supported compilers are:
compaq,absoft,intel,gnu,sun,f,vast,ibm,lahey,intelv,intele,pg,compaqv,mips,hpux,intelev,nag)

Cheers,

t.

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


Re: f2py and Fortran90 gfortran_filename error

2007-02-28 Thread Beliavsky
On Feb 28, 12:40 am, Robert Kern <[EMAIL PROTECTED]> wrote:
> Tyler wrote:
> > Hello All:
>
> > Since my last post I have attempted to use the f2py program which
> > comes with numpy.
>
> It's better to ask these questions on numpy-discussion, instead. There are 
> more
> f2py users per capita there.
>
>  http://www.scipy.org/Mailing_Lists

I wish the Google Groups interface to the list 
http://groups.google.com/group/Numpy-discussion
worked. When I use it to post my messages bounce, but messages from
the list do show up on Google Groups. The "bounces" say

"This mailing list is now defunct. Please use
[email protected] to discuss NumPy, Numeric, and numarray.

http://projects.scipy.org/mailman/listinfo/numpy-discussion";

Yes, I know I could follow these instructions, but I prefer to use
Google Groups.

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


Re: pyopengl vs directpython

2007-02-28 Thread Diez B. Roggisch
Gigs_ wrote:

> can someone tell me which is better for making 3d game in python.
> something like tennis simulation

OpenGL is platform-agnostic. If you ever want to reach people on linux or
macs, use that.

Beyond that I've got no idea which is technically superior - but John
Carmack seems to favor OpenGL :)

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


Re: installing "pysqlite"

2007-02-28 Thread Nader
On Feb 28, 12:51 pm, "Paul Boddie" <[EMAIL PROTECTED]> wrote:
> On 28 Feb, 12:07, Nader Emami <[EMAIL PROTECTED]> wrote:
>
>
>
> > I am back with another problem. I suppose that I can tell it!
> > I have installed both, 'sqlite' and 'pysqlite' without any problem. But
> > If I try to test whether the 'pysqlite' interface works, I get the next
> > error message:
>
> [...]
>
> > /usr/people/emami/lib/python2.4/site-packages/pysqlite2/_sqlite.so:
> > undefined symbol: sqlite3_set_authorizer
>
> > I don't understand it. Could you tell me how I can solve this last
> > point? I hope so!
>
> It looks like Python (although it's really the dynamic linker) can't
> locate the SQLite libraries. If you have installed SQLite into a non-
> standard place, which I'm guessing is the case, then you will need to
> set your LD_LIBRARY_PATH environment variable to refer to the
> directory where the libraries were installed.
>
> So, if you installed SQLite into /usr/people/emami and you see files
> like libsqlite3.so in /usr/people/emami/lib, then you need to change
> your LD_LIBRARY_PATH as follows:
>
> export LD_LIBRARY_PATH=${LD_LIBRARY_PATH}:/usr/people/emami/lib
>
> (The actual directory should be the same as the one you specified for
> library_dirs in the setup.cfg file for pysqlite.)
>
> If you're not using bash as your shell, the syntax for the command may
> be different. Don't forget to add this command to your shell
> configuration file (eg. .bashrc) so that your system remembers this
> information.
>
> Paul

I see now your respond to my problem, but i can check it tomorrow
because I don't have at this moment on this machine. However thank for
the reaction and I will tell about it after assiging the new lib to
its PATH.

Nader

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


Re: pyopengl vs directpython

2007-02-28 Thread sturlamolden
On Feb 28, 2:59 pm, "Diez B. Roggisch" <[EMAIL PROTECTED]> wrote:

> OpenGL is platform-agnostic. If you ever want to reach people on linux or
> macs, use that.
>
> Beyond that I've got no idea which is technically superior - but John
> Carmack seems to favor OpenGL :)

To ask which is better, OpenGL or Direct3D, is trolling with flame
bait.

Both systems deliver excellent 3D graphics, and which is faster
depends on the video card.

There are also PyOGRE and Panda3D (from Disney), and PyGame (the
project seems to be torpid).

John Carmack denounced the Direct3D8. DirectPython uses Direct3D9 and
hides away the nasty COM-programming details.






















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


Re: design question: no new attributes

2007-02-28 Thread Alan Isaac

"Steven D'Aprano" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
> The easy, but inelegant, way is to set a flag.

That is the approach I explored here:
http://mail.python.org/pipermail/python-list/2007-February/428562.html
Btw, I add some background comments about "why" here:
http://mail.python.org/pipermail/python-list/2007-February/428651.html

fwiw,
Alan Isaac


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


pyscripter

2007-02-28 Thread Gigs_
im using pyscripter ide

it is all alright till the next def

class Checkbar(Frame):
 def __init__(self, parent=None, picks=[], side=LEFT, anchor=W):
 Frame.__init__(self, parent)
 self.vars = []
 for pick in picks:
 var = IntVar()
 chk = Checkbutton(self, text=pick, variable=var)
 chk.pack(side=side, anchor=anchor, expand=YES)
 self.vars.append(var)
# it is all alright till here, but if im going to write next
# class method it wont go with tab for 4 fields
# it goes here all the time (8 fields)




if i remove for statement it all work fine
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: os.system and quoted strings

2007-02-28 Thread Sion Arrowsmith
Dennis Lee Bieber  <[EMAIL PROTECTED]> wrote:
 import os.path
 os.path.join("c:",
>..."Documents and Settings",
>..."somepath")
>'c:Documents and Settings\\somepath'

>
>Hmmm, a quick test with 
>
>dir "e:userdata"
>
>worked, so the top level \ may not be needed...

"drive:" is the 'cwd' on the drive, so "drive:directory" is relative
to that. Try "cd e:userdata" and repeat "dir e:userdata" and see what
happens. os.path.join() has to behave as above, otherwise you wouldn't
be able to use it to construct a relative path like that.

(And since I don't think anyone's mentioned it in this thread yet,
subprocess.call() instead of os.system().)

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

Re: design question: no new attributes

2007-02-28 Thread Diez B. Roggisch
> However I will observe that
> - entire languages are structured on the premise that dynamic
> attribute creation can be hazardous

Yup, and you are free to use one of them. And as an additional benefit, they
will be more performant because you then can optimize the code further.

But they certainly do need more code to accomplish the same things easily
done in python (or other dynamic languages for that matter)

> - debuggers watch out for dynamic attribute creation, which
> tells us it is a common source of bugs
> - I sincerely doubt that anyone who has written more than
> a couple scripts in Python has never accidentally created an
> attribute dynamically while intending to assign to an existing
> attribute.

Certainly that happened, but not in a number of occasions that its impact on
every day programming isn't dwarfed by the much more prevalent gain in
productivity using python.

You strive for the combination of disadvantages of statically typed
languages with the disadvantages of a dynamically typed one.

Not too much of an convincing goal IMHO. 

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


Re: msvcr71.dll

2007-02-28 Thread Fredrik Lundh
Simon Brunning wrote:

>> Are there news about the impossibility of redistributing msvcr71.ddl
>> with own stand-alone application written in python for who doesn't have
>> MSVC7 license?
>
> Last I heard the consensus was that it's OK to distribute msvcr71.ddl.
> But IANAL, and neither is anyone else that I've heard discussing the
> matter.

it is perfectly okay to include the Microsoft DLL if you're redistributing a 
Python
build downloaded from python.org (since it's built with a properly licensed com-
piler).

 



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


Re: PyCon blogs?

2007-02-28 Thread Max Erickson
[EMAIL PROTECTED] wrote:

> Was anybody blogging about PyCon (talks and/or sprints)?  Got any
> pointers? 
> 
> Thanks,
> 
> Skip

In no particular order:

http://www.nedbatchelder.com/blog/20070226T075948.html
http://www.oreillynet.com/onlamp/blog/2007/02/pycon_day_1_1.html
http://wamber.net/PyCon-2007/


max

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


Re: finding out the precision of floats

2007-02-28 Thread John Machin
On Feb 28, 10:38 pm, "Bart Ogryczak" <[EMAIL PROTECTED]> wrote:

> [1] eg. consider calculating interests rate, which often is defined as
> math.pow(anualRate,days/365.0).

In what jurisdiction for what types of transactions? I would have
thought/hoped that the likelihood that any law, standard or procedure
manual would define an interest calculation in terms of the C stdlib
would be somewhere in the region of math.pow(epsilon, HUGE), not
"often".

More importantly, the formula you give is dead wrong. The correct
formula for converting an annual rate of interest to the rate of
interest to be used for n days (on the basis of 365 days per year) is:

(1 + annual_rate) ** (n / 365.0) - 1.0
or
math.pow(1 + annual_rate, n / 365.0) - 1.0
if you prefer.

> BTW, math.* functions do not return Decimals.

For which Bell Labs be praised, but what's your point?

Cheers,
John

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


Mail System Error - Returned Mail

2007-02-28 Thread Mail Administrator
The original message was received at Wed, 28 Feb 2007 15:56:52 +0100 from 
[137.64.156.226]

- The following addresses had permanent fatal errors -


- Transcript of session follows -
... while talking to 189.80.161.199:
554 5.0.0 Service unavailable; [35.216.143.37] blocked using bl.spamcop.net, 
reason: Blocked
Session aborted



Deleted0.txt 
Description: Binary data
-- 
http://mail.python.org/mailman/listinfo/python-list

Curses and resizing windows

2007-02-28 Thread Nick !
> Chris Share  wrote:
> > I've been writing an application using curses, and have been trying to
> > handle resizing the terminal, if running in xterm or similar. Increasing
> > the window size is working perfectly, however shrinking it is not
> > working at all. No matter how much I shrink the window, the size
> > returned by getmaxyx() does not change. However as soon as I increase it
> > again, it works fine.
>
> > I've tracked the problem down to the fact I have created a window
> > derived from stdscr. A small script showing the effect is at the end of
> > this post.
>
> odd (thanks for the example - I don't know if this is a problem in
> ncurses or in the python interface to it, but will check/see).
>
> > Can anyone suggest how to solve this problem, that doesn't involve not
> > making a derwin of stdscr?
>
> > I've been googling for hours, but found nothing to help.
>
> > Python version is 2.3.4 on debian testing.
>
> probably should report it as a bug (so it's not overlooked).
>
> --
> Thomas E. Dickey
> http://invisible-island.net
> ftp://invisible-island.net

http://web.cs.mun.ca/~rod/ncurses/ncurses.html#xterm says "The ncurses
library does not catch [the SIGWINCH aka resizing] signal, because it
cannot in general know how you want the screen re-painted". First, is
this really true? When I make my xterms smaller they clip what is
displayed--is that a function of curses or the xterm?
Second, if true, it explains /what/ is going on--stdscr, only--, but
isn't really satisfactory; it doesn't solve the original poster's bug.

#!/usr/bin/env python
"""
curses_resize.py -> run the program without hooking SIGWINCH
curses_resize.py 1 -> run the program with hooking SIGWINCH
"""


import sys, curses, signal, time

def sigwinch_handler(n, frame):
curses.endwin()
curses.initscr()

def main(stdscr):
"""just repeatedly redraw a long string to reveal the window 
boundaries"""
while 1:
stdscr.insstr(0,0,"abcd"*40)
time.sleep(1)

if __name__=='__main__':
if len(sys.argv)==2 and sys.argv[1]=="1":
signal.signal(signal.SIGWINCH, sigwinch_handler)
curses.wrapper(main)

If you run this without sigwinch then the line never gets resized, but
if you do then it works fine. What we can glean from this is that
stdscr only reads off it's size upon initialization. This behaviour
may seem a bit strange, but 1) it's legacy and 2) avoids breaking the
semantics of windows (which don't change size on their own).

The "curses.initscr()" part is kind of unhappy though. It modifies the
stdscr variable without us explicitly assigning anything (but I can't
think of any other way to do it, beyond making stdscr a global, and
that feels worse) and will break if initscr() ever returns a new
Window structure instead of just updating and returning the old one.
Does anyone have any tips for how to structure this so that the screen
can actually be assigned to?

In conclusion, it's not a bug, it's a feature. Joy! The workaround is
to write a sigwinch_handler that at least does `endwin(); initscr()`.

Sorry for reviving an old thread, but it doesn't seem the issue was
ever resolved (the thread doesn't go anywhere and there's no warning
about this in the docs that I noticed).

(please CC: me if anyone cares, I'm not on the list)

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


Re: The Python interactive interpreter has no command history

2007-02-28 Thread ThomasC
On 2月16日, 上午1時14分, "Eduardo \"EdCrypt\" O. Padoan"
<[EMAIL PROTECTED]> wrote:
> > Hello,
>
> > How to configure Python2.5's interactive interpreter to get command
> > history ?
>
> > I always got ^[[A and ^[[B .
>
> Are you using Ubuntu? The last comes with 2.4.x and 2.5. This only
> occurs on 2.5. This happens when you compile Python with libreadline
> installed, AFAIK.
> FIll a bug in the Ubuntu launchpad. You can install libreadline (and
> build-essential), download the 2.5 source and compile yourself.
>
> --
> EduardoOPadoan (eopadoan->altavix::com)
> Bookmarks:http://del.icio.us/edcrypt


I have fixed this issue by recompile python2.5 with libreadline and
libncursesw.
I run python on Zaurus, but Zaurus toolchain has no readline and
ncursesw libraries, so I add those libraries.
I have posted my experience on 
http://bean-pig.idv.tw/emb_study/archives/001059.html
Thanks a lot!!

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

Re: Running Python scripts from BASH

2007-02-28 Thread ina
On Feb 27, 11:16 pm, "Hendrik van Rooyen" <[EMAIL PROTECTED]>
wrote:
> "Ishpeck" <[EMAIL PROTECTED]> wrote:
>
> 8<--- a bash problem -
>
> If it were Python, the advice would have been to use the
> print statement to figure out what the content of the
> variables were.
>
> As it is Bash, you may have to stoop to something like
> echo to see what is in $i...
>
> hth - Hendrik

When you print the string in bash it looks correct. It isn't until you
try to execute it you have the problem.

os.system is the solution to this problem anyway.

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


Re: PyCon blogs?

2007-02-28 Thread Kumar McMillan
> > Was anybody blogging about PyCon (talks and/or sprints)?  Got any
> > pointers?

or ... if you're lazy like me, read them all in one place!

http://planetpython.org/
http://www.pythonware.com/daily/
http://planet.python.org/

ps. http://flickr.com/search/?q=pycon2007

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


Re: Python Source Code Beautifier

2007-02-28 Thread Alan Franzoni
Il Wed, 28 Feb 2007 07:53:47 +1100, Delaney, Timothy (Tim) ha scritto:

> Alan Franzoni wrote:
>> 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.
> 
> This change can have semantic differences, and so should not be done for
> anything except basic, immutable objects (such as integers). As such, it
> can't be done automatically.

Yeah, that's right, it could have semantic differences, but that shouldn't
be the case anyway. I mean, if I don't define an __iadd__ method, writing

a += n

or

a = a + n

is just the same, right?


So, if I bother to define an __iadd__ method, I should make sure it works
just the same, or I would introduce a very strange and hard-to-understand
behaviour.



-- 
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


Eric on XP for Newbie

2007-02-28 Thread jeffwatkins2000
I'm starting on the path of freeing myself from proprietory software
but I need to migrate, not make one huge jump.

I'm looking at using Python and Eric for programming

I've got Python up and running but can someone please point me to a
simple step by step guide for installing Eric? I've downloaded the tar
files, but what do I do with them?

Thanks

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


Re: Python Source Code Beautifier

2007-02-28 Thread Alan Franzoni
Il 27 Feb 2007 16:14:20 -0800, [EMAIL PROTECTED] ha scritto:

> Those mean different things:
> 
 a=[1]
 b=a
 a += [2]
 a
> [1, 2]
 b
> [1, 2]
 a=[1]
 b=a
 a = a + [2]
 a
> [1, 2]
 b
> [1]

This is a really nasty one! I just answered to Tim above here, and then I
saw your example... I had never realized that kind of list behaviour.
That's probably because i never use + and += on lists (i prefer the more
explicit append() or extend() and i do copy list explictly when I want to)
, BTW I think this behaviour is tricky!


-- 
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: Eric on XP for Newbie

2007-02-28 Thread Alan Franzoni
Il 28 Feb 2007 08:13:42 -0800, [EMAIL PROTECTED] ha scritto:

[cut]

Forget the tars.

http://www.quadgames.com/download/pythonqt/

Get the two EXEs here. BTW, I don't think Eric3 is a really good IDE on
Windows (yet). Try something like SPE, or Scite, or any other editor like
UltraEdit32.

N.B: you need first to install python, then pyqtgpl, then eric.

-- 
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: Python Source Code Beautifier

2007-02-28 Thread Duncan Booth
Alan Franzoni <[EMAIL PROTECTED]> wrote:

> Yeah, that's right, it could have semantic differences, but that
> shouldn't be the case anyway. I mean, if I don't define an __iadd__
> method, writing 
> 
> a += n
> 
> or
> 
> a = a + n
> 
> is just the same, right?
> 
> 
> So, if I bother to define an __iadd__ method, I should make sure it
> works just the same, or I would introduce a very strange and
> hard-to-understand behaviour.
> 

If a is mutable and has an appropriate __iadd__ method which mutates it 
then the first of those will mutate the original object and the second 
will create a new object. That might not matter much if 'a' is the only 
name referring to the object, but if there are any other ways to access 
it then it will matter.

Compare:
>>> lst = [1, 2, 3]
>>> n = ['oops']
>>> a = lst
>>> a = a + n
>>> a
[1, 2, 3, 'oops']
>>> lst
[1, 2, 3]

>>> lst = [1, 2, 3]
>>> n = ['oops']
>>> a = lst
>>> a += n
>>> a
[1, 2, 3, 'oops']
>>> lst
[1, 2, 3, 'oops']
-- 
http://mail.python.org/mailman/listinfo/python-list


cPickle FU on Solaris

2007-02-28 Thread Bart Ogryczak
It seems, that on Solaris cPickle is unable to unpickle some values,
which it is able to pickle.

>>> import cPickle
>>> cPickle.dumps(1e-310)
'F9.9694e-311\n.'
>>> cPickle.loads(_)
Traceback (most recent call last):
  File "", line 1, in ?
ValueError: could not convert string to float
>>> import pickle
>>> pickle.loads(_)
9.9694e-311

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


SocketServer.ForkingMixIn and zombie processes

2007-02-28 Thread [EMAIL PROTECTED]
Hi,

I noticed that when I used SocketServer.ForkingMixIn
(ForkingTCPServer), there were always  zombie processes around.  I
searched for where waitpid() is called in ForkingMixIn and found it in
SocketServer.py:

def process_request(self, request, client_address):
"""Fork a new subprocess to process the request."""
self.collect_children()
pid = os.fork()
if pid:
# Parent process
if self.active_children is None:
self.active_children = []
self.active_children.append(pid)
self.close_request(request)
return
else:
# Child process.
# This must never return, hence os._exit()!
try:
self.finish_request(request, client_address)
os._exit(0)
except:
try:
self.handle_error(request, client_address)
finally:
os._exit(1)

So waitpid() is called just before fork().  This means that if next
request does not come in, zombie processes are not reclaimed forever!
Is this an intentional behavior?  Is there any workaround?

--
Kazu Nisimura

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


Re: spawnl and waitpid

2007-02-28 Thread naima . mans
On 28 fév, 11:23, [EMAIL PROTECTED] wrote:
> On 27 fév, 19:32, Thinker <[EMAIL PROTECTED]> wrote:
>
>
>
>
>
> > -BEGIN PGP SIGNED MESSAGE-
> > Hash: SHA1
>
> > [EMAIL PROTECTED] wrote:
> > > On 27 f憝, 18:54, Thinker <[EMAIL PROTECTED]> wrote:
> > > hello
> > > ha ok...
> > > i tried this one and the browser don't write the message at once...
> > > I have alos tried with thread and have the same result... :(
>
> > Does child-process terminate it-self in a very short time ?
> > It can be a race condition, here.
> > You can try to sleep for a while in child-process to make sure parent
> > being executed. Parent process may not schedule to run immediately
> > after spawn. And, you can print some thing before os.spawnl() to make
> > sure that message can be delivered successfully.
>
> > - --
> > 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
>
> > iD8DBQFF5Hkp1LDUVnWfY8gRAtDdAKCKy8/ap5VJvZV14nhSCWYfLZdyYACffJ+Y
> > 0sHMgyaQBmsOMwq/rxEvm1Q=
> > =qjTU
> > -END PGP SIGNATURE-
>
> hello
>
> oki, i have test a simple script that only wait...
> when i tun the script without the server it write on 2 time which is
> normal:
> 
> Content-Type: text/html
> wait
> The main program continues to run in foreground.
> (((then after 5 second ))]]]
> Fin background
> Main program waited until background was done.
> ==
>
> BUT when i call it under the server web it write after 5 second all
> the message in 1 time :
> ===
> wait The main program continues to run in foreground. Fin background
> Main program waited until background was done.
> ===
>
> ---THE SCRIPT ---
> import cgitb; cgitb.enable()
> import os,sys
> import threading, zipfile,time,Main
>
> print "Content-Type: text/html"
> print
> print "wait"
> sys.stdout.flush()
>
> class AsyncZip(threading.Thread):
>     def __init__(self, infile):
>         threading.Thread.__init__(self)
>         self.infile = infile
>     def run(self):
>         time.sleep(5.0)
>         print 'Fin background'
>
> background = AsyncZip('Main.py')
> background.start()
> print 'The main program continues to run in foreground.'
> sys.stdout.flush()
> background.join()    # Wait for background task to finish
> print 'Main program waited until background was done.'
> sys.stdout.flush()
>  Masquer le 
> texte des messages précédents -
>
> - Afficher le texte des messages précédents -

hello

The pb seems to be solve but no idee why as i have done lot of
changes :/  (may be the last flush or the "\n".. i'm gone
investigate..)

THANKS for helping :)

for information here the code

--

#! C:/Python25/python.exe -u
# -*- coding: cp1252 -*-
import cgitb; cgitb.enable()
import os, commands, time,Parser,config
import cgi

import sys,Function
sys.stderr = sys.stdout
print "Content-Type: text/html"
print

pid =  os.spawnl(os.P_NOWAIT,"c:\\python25\
\python.exe","python","Main.py")
print "please wait...\n"
print """Le fichier de log est consultable sur fr9033256d
\execute\%s \n""" %config.nom_log
sys.stdout.flush()
ret = os.waitpid(pid,0)
if ret[1]:
print "Non-zero exit code: %s %s" % (ret[1], ret[0])
else:
print "Successful exit"
sys.stdout.flush()

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

Curious UnboundLocalError Behavior

2007-02-28 Thread Matthew Franz
I'm probably fundamentally misunderstanding the way the interpreter
works with regard to scope, but is this the intended behavior...

franz-macbook:~ mdfranz$ python unboundlocal.py
('Darwin', 'franz-macbook.local', '8.8.5', 'Darwin Kernel Version
8.8.5: Mon Dec 11 19:39:17 PST 2006;
root:xnu-792.16.5.obj~1/RELEASE_I386', 'i386')
2.4.3 (#1, Feb 24 2007, 23:01:32)
[GCC 4.0.1 (Apple Computer, Inc. build 5367)]
{'__builtins__': , '__file__':
'unboundlocal.py', 'SOMEGLOBAL': 1, 'sys': ,
'__name__': '__main__', 'foo': , 'os':
,
'__doc__': None}
SOMEGLOBAL:
Traceback (most recent call last):
  File "unboundlocal.py", line 15, in ?
foo()
  File "unboundlocal.py", line 11, in foo
print "SOMEGLOBAL:",SOMEGLOBAL
UnboundLocalError: local variable 'SOMEGLOBAL' referenced before assignment


Where unboundlocal.py is...

import os,sys

SOMEGLOBAL=1

def foo():
dome=False
if dome:
SOMEGLOBAL = 0

print globals()
print "SOMEGLOBAL:",SOMEGLOBAL

print os.uname()
print sys.version
foo()

Is SOMEGLOBAL is some weird in-between state, since it is referenced
within foo() but not actually assigned?

If I set dome to True SOMEGLOBAL gets overriden (as I would have expected)

franz-macbook:~ mdfranz$ python unboundlocal.py
('Darwin', 'franz-macbook.local', '8.8.5', 'Darwin Kernel Version
8.8.5: Mon Dec 11 19:39:17 PST 2006;
root:xnu-792.16.5.obj~1/RELEASE_I386', 'i386')
2.4.3 (#1, Feb 24 2007, 23:01:32)
[GCC 4.0.1 (Apple Computer, Inc. build 5367)]
{'__builtins__': , '__file__':
'unboundlocal.py', 'SOMEGLOBAL': 1, 'sys': ,
'__name__': '__main__', 'foo': , 'os':
,
'__doc__': None}
SOMEGLOBAL: 0



-- 
Matthew Franz
http://www.threatmind.net/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Eric on XP for Newbie

2007-02-28 Thread jeffwatkins2000
On Feb 28, 4:27 pm, Alan Franzoni
<[EMAIL PROTECTED]> wrote:
> Il 28 Feb 2007 08:13:42 -0800, [EMAIL PROTECTED] ha scritto:
>
> [cut]
>
> Forget the tars.
>
> http://www.quadgames.com/download/pythonqt/
>
> Get the two EXEs here. BTW, I don't think Eric3 is a really good IDE on
> Windows (yet). Try something like SPE, or Scite, or any other editor like
> UltraEdit32.
>

Thanks

I've installed SPE. But what now? How do I run it? It doesn't appear
in "all programs" and ther's no .exe file that I can find

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


Re: finding out the precision of floats

2007-02-28 Thread Bart Ogryczak
On Feb 28, 3:53 pm, "John Machin" <[EMAIL PROTECTED]> wrote:
> On Feb 28, 10:38 pm, "BartOgryczak" <[EMAIL PROTECTED]> wrote:
>
> > [1] eg. consider calculating interests rate, which often is defined as
> > math.pow(anualRate,days/365.0).
>
> In what jurisdiction for what types of transactions? I would have
> thought/hoped that the likelihood that any law, standard or procedure
> manual would define an interest calculation in terms of the C stdlib
> would be somewhere in the region of math.pow(epsilon, HUGE), not
> "often".

YPB? Have you ever heard of real-time systems?

> More importantly, the formula you give is dead wrong. The correct
> formula for converting an annual rate of interest to the rate of
> interest to be used for n days (on the basis of 365 days per year) is:
>
> (1 + annual_rate) ** (n / 365.0) - 1.0
> or
> math.pow(1 + annual_rate, n / 365.0) - 1.0
> if you prefer.

YPB? Anyone with half a brain knows, that you can either express rate
as 0.07 and do all those ridiculous conversions above, or express it
as 1.07 and apply it directly.

> > BTW, math.* functions do not return Decimals.
>
> For which Bell Labs be praised, but what's your point?

That Decimal is useless, for anything but invoices.




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


Re: Curious UnboundLocalError Behavior

2007-02-28 Thread Daniel Nogradi
> I'm probably fundamentally misunderstanding the way the interpreter
> works with regard to scope, but is this the intended behavior...
>

[]

> SOMEGLOBAL:
> Traceback (most recent call last):
>   File "unboundlocal.py", line 15, in ?
> foo()
>   File "unboundlocal.py", line 11, in foo
> print "SOMEGLOBAL:",SOMEGLOBAL
> UnboundLocalError: local variable 'SOMEGLOBAL' referenced before assignment

[..]

> import os,sys
>
> SOMEGLOBAL=1
>
> def foo():
> dome=False
> if dome:
> SOMEGLOBAL = 0
>
> print globals()
> print "SOMEGLOBAL:",SOMEGLOBAL
>
> print os.uname()
> print sys.version
> foo()
>


Try:

import os,sys

SOMEGLOBAL=1

def foo():
global SOMEGLOBAL
dome=False
if dome:
SOMEGLOBAL = 0

print globals()
print "SOMEGLOBAL:",SOMEGLOBAL

print os.uname()
print sys.version
foo()

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


Re: finding out the precision of floats

2007-02-28 Thread Arnaud Delobelle
On 28 Feb, 11:38, "Bart Ogryczak" <[EMAIL PROTECTED]> wrote:
> On Feb 27, 7:58 pm, "Arnaud Delobelle" <[EMAIL PROTECTED]> wrote:
> > This is one of the reasons (by no means the main) why I decided to
> > write my own class.
>
> Why not GMP?

I need decimals.

> My point is, that neither is Decimal. It doesn't solve the problem,
> creating additional problem with efficiency.
>
> > >>> 0.1+0.1+0.1==0.3
> > False
> > >>> 3*0.1==0.3
>
> > False
>
> > Decimals will behave better in this case.
>
> Decimal will work fine as long as you deal only with decimal numbers
> and the most basic arithmetic. Any rational number with base that is
> not power of 10, or any irrational number won't have an exact
> representation.

My problem is precisely to represent rational numbers whose
denominator is a power of 10 (aka decimals) accurately.

> So as long as you're dealing with something like
> invoices, Decimal does just fine. When you start real calculations,
> not only scientific, but even financial ones[1], it doesn't do any
> better then binary float, and it's bloody slow.

I'm not doing 'real world' calcultations, I'm making an app to help
teach children maths.  I need numerical values that behave well as
decimals. I also need them to have an arbitrary number of significant
figures. Floats are great but they won't help me with either. Amongst
other things, I need 3.0*0.1==0.3 to be True.

Please do not make the assumption that I have chosen to use a decimal
type without some careful consideration.

--
Arnaud

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


Writing an interpreter for language similar to python!!

2007-02-28 Thread luvsat
Hello all,

I am new to python and working on a project that involves designing a
new language. The grammar of the language is very much inspired from
python as in is supports nearly all the statements and expressions
that are supported by python. Since my project is in initial stage, so
I think it would be appropriate if I clarify the following questions:

1. Would it make sense if I parse the whole program from scratch and
then construct the valid python strings back so that they can be
executed using ''exec'' and ''eval'' commands?
2. Recently, I came across PLY (Python-Lex-Yacc) module that can be
used to implement interpreters. It seems quite friendly to work with.
Is there any implementation of python interpreter using ply? Any such
reference would be extermely helpful for me to continue.

Any kind of suggestions/ comments would be highly appreciated.

Thanks,
Luvish Satija

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


Re: pyHook or SetWindowsHookEx

2007-02-28 Thread abcd
anyone?

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


Re: finding out the precision of floats

2007-02-28 Thread Bart Ogryczak
On Feb 28, 6:34 pm, "Arnaud Delobelle" <[EMAIL PROTECTED]> wrote:
> > So as long as you're dealing with something like
> > invoices, Decimal does just fine. When you start real calculations,
> > not only scientific, but even financial ones[1], it doesn't do any
> > better then binary float, and it's bloody slow.
>
> I'm not doing 'real world' calcultations, I'm making an app to help
> teach children maths.

Without divisions?

> I need numerical values that behave well as
> decimals. I also need them to have an arbitrary number of significant
> figures. Floats are great but they won't help me with either. Amongst
> other things, I need 3.0*0.1==0.3 to be True.

How about (1.0/3.0)*3.0 == 1.0? That doesn't need to be True?

> Please do not make the assumption that I have chosen to use a decimal
> type without some careful consideration.

Well, you didn't indicate this before. Anyway, in that case efficiency
has no impact at all, so you might as well use Decimal.


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


Re: Automatic reloading, metaclasses, and pickle

2007-02-28 Thread andrewfelch
On Feb 27, 6:47 pm, "Ziga Seilnacht" <[EMAIL PROTECTED]> wrote:
> Andrew Felch wrote:
> > Thanks for checking.  I think I narrowed the problem down to
> > inheritance.  I inherit from list or some other container first:
>
> > class PointList( list, AutoReloader ):
> > def PrintHi1(self):
> > print "Hi2"
>
> > class MyPrintingClass( AutoReloader ):
> > def PrintHi2(self):
> > print "Hi2v2"
>
> > Automatic reloading works for MyPrintingClass but not for PointList.
> > Any ideas?
>
> > -Andrew
>
> Ah yes, this is the problem of list.__new__ not calling the next
> class in MRO. Try to switch the bases, so that AutoReloader's
> __new__ method will be called first.
>
> Ziga- Hide quoted text -
>
> - Show quoted text -

So there is another bug crippling Python (see
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=628925&group_id=5470
).  Pickle and cPickle get confused after reloading, and won't let you
dump the objects to file using protocol 2.  The bug occurred for me
when an instance of an AutoReloader class had a member not derived
from AutoReloader (error text: "it's not the same object" ).  The
workaround is to use text mode, which I assume means not using
protocol 2.  After that, you can reload them in text mode, and then
dump them using protocol 2.  This is not so bad since you only do it
when you were going to dump objects to file anyway, so it really only
takes 3x as long on those occassions.  The metaclass adaptation is
still incredibly useful because it avoids having to do pickle dump-
loads when you wouldn't otherwise have had to (approaching an infinite
speedup in those cases, thanks Ziga! :-).

Another caveat is that pickle dumping doesn't work if there is a
pointer to a global function (that changes) that is a member of an
instance of a class derived from AutoLoader.  The error message has
subtext: "it's not the same object ".  That doesn't seem so bad to me,
since you don't have to do that type of thing (function pointers) so
much now that you can use classes!

The best solution would be to make pickle protocol 2 have the same
behavior as the text protocol (i.e. actually work in this case).

Regarding the function pointers, anybody (Ziga :-) know why it is that
pickle chokes so hard on this?  Is there some adaptation of the
metaclass or a less beautiful hack that could fix it?

Thanks to those readers following me down the rabbit hole.  Ziga's
metaclass adaptation has saved Python in my mind, and these nits seem
to be worth discussing.

- Andrew Felch

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


Re: f2py and Fortran90 gfortran_filename error

2007-02-28 Thread Robert Kern
Beliavsky wrote:
> On Feb 28, 12:40 am, Robert Kern <[EMAIL PROTECTED]> wrote:
>> Tyler wrote:
>>> Hello All:
>>> Since my last post I have attempted to use the f2py program which
>>> comes with numpy.
>> It's better to ask these questions on numpy-discussion, instead. There are 
>> more
>> f2py users per capita there.
>>
>>  http://www.scipy.org/Mailing_Lists
> 
> I wish the Google Groups interface to the list 
> http://groups.google.com/group/Numpy-discussion
> worked. When I use it to post my messages bounce, but messages from
> the list do show up on Google Groups. The "bounces" say
> 
> "This mailing list is now defunct. Please use
> [email protected] to discuss NumPy, Numeric, and numarray.
> 
> http://projects.scipy.org/mailman/listinfo/numpy-discussion";
> 
> Yes, I know I could follow these instructions, but I prefer to use
> Google Groups.

Well, you'll have to find out who set up that interface or whoever at Google is
in charge of maintaining such gatewayed groups to let them know that the mailing
list has migrated. I used the "Send email to the owner" link, but I have no idea
who that is supposed to go to.

-- 
Robert Kern

"I have come to believe that the whole world is an enigma, a harmless enigma
 that is made terrible by our own mad attempt to interpret it as though it had
 an underlying truth."
  -- Umberto Eco

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


How do I Color a QTableView row in PyQt4

2007-02-28 Thread Mel
I am currently porting an SQL centered Visual Basic application to run
on Linux, Python, and Qt4.  Currently I am stumped on changing row
colors in the QTableView widget.  My test code is based on code from
the PyQt4  examples and looks like this:

*** Start Code ***

import sys
from PyQt4 import QtCore, QtGui, QtSql

import connection


class CustomSqlModel(QtSql.QSqlQueryModel):
def data(self, index, role):
value = QtSql.QSqlQueryModel.data(self, index, role)
if value.isValid() and role == QtCore.Qt.DisplayRole:
if index.column() == 0:
return QtCore.QVariant(value.toString().prepend("#"))
elif index.column() == 2:
return QtCore.QVariant(value.toString().toUpper())
if role == QtCore.Qt.TextColorRole and index.column() == 1:
return QtCore.QVariant(QtGui.QColor(QtCore.Qt.blue))
return value

def initializeModel(model):
model.setQuery("SELECT * FROM WaterOrder Where DateCanceled is
NULL AND ActDateTimeOff is NULL and ActDateTimeOn is NOT NULL")

offset = 0
views = []

def createView(title, model):
global offset, views

view = QtGui.QTableView()
views.append(view)
view.setModel(model)
view.setWindowTitle(title)
for i in range(model.columnCount()):
view.resizeColumnToContents(i)
view.setAlternatingRowColors(1)

view.move(100 + offset, 100 + offset)
offset += 20
view.show()


if __name__ == "__main__":
app = QtGui.QApplication(sys.argv)
if not connection.createConnection():
sys.exit(1)

customModel = CustomSqlModel()
initializeModel(customModel)
createView(QtCore.QObject.tr(customModel, "Running Water"),
customModel)

sys.exit(app.exec_())

*** End Code ***


Column 18 in the table shows a number from 1 to 3.  I would like to
change the color of the row based on the value in column 18 but I have
not been able to find any resources that show me how.  Can anyone lend
a hand?

Thanks,
Mel

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


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

2007-02-28 Thread Ray Dillinger

> Actually, it just occurred to me that the company location was also in 
> the subject line of this thread ;-)

D'oh!  Should have looked at the verbose header before responding.
I've got my newsreader set to display one title per line, and then
didn't give it enough horizontal room to see your full title.

Well, I'm not moving to LA, so I won't waste your time (and mine)
applying.  Best of luck!

Bear

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


Re: Py2EXE problem

2007-02-28 Thread Sick Monkey

Ok I found an extremely easy way to resolving this issue (I cannot believe I
did not think of it sooner).

After Py2exe created the .exe file I noticed a "library.zip" file.  I took a
look at the Py2exe output, and saw all of the libraries that it failed to
insert.  I copied all of the .pyc that my application needed and inserted
them in the "email folder" within the library.zip.  I fired up the
application and it worked like a champ.



On 2/27/07, Sick Monkey <[EMAIL PROTECTED]> wrote:


Maybe this is not the board to post this, but hopefully with all of the
python experts out there maybe one of  you have encountered this.

I wrote an application that sends an email with an attachment.  When I run
it, it runs great with no issues what-so--ever.

When I thought I was finally finished, I created an executable file using
py2exe.

Now, when I run the application, I am getting the following error:
---
Exception in Tkinter callback
Traceback (most recent call last):
  File "Tkinter.pyc", line 1403, in __call__
  File "Suppression.py", line 401, in startProc
  File "Suppression.py ", line 318, in emailInfo
  File "email\__init__.pyc", line 79, in __getattr__
ImportError: No module named multipart
---
Any ideas on how to get around this one?

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

Re: pyopengl vs directpython

2007-02-28 Thread Gigs_
thanks

hey, is there any good tutorial for directpython?
or maybe you could suggest me the book
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Py2EXE problem

2007-02-28 Thread Thomas Heller
Sick Monkey schrieb:
> Ok I found an extremely easy way to resolving this issue (I cannot believe I
> did not think of it sooner).
> 
> After Py2exe created the .exe file I noticed a "library.zip" file.  I took a
> look at the Py2exe output, and saw all of the libraries that it failed to
> insert.  I copied all of the .pyc that my application needed and inserted
> them in the "email folder" within the library.zip.  I fired up the
> application and it worked like a champ.
> 

Even easier would be to let py2exe include the whole email package.
One solution is to run
   'setup.py py2exe -p email'

Thomas

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


Re: PyCon blogs?

2007-02-28 Thread Luis M. González
On Feb 27, 9:36 pm, [EMAIL PROTECTED] wrote:
> Was anybody blogging about PyCon (talks and/or sprints)?  Got any pointers?
>
> Thanks,
>
> Skip



http://blogsearch.google.com/blogsearch?hl=en&tab=wb&q=pycon&btnG=Search+Blogs

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


Re: Eric on XP for Newbie

2007-02-28 Thread SPE - Stani's Python Editor
On Feb 28, 6:15 pm, [EMAIL PROTECTED] wrote:
> On Feb 28, 4:27 pm, Alan Franzoni
>
> <[EMAIL PROTECTED]> wrote:
> > Il 28 Feb 2007 08:13:42 -0800, [EMAIL PROTECTED] ha scritto:
>
> > [cut]
>
> > Forget the tars.
>
> >http://www.quadgames.com/download/pythonqt/
>
> > Get the two EXEs here. BTW, I don't think Eric3 is a really good IDE on
> > Windows (yet). Try something likeSPE, or Scite, or any other editor like
> > UltraEdit32.
>
> Thanks
>
> I've installedSPE. But what now? How do I run it? It doesn't appear
> in "all programs" and ther's no .exe file that I can find

Which installer did you use? If you used the python25 installer, use
the python24 installer instead. (It will also work as it is not
specific to 2.4 I have removed the python25 installer.) Than the
shortcuts should appear in your "All Programs".

Stani

PS. A new version is about to released: http://pythonide.stani.be

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


Re: Py2EXE problem

2007-02-28 Thread Sick Monkey

Awesome.  That is good to know.

On 2/28/07, Thomas Heller <[EMAIL PROTECTED]> wrote:


Sick Monkey schrieb:
> Ok I found an extremely easy way to resolving this issue (I cannot
believe I
> did not think of it sooner).
>
> After Py2exe created the .exe file I noticed a "library.zip" file.  I
took a
> look at the Py2exe output, and saw all of the libraries that it failed
to
> insert.  I copied all of the .pyc that my application needed and
inserted
> them in the "email folder" within the library.zip.  I fired up the
> application and it worked like a champ.
>

Even easier would be to let py2exe include the whole email package.
One solution is to run
   'setup.py py2exe -p email'

Thomas

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

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

Reading csv files using SQL

2007-02-28 Thread Pablo was Paolo
Hi,
exists a Python library that allows to interface to csv files as if you 
manage a database, using SQL language?

Something like csvjdbc in Java, where table name is file name and the 
field's names are in first row.

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


Question about raise and exceptions.

2007-02-28 Thread Steven W. Orr
In my class I have

 class Error(Exception):
 """Base class for exceptions in this module."""
 pass

 class TransitionError(Error):
 """Raised when an operation attempts a state transition that's not
 allowed.

 Attributes:
 previous -- state at beginning of transition
 next -- attempted new state
 message -- explanation of why the specific transition is not 
allowed
 """

 def __init__(self, previous, next, message):
 self.previous = previous
 self.next = next
 self.message = message

Also in my class I check to see if a transition is legal or not:

 newstate = self.fsm[self.curr_state][self._ev]
 if newstate == self.error_state:
 raise TransitionError, self.curr_state, newstate, \
"Going to error state %d from state %d" % (self.curr_state, newstate)
 self.curr_state= self.fsm[newstate][self._ev]

When I run it I get this:

884 > ./t_fsm.py
Traceback (most recent call last):
   File "./t_fsm.py", line 3, in ?
 from fsm import *
   File "/home/boston/VIASAT/sorr/py/fsm/fsm.py", line 76
 raise TransitionError, self.curr_state, newstate, "Going to error 
state %d from state %d" % (self.curr_state, newstate)
 ^
SyntaxError: invalid syntax

(The carat is really under the comma before "Going.)

I hate to bother people with syntax problems, but I have no idea what to 
do. Sorry.

TIA :-(

-- 
Time flies like the wind. Fruit flies like a banana. Stranger things have  .0.
happened but none stranger than this. Does your driver's license say Organ ..0
Donor?Black holes are where God divided by zero. Listen to me! We are all- 000
individuals! What if this weren't a hypothetical question?
steveo at syslang.net
-- 
http://mail.python.org/mailman/listinfo/python-list


RE: Eric on XP for Newbie

2007-02-28 Thread Sells, Fred
I've been using Eclipse with the PyDev extension.  it's not bad, although
you need a reasonably powerful computer to handle the bloat of Eclipse.

For short programs, I still like emacs, but I'm old school.

-Original Message-
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED]
Behalf Of SPE - Stani's Python Editor
Sent: Wednesday, February 28, 2007 1:38 PM
To: [email protected]
Subject: Re: Eric on XP for Newbie


On Feb 28, 6:15 pm, [EMAIL PROTECTED] wrote:
> On Feb 28, 4:27 pm, Alan Franzoni
>
> <[EMAIL PROTECTED]> wrote:
> > Il 28 Feb 2007 08:13:42 -0800, [EMAIL PROTECTED] ha scritto:
>
> > [cut]
>
> > Forget the tars.
>
> >http://www.quadgames.com/download/pythonqt/
>
> > Get the two EXEs here. BTW, I don't think Eric3 is a really good IDE on
> > Windows (yet). Try something likeSPE, or Scite, or any other editor like
> > UltraEdit32.
>
> Thanks
>
> I've installedSPE. But what now? How do I run it? It doesn't appear
> in "all programs" and ther's no .exe file that I can find

Which installer did you use? If you used the python25 installer, use
the python24 installer instead. (It will also work as it is not
specific to 2.4 I have removed the python25 installer.) Than the
shortcuts should appear in your "All Programs".

Stani

PS. A new version is about to released: http://pythonide.stani.be

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

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


Re: Question about raise and exceptions.

2007-02-28 Thread Daniel Klein
On Wed, 28 Feb 2007 13:48:54 -0500 (EST), "Steven W. Orr"
<[EMAIL PROTECTED]> wrote:

>When I run it I get this:
>
>884 > ./t_fsm.py
>Traceback (most recent call last):
>   File "./t_fsm.py", line 3, in ?
> from fsm import *
>   File "/home/boston/VIASAT/sorr/py/fsm/fsm.py", line 76
> raise TransitionError, self.curr_state, newstate, "Going to error 
>state %d from state %d" % (self.curr_state, newstate)
> ^
>SyntaxError: invalid syntax

The arguments for TransitionError must be a tuple, eg:

msg = "Going to error state %d from state %d" % (self.curr_state,
newstate)
raise TransitionError(self, curr_state, newstate, msg)

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


class declaration shortcut

2007-02-28 Thread Luis M. González
I've come across a code snippet in www.rubyclr.com where they show how
easy it is to declare a class compared to equivalent code in c#.
I wonder if there is any way to emulate this in Python.

The code is as follows:

Person = struct.new( :name, :birthday, :children)

I tried something like this, but it's nothing close to what I'd like:

def klass(table, *args):
cls = new.classobj(table, (), {})
for i in args:
setattr(cls, i, i)
return cls

But this above is not what I want.
I guess I should find a way to include the constructor code inside
this function, but I don't know if this is possible.
Also, I wonder if there is a way to use the variable name in order to
create a class with the same name (as in "Person"above).

Well, if anyone has an idea, I'd like to know...

Luis

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


  1   2   >