Re: problems with tkinter updates

2012-01-27 Thread yves

On 2012-01-24 02:52, Peter Otten wrote:


Have update() (renamed to read_more() in my code) do the reading:

import sys
import tkinter
import tkinter.scrolledtext

root = tkinter.Tk()

text_window = tkinter.Toplevel()
text = tkinter.scrolledtext.ScrolledText(text_window)
text.pack()

infile = open(sys.argv[1])

def read_more():
 line = next(infile, None)
 if line is not None:
 text.insert(tkinter.END, line)
 root.after(100, read_more)
 else:
 text.insert(tkinter.END, "\nThat's all folks", "looney")
 text.tag_configure("looney", foreground="RED")
 text.see(tkinter.END)

read_more()
root.mainloop()




Thank you, this was very useful!

--
Yves.  http://www.SollerS.ca/
   http://ipv6.SollerS.ca
   http://blog.zioup.org/
--
http://mail.python.org/mailman/listinfo/python-list


Re: The devolution of English language and slothful c.l.p behaviors exposed!

2012-01-27 Thread Emile van Sebille

On 1/25/2012 9:14 PM Steven D'Aprano said...

In the
same way that a native English speaker would never make the mistake of
using "organ" to refer to an unnamed mechanical device, so she would
never use "gadget" to refer to an unnamed body part.


My wife introduced me to the term "picnic gadget" as the means by which 
males avoid restroom lines...


Emile


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


runtime error

2012-01-27 Thread nikos spanakis
Hi 


I just  minstalled python 3.1 on my windons XP SP3 


but on the start up I get the following error message:

Fatal Python error: Py_Initialize: can't initialize sys standard streams
ImportError: No module named encodings.utf_8

This application has requested the Runtime to terminate it in an unusual way.
Please contact the application's support team for more information.#

What should I do

Many thanks 


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


Re: The devolution of English language and slothful c.l.p behaviors exposed!

2012-01-27 Thread Steven D'Aprano
On Fri, 27 Jan 2012 09:06:57 -0800, Emile van Sebille wrote:

> On 1/25/2012 9:14 PM Steven D'Aprano said...
>> In the
>> same way that a native English speaker would never make the mistake of
>> using "organ" to refer to an unnamed mechanical device, so she would
>> never use "gadget" to refer to an unnamed body part.
> 
> My wife introduced me to the term "picnic gadget" as the means by which
> males avoid restroom lines...

Well, that's hardly an *unnamed* organ, is it?



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


Re: Constraints -//- first release -//- Flexible abstract class based validation for attributes, functions and code blocks

2012-01-27 Thread Jon Clements
On Jan 27, 6:38 am, Nathan Rice 
wrote:
> > May I suggest a look at languages such as ATS and Epigram? They use
> > types that constrain values specifically to prove things about your
> > program. Haskell is a step, but as far as proving goes, it's less
> > powerful than it could be. ATS allows you to, at compile-time, declare
> > that isinstance(x, 0 <= Symbol() < len(L)) for some list L. So it
> > might align well with your ideas.
>
> Thanks for the tip.
>
> >>> Probably deserves a better name than "constraintslib", that makes one
> >>> think of constraint satisfaction.
>
> >> As you can probably tell from my other projects, I'm bad at coming up
> >> with snappy names.
>
> > I'm bad at doing research on previous projects ;)
>
> I guess I'm not plugging my other projects enough...  You should check
> out elementwise.
>
> Thanks,
>
> Nathan

I love elementwise and this one - thanks.

If I can be so bold, I would call it 'contracts'. Or, if you want to
be more imaginative and esoteric - 'judge'/'barrister'/'solicitor'.

Thanks again,

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


Re: Where to put data

2012-01-27 Thread John Nagle

On 1/25/2012 9:26 AM, bvdp wrote:

I'm having a disagreement with a buddy on the packaging of a program
we're doing in Python. It's got a number of modules and large number
of library files. The library stuff is data, not code.


How much data?  Megabytes? Gigabytes?

I have some modules which contain nothing but big
constants, written by a program in Python format.

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


Patching CGIHTTPServer.py

2012-01-27 Thread Giovanni Funchal
Hi everyone,

I was fiddling around with CGIHTTPServer.py --- a very handy module
for quickly setting up a full HTTP server with CGI support --- when I
noticed that it doesn't support responses other than "200 OK". So, for
instance if your page wants to do a redirect (response 303), it just
isn't supported. I think this is a major drawback that can be easily
overcome and I'd very happily contribute that as an enhancement.

But... I'm new to Python and as a matter of fact web programming as a
whole isn't really my specialty. I was thinking that maybe someone
could spend half an hour looking at my solution and help raising it's
quality to the level I can submit it as a patch proposal.

Cheers,
-- Giovanni
--- /usr/lib/python2.7/CGIHTTPServer.py	2011-10-04 22:24:00.0 +0100
+++ CGIHTTPServer.py	2012-01-27 22:38:01.785587952 +
@@ -30,6 +30,7 @@
 import SimpleHTTPServer
 import select
 import copy
+import re
 
 
 class CGIHTTPRequestHandler(SimpleHTTPServer.SimpleHTTPRequestHandler):
@@ -218,8 +219,6 @@
   'HTTP_USER_AGENT', 'HTTP_COOKIE', 'HTTP_REFERER'):
 env.setdefault(k, "")
 
-self.send_response(200, "Script output follows")
-
 decoded_query = query.replace('+', ' ')
 
 if self.have_fork:
@@ -229,10 +228,23 @@
 args.append(decoded_query)
 nobody = nobody_uid()
 self.wfile.flush() # Always flush before forking
+r, w = os.pipe()
 pid = os.fork()
 if pid != 0:
 # Parent
+os.close(w)
 pid, sts = os.waitpid(pid, 0)
+# read and translate status header
+r = os.fdopen(r)
+data = r.readline()
+status = re.match('Status: ([0-9]+) (.+)', data)
+if status:
+self.send_response(int(status.group(1)), status.group(2))
+else:
+self.send_response(200, 'OK')
+self.wfile.write(data)
+# pipe rest of contents
+self.wfile.write(r.read())
 # throw away additional data [see bug #427345]
 while select.select([self.rfile], [], [], 0)[0]:
 if not self.rfile.read(1):
@@ -242,12 +254,13 @@
 return
 # Child
 try:
+os.close(r)
 try:
 os.setuid(nobody)
 except os.error:
 pass
 os.dup2(self.rfile.fileno(), 0)
-os.dup2(self.wfile.fileno(), 1)
+os.dup2(w, 1)
 os.execve(scriptfile, args, env)
 except:
 self.server.handle_error(self.request, self.client_address)
@@ -285,8 +298,16 @@
 while select.select([self.rfile._sock], [], [], 0)[0]:
 if not self.rfile._sock.recv(1):
 break
-stdout, stderr = p.communicate(data)
-self.wfile.write(stdout)
+r, stderr = p.communicate(data)
+data = r.split('\n', 1)
+status = re.match('Status: ([0-9]+) (.+)', data[0])
+if status:
+self.send_response(int(status.group(1)), status.group(2))
+else:
+self.send_response(200, 'OK')
+self.wfile.write(data[0]+'\n')
+# pipe rest of contents
+self.wfile.write(data[1])
 if stderr:
 self.log_error('%s', stderr)
 p.stderr.close()
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: calling a simple PyQt application more than once

2012-01-27 Thread John Posner
Jabba Laci wrote:
> Hi,
>
> I have a simple PyQt application that creates a webkit instance to
> scrape AJAX web pages. It works well but I can't call it twice. I
> think the application is not closed correctly, that's why the 2nd call
> fails. Here is the code below. I also put it on pastebin:
> http://pastebin.com/gkgSSJHY .
>
> The question is: how to call this code several times within a script.

You want to create/execute/quit a QApplication just once, not multiple
times.

I don't know either WebKit  or AJAX. In fact, I've never done any
networking with PyQt. But a little playing with the QtNetwork module
yielded this, using the QNetworkAccessManager and QNetworkRequest classes:

from PyQt4.QtCore import QUrl
from PyQt4.QtGui import QApplication, QPushButton
from PyQt4.QtNetwork import QNetworkAccessManager, QNetworkRequest

def process_page(reply_obj):
resp = reply_obj.readAll()
reply_obj.close()
print str(resp).strip()

def do_click():
req = QNetworkRequest(QUrl(MYURL))
mgr.finished.connect(process_page)
mgr.get(req)

MYURL = 'http://simile.mit.edu/crowbar/test.html'

if __name__ == "__main__":
# we need only one application object and one net-access mgr
app = QApplication([])
mgr = QNetworkAccessManager()

# the entire GUI is one button
btn = QPushButton("Press me")
btn.clicked.connect(do_click)
btn.show()

# start the event loop
app.exec_()

You can click the "Press me" button as many times as you wish; it
retrieves and displays/prints the same HTML file on each click.

HTH,
John

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


Re: Where to put data

2012-01-27 Thread bvdp
On Thursday, January 26, 2012 8:20:24 PM UTC-7, Michael Torrie wrote:
>
> > I'm getting mangled by the debian maintainers and friends who seem to
> > believe that python modules need to go into /usr/lib/python...
> 
> I guess the maintainers aren't distinguishing between python apps and
> their submodules and general python modules (libraries), which is pretty
> silly.  Even as a mere user I would not like my /usr/lib/python
> directory cluttered with python code that is not useful generally but is
> only for specific apps.  Namespace collisions are inevitable with other
> python apps (not libraries) if folks insist on doing this.

Well, I might be wrong in my assumptions. Never got invited to join the inner 
circle so I'm looking at all this from the outside.

> 
> Calibre appears to be in the Ubuntu standard repositories.  I just

Yeah, I looked at that as well after your earlier post.

> checked and in calibre proper (not talking about dependent libraries and
> things that would be useful outside of calibre), there are no python
> files installed in /usr/lib/python/.  Calibre modules that belong to

But, when you dl from the calibre site the default location is /opt.

> calibre proper are in /usr/lib/calibre.  Recipes (really just python
> scripts) are in /usr/share/calibre.  Maybe Ubuntu is doing things
> differently than Debian, but I'm hard pressed to see the logic in
> forcing everything ever written in python, such as submodules, installed
> to /usr/lib/python.  Baffles the mind.

I completely agree.

Mind you, one consolation in putting things in, for example, /usr/lib/pythonX.Y 
are:

   - you can let setup find that that magic location
   - you don't need to worry about your app finding the lib (python modules).

But, I've pretty much decided that the easy way (and dare I say the correct 
way?) is to let my packager decide where to install the modules. My program 
really doesn't care (nor do I). And, then I'll end up with my program's stuff 
something like:

  myprogram
 mymodules ...
 mylib ...
 program-bin

And then have a link in the users path which is a link or a one line call to 
program-bin. With modules in a directory at the same level as program-bin I 
don't have to do any module searches, etc. Seems to be a simple and 
sort-of-elegant solution.

I've tried this with one-line callers and links and it seems to work in all 
cases. Any gotchas? 
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Where to put data

2012-01-27 Thread bvdp
On Friday, January 27, 2012 3:15:44 PM UTC-7, John Nagle wrote:
> On 1/25/2012 9:26 AM, bvdp wrote:
> > I'm having a disagreement with a buddy on the packaging of a program
> > we're doing in Python. It's got a number of modules and large number
> > of library files. The library stuff is data, not code.
> 
>  How much data?  Megabytes? Gigabytes?
> 
>  I have some modules which contain nothing but big
> constants, written by a program in Python format.
> 
>   John Nagle

A couple of hundred files totaling about 2 meg. Not a lot. Gosh, I remember 
when this was several full floppies :)

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


to express unicode string

2012-01-27 Thread contro opinion
>>> s='你好'
>>> t=u'你好'
>>> s
'\xc4\xe3\xba\xc3'
>>> t
u'\u4f60\u597d'
>>> t=us
Traceback (most recent call last):
  File "", line 1, in 
NameError: name 'us' is not defined
>>>
how can i use us to express  u'你好'??
can i add someting in  us  to  express   u'你好'??
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Re: How do I call super() in c extention ?

2012-01-27 Thread YASUDA Hideyuki

> Have you considered using Cython for this?

No. I hadn't known Cython.
Now, I'll try to use Cython.

thanks.

umedoblock

(-28163年01月-9日 04:59), Stefan Behnel wrote:

umedoblock, 27.01.2012 03:03:

I'd like to call super() in c extension.
I'd like to rewrite class Baa as c extension.


Have you considered using Cython for this? It will allow you to do exactly
that with only minor changes to your Python code (if any). And it's quite
likely that the C code that it generates from your Python code will be more
efficient than what you'd write manually. Certainly more readable and
maintainable.

Stefan




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


what is the unicode?

2012-01-27 Thread contro opinion
as far as i know

>>> u'中国'.encode('utf-8')
'\xe4\xb8\xad\xe5\x9b\xbd'

so,'\xe4\xb8\xad\xe5\x9b\xbd'  is the  utf-8  of  '中国'

>>> u'中国'.encode('gbk')
'\xd6\xd0\xb9\xfa'
so,'\xd6\xd0\xb9\xfa' is the  utf-8  of  '中国'

>>> u'中国'
u'\u4e2d\u56fd'

what is the meaning of u'\u4e2d\u56fd'?
u'\u4e2d\u56fd'  =  \x4e2d\x56fd  ??
-- 
http://mail.python.org/mailman/listinfo/python-list


PyPI - how do you pronounce it?

2012-01-27 Thread Chris Angelico
Hopefully this will be a step up from Rick's threads in usefulness,
but I'm aware it's not of particularly great value!

How do you pronounce PyPI? Is it:
* Pie-Pie?
* Pie-Pip, but without the last p? (same as above but short i)
* Pie-Pea-Eye?
* Something else?

I've been saying Pie-Pea-Eye myself, but am wondering what the most
normal pronunciation is. And am fully prepared for the possibility
that there is no one "most normal"!

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