Re: How to know locals of script without running it

2009-10-26 Thread Gabriel Genellina
En Mon, 26 Oct 2009 14:06:22 -0300, Nadav Chernin  
 escribió:



Is there a way to know locals of the script without running it?


I don't quite understand the question, could you explain it? A concrete  
example would help.


--
Gabriel Genellina

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


Re: why python cache the string > 256?

2009-10-26 Thread Gabriel Genellina
En Mon, 26 Oct 2009 23:42:54 -0300, s7v7nislands   
escribió:



On Oct 27, 4:03 am, "Diez B. Roggisch"  wrote:

s7v7nislands schrieb:

> test.py
> #!/usr/bin/python
> a = []
> for i in xrange(100):
> a.append('a'*500)

> $python -i test.py #virt mem 514m in top output
>>> del a   #virt mem 510m

> why python cache these string?
> In source, I see when object size > SMALL_REQUEST_THRESHOLD, python
> would use malloc.
> also use free() when string refcount == 0.

> do I miss somethong?

http://effbot.org/pyfaq/why-doesnt-python-release-the-memory-when-i-d...


thanks. but it can't explain why cache string size bigger than
SMALL_REQUEST_THRESHOLD.
In source, It seems only allocate from cache pool when object's size <
SMALL_REQUEST_THRESHOLD (256),
when size > SMALL_REQUEST_THRESHOLD, it will direct use malloc.
see void *PyObject_Malloc(size_t nbytes) in Objects/obmalloc.c

I know the range & xrange's memory use. the int,str object has their
memory manager above Python's object allocator.
but why python don't free big string's memory, which size >
SMALL_REQUEST_THRESHOLD


It does - it isn't Python who keeps those memory blocks, but the C stdlib.  
Apparently free doesn't bring the memory block back to the OS, but keeps  
itself internally as free blocks.
If you repeat the cycle again, you should see that memory usage doesn't  
grow beyond the previous value; when those big strings are malloc()ed  
again, the C stdlib fulfills the memory request using those free blocks it  
originally got from the OS.


This is what I see on Windows (using the pslist utility from sysinternals):

# memory usage right when Python starts:
D:\USERDATA\Gabriel>pslist -m python

PsList 1.23 - Process Information Lister
Copyright (C) 1999-2002 Mark Russinovich
Sysinternals - www.sysinternals.com

Process memory detail for LEPTON:

Name  Pid  VM  WS   WS PkPriv   Faults NonP Page  
PageFile
python   3672   32916473247322828 12122   55  
2828


# after creating the big list of strings
python   3672  622892  533820  533820  531724   1417372   55
531724


# after `del a`
python   3672  6187126656  5338284212   1417472   55  
4212


# after re-creating the list
python   3672  622960  533844  533844  531732   2810372   55
531732


# after `del a` again, repeating a few times
python   3672  6187126708  5338444244   2810372   55  
4244
python   3672  6187126672  5338484220   4203172   55  
4220
python   3672  6187126696  5338484252   5596082   55  
4252
python   3672  6187126680  5338484228   6988912   55  
4228


Note the 'VM' and 'Priv' columns (virtual address space and private bytes,  
respectively).


--
Gabriel Genellina

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


Problem embedding Python.

2009-10-26 Thread Brandon Keown
I am going to try to embed python in an application, but in simple
testing, I could not get it to work.  The following code seems like it
should work, but it crashes, and I have tried several things.  What
could I be doing wrong?

#include 

int main(int argc, char* argv[])
{
FILE* fp = fopen("test.py","r");
Py_Initialize();
PyRun_SimpleFile(fp,"test.py");
Py_Finalize();
return 0;
}
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Surprising timeit result

2009-10-26 Thread Steven D'Aprano
On Tue, 27 Oct 2009 04:36:12 +, John O'Hagan wrote:

> I sometimes use timeit to see if it's better to check if something needs
> doing, or to just do it anyway. This result was surprising:
> 
> setup =  'd1 = {"a":0, "b":0}; d2 = {"a":0, "b":1}'
> 
> Timer('d1.update(d2)', setup).timeit() 2.6499271392822266
> 
> Timer('if d1 != d2: d1.update(d2)', setup).timeit() 1.0235211849212646
> 
> In other words, in this case it's substantially quicker to check for
> something and then proceed, than it is to just proceed! I'm curious
> about the explanation.

The code snippet is executed inside a loop. The first snippet runs 
d1.update(d2) one million times. The second snippet runs "if d1 != d2" 
one million times, and d1.update(d2) once.


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


Re: Surprising timeit result

2009-10-26 Thread John O'Hagan
On Tue, 27 Oct 2009, Paul Rubin wrote:
> "John O'Hagan"  writes:
> > Timer('d1.update(d2)', setup).timeit()
> > 2.6499271392822266
> >
> > Timer('if d1 != d2: d1.update(d2)', setup).timeit()
> > 1.0235211849212646
> >
> > In other words, in this case it's substantially quicker to check for
> > something and then proceed, than it is to just proceed! I'm curious
> > about the explanation.
> 
> Looks to me like in both versions, d2 is only initialized once, so
> the d1.update in the second case only gets called on the first loop.
> It's not so surprising that comparing d1 and d2 is faster than
> actually updating d1.
> 

Of course:

Timer('d1 = {"a":0}; d2 = {"a":1}\nif d1 != d2: d1.update(d2)').timeit()
1.9810600280761719

Timer('d1 = {"a":0}; d2 = {"a":1}\nd1.update(d2)').timeit()
1.7072379589080811

as expected. I wasn't quite clear about how Timer() worked, is my excuse!

Thanks,

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


Re: how to get os.system () call to cooperate on Windows

2009-10-26 Thread Kushal Kumaran
On Tue, Oct 27, 2009 at 2:04 AM, Anthra Norell  wrote:
> 
>
> No, I didn't. There's a number of modules I know by name only and shutils
> was one of them. A quick peek confirmed that it is exactly what I am looking
> for. Thank you very much for the advice.
>

Then Doug Hellmann's PyMOTW is for you. http://blog.doughellmann.com/

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


Re: Surprising timeit result

2009-10-26 Thread Paul Rubin
"John O'Hagan"  writes:
> Timer('d1.update(d2)', setup).timeit()
> 2.6499271392822266
> 
> Timer('if d1 != d2: d1.update(d2)', setup).timeit()
> 1.0235211849212646
> 
> In other words, in this case it's substantially quicker to check for
> something and then proceed, than it is to just proceed! I'm curious
> about the explanation.

Looks to me like in both versions, d2 is only initialized once, so
the d1.update in the second case only gets called on the first loop.
It's not so surprising that comparing d1 and d2 is faster than
actually updating d1.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: python web service or Apache?

2009-10-26 Thread Gabriel Genellina

En Sun, 25 Oct 2009 17:47:43 -0300, Peng Yu  escribió:


Although, python can be used to provide web service. The following
webpage also mentioned, "Apache the best and most widely used web
server on the Internet today, check it out. If you want to run your
own web server this is the one to get, you can get binaries for both
Windows and Unix. You can download the entire sourcecode if you want
to check how it was made." Therefore, it would be better to use Apache
rather than python to provide web service, right?


Note that web server != web service.

Apache is a "web server"; it handles HTTP requests to serve web pages,  
typically HTML documents, images, videos, etc. Usually those requests come  
from a human browsing the web. Apache is highly optimized to serve  
"static" documents (those that are already prebuilt, and aren't dependent  
on specific details of the current request, e.g. a photo).
"dynamic" documents (e.g. your bank account statement) have to be  
generated for each specific request - there is a program behind those  
dynamic documents, and that program may be written in Python (or Perl, or  
PHP, or whatever). That is, Python is used to build dynamic content --  
pages that cannot be prebuilt.


Although you can write a web server in Python itself, and it works fine  
for low-volume sites, it cannot compete (in speed, number of concurrent  
transactions, and other features) with Apache or lighttpd.


A "web service" is a program that exposes some sort of API that can be  
accessed thru a web interfase, mostly intended to be used by other  
programs, not humans. Web services usually are built on top of HTTP as the  
transport layer, so they run behind Apache or other web server. Python is  
perfectly adequate to write web services.


--
Gabriel Genellina

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


Surprising timeit result

2009-10-26 Thread John O'Hagan
I sometimes use timeit to see if it's better to check if something needs doing, 
or to just do it anyway. This result was surprising:

setup =  'd1 = {"a":0, "b":0}; d2 = {"a":0, "b":1}'

Timer('d1.update(d2)', setup).timeit()
2.6499271392822266

Timer('if d1 != d2: d1.update(d2)', setup).timeit()
1.0235211849212646

In other words, in this case it's substantially quicker to check for something 
and
then proceed, than it is to just proceed! I'm curious about the explanation.

Regards,

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


Re: quit button

2009-10-26 Thread Gabriel Genellina
En Sat, 24 Oct 2009 23:59:06 -0300, linda.s   
escribió:



When I click "quit" button, why the following code has problem?

[...]

if __name__ == '__main__':
root = Tk()
gridbox(Toplevel())
packbox(Toplevel())
Button(root, text='Quit', command=root.quit).pack()
mainloop()


If you run the code from inside IDLE, you'll have to add this line at the  
end:


root.destroy()

as explained here:

http://www.effbot.org/tkinterbook/tkinter-hello-again.htm

--
Gabriel Genellina

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


Re: Problem with urllib2.urlopen() opening a local file

2009-10-26 Thread Gabriel Genellina
En Sat, 24 Oct 2009 20:10:21 -0300, deja user   
escribió:



I want to use urlopen() to open either a http://... file or a local
file File:C:/...  I don't have problems opening and reading the file
either way.  But when I run the script on a server (ArcGIS server),
the request won't complete if it was trying to open a local file.
Even though I call close() in either case, something seemed to be
preventing the script to complete if urlopen is trying to open a local
file.  I wonder if there is anything else I should do in the code to
kill the file descriptor, or if it is a known issue that something is
leaking

When running the script standalone, this is not an issue.


I don't know about the ArcGIS server, but leaking a file descriptor  
usually is not a reason to not finish a request. I'd look into the server  
log files for any errors. The server might be configured to not allow  
open() of arbitrary files, by example. This seems more an ArcGIS question  
than a Python one.


Just to be sure, "local file" in this context means "local to the server",  
ok? An url like "file://c:/path/..." (note the differences with yours) is  
only meaningful if the server is running Windows, ok?


--
Gabriel Genellina

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


Re: Adding a menu to Tkinter

2009-10-26 Thread John Posner

Ronn Ross wrote:


I'm attempting to add a menu bar to my Tkinter app. I can't figure out the 
correct syntax. Can someone help?  I get this error when I run the app:

Traceback (most recent call last):
  File "tkgrid.py", line 26, in 

app = App(root)
  File "tkgrid.py", line 10, in __init__
menubar = Menu(master).grid(row=0)
  File 
"/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/lib-tk/Tkinter.py",
 line 1859, in grid_configure

+ self._options(cnf, kw))
_tkinter.TclError: can't manage ".4300345712": it's a top-level window


from Tkinter import *

class App:

def __init__(self, master):



def hello():
print "hello!"

menubar = Menu(master).grid(row=0)
menubar.add_command(label="Hello!", command=hello)
Label(master, text="First").grid(row=1)

Label(master, text="Second").grid(row=2)

e1 = Entry(master)

e2 = Entry(master)
e3 = Entry(master)

e1.grid(row=0, column=1)
e2.grid(row=1, column=1)

e2.grid(row=2, column=1)


root = Tk()

app = App(root)

root.mainloop()
  



Ronn, I'm not sure what you're trying to accomplish, but it looks like 
you're getting wrapped around the axle a bit. Did you want your "App" 
object to instantiate a new Tkinter window, in addition to the "root" 
window? For that, you'd need to do this:


 class App(Toplevel):
  ...


But maybe you don't really want/need to do that. Here's a template for 
creating a single Tkinter window, with a menubar that contains a single 
menu item, "File". And clicking the "File" item, opens a submenu with a 
single command, "Hello".


#--
from Tkinter import *

def hello():
   print "hello!"

class App(Tk):
   def __init__(self):
   Tk.__init__(self)
  
   # create a Menu object

   mbar = Menu(self)
   # set this Menu to be the App window's menu bar   
   self['menu'] = mbar


   # create another Menu object
   fileMenu = Menu(mbar)
   # set this Menu to be a submenu of the menu bar, under the name "File"
   mbar.add_cascade(label="File", menu=fileMenu)
  
   # add a command named "Hello" to the submenu, and have it

   # invoke the function "hello"
   fileMenu.add_command(label="Hello", command=hello)

app = App()
app.mainloop()
#--

Note that instead of this:

   self['menu'] = mbar

... you could use this:

   self.config(menu=mbar)

HTH,
-John

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


Re: Web development with Python 3.1

2009-10-26 Thread Aaron Watters
On Oct 25, 7:52 pm, Alan Harris-Reid  wrote:
> I am very much new to Python, and one of my first projects is a simple
> data-based website. I am starting with Python 3.1 (I can hear many of
> you shouting "don't - start with 2.6"), but as far as I can see, none of
> the popular python-to-web frameworks (Django, CherryPy, web.py, etc.)
> are Python3 compatible yet.
>
> So, what can I use to start my web programming experience using 3.1?
>
> Any help would be appreciated.
>
> Alan

Don't. use python 2.6 with WHIFF :)
  http://aaron.oirt.rutgers.edu/myapp/GenBankTree/index
  http://whiff.sourceforge.net

-- Aaron Watters

===
It gotta be rock-roll music
if you wanna dance with me
if you wanna dance with me
-- 
http://mail.python.org/mailman/listinfo/python-list


ANN: WHIFF += Mako & treeview & url rewrites

2009-10-26 Thread Aaron Watters
WHIFF 0.6 RELEASED

WHIFF += Mako & treeview & url rewrites

WHIFF is a collection of support services
for Python/WSGI Web applications which
allows applications to be composed by
"dropping" dynamic pages into container
directories.

This mode of development will be familiar
to developers who have created PHP
applications, vanilla CGI scripts,
Apache/modpy Publisher applications,
JSP pages, or static web content.

The new WHIFF 0.6 release now includes

** Treeview widgets

WHIFF now includes components for
implementing "tree views" for web navigation panes
or other purposes, either using AJAX or frame
reloads.  Try the GenBank demo at

http://aaron.oirt.rutgers.edu/myapp/GenBankTree/index

Read more in the tree view tutorial:

http://aaron.oirt.rutgers.edu/myapp/docs/W1100_2200.TreeView

** Mako template support

New standard middleware provides built in support
for using the fast, powerful, elegant, and popular
Mako template engine in WHIFF applications. Read
more in the Mako tutorial:

http://aaron.oirt.rutgers.edu/myapp/docs/W1100_1075.MakoGrading

** Url rewrites

The URL rewrite tutorial explains how to
implement WHIFF applications using URLs that
are shorter and easier to understand.  Read
it here:

http://aaron.oirt.rutgers.edu/myapp/docs/W1100_2050.UrlMapping

WHIFF HOME PAGE: http://whiff.sourceforge.net

I hope you like it!  -- Aaron Watters

===
less is more.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: why python cache the string > 256?

2009-10-26 Thread s7v7nislands
On Oct 27, 4:03 am, "Diez B. Roggisch"  wrote:
> s7v7nislands schrieb:
>
>
>
> > hi all:
>
> > test.py
> > #!/usr/bin/python
> > a = []
> > for i in xrange(100):
> >     a.append('a'*500)
>
> > $python -i test.py     #virt mem 514m in top output
> >>> del a                   #virt mem 510m
>
> > why python cache these string?
> > In source, I see when object size > SMALL_REQUEST_THRESHOLD, python
> > would use malloc.
> > also use free() when string refcount == 0.
>
> > do I miss somethong?
>
> http://effbot.org/pyfaq/why-doesnt-python-release-the-memory-when-i-d...
>
> Diez

thanks. but it can't explain why cache string size bigger than
SMALL_REQUEST_THRESHOLD.
In source, It seems only allocate from cache pool when object's size <
SMALL_REQUEST_THRESHOLD (256),
when size > SMALL_REQUEST_THRESHOLD, it will direct use malloc.
see void *PyObject_Malloc(size_t nbytes) in Objects/obmalloc.c

I know the range & xrange's memory use. the int,str object has their
memory manager above Python's object allocator.
but why python don't free big string's memory, which size >
SMALL_REQUEST_THRESHOLD

sorry for poor english.
thanks!
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Adding a menu to Tkinter

2009-10-26 Thread MRAB

Ronn Ross wrote:
I'm attempting to add a menu bar to my Tkinter app. I can't figure out 
the correct syntax. Can someone help?  I get this error when I run the app:


Traceback (most recent call last):
  File "tkgrid.py", line 26, in 
app = App(root)
  File "tkgrid.py", line 10, in __init__
menubar = Menu(master).grid(row=0)
  File 
"/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/lib-tk/Tkinter.py", 
line 1859, in grid_configure

+ self._options(cnf, kw))
_tkinter.TclError: can't manage ".4300345712": it's a top-level window


from Tkinter import *

class App:

def __init__(self, master):
   
def hello():

print "hello!"

menubar = Menu(master).grid(row=0)
menubar.add_command(label="Hello!", command=hello)
Label(master, text="First").grid(row=1)
Label(master, text="Second").grid(row=2)
   
e1 = Entry(master)

e2 = Entry(master)
e3 = Entry(master)

e1.grid(row=0, column=1)
e2.grid(row=1, column=1)
e2.grid(row=2, column=1)


root = Tk()

app = App(root)

root.mainloop()


This might help:

http://effbot.org/zone/tkinter-menubar.htm

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


Adding a menu to Tkinter

2009-10-26 Thread Ronn Ross
I'm attempting to add a menu bar to my Tkinter app. I can't figure out the
correct syntax. Can someone help?  I get this error when I run the app:

Traceback (most recent call last):
  File "tkgrid.py", line 26, in 
app = App(root)
  File "tkgrid.py", line 10, in __init__
menubar = Menu(master).grid(row=0)
  File
"/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/lib-tk/Tkinter.py",
line 1859, in grid_configure
+ self._options(cnf, kw))
_tkinter.TclError: can't manage ".4300345712": it's a top-level window


from Tkinter import *

class App:

def __init__(self, master):

def hello():
print "hello!"

menubar = Menu(master).grid(row=0)
menubar.add_command(label="Hello!", command=hello)
Label(master, text="First").grid(row=1)
Label(master, text="Second").grid(row=2)

e1 = Entry(master)
e2 = Entry(master)
e3 = Entry(master)

e1.grid(row=0, column=1)
e2.grid(row=1, column=1)
e2.grid(row=2, column=1)


root = Tk()

app = App(root)

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


Re: Web development with Python 3.1

2009-10-26 Thread Alan Harris-Reid


Hi Paul, thanks for the reply (despite the sarcasm ;-) ),

>Does it occur to you that the unavailability of those frameworks is 
part of the REASON they say to use 2.x?
Of course, but that doesn't mean that there isn't someone out there who 
may know of a framework that is already Python3 compatible, or is being 
worked-on.


>Have you answered your own question?
No

>Anyway, for simple web programming, frameworks are not worth the 
hassle. Just use the cgi module.

Ok - I'll look into it.

>... you are the one who decided to zoom off into the 3.1 wilderness 
before the framework developers got there.
I haven't zoomed-off anywhere yet - in fact I've hardly started.  I made 
the decision to start with 3.1 based on the fact that it was the latest 
version, and hoping that there may be some framework stuff out there 
(because 3.0 has been out for a while now).  However, it looks as though 
I might have to review that decision, but what I've learned so far is 
pretty simple stuff, so it won't be wasted.


Regards,
Alan

Alan Harris-Reid  writes:
  

I am very much new to Python, and one of my first projects is a simple
data-based website. I am starting with Python 3.1 (I can hear many of
you shouting "don't - start with 2.6"), but as far as I can see, none
of the popular python-to-web frameworks (Django, CherryPy, web.py,
etc.) are Python3 compatible yet.

So, what can I use to start my web programming experience using 3.1?



Does it occur to you that the unavailability of those frameworks is
part of the REASON they say to use 2.x?  Have you answered your own
question?

Anyway, for simple web programming, frameworks are not worth the
hassle.  Just use the cgi module.

If you want to use a framework, well, you are the one who decided to
zoom off into the 3.1 wilderness before the framework developers got
there.  If you're an experienced programmer in other languages and
you're determined to use a framework, maybe a worthwhile Python
learning project would be to help port your favorite framework to 3.1.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Is there a command that returns the number of substrings in a string?

2009-10-26 Thread alex23
Gerard Flanagan  wrote:
> def count(text, *args):

Other than the ability to handle multiple substrings, you do realise
you've effectively duplicated str.count()?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Web development with Python 3.1

2009-10-26 Thread Alan Harris-Reid




Anyway, for simple web programming, frameworks are not worth the
hassle.  Just use the cgi module.


I can vouch for what Paul says. I started in Python 3 years ago, and I 
did so with a web application (still working on it!). I'm using the 
cgi approach, and it certainly teaches you the concepts. I fail to see 
how starting with a framework is a good idea if you don't know how the 
frameworks work (or what they're actually doing). It would be a bit 
like doing a web page in Dreamw***er and thinking you understand 
HTML/CSS.


B

Hi Brendon, thanks for the advice.  Looks like I'll have to go the cgi 
route myself if I want to stick with with Python3.


Regards,
Alan
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Web development with Python 3.1

2009-10-26 Thread Alan Harris-Reid

Exarkun - thanks for the reply

> don't - start with 2.6
Thought you might say that ;-)

Regards,
Alan

On 25 Oct, 11:52 pm, a...@baselinedata.co.uk wrote:


I am very much new to Python, and one of my first projects is a simple
data-based website. I am starting with Python 3.1 (I can hear many of 
you shouting "don't - start with 2.6"), but as far as I can see, none 
of the popular python-to-web frameworks (Django, CherryPy, web.py, 
etc.) are Python3 compatible yet.


So, what can I use to start my web programming experience using 3.1?

Any help would be appreciated.


don't - start with 2.6

Alan

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



No virus found in this incoming message.
Checked by AVG - www.avg.com 
Version: 8.5.423 / Virus Database: 270.14.31/2458 - Release Date: 10/25/09 
08:10:00

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


Re: Does someone has a 5-line working example of SOAP server request ?

2009-10-26 Thread Dan Sommers
On Tue, 27 Oct 2009 01:45:09 +0100, Stef Mientki wrote:

> So could someone tell me what libraries I need to perform a SOAP
> query ? ...

Check out suds (https://fedorahosted.org/suds/).

> Is there a 5-line (Dive into Python had a 4-line example ;-) that can
> show the SOAP query is working ?

My working examples are all at work, but there are a bunch of complete 
examples at .

FWIW, the consensus (as per google!) is correct:  SOAP is a miserable 
protocol, don't use it if you don't have to, and Python support for it is 
in sad shape.

HTH,
Dan

-- 
Dan Sommers   A death spiral goes clock-
   wise north of the equator.
Atoms are not things. -- Werner Heisenberg  -- Dilbert's PHB

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


Does someone has a 5-line working example of SOAP server request ?

2009-10-26 Thread Stef Mientki

hello,

I want to ask some simple queries to a SOAP server ( through wdsl). The 
ICT department advised me to use a dot-net environment, because that 
should be able to handle wdsl automatically. As I have a quite large 
Python desktop application and I still don't understand what a "dot-net 
program" is, I prefer to add SOAP to my existing Python desktop application.


Reading Dive into Python, the chapter SOAP web services, I estimated 
that would be very doable, without  diving to deep in  the details of 
SOAP and other web-protocols. But following the instructions in that 
book, I couldn't get it working. I also noticed that the libraries they 
suggest pyXML, fpconst, SOAPpy are relatively old 4,5 years, so these 
libs are either perfect or dead. So I tried some other libraries lxml, 
zsi,soaplib, but probably due to a lack of detailed knowledge of the 
soap protocol and it's usage, I couldn't get anything working.


So could someone tell me what libraries I need to perform a SOAP query ?
Is there a 5-line (Dive into Python had a 4-line example ;-) that can 
show the SOAP query is working ?


(btw I use Python 2.5 on Windows if that matters)

thanks,
Stef Mientki

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


Re: unicode and dbf files

2009-10-26 Thread John Machin
On Oct 27, 7:15 am, Ethan Furman  wrote:
> John Machin wrote:
> > On Oct 27, 3:22 am, Ethan Furman  wrote:
>
> >>John Machin wrote:
>
> >>>Try this:
> >>>http://webhelp.esri.com/arcpad/8.0/referenceguide/
>
> >>Wow.  Question, though:  all those codepages mapping to 437 and 850 --
> >>are they really all the same?
>
> > 437 and 850 *are* codepages. You mean "all those language driver IDs
> > mapping to codepages 437 and 850". A codepage merely gives an
> > encoding. An LDID is like a locale; it includes other things besides
> > the encoding. That's why many Western European languages map to the
> > same codepage, first 437 then later 850 then 1252 when Windows came
> > along.
>
> Let me rephrase -- say I get a dbf file with an LDID of \x0f that maps
> to a cp437, and the file came from a german oem machine... could that
> file have upper-ascii codes that will not map to anything reasonable on
> my \x01 cp437 machine?  If so, is there anything I can do about it?

ASCII is defined over the first 128 codepoints; "upper-ascii codes" is
meaningless. As for the rest of your question, if the file's encoded
in cpXXX, it's encoded in cpXXX. If either the creator or the reader
or both are lying, then all bets are off.

> > BTW, what are you planning to do with an LDID of 0x00?
>
> Hmmm.  Well, logical choices seem to be either treating it as plain
> ascii, and barfing when high-ascii shows up; defaulting to \x01; or
> forcing the user to choose one on initial access.

It would be more useful to allow the user to specify an encoding than
an LDID.

You need to be able to read files created not only by software like
VFP or dBase but also scripts using third-party libraries. It would be
useful to allow an encoding to override an LDID that is incorrect e.g.
the LDID implies cp1251 but the data is actually encoded in koi8[ru]

Read this: http://en.wikipedia.org/wiki/Code_page_437
With no LDID in the file and no encoding supplied, I'd be inclined to
make it barf if any codepoint not in range(32, 128) showed up.

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


Re: Socket logic problem

2009-10-26 Thread John O'Hagan
On Sun, 25 Oct 2009, Gabriel Genellina wrote:
> En Sat, 24 Oct 2009 06:40:08 -0300, John O'Hagan 
> 
> escribió:
> > I have several instances of the same generator function running
> > simultaneously, some within the same process, others in separate
> > processes. I
> > want them to be able to share data (the dictionaries passed to them as
> > arguments), in such a way that instances designated as "leaders" send
> > their
> > dictionaries to "follower" instances.
> >
> > I'm trying to use sockets to relay the dicts in pickled form, like this:
> >
> > from socket import socket
> >
> > PORT = 2050
> > RELAY = socket()
> > RELAY.bind(('', PORT))
> > RELAY.listen(5)
> >
> > PICKLEDICT = ''
> > while 1:
> > INSTANCE = RELAY.accept()[0]
> > STRING = INSTANCE.recv(1024)
> > if STRING == "?":
> > INSTANCE.send(PICKLEDICT)
> > else:
> > PICKLEDICT = STRING
> >
> > What I was hoping this would do is allow the leaders to send their dicts
> > to
> > this socket and the followers to read them from it after sending an
> > initial
> > "?", and that the same value would be returned for each such query until
> > it
> > was updated.
> >
> > But clearly I have a fundamental misconception of sockets, as this logic
> > only
> > allows a single query per connection, new connections break the old
> > ones, and
> > a new connection is required to send in a new value.
> 
> You may use sockets directly, but instead of building all infrastructure
> yourself, use a ThreadingTCPServer (or ForkingTCPServer), they allow for
> simultaneous request processing. Even setting up a SimpleXMLRPCServer
> (plus either ThreadingMixIn or ForkingMixIn) is easy enough.
> 
> > Are sockets actually the best way to do this? If so, how to set it up to
> > do
> > what I want? If not, what other approaches could I try?
> 
> See the wiki page on distributed systems:
> http://wiki.python.org/moin/DistributedProgramming
> 
Thanks for that, I didn't realize this was such a complex problem until 
reading the SocketServer docs and the above link. I think I'll aim for using 
something like Pyro when I can get a handle on it; but this quote from the 
socket how-to docs was interesting:

"If you need fast IPC between two processes on one machine, you should look 
into whatever form of shared memory the platform offers. A simple protocol 
based around shared memory and locks or semaphores is by far the fastest 
technique."

So I'll also look into that approach - ICBW but I get the feeling the threaded 
client/server network model may be too much baggage for what is really an IPC 
problem. In fact, while looking into this I've just been using a simple temp 
file to share the data and that's working fine, although it's relatively slow.

Thanks for the pointers,

Regards,

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


playing mp3

2009-10-26 Thread Jabba Laci
Hi,

What do you suggest for playing mp3 files with Python? I found a
simple module (http://code.google.com/p/mp3play/) but it only works
with Windows. I'd need Linux support too.

Thanks,

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


Re: a splitting headache

2009-10-26 Thread Mensanator
On Oct 26, 7:28 am, Vlastimil Brom  wrote:
> 2009/10/26 jhermann :
>
>
>
>
>
> > On 16 Okt., 02:18, Mensanator  wrote:
> >> All I wanted to do is split a binary number into two lists,
> >> a list of blocks of consecutive ones and another list of
> >> blocks of consecutive zeroes.
>
> > Back to the OP's problem, the obvious (if you know the std lib) and
> > easy solution is:
>
>  c = '00101000101'
>  filter(None, re.split("(1+)", c))
> > ['00', '1', '0', '1', '0', '', '00', '1', '0', '1']
>
> > In production code, you compile the regex once, of course.
> > --
> >http://mail.python.org/mailman/listinfo/python-list
>
> Maybe one can even forget the split function here entirely
>
> >>> re.findall(r"0+|1+", '00101000101')
>
> ['00', '1', '0', '1', '0', '', '00', '1', '0', '1']
>

Very good. Thanks to both of you. Now if I could only remember
why I wanted to do this.

>
>
> vbr

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


RELEASED Python 2.6.4

2009-10-26 Thread Barry Warsaw
On behalf of the Python community, I'm happy to announce the  
availability of Python 2.6.4.  This is the latest production-ready  
version in the Python 2.6 series.


We had a little trouble with the Python 2.6.3 release; a number of  
unfortunate regressions were introduced.  I take responsibility for  
rushing it out, but the good news is that Python 2.6.4 fixes the known  
regressions in 2.6.3.  We've had a lengthy release candidate cycle  
this time, and are confident that 2.6.4 is a solid release.  We highly  
recommend you upgrade to Python 2.6.4.


Please see the NEWS file for all the gory details.

http://www.python.org/download/releases/2.6.4/NEWS.txt

Source tarballs and the Windows installers can be downloaded from the  
Python 2.6.4 page.  The Mac OS X disk image will be uploaded soon.


   http://www.python.org/download/releases/2.6.4/

For more information on Python 2.6 in general, please see

   http://docs.python.org/whatsnew/2.6.html

Please report bugs for any Python version in the Python tracker.

   http://bugs.python.org

Enjoy,
-Barry

Barry Warsaw
ba...@python.org
Python 2.6 Release Manager
(on behalf of the entire python-dev team)



PGP.sig
Description: This is a digitally signed message part
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Read any function in runtime

2009-10-26 Thread Jack Norton

Matt McCredie wrote:

Rhodri James  wildebst.demon.co.uk> writes:

  
On Fri, 23 Oct 2009 17:39:40 +0100, Matt McCredie  gmail.com>  
wrote:




joao abrantes  gmail.com> writes:

  

Hey. I want to make a program like this:print "Complete the function

f(x)="then the user would enter x+2 or 1/x or any other function that  
only uses
the variable x. Then my python program would calculate f(x) in some  
points for

example in f(2),f(4).. etc . How can I do this?
  
check out 'eval' or 'exec'.
  

Then check out all the reasons you shouldn't use them in an
environment that you don't trust absolutely -- if someone wipes
your hard disc, you won't get any sympathy from here.

The safe answer is to write yourself a small parser.  Given that
you've got a very limited symbol set, that shouldn't be too hard.




This should only be a concern if it is some sort of client/server app (like a
web-app). If this is something that is going to be run on a local machine then
the person running it could do just as much damage via the command line.

While I agree that there is a danger if the input might come from untrusted
users, and the original poster should be aware of that, writing your own parser
only makes sense in those instances. If this application is run locally then
users have access to the machine anyway.

I don't want to give a (potentially) new user to python the impression that they
need to be writing their own parser to solve this problem. It depends on where
the input is coming from. 

Two things to note: 
1. eval and exec are perfectly safe if the input is from a trusted source.

2. eval and exec are never safe if the input is not from a trusted source.

Matt McCredie


  
I'd like to add that there are several lisp apps out there that give you 
a REPL (for example stumpwm).  A REPL could be seen as a sophisticated 
`eval' loop. 
Case in point, it is common in the lisp world.  You could, in theory, 
hose your system from inside emacs (and you may not even know 
it...hahaha). 


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


Re: handling PAMIE and lxml

2009-10-26 Thread elca



Simon Forman-2 wrote:
> 
> On Mon, Oct 26, 2009 at 3:05 AM, elca  wrote:
>>
>> Hello,
>> i was open anther new thread ,old thread is too long.
> 
> Too long for what?
> 
>> first of all,i really appreciate other many people's help in this
>> newsgroup.
>> im making webscraper now.
>> but still problem with my script source.
>> http://elca.pastebin.com/m52e7d8e0
>> i was upload my script in here.
>> so anybody can modify it.
>> main problem is , if you see line number 74 ,75 in my source,
>> you can see this line "thepage = urllib.urlopen(theurl).read()".
>> i want to change this line to work with Pamie not urllib.
> 
> Why?
> 
>> if anyone help me,really appreciate.
>> thanks in advance.
> 
> I just took a look at your code.  I don't want to be mean but your
> code is insane.
> 
> 1.) you import HTMLParser and fromstring but don't use them.
> 
> 2.) the page_check() function is useless.  All it does is sleep for
> len("www.naver.com") seconds.  Why are you iterating through the
> characters in that string anyway?
> 
> 3.) On line 21 you have a pointless pass statement.
> 
> 4.) The whole "if x:" statement on line 19 is pointless because both
> branches do exactly the same thing.
> 
> 5.) The variables start_line and end_line you're using strings.  This
> is not php. Strings are not automatically converted to integers.
> 
> 6.) Because you never change end_line anywhere, and because you don't
> use break anywhere in the loop body, the while loop on line 39 will
> never end.
> 
> 7.) The while loop on line 39 defines the getit() function (over and
> over again) but never calls it.
> 
> 8.) On line 52 you define a list call "results" and then never use it
> anywhere.
> 
> 9.) In getit() the default value for howmany is 0, but on line 68 you
> subtract 1 from it and the next line you return if not howmany.  This
> means if you ever forget to call getit() with a value of howmany above
> zero that if statement will never return.
> 
> 8.) In the for loop on line 54, in the while loop on line 56, you
> recursively call getit() on line 76.  wtf?  I suspect lines 73-76 are
> at the wrong indentation level.
> 
> 9.) On line 79 you have a "bare" except, which just calls exit(1) on
> the next line.  This replaces the exception you had (which contains
> important information about the error encountered) with a SystemExit
> exception (which does not.)  Note that an uncaught exception will exit
> your script with a non-zero return code, so all you're doing here is
> throwing away debugging information.
> 
> 10.) On line 81 you have 'return()'.  This line will never be reached
> because you just called exit() on the line before.  Also, return is
> not a function, you do not need '()' after it.
> 
> 11.) Why do you sleep for half a second on line 83?
> 
> 
> I cannot believe that this script does anything useful.  I would
> recommend playing with the interactive interpreter for awhile until
> you understand python and what you're doing.  Then worry about Pamie
> vs. urllib.
> -- 
> http://mail.python.org/mailman/listinfo/python-list
> 
> 


Hi,
thanks for your advice,
all your words is correct.
first of all, i would like to say
that script source is not finished version,
just i was get it here and there, and just collect it.
im not familiar with python,currently im learning python.
but where is end of learning pyton? there is some end of learning python or
programming? 
i don't think so . also i know what i doing with my script at least.
and what is 'wtf' ? :)

-- 
View this message in context: 
http://www.nabble.com/handling-PAMIE-and-lxml-tp26055230p26068732.html
Sent from the Python - python-list mailing list archive at Nabble.com.

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


Re: how to get os.system () call to cooperate on Windows

2009-10-26 Thread Anthra Norell

Diez B. Roggisch wrote:

Anthra Norell wrote:

  

I have a Python program that needs to copy files around. I could read
and write which would be inefficient and would time-stamp the copy. The
module "os" has lots of operating system functions, but none that copies
files I could make out reading the doc twice. The function "os.system
('copy file_name directory_name')" turns out doesn't do anything except
flashing a DOS command window for half a second. So my question is: How
can one copy files on the OS level?
   This simple question would surely have been asked many times before.
Not to impose on anyone's patience I expect it can be answered between
two sips of coffee.

Thanks very much



Did you take a look at the shutil-module?

Diez
  
No, I didn't. There's a number of modules I know by name only and 
shutils was one of them. A quick peek confirmed that it is exactly what 
I am looking for. Thank you very much for the advice.


Frederic

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


Re: Please help with regular expression finding multiple floats

2009-10-26 Thread Jeremy
On Oct 24, 12:00 am, Edward Dolan  wrote:
> No, you're not missing a thing. I am ;) Something was happening with
> the triple-quoted
> strings when I pasted them. Here is hopefully, the correct 
> code.http://codepad.org/OIazr9lA
> The output is shown on that page as well.
>
> Sorry for the line noise folks. One of these days I'm going to learn
> gnus.

Yep now that works.  Thanks for the help.
Jeremy
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: virtualenv under Win7: easy_install fails in virtual environments

2009-10-26 Thread Michel Claveau - MVP
Hi!

Try to unactive UAC...

@+
-- 
Michel Claveau 
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: unicode and dbf files

2009-10-26 Thread Ethan Furman

John Machin wrote:

On Oct 27, 3:22 am, Ethan Furman  wrote:


John Machin wrote:


Try this:
http://webhelp.esri.com/arcpad/8.0/referenceguide/


Wow.  Question, though:  all those codepages mapping to 437 and 850 --
are they really all the same?


437 and 850 *are* codepages. You mean "all those language driver IDs
mapping to codepages 437 and 850". A codepage merely gives an
encoding. An LDID is like a locale; it includes other things besides
the encoding. That's why many Western European languages map to the
same codepage, first 437 then later 850 then 1252 when Windows came
along.


Let me rephrase -- say I get a dbf file with an LDID of \x0f that maps 
to a cp437, and the file came from a german oem machine... could that 
file have upper-ascii codes that will not map to anything reasonable on 
my \x01 cp437 machine?  If so, is there anything I can do about it?




   '\x68' : ('cp895', 'Kamenicky (Czech) MS-DOS'), # iffy



Indeed iffy. Python doesn't have a cp895 encoding, and it's probably
not alone. I suggest that you omit Kamenicky until someone actually
wants it.


Yeah, I noticed that.  Tentative plan was to implement it myself (more
for practice than anything else), and also to be able to raise a more
specific error ("Kamenicky not currently supported" or some such).



The error idea is fine, but I don't get the "implement it yourself for
practice" bit ... practice what? You plan a long and fruitful career
inplementing codecs for YAGNI codepages?


ROFL.  Playing with code; the unicode/code page interactions.  Possibly 
looking at constructs I might not otherwise.  Since this would almost 
certainly (I don't like saying "absolutely" and "never" -- been 
troubleshooting for too many years for that!-) be a YAGNI, implementing 
it is very low priority




   '\x7b' : ('iso2022_jp', 'Japanese Windows'),# wag



Try cp936.


You mean 932?



Yes.



Very helpful indeed.  Many thanks for reviewing and correcting.



You're welcome.



Learning to deal with unicode is proving more difficult for me than
learning Python was to begin with!  ;D



?? As far as I can tell, the topic has been about mapping from
something like a locale to the name of an encoding, i.e. all about the
pre-Unicode mishmash and nothing to do with dealing with unicode ...


You are, of course, correct.  Once it's all unicode life will be easier 
(he says, all innocent-like).  And dbf files even bigger, lol.




BTW, what are you planning to do with an LDID of 0x00?


Hmmm.  Well, logical choices seem to be either treating it as plain 
ascii, and barfing when high-ascii shows up; defaulting to \x01; or 
forcing the user to choose one on initial access.


I am definitely open to ideas!



Cheers,

John


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


Re: why python cache the string > 256?

2009-10-26 Thread Diez B. Roggisch

s7v7nislands schrieb:

hi all:

test.py
#!/usr/bin/python
a = []
for i in xrange(100):
a.append('a'*500)


$python -i test.py #virt mem 514m in top output

del a   #virt mem 510m


why python cache these string?
In source, I see when object size > SMALL_REQUEST_THRESHOLD, python
would use malloc.
also use free() when string refcount == 0.

do I miss somethong?


http://effbot.org/pyfaq/why-doesnt-python-release-the-memory-when-i-delete-a-large-object.htm

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


Re: Python 3.1.1 bytes decode with replace bug

2009-10-26 Thread Joe

Thanks Mark, that is a great suggestion!

> You can also replace the Unicode replacement character U+FFFD with a valid
> cp437 character before displaying it:
>
> >>> b'\x80abc'.decode('utf8','replace').replace('\ufffd','?')
>
> '?abc'
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python 3.1.1 bytes decode with replace bug

2009-10-26 Thread Joe

Thanks Benjamin for solving the mystery of where the cp437 usage was
coming from.

So b'\x80abc'.decode("utf-8", "replace") was working properly but then
when the interactive prompt tried to print it, it was basically taking
the results and doing a
encode('cp437', 'strict') which failed because of the characters that
are not part of cp437.

It might not be a bad idea to put a note on that documentation page
because I sure others will work though the samples like I did and if
they are on Windows run into the same issue.









> Try checking sys.stdout.encoding. Then run the command chcp (not in
> the python interpreter). You'll probably get 437 from both of those.
> Just because the system encoding is set to utf-8 doesn't mean the
> console is. Nobody really uses cp437 anymore- it was replaced years
> ago by cp1252- but Microsoft is scared to do anything to cmd.exe
> because it might break somebody's 20-year-old DOS script
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Why is python so sad?

2009-10-26 Thread Matias Ribecky
On Wed, Oct 14, 2009 at 2:16 PM, Chris Withers wrote:

> Zac Burns wrote:
>
>> There are 10741 occurences of ): or :( in our source code and only 2
>> occurrences of :) or (:. Not what you would expect from a language
>> named after a comedian.
>>
>
> def ...(...):
>  ...
>
> class ...(...):
>  ...
>
> etc
>
> ;-)
>
> Chris
>
> Maybe we should change it to

def ...(...(:
...

class ...(...(:
...

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


Re: unicode and dbf files

2009-10-26 Thread John Machin
On Oct 27, 3:22 am, Ethan Furman  wrote:
> John Machin wrote:
> > On Oct 24, 4:14 am, Ethan Furman  wrote:
>
> >>John Machin wrote:
>
> >>>On Oct 23, 3:03 pm, Ethan Furman  wrote:
>
> John Machin wrote:
>
> >On Oct 23, 7:28 am, Ethan Furman  wrote:
>
> > Try this:
> >http://webhelp.esri.com/arcpad/8.0/referenceguide/
>
> Wow.  Question, though:  all those codepages mapping to 437 and 850 --
> are they really all the same?

437 and 850 *are* codepages. You mean "all those language driver IDs
mapping to codepages 437 and 850". A codepage merely gives an
encoding. An LDID is like a locale; it includes other things besides
the encoding. That's why many Western European languages map to the
same codepage, first 437 then later 850 then 1252 when Windows came
along.

> >>     '\x68' : ('cp895', 'Kamenicky (Czech) MS-DOS'),     # iffy
>
> > Indeed iffy. Python doesn't have a cp895 encoding, and it's probably
> > not alone. I suggest that you omit Kamenicky until someone actually
> > wants it.
>
> Yeah, I noticed that.  Tentative plan was to implement it myself (more
> for practice than anything else), and also to be able to raise a more
> specific error ("Kamenicky not currently supported" or some such).

The error idea is fine, but I don't get the "implement it yourself for
practice" bit ... practice what? You plan a long and fruitful career
inplementing codecs for YAGNI codepages?
>
> >>     '\x7b' : ('iso2022_jp', 'Japanese Windows'),        # wag
>
> > Try cp936.
>
> You mean 932?

Yes.

> Very helpful indeed.  Many thanks for reviewing and correcting.

You're welcome.

> Learning to deal with unicode is proving more difficult for me than
> learning Python was to begin with!  ;D

?? As far as I can tell, the topic has been about mapping from
something like a locale to the name of an encoding, i.e. all about the
pre-Unicode mishmash and nothing to do with dealing with unicode ...

BTW, what are you planning to do with an LDID of 0x00?

Cheers,

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


Re: Python IDE

2009-10-26 Thread TerryP
On Oct 26, 11:57 am, Girish  wrote:
> Hello, Which is the best software to create GUI other then Boa.
>
> Thanks,
> Girish.

Any editor can be used to create a "GUI" program in Python. Beyond
that it depends on what you are using; since you stated Boa, I assume
WxPython - so take a look at WxGlade.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: python web service or Apache?

2009-10-26 Thread Paul Rubin
ru...@yahoo.com writes:
> Apache requires root access to the server machine,

Only to access the privileged ports.

> A small simple custom web server built with Python will likely...
> You can run it on a non-privileged port if you do not have
> root access to your server machine.

You can do that with apache as well.  Which is more complicated is a
little bit subjective.  I use both, and for something simple I
generally find it easier to throw together a custom server with
SocketServer.py, but it takes some familiarity with Python networking
to be able to do that.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: python web service or Apache?

2009-10-26 Thread rurpy
On 10/26/2009 08:00 AM, Peng Yu wrote:
> On Sun, Oct 25, 2009 at 11:09 PM, Simon Forman  wrote:
>> On Sun, Oct 25, 2009 at 4:47 PM, Peng Yu  wrote:
>>> Although, python can be used to provide web service. The following
>>> webpage also mentioned, "Apache the best and most widely used web
>>> server on the Internet today, check it out. If you want to run your
>>> own web server this is the one to get, you can get binaries for both
>>> Windows and Unix. You can download the entire sourcecode if you want
>>> to check how it was made." Therefore, it would be better to use Apache
>>> rather than python to provide web service, right?
>>>
>>> http://fragments.turtlemeat.com/pythonwebserver.php
>>
>>
>> Both "best" and "better" (that website and you, respectively) omit
>> mention of the criteria used for the evaluation.
>>
>> To determine what is "best" you must first answer "for what?"
>>
>>
>> (Also, it is reasonable to use /both/ apache and python together, with
>> mod_python or mod_wsgi, etc...)
>
> I have never made a web server before. So I don't know what criterion
> I should use? If possible, would you please let me know what pros and
> cons you can think of?

Apache requires root access to the server machine, is quite complex
and requires some learning and work to setup and use.
On the other hand it is very powerful, will handle high traffic,
and can handle the requirements of most any web site, so even if
you start with a simple site you can be pretty sure it will handle
your needs in the future as your web site grows.  Because Apache
is widely used, there an many places and people that can provide
help and advice on how to run it.

A small simple custom web server built with Python will likely
only work well with a very small traffic volume and will have
very limited capabilities but is very quick to get up and running.
You can run it on a non-privileged port if you do not have
root access to your server machine.

> How to use apache and python together? Does each of them offer some
> functions that are not available in the other? Thank you!

Apache, like most general purpose web servers, supports the CGI
protocol.  You can setup Apache so that when a request is made
for a file ending with ".py", it will run the python file and
send the program's output to the client browser.  This allows
you to generate html output from the Python program.  Python's
standard lib contains the "cgi" module that will help in writing
python code for this.

There are other more efficient ways of using Python with
a web server such as mod_python, or wsgi, but cgi is probably
the simplest, and has the most "how-to" info available.

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


Re: handling PAMIE and lxml

2009-10-26 Thread Simon Forman
On Mon, Oct 26, 2009 at 3:05 AM, elca  wrote:
>
> Hello,
> i was open anther new thread ,old thread is too long.

Too long for what?

> first of all,i really appreciate other many people's help in this newsgroup.
> im making webscraper now.
> but still problem with my script source.
> http://elca.pastebin.com/m52e7d8e0
> i was upload my script in here.
> so anybody can modify it.
> main problem is , if you see line number 74 ,75 in my source,
> you can see this line "thepage = urllib.urlopen(theurl).read()".
> i want to change this line to work with Pamie not urllib.

Why?

> if anyone help me,really appreciate.
> thanks in advance.

I just took a look at your code.  I don't want to be mean but your
code is insane.

1.) you import HTMLParser and fromstring but don't use them.

2.) the page_check() function is useless.  All it does is sleep for
len("www.naver.com") seconds.  Why are you iterating through the
characters in that string anyway?

3.) On line 21 you have a pointless pass statement.

4.) The whole "if x:" statement on line 19 is pointless because both
branches do exactly the same thing.

5.) The variables start_line and end_line you're using strings.  This
is not php. Strings are not automatically converted to integers.

6.) Because you never change end_line anywhere, and because you don't
use break anywhere in the loop body, the while loop on line 39 will
never end.

7.) The while loop on line 39 defines the getit() function (over and
over again) but never calls it.

8.) On line 52 you define a list call "results" and then never use it anywhere.

9.) In getit() the default value for howmany is 0, but on line 68 you
subtract 1 from it and the next line you return if not howmany.  This
means if you ever forget to call getit() with a value of howmany above
zero that if statement will never return.

8.) In the for loop on line 54, in the while loop on line 56, you
recursively call getit() on line 76.  wtf?  I suspect lines 73-76 are
at the wrong indentation level.

9.) On line 79 you have a "bare" except, which just calls exit(1) on
the next line.  This replaces the exception you had (which contains
important information about the error encountered) with a SystemExit
exception (which does not.)  Note that an uncaught exception will exit
your script with a non-zero return code, so all you're doing here is
throwing away debugging information.

10.) On line 81 you have 'return()'.  This line will never be reached
because you just called exit() on the line before.  Also, return is
not a function, you do not need '()' after it.

11.) Why do you sleep for half a second on line 83?


I cannot believe that this script does anything useful.  I would
recommend playing with the interactive interpreter for awhile until
you understand python and what you're doing.  Then worry about Pamie
vs. urllib.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Strangeness: Cannot write to a file from a process created by Windows Task Scheduler ...

2009-10-26 Thread MRAB

Sandy Walsh wrote:
Yes it seems to be a flush problem. Strange how it doesn't require the 
explicit flush() when the console window appears, but does otherwise. 
Either way, it gives me a good direction to chase after.



[snip]
It buffers for efficiency reasons, but if it can detect that it's
connected to a console then it won't bother buffering because there's
nothing to gain.

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


Re: Strangeness: Cannot write to a file from a process created by Windows Task Scheduler ...

2009-10-26 Thread Sandy Walsh

Thanks Marco & Al,

Yes it seems to be a flush problem. Strange how it doesn't require the 
explicit flush() when the console window appears, but does otherwise. 
Either way, it gives me a good direction to chase after.


Thanks again for your quick help guys!
-Sandy


Marco Bizzarri wrote:

You could try to flush the file? Maybe it would flush once you close,
which never happens; did you try to limit the amount of times it run
inside the 'while' loop?

Regards
Marco



On Mon, Oct 26, 2009 at 6:17 PM, Sandy Walsh  wrote:
  

Hi there,

Seeing some really weird behavior and perhaps someone has seen something
similar:

I have a python script that launches as a Windows Scheduled Task. The
program simply opens a disk file and writes some text to it:

---
f = open("waiting.txt", "w")
x = 0
while 1:
  f.write("Sleeping: %d\r\n" % x)
  x += 1
  time.sleep(2)

f.close()
---

I've run it under my user account. I've run it as Local Account. I've run it
via pythonw and python ... only one way works:

When I run with full credentials (not local account) and python (not
pythonw) I get output in the file (and a CMD window appears while it's
running). In every other combination it creates the 'waiting.txt' file, but
doesn't write any output to the file. The length of the file is 0 bytes.

Anyone have ideas what could be causing this? I suspect it's blocking on
something, but I can't imagine where.

There is no stderr/stdout output anywhere in the program so it's not
blocking on anything stdio related (that I can imagine)

Thoughts?
-Sandy



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







  


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


Re: Python 2.6 Deprecation Warnings with __new__ — Can someone explain why?

2009-10-26 Thread Simon Forman
On Mon, Oct 26, 2009 at 12:04 AM, rh0dium  wrote:
[snip]
>
>
> Now the real question I have on this is scalability.  The real

What you're describing isn't "scalability".  It could be called "extensibility".

> advantage to using *args and **kwargs is that down the road (through
> inheritance/polymorphism) I may not know what I'm being given (isn't
> that the essence of duck-typing). My long standing belief is that by
> using *args and **kwargs I plan for future additions with minimal
> changes to my code.  So doesn't restricting this just defeat the
> purpose?

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


Re: Strangeness: Cannot write to a file from a process created by Windows Task Scheduler ...

2009-10-26 Thread MRAB

Sandy Walsh wrote:

Hi there,

Seeing some really weird behavior and perhaps someone has seen something 
similar:


I have a python script that launches as a Windows Scheduled Task. The 
program simply opens a disk file and writes some text to it:


---
f = open("waiting.txt", "w")
x = 0
while 1:
   f.write("Sleeping: %d\r\n" % x)
   x += 1
   time.sleep(2)

f.close()
---

I've run it under my user account. I've run it as Local Account. I've 
run it via pythonw and python ... only one way works:


When I run with full credentials (not local account) and python (not 
pythonw) I get output in the file (and a CMD window appears while it's 
running). In every other combination it creates the 'waiting.txt' file, 
but doesn't write any output to the file. The length of the file is 0 
bytes.


Anyone have ideas what could be causing this? I suspect it's blocking on 
something, but I can't imagine where.


There is no stderr/stdout output anywhere in the program so it's not 
blocking on anything stdio related (that I can imagine)


Thoughts?


1. I don't see "import time" anywhere.

2. Output to the file is buffered. When the script is terminated
whatever is still in the output buffer will be lost.

BTW, the "f.close()" is pointless because of the infinite loop.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Strangeness: Cannot write to a file from a process created by Windows Task Scheduler ...

2009-10-26 Thread Marco Bizzarri
You could try to flush the file? Maybe it would flush once you close,
which never happens; did you try to limit the amount of times it run
inside the 'while' loop?

Regards
Marco



On Mon, Oct 26, 2009 at 6:17 PM, Sandy Walsh  wrote:
> Hi there,
>
> Seeing some really weird behavior and perhaps someone has seen something
> similar:
>
> I have a python script that launches as a Windows Scheduled Task. The
> program simply opens a disk file and writes some text to it:
>
> ---
> f = open("waiting.txt", "w")
> x = 0
> while 1:
>   f.write("Sleeping: %d\r\n" % x)
>   x += 1
>   time.sleep(2)
>
> f.close()
> ---
>
> I've run it under my user account. I've run it as Local Account. I've run it
> via pythonw and python ... only one way works:
>
> When I run with full credentials (not local account) and python (not
> pythonw) I get output in the file (and a CMD window appears while it's
> running). In every other combination it creates the 'waiting.txt' file, but
> doesn't write any output to the file. The length of the file is 0 bytes.
>
> Anyone have ideas what could be causing this? I suspect it's blocking on
> something, but I can't imagine where.
>
> There is no stderr/stdout output anywhere in the program so it's not
> blocking on anything stdio related (that I can imagine)
>
> Thoughts?
> -Sandy
>
>
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>
>



-- 
Marco Bizzarri
http://code.google.com/p/qt-asterisk/
http://notenotturne.blogspot.com/
http://iliveinpisa.blogspot.com/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Strangeness: Cannot write to a file from a process created by Windows Task Scheduler ...

2009-10-26 Thread Al Fansome

Do you "import time"?

Sandy Walsh wrote:

Hi there,

Seeing some really weird behavior and perhaps someone has seen something 
similar:


I have a python script that launches as a Windows Scheduled Task. The 
program simply opens a disk file and writes some text to it:


---
f = open("waiting.txt", "w")
x = 0
while 1:
   f.write("Sleeping: %d\r\n" % x)
   x += 1
   time.sleep(2)

f.close()
---

I've run it under my user account. I've run it as Local Account. I've 
run it via pythonw and python ... only one way works:


When I run with full credentials (not local account) and python (not 
pythonw) I get output in the file (and a CMD window appears while it's 
running). In every other combination it creates the 'waiting.txt' file, 
but doesn't write any output to the file. The length of the file is 0 
bytes.


Anyone have ideas what could be causing this? I suspect it's blocking on 
something, but I can't imagine where.


There is no stderr/stdout output anywhere in the program so it's not 
blocking on anything stdio related (that I can imagine)


Thoughts?
-Sandy



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


Re: python web service or Apache?

2009-10-26 Thread Simon Forman
On Mon, Oct 26, 2009 at 10:00 AM, Peng Yu  wrote:
> On Sun, Oct 25, 2009 at 11:09 PM, Simon Forman  wrote:
>> On Sun, Oct 25, 2009 at 4:47 PM, Peng Yu  wrote:
>>> Although, python can be used to provide web service. The following
>>> webpage also mentioned, "Apache the best and most widely used web
>>> server on the Internet today, check it out. If you want to run your
>>> own web server this is the one to get, you can get binaries for both
>>> Windows and Unix. You can download the entire sourcecode if you want
>>> to check how it was made." Therefore, it would be better to use Apache
>>> rather than python to provide web service, right?
>>>
>>> http://fragments.turtlemeat.com/pythonwebserver.php
>>
>>
>> Both "best" and "better" (that website and you, respectively) omit
>> mention of the criteria used for the evaluation.
>>
>> To determine what is "best" you must first answer "for what?"
>>
>>
>> (Also, it is reasonable to use /both/ apache and python together, with
>> mod_python or mod_wsgi, etc...)
>
> I have never made a web server before. So I don't know what criterion
> I should use? If possible, would you please let me know what pros and
> cons you can think of?

Well, criteria like, how much traffic do you need to support?  How
often will you be changing your code?  Do you have your own server or
are you using some sort of "hosting plan" with another company?  Those
are pretty general.  I'm not a web server expert.

I recently wrote a small server script. It's only job was to listen
for POST requests from a third-party SVN repository service that
indicated a commit had been made and then trigger a buildbot
build/test cycle.  For this the BaseHTTPServer module was sufficient.

Apache is highly regarded, but I've heard Nginx is, or can be, faster
(I don't know if that's true, but I've heard it...)

Apache has a /lot/ of features and capabilities, which can mean it
will have a steep learning curve (again depending on what you want to
do with it.)  But if you're using an OS with good package support,
like Ubuntu linux, getting a basic Apache installation up and running
takes one command. (And some time understanding the default
configuration...)

There are also options like CherryPy (http://www.cherrypy.org/) or
Twisted Web (http://twistedmatrix.com/trac/) which are HTTP servers
(and more) written in python.

Probably the most important question to answer is, "How much do you
want to learn?"

> How to use apache and python together? Does each of them offer some
> functions that are not available in the other? Thank you!

You're welcome. :)

Possibly the simplest method is to write a CGI script in python.  I've
already mentioned mod_python and mod_wsgi which are Apache modules
that let you use python with Apache.

There are also web frameworks like Django and TurboGears which can
work with Apache.

These options all offer different functions while providing
essentially the same functionality.  You'll have to do your own
homework to figure out which is the best for you.

Regards,
~Simon
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: C++: Py_CompileString crash

2009-10-26 Thread KillSwitch
On Oct 26, 10:06 am, Christian Heimes  wrote:
> KillSwitch wrote:
> > int main(int argc, char *argv[])
> > {
> >    Py_Initialize();
>
> >    const char* filename = "asdf.py";
>
> >    const char* str = "print('lol')";
>
> >    Py_CompileString(str, filename, 0);
>
> >    Py_Finalize();
> >    system("PAUSE");
> >    return 0;
> > }
>
> > On running, it immediately crashes.
>
> 0 is wrong here, 
> seehttp://docs.python.org/c-api/veryhigh.html?highlight=py_compilestring...
>
> Christian

Yeah that's what I needed, thank you very much.
-- 
http://mail.python.org/mailman/listinfo/python-list


Strangeness: Cannot write to a file from a process created by Windows Task Scheduler ...

2009-10-26 Thread Sandy Walsh

Hi there,

Seeing some really weird behavior and perhaps someone has seen something 
similar:


I have a python script that launches as a Windows Scheduled Task. The 
program simply opens a disk file and writes some text to it:


---
f = open("waiting.txt", "w")
x = 0
while 1:
   f.write("Sleeping: %d\r\n" % x)
   x += 1
   time.sleep(2)

f.close()
---

I've run it under my user account. I've run it as Local Account. I've 
run it via pythonw and python ... only one way works:


When I run with full credentials (not local account) and python (not 
pythonw) I get output in the file (and a CMD window appears while it's 
running). In every other combination it creates the 'waiting.txt' file, 
but doesn't write any output to the file. The length of the file is 0 bytes.


Anyone have ideas what could be causing this? I suspect it's blocking on 
something, but I can't imagine where.


There is no stderr/stdout output anywhere in the program so it's not 
blocking on anything stdio related (that I can imagine)


Thoughts?
-Sandy


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


"(8)Exec format error: exec of" a java script file

2009-10-26 Thread Bhanu Mangipudi
Hi all,

When I am trying to access a javascript file I am getting an error like this
"(8)Exec format error: exec of '/var/www/cgi-bin/website/js/layout.js'
failed, referer: http://localhost/cgi-bin/website/index.py";.

Can any one please help me how to fix this error ??

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


Re: C++: Py_CompileString crash

2009-10-26 Thread Christian Heimes
KillSwitch wrote:
> int main(int argc, char *argv[])
> {
>   Py_Initialize();
> 
>   const char* filename = "asdf.py";
> 
>   const char* str = "print('lol')";
> 
>   Py_CompileString(str, filename, 0);
> 
>   Py_Finalize();
>   system("PAUSE");
>   return 0;
> }
> 
> On running, it immediately crashes.

0 is wrong here, see
http://docs.python.org/c-api/veryhigh.html?highlight=py_compilestring#Py_CompileStringFlags

Christian

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


How to know locals of script without running it

2009-10-26 Thread Nadav Chernin
Hi, all

 

Is there a way to know locals of the script without running it?

 

Thanks, Nadav

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


Re: How about adding slice notation to iterators/generators?

2009-10-26 Thread Anh Hai Trinh
I've written something that is better than you could've imagine.

Get it here: 

It works with anything iterable, no need to alter anything.

  from itertools import count
  from stream import item
  c = count()
  c >> item[1:10:2]
->[1, 3, 5, 7, 9]
  c >> item[:5]
->[10, 11, 12, 13, 14]

There is a ton more you could do with that library, i.e. piping & lazy-
evaluation.
-- 
http://mail.python.org/mailman/listinfo/python-list


C++: Py_CompileString crash

2009-10-26 Thread KillSwitch
I run this code in VC++:

#include 
#include 
#include 

using namespace std;

int main(int argc, char *argv[])
{
Py_Initialize();

const char* filename = "asdf.py";

const char* str = "print('lol')";

Py_CompileString(str, filename, 0);

Py_Finalize();
system("PAUSE");
return 0;
}

On running, it immediately crashes.

I use PyRun_SimpleString and other high level stuff from the API with
no problem, but Py_CompileString is not working. I'm probably using it
wrong.

Any help is appreciated.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: unicode and dbf files

2009-10-26 Thread Ethan Furman

John Machin wrote:

On Oct 24, 4:14 am, Ethan Furman  wrote:


John Machin wrote:


On Oct 23, 3:03 pm, Ethan Furman  wrote:



John Machin wrote:



On Oct 23, 7:28 am, Ethan Furman  wrote:



Greetings, all!



I would like to add unicode support to my dbf project.  The dbf header
has a one-byte field to hold the encoding of the file.  For example,
\x03 is code-page 437 MS-DOS.



My google-fu is apparently not up to the task of locating a complete
resource that has a list of the 256 possible values and their
corresponding code pages.



What makes you imagine that all 256 possible values are mapped to code
pages?



I'm just wanting to make sure I have whatever is available, and
preferably standard.  :D



So far I have found this, plus variations:http://support.microsoft.com/kb/129631



Does anyone know of anything more complete?



That is for VFP3. Try the VFP9 equivalent.



dBase 5,5,6,7 use others which are not defined in publicly available
dBase docs AFAICT. Look for "language driver ID" and "LDID". Secondary
source: ESRI support site.



Well, a couple hours later and still not more than I started with.
Thanks for trying, though!



Huh? You got tips to (1) the VFP9 docs (2) the ESRI site (3) search
keywords and you couldn't come up with anything??


Perhaps "nothing new" would have been a better description.  I'd already
seen the clicketyclick site (good info there)



Do you think so? My take is that it leaves out most of the codepage
numbers, and these two lines are wrong:
65h Nordic MS-DOS   code page 865
66h Russian MS-DOS  code page 866


That was the site I used to get my whole project going, so ignoring the 
unicode aspect, it has been very helpful to me.




and all I found at ESRI
were folks trying to figure it out, plus one link to a list that was no
different from the vfp3 list (or was it that the list did not give the
hex values?  Either way, of no use to me.)



Try this:
http://webhelp.esri.com/arcpad/8.0/referenceguide/


Wow.  Question, though:  all those codepages mapping to 437 and 850 -- 
are they really all the same?




I looked at dbase.com, but came up empty-handed there (not surprising,
since they are a commercial company).



MS and ESRI have docs ... does that mean that they are non-commercial
companies?


I don't know enough about ESRI to make an informed comment, so I'll just 
say I'm grateful they have them!  MS is a complete mystery... perhaps 
they are finally seeing the light?  Hard to believe, though, from a 
company that has consistently changed their file formats with every release.




I searched some more on Microsoft's site in the VFP9 section, and was
able to find the code page section this time.  Sadly, it only added
about seven codes.

At any rate, here is what I have come up with so far.  Any corrections
and/or additions greatly appreciated.

code_pages = {
'\x01' : ('ascii', 'U.S. MS-DOS'),



All of the sources say codepage 437, so why ascii instead of cp437?


Hard to say, really.  Adjusted.



'\x02' : ('cp850', 'International MS-DOS'),
'\x03' : ('cp1252', 'Windows ANSI'),
'\x04' : ('mac_roman', 'Standard Macintosh'),
'\x64' : ('cp852', 'Eastern European MS-DOS'),
'\x65' : ('cp866', 'Russian MS-DOS'),
'\x66' : ('cp865', 'Nordic MS-DOS'),
'\x67' : ('cp861', 'Icelandic MS-DOS'),
'\x68' : ('cp895', 'Kamenicky (Czech) MS-DOS'), # iffy



Indeed iffy. Python doesn't have a cp895 encoding, and it's probably
not alone. I suggest that you omit Kamenicky until someone actually
wants it.


Yeah, I noticed that.  Tentative plan was to implement it myself (more 
for practice than anything else), and also to be able to raise a more 
specific error ("Kamenicky not currently supported" or some such).




'\x69' : ('cp852', 'Mazovia (Polish) MS-DOS'),  # iffy



Look 5 lines back. cp852 is 'Eastern European MS-DOS'. Mazovia
predates and is not the same as cp852. In any case, I suggest that you
omit Masovia until someone wants it. Interesting reading:

http://www.jastra.com.pl/klub/ogonki.htm


Very interesting reading.



'\x6a' : ('cp737', 'Greek MS-DOS (437G)'),
'\x6b' : ('cp857', 'Turkish MS-DOS'),
'\x78' : ('big5', 'Traditional Chinese (Hong Kong SAR, Taiwan)\



big5 is *not* the same as cp950. The products that create DBF files
were designed for Windows. So when your source says that LDID 0xXX
maps to Windows codepage YYY, I would suggest that all you should do
is translate that without thinking to python encoding cpYYY.


Ack.  Not sure how I missed 'Windows' at the end of that description.



   Windows'),   # wag


What does "wag" mean?


wag == 'wild ass guess'



'\x79' : ('iso2022_kr', 'Korean Windows'),  # wag


Try cp949.


Done.



'\x7a' : ('iso2022_jp_2', 'Chinese Simplified (PRC, Singapore)\
   Windows'),   # wag



Very wrong. iso2022_jp_2 is supposed to include basic Japanese, basic
(1980) Chinese (GB2312) and a basic Korean kit.

Re: Read any function in runtime

2009-10-26 Thread Matt McCredie
Rhodri James  wildebst.demon.co.uk> writes:

> 
> On Fri, 23 Oct 2009 17:39:40 +0100, Matt McCredie  gmail.com>  
> wrote:
> 
> > joao abrantes  gmail.com> writes:
> >
> >>
> >> Hey. I want to make a program like this:print "Complete the function
> > f(x)="then the user would enter x+2 or 1/x or any other function that  
> > only uses
> > the variable x. Then my python program would calculate f(x) in some  
> > points for
> > example in f(2),f(4).. etc . How can I do this?
> >>
> >
> > check out 'eval' or 'exec'.
> 
> Then check out all the reasons you shouldn't use them in an
> environment that you don't trust absolutely -- if someone wipes
> your hard disc, you won't get any sympathy from here.
> 
> The safe answer is to write yourself a small parser.  Given that
> you've got a very limited symbol set, that shouldn't be too hard.
> 

This should only be a concern if it is some sort of client/server app (like a
web-app). If this is something that is going to be run on a local machine then
the person running it could do just as much damage via the command line.

While I agree that there is a danger if the input might come from untrusted
users, and the original poster should be aware of that, writing your own parser
only makes sense in those instances. If this application is run locally then
users have access to the machine anyway.

I don't want to give a (potentially) new user to python the impression that they
need to be writing their own parser to solve this problem. It depends on where
the input is coming from. 

Two things to note: 
1. eval and exec are perfectly safe if the input is from a trusted source.
2. eval and exec are never safe if the input is not from a trusted source.

Matt McCredie


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


Re: Building static Python binary

2009-10-26 Thread mk

P.S.

If I add -static to LDFLAGS in Makefile, I get this:

gcc -pthread -static  -Xlinker -export-dynamic -o python \
Modules/python.o \
libpython2.6.a -lpthread -ldl  -lutil 
-L/usr/local/ssl/lib -lssl -lcrypto   -lm

libpython2.6.a(dynload_shlib.o): In function `_PyImport_GetDynLoadFunc':
/var/www/html/tmp/Python-2.6.2/Python/dynload_shlib.c:130: warning: 
Using 'dlopen' in statically linked applications requires at runtime the 
shared libraries from the glibc version used for linking

libpython2.6.a(posixmodule.o): In function `posix_tmpnam':
/var/www/html/tmp/Python-2.6.2/./Modules/posixmodule.c:7129: warning: 
the use of `tmpnam_r' is dangerous, better use `mkstemp'

libpython2.6.a(posixmodule.o): In function `posix_tempnam':
/var/www/html/tmp/Python-2.6.2/./Modules/posixmodule.c:7084: warning: 
the use of `tempnam' is dangerous, better use `mkstemp'

libpython2.6.a(pwdmodule.o): In function `pwd_getpwall':
/var/www/html/tmp/Python-2.6.2/./Modules/pwdmodule.c:157: warning: Using 
'getpwent' in statically linked applications requires at runtime the 
shared libraries from the glibc version used for linking

libpython2.6.a(pwdmodule.o): In function `pwd_getpwnam':
/var/www/html/tmp/Python-2.6.2/./Modules/pwdmodule.c:131: warning: Using 
'getpwnam' in statically linked applications requires at runtime the 
shared libraries from the glibc version used for linking

libpython2.6.a(pwdmodule.o): In function `pwd_getpwuid':
/var/www/html/tmp/Python-2.6.2/./Modules/pwdmodule.c:110: warning: Using 
'getpwuid' in statically linked applications requires at runtime the 
shared libraries from the glibc version used for linking

libpython2.6.a(pwdmodule.o): In function `pwd_getpwall':
/var/www/html/tmp/Python-2.6.2/./Modules/pwdmodule.c:156: warning: Using 
'setpwent' in statically linked applications requires at runtime the 
shared libraries from the glibc version used for linking
/var/www/html/tmp/Python-2.6.2/./Modules/pwdmodule.c:167: warning: Using 
'endpwent' in statically linked applications requires at runtime the 
shared libraries from the glibc version used for linking
/usr/lib/gcc/i386-redhat-linux/4.1.2/../../../libssl.a(kssl.o): In 
function `get_rc_clockskew':

(.text+0xe1): undefined reference to `krb5_rc_default'
/usr/lib/gcc/i386-redhat-linux/4.1.2/../../../libssl.a(kssl.o): In 
function `get_rc_clockskew':

(.text+0xfc): undefined reference to `krb5_rc_initialize'
/usr/lib/gcc/i386-redhat-linux/4.1.2/../../../libssl.a(kssl.o): In 
function `get_rc_clockskew':

(.text+0x122): undefined reference to `krb5_rc_get_lifespan'
/usr/lib/gcc/i386-redhat-linux/4.1.2/../../../libssl.a(kssl.o): In 
function `get_rc_clockskew':

(.text+0x13c): undefined reference to `krb5_rc_destroy'
/usr/lib/gcc/i386-redhat-linux/4.1.2/../../../libssl.a(kssl.o): In 
function `kssl_validate_times':

(.text+0x174): undefined reference to `krb5_init_context'
/usr/lib/gcc/i386-redhat-linux/4.1.2/../../../libssl.a(kssl.o): In 
function `kssl_validate_times':

(.text+0x197): undefined reference to `krb5_timeofday'
/usr/lib/gcc/i386-redhat-linux/4.1.2/../../../libssl.a(kssl.o): In 
function `kssl_validate_times':

(.text+0x1ba): undefined reference to `krb5_free_context'
/usr/lib/gcc/i386-redhat-linux/4.1.2/../../../libssl.a(kssl.o): In 
function `kssl_krb5_free_data_contents':

(.text+0x241): undefined reference to `krb5_free_data_contents'
/usr/lib/gcc/i386-redhat-linux/4.1.2/../../../libssl.a(kssl.o): In 
function `kssl_tgt_is_available':

(.text+0x2ba): undefined reference to `krb5_init_context'
/usr/lib/gcc/i386-redhat-linux/4.1.2/../../../libssl.a(kssl.o): In 
function `kssl_tgt_is_available':

(.text+0x2d6): undefined reference to `krb5_free_principal'
/usr/lib/gcc/i386-redhat-linux/4.1.2/../../../libssl.a(kssl.o): In 
function `kssl_tgt_is_available':

(.text+0x2ec): undefined reference to `krb5_free_principal'
/usr/lib/gcc/i386-redhat-linux/4.1.2/../../../libssl.a(kssl.o): In 
function `kssl_tgt_is_available':

(.text+0x2fb): undefined reference to `krb5_free_context'
/usr/lib/gcc/i386-redhat-linux/4.1.2/../../../libssl.a(kssl.o): In 
function `kssl_tgt_is_available':

(.text+0x33b): undefined reference to `krb5_sname_to_principal'
/usr/lib/gcc/i386-redhat-linux/4.1.2/../../../libssl.a(kssl.o): In 
function `kssl_tgt_is_available':

(.text+0x355): undefined reference to `krb5_cc_default'
/usr/lib/gcc/i386-redhat-linux/4.1.2/../../../libssl.a(kssl.o): In 
function `kssl_tgt_is_available':

(.text+0x376): undefined reference to `krb5_cc_get_principal'
/usr/lib/gcc/i386-redhat-linux/4.1.2/../../../libssl.a(kssl.o): In 
function `kssl_tgt_is_available':

(.text+0x3a8): undefined reference to `krb5_get_credentials'
/usr/lib/gcc/i386-redhat-linux/4.1.2/../../../libssl.a(kssl.o): In 
function `kssl_keytab_is_available':

(.text+0x415): undefined reference to `krb5_init_context'
/usr/lib/gcc/i386-redhat-linux/4.1.2/../../../libssl.a(kssl.o): In 
function `kssl_keytab_is_available':

(

Re: Pause a thread/ execfile()

2009-10-26 Thread Terry Reedy

Babloo wrote:


Any ideas how to  pause execfile()?


As far as the calling instance of the Python interpreter is concerned, 
calling execfile (or any C function) is an atomic action. You need to 
rewrite the code in the file executed to have it monitor a semaphore.


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


Re: Pause a thread/ execfile()

2009-10-26 Thread Sean DiZazzo
On Oct 26, 1:25 am, Babloo  wrote:
> On Oct 26, 1:01 pm, Sean DiZazzo  wrote:
>
>
>
> > On Oct 25, 11:58 pm, Babloo  wrote:
>
> > > i have a small python application with GUI (frontend) which has
> > > various functions. I have a "RUN" button which runs python scripts in
> > > the background . It basically calls execfile() function internally
> > > which runs in a thread ,  to run the python script .
>
> > > I want to implement a "PAUSE" feature which would pause the running
> > > python script . So do that i have to either pause the thread in which
> > > execfile() runs or pause execfile itself .
>
> > > When the user presses "RUN" again then the python script should resume
> > > running .
>
> > > Any ideas how to pause the thread / pause execfile() . Any other ideas
> > > for the same would be helpful .
>
> > > Thanks
>
> > I think you can do that with a threading.event().  In the gui, create
> > a new threading.event() and pass it in to the worker thread.  Set up
> > your code in the worker so that on every iteration of "work", it
> > checks to see if the event is set.  If it finds it set, then it
> > sleeps, but keeps checking until the event is unset.  When unset
> > again, it picks up and begins work again.
>
> > In the gui, your pause button just sets and unsets the event, and the
> > worker will find out and pause at the next iteration.
>
> > Depending on what kind of work your worker thread is doing, it might
> > be tough to structure the code so the event gets checked reasonably
> > often.  Hope this helps.
>
> > ~Sean
>
> > PS.  Not sure this idea will hold up when using execfile()
>
> Hi..
> Thanks for the reply . Yes tried doing exactly what you have
> suggested . i could show you the sample code .
> But some how it doesn't work and main reason could be i am using
> execfile() in the thread .
> I was trying to set the event on the press of a button . It doesnt
> pause the thread and instead keeps on executing .
> Dont know what the problem could be ???
>
> Sample code :-
>
> $$$
> import threading
>
> class TestThread(threading.Thread):
>     """
>     A sample thread class
>     """
>
>     def __init__(self):
>         """
>         Constructor, setting initial variables
>         """
>         self._stopevent = threading.Event()
>         self._sleepperiod = 1.0
>
>         threading.Thread.__init__(self, name="TestThread")
>
>     def run(self):
>         """
>         overload of threading.thread.run()
>         main control loop
>         """
>         print "%s starts" % (self.getName(),)
>
>         count = 0
>         while not self._stopevent.isSet():
>             count += 1
>             print "loop %d" % (count,)
>             self._stopevent.wait(self._sleepperiod)
>
>         print "%s ends" % (self.getName(),)
>
>     def join(self,timeout=None):
>         """
>         Stop the thread
>         """
>         self._stopevent.set()
>         threading.Thread.join(self, timeout)
>
> if __name__ == "__main__":
>     testthread = TestThread()
>     testthread.start()
>
>     import time
>     time.sleep(10.0)
>
>     testthread.join()
>
> $

I was thinking along the lines of this.  I'll bet you can find a more
efficient way of doing it, but this demonstrates what I was thinking.

import threading, time

class TestThread(threading.Thread):
def __init__(self):
self._stopevent = threading.Event()
threading.Thread.__init__(self)


def run(self):
count = 0
while 1:
if not self._stopevent.isSet():
count += 1
print count
time.sleep(1)
else:
print "paused"
time.sleep(1)

def pause(self):
self._stopevent.set()

def play(self):
self._stopevent.clear()


if __name__ == "__main__":
th = TestThread()
th.start()

time.sleep(5)
th.pause()

time.sleep(5)
th.play()

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


Re: Python 2.6 Deprecation Warnings with __new__ — Can someone expla in why?

2009-10-26 Thread Terry Reedy

Carl Banks wrote:


So what is the point of using __new__?


.__new__ creates new objects. It also inializes 'immutable' objects.


It's mostly for types written in C, or for subclassing types written
in C.


Specifically, for subclassing immutable classes where one wants 
initialization behavior different from that provided by the superclass.


> Advanced programmers can take advantage of it to do some

interesting things, but most of the time __init__ suffices.


Initialization of mutables should be done in .__init__. Most 
user-defined classes define mutables.


Terry Jan Reedy


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


Building static Python binary

2009-10-26 Thread mk

Hello,

I have trouble building Python static binary (for use with 'freeze.py', 
as frozen Python programs do not include dynamically linked libs). Anybody?


./configure --disable-shared --with-ldflags=-ldl

And yet after compiling the resulting binary is linked with following 
dynamic libraries:


[r...@localhost Python-2.6.2]# ldd python
linux-gate.so.1 =>  (0x0075b000)
libpthread.so.0 => /lib/libpthread.so.0 (0x0090)
libdl.so.2 => /lib/libdl.so.2 (0x008d1000)
libutil.so.1 => /lib/libutil.so.1 (0x03bbe000)
libssl.so.6 => /lib/libssl.so.6 (0x002e3000)
libcrypto.so.6 => /lib/libcrypto.so.6 (0x001a1000)
libm.so.6 => /lib/libm.so.6 (0x008d7000)
libc.so.6 => /lib/libc.so.6 (0x0078b000)
/lib/ld-linux.so.2 (0x0076d000)
libgssapi_krb5.so.2 => /usr/lib/libgssapi_krb5.so.2 (0x005ae000)
libkrb5.so.3 => /usr/lib/libkrb5.so.3 (0x004ce000)
libcom_err.so.2 => /lib/libcom_err.so.2 (0x00767000)
libk5crypto.so.3 => /usr/lib/libk5crypto.so.3 (0x00719000)
libresolv.so.2 => /lib/libresolv.so.2 (0x037ab000)
libz.so.1 => /usr/lib/libz.so.1 (0x00919000)
libkrb5support.so.0 => /usr/lib/libkrb5support.so.0 (0x00741000)
libkeyutils.so.1 => /lib/libkeyutils.so.1 (0x03909000)
libselinux.so.1 => /lib/libselinux.so.1 (0x00caf000)
libsepol.so.1 => /lib/libsepol.so.1 (0x00566000)



How can I make the python binary static?

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


Re: OT Virtual Server Host

2009-10-26 Thread Victor Subervi
You're saving my neck, man. Thanks!!!
V

On Mon, Oct 26, 2009 at 11:10 AM, Ryan Lynch  wrote:

> On Mon, Oct 26, 2009 at 10:56, Victor Subervi 
> wrote:
> > YES, that is what I want! How do I google this service? Or just flat-out
> > recommend one for me (or both). Googling "high-end virtual dedicated
> > servers" gave me *one* company...in England. I'd prefer the states (or
> > Caribbean, where I reside).
> > Thanks,
> > V
> >
> > On Sun, Oct 25, 2009 at 10:55 PM, geremy condra 
> wrote:
> >>
> >> On Sun, Oct 25, 2009 at 2:52 PM, Victor Subervi <
> victorsube...@gmail.com>
> >> wrote:
> >> > Hi;
> >> > Completely OT, but my back's up against the wall. I'm convinced that
> the
> >> > reason my codes keep breaking--and even stable installations of s/w
> from
> >> > SourceForge such as SimpleMail--on the hosts I've been using is
> because
> >> > their hardware should have conservatively been trashed 5 years ago.
> It's
> >> > simply impossible to code around garbage. My ultimate solution will be
> >> > to
> >> > colo two of my own servers (for redundancy), but for a few months
> while
> >> > I
> >> > get built back up, I still need to find some place where I can get my
> >> > client's sites up and running or I'll never be able to earn a
> paycheck.
> >> > I'm
> >> > more than happy to pay $100/mo or even more. I don't want one of those
> >> > $99/mo dedicated server plans, either, because their hardware is trash
> >> > too.
> >> > I've been in this game long enough to figure these guys out. What I
> need
> >> > is
> >> > a virtual server with some small company that has hardware that was
> >> > purchased in this century not the last one. But I don't know where to
> >> > find
> >> > the same. Google just brings up all the GoDaddys and eNoms of the
> world.
> >> > Any
> >> > ideas?
> >> > TIA,
> >> > Victor
> >>
> >> I've had good luck with high-end virtual dedicated servers. They
> >> can be pricey, but since a single machine going down tends to
> >> earn them a lot of ire, IME they work a bit harder to keep
> >> everything running.
>
>
> WebHostingTalk is a pretty rich source of info for hosting services,
> generally:
>
>  * http://www.webhostingtalk.com/
>
> They have a forum dedicated to discussions of VPS hosting services,
> and another forum where VPS hosting vendors can post ads, links,
> coupons, etc. It's a good place to start shopping, and the reviews
> should give you a pretty good idea of what to expect from different
> providers.
>
> FWIW, here's a few words of advice, based on my early VPS experiences:
>
>  - Avoid OpenVZ platforms, if you can help it. No matter what the
> vendor promises you, they are full of little "gotchas" and
> limitations, and they will drive you nuts.
>  - With managed or unmanaged VPS hosting, you get what you pay for, or
> worse. If they charge you $10/month for a 512MB RAM VPS instance, you
> can count on dangerously incompetent tech support and lots of
> downtime.
>  - Avoid VAServ, which also operates the FSCKVPS and CheapVPS brands
> for unmanaged VPS instances.
>
> But those are just what I learned from my personal horror stories,
> take it with a grain of salt.
>
> -Ryan
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: efficient running median

2009-10-26 Thread denis
Based on Perreault + Hebert, here's python code for a rather different
algorithm:
- for quantized e.g. 8-bit data
- runs faster for wider windows / slowly changing medians
- no heaps, no trees: the only import is numpy, and even that's not
essential

http://stackoverflow.com/questions/1309263/rolling-median-algorithm-in-c

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


Re: Why is python so sad?

2009-10-26 Thread Erez
That statistics may seem slightly more optimistic if you also count [:
and :]
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: OT Virtual Server Host

2009-10-26 Thread Ryan Lynch
On Mon, Oct 26, 2009 at 10:56, Victor Subervi  wrote:
> YES, that is what I want! How do I google this service? Or just flat-out
> recommend one for me (or both). Googling "high-end virtual dedicated
> servers" gave me *one* company...in England. I'd prefer the states (or
> Caribbean, where I reside).
> Thanks,
> V
>
> On Sun, Oct 25, 2009 at 10:55 PM, geremy condra  wrote:
>>
>> On Sun, Oct 25, 2009 at 2:52 PM, Victor Subervi 
>> wrote:
>> > Hi;
>> > Completely OT, but my back's up against the wall. I'm convinced that the
>> > reason my codes keep breaking--and even stable installations of s/w from
>> > SourceForge such as SimpleMail--on the hosts I've been using is because
>> > their hardware should have conservatively been trashed 5 years ago. It's
>> > simply impossible to code around garbage. My ultimate solution will be
>> > to
>> > colo two of my own servers (for redundancy), but for a few months while
>> > I
>> > get built back up, I still need to find some place where I can get my
>> > client's sites up and running or I'll never be able to earn a paycheck.
>> > I'm
>> > more than happy to pay $100/mo or even more. I don't want one of those
>> > $99/mo dedicated server plans, either, because their hardware is trash
>> > too.
>> > I've been in this game long enough to figure these guys out. What I need
>> > is
>> > a virtual server with some small company that has hardware that was
>> > purchased in this century not the last one. But I don't know where to
>> > find
>> > the same. Google just brings up all the GoDaddys and eNoms of the world.
>> > Any
>> > ideas?
>> > TIA,
>> > Victor
>>
>> I've had good luck with high-end virtual dedicated servers. They
>> can be pricey, but since a single machine going down tends to
>> earn them a lot of ire, IME they work a bit harder to keep
>> everything running.


WebHostingTalk is a pretty rich source of info for hosting services, generally:

 * http://www.webhostingtalk.com/

They have a forum dedicated to discussions of VPS hosting services,
and another forum where VPS hosting vendors can post ads, links,
coupons, etc. It's a good place to start shopping, and the reviews
should give you a pretty good idea of what to expect from different
providers.

FWIW, here's a few words of advice, based on my early VPS experiences:

 - Avoid OpenVZ platforms, if you can help it. No matter what the
vendor promises you, they are full of little "gotchas" and
limitations, and they will drive you nuts.
 - With managed or unmanaged VPS hosting, you get what you pay for, or
worse. If they charge you $10/month for a 512MB RAM VPS instance, you
can count on dangerously incompetent tech support and lots of
downtime.
 - Avoid VAServ, which also operates the FSCKVPS and CheapVPS brands
for unmanaged VPS instances.

But those are just what I learned from my personal horror stories,
take it with a grain of salt.

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


Re: OT Virtual Server Host

2009-10-26 Thread Victor Subervi
YES, that is what I want! How do I google this service? Or just flat-out
recommend one for me (or both). Googling "high-end virtual dedicated
servers" gave me *one* company...in England. I'd prefer the states (or
Caribbean, where I reside).
Thanks,
V

On Sun, Oct 25, 2009 at 10:55 PM, geremy condra  wrote:

> On Sun, Oct 25, 2009 at 2:52 PM, Victor Subervi 
> wrote:
> > Hi;
> > Completely OT, but my back's up against the wall. I'm convinced that the
> > reason my codes keep breaking--and even stable installations of s/w from
> > SourceForge such as SimpleMail--on the hosts I've been using is because
> > their hardware should have conservatively been trashed 5 years ago. It's
> > simply impossible to code around garbage. My ultimate solution will be to
> > colo two of my own servers (for redundancy), but for a few months while I
> > get built back up, I still need to find some place where I can get my
> > client's sites up and running or I'll never be able to earn a paycheck.
> I'm
> > more than happy to pay $100/mo or even more. I don't want one of those
> > $99/mo dedicated server plans, either, because their hardware is trash
> too.
> > I've been in this game long enough to figure these guys out. What I need
> is
> > a virtual server with some small company that has hardware that was
> > purchased in this century not the last one. But I don't know where to
> find
> > the same. Google just brings up all the GoDaddys and eNoms of the world.
> Any
> > ideas?
> > TIA,
> > Victor
>
> I've had good luck with high-end virtual dedicated servers. They
> can be pricey, but since a single machine going down tends to
> earn them a lot of ire, IME they work a bit harder to keep
> everything running.
>
> Geremy Condra
>
-- 
http://mail.python.org/mailman/listinfo/python-list


RE: Copying a ZipExtFile

2009-10-26 Thread Moore, Mathew L
> En Fri, 23 Oct 2009 14:15:33 -0300, Moore, Mathew L
> 
> escribió:
> 
> > with io.BytesIO() as memio:
> > shutil.copyfileobj(f, memio)
> > zip = zipfile.ZipFile(file=memio)
> > # Can't use zip.extract(), because I want to ignore paths
> > # within archive.
> > src = zip.open('unknowndir/src.txt')
> > with open('dst.txt', mode='wb') as dst:
> > shutil.copyfileobj(src, dst)
> >
> >
> > The last line throws an Error:
> >
> >
> > Traceback (most recent call last):
> >   File "test.py", line 25, in 
> > shutil.copyfileobj(src, dst)
> >   File "C:\Python26\lib\shutil.py", line 27, in copyfileobj
> > buf = fsrc.read(length)
> >   File "C:\Python26\lib\zipfile.py", line 594, in read
> > bytes = self.fileobj.read(bytesToRead)
> > TypeError: integer argument expected, got 'long'
> 
> Try adding a length parameter to the copyfileobj call, so the copy is
> done in small enough chunks.
> 


Hmmm...tried a variety of lengths (512, 1024, etc.) with no luck.  Maybe this 
is a good opportunity for me to learn some Python debugging tools.

Thanks!
--Matt

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


Re: Web development with Python 3.1

2009-10-26 Thread Echo
bottle (http://bottle.paws.de/) can run on python 3.1 after running
the 2to3 tool on it. It is a very lightweight framework. CherryPy 3.2
also runs on python 3.x

I don't know if there are any others.

On Sun, Oct 25, 2009 at 7:52 PM, Alan Harris-Reid
 wrote:
>
> I am very much new to Python, and one of my first projects is a simple
> data-based website. I am starting with Python 3.1 (I can hear many of you
> shouting "don't - start with 2.6"), but as far as I can see, none of the
> popular python-to-web frameworks (Django, CherryPy, web.py, etc.) are
> Python3 compatible yet.
>
> So, what can I use to start my web programming experience using 3.1?
>
> Any help would be appreciated.
>
> Alan
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>



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


Re: python web service or Apache?

2009-10-26 Thread Peng Yu
On Sun, Oct 25, 2009 at 11:09 PM, Simon Forman  wrote:
> On Sun, Oct 25, 2009 at 4:47 PM, Peng Yu  wrote:
>> Although, python can be used to provide web service. The following
>> webpage also mentioned, "Apache the best and most widely used web
>> server on the Internet today, check it out. If you want to run your
>> own web server this is the one to get, you can get binaries for both
>> Windows and Unix. You can download the entire sourcecode if you want
>> to check how it was made." Therefore, it would be better to use Apache
>> rather than python to provide web service, right?
>>
>> http://fragments.turtlemeat.com/pythonwebserver.php
>
>
> Both "best" and "better" (that website and you, respectively) omit
> mention of the criteria used for the evaluation.
>
> To determine what is "best" you must first answer "for what?"
>
>
> (Also, it is reasonable to use /both/ apache and python together, with
> mod_python or mod_wsgi, etc...)

I have never made a web server before. So I don't know what criterion
I should use? If possible, would you please let me know what pros and
cons you can think of?

How to use apache and python together? Does each of them offer some
functions that are not available in the other? Thank you!
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: a splitting headache

2009-10-26 Thread Vlastimil Brom
2009/10/26 jhermann :
> On 16 Okt., 02:18, Mensanator  wrote:
>> All I wanted to do is split a binary number into two lists,
>> a list of blocks of consecutive ones and another list of
>> blocks of consecutive zeroes.
>
> Back to the OP's problem, the obvious (if you know the std lib) and
> easy solution is:
>
 c = '00101000101'
 filter(None, re.split("(1+)", c))
> ['00', '1', '0', '1', '0', '', '00', '1', '0', '1']
>
> In production code, you compile the regex once, of course.
> --
> http://mail.python.org/mailman/listinfo/python-list
>

Maybe one can even forget the split function here entirely

>>> re.findall(r"0+|1+", '00101000101')
['00', '1', '0', '1', '0', '', '00', '1', '0', '1']
>>>

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


Python IDE

2009-10-26 Thread Girish
Hello, Which is the best software to create GUI other then Boa.

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


Re: Web development with Python 3.1

2009-10-26 Thread Chris Withers

Brendon Wickham wrote:
I can vouch for what Paul says. I started in Python 3 years ago, and I 
did so with a web application (still working on it!). I'm using the cgi 
approach, and it certainly teaches you the concepts. I fail to see how 
starting with a framework is a good idea if you don't know how the 
frameworks work (or what they're actually doing). It would be a bit like 
doing a web page in Dreamw***er and thinking you understand HTML/CSS.


I couldn't agree less. Using the CGI module is more akin to trying to 
write Dreamweaver when you want to build a static website...


Just use 2.6 and pick a framework of your choice. From what the OP 
described, Django or Pylons would fit the bill well.


Chris

--
Simplistix - Content Management, Batch Processing & Python Consulting
   - http://www.simplistix.co.uk
--
http://mail.python.org/mailman/listinfo/python-list


Re: Read any function in runtime

2009-10-26 Thread Rhodri James
On Fri, 23 Oct 2009 17:39:40 +0100, Matt McCredie   
wrote:



joao abrantes  gmail.com> writes:



Hey. I want to make a program like this:print "Complete the function
f(x)="then the user would enter x+2 or 1/x or any other function that  
only uses
the variable x. Then my python program would calculate f(x) in some  
points for

example in f(2),f(4).. etc . How can I do this?




check out 'eval' or 'exec'.


Then check out all the reasons you shouldn't use them in an
environment that you don't trust absolutely -- if someone wipes
your hard disc, you won't get any sympathy from here.

The safe answer is to write yourself a small parser.  Given that
you've got a very limited symbol set, that shouldn't be too hard.

--
Rhodri James *-* Wildebeest Herder to the Masses
--
http://mail.python.org/mailman/listinfo/python-list


Re: Is there a command that returns the number of substrings in a string?

2009-10-26 Thread Gerard Flanagan

Peng Yu wrote:

For example, the long string is 'abcabc' and the given string is
'abc', then 'abc' appears 2 times in 'abcabc'. Currently, I am calling
'find()' multiple times to figure out how many times a given string
appears in a long string. I'm wondering if there is a function in
python which can directly return this information.


re.findall?

>>> patt = re.compile('abc')
>>> len(patt.findall('abcabc'))
2

For groups of non-overlapping substrings, tested only as far as you see:

8<--

import re
from collections import defaultdict

def count(text, *args):
"""
>>> ret = count('abcabc', 'abc')
>>> ret['abc']
2
>>> ret = count('xabcxabcx', 'abc', 'x')
>>> ret['abc']
2
>>> ret['x']
3
>>> ret = count('abcabc', 'abc', 'cab')
>>> ret['abc']
2
>>> ret['cab']
0
>>> ret = count('abcabc', 'abc', 'ab')
>>> ret['abc']
2
>>> ret['ab']
0
"""
args = map(re.escape, args)
args.sort()
args.reverse()
pattern = re.compile('|'.join(args))
result = defaultdict(int)
def callback(match):
matched = match.group(0)
result[matched] += 1
return matched
pattern.sub(callback, text)
return result


if __name__ == '__main__':
import doctest
doctest.testmod()
8<--

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


Re: a splitting headache

2009-10-26 Thread jhermann
On 16 Okt., 02:18, Mensanator  wrote:
> All I wanted to do is split a binary number into two lists,
> a list of blocks of consecutive ones and another list of
> blocks of consecutive zeroes.

Back to the OP's problem, the obvious (if you know the std lib) and
easy solution is:

>>> c = '00101000101'
>>> filter(None, re.split("(1+)", c))
['00', '1', '0', '1', '0', '', '00', '1', '0', '1']

In production code, you compile the regex once, of course.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: how to get os.system () call to cooperate on Windows

2009-10-26 Thread Diez B. Roggisch
Anthra Norell wrote:

> I have a Python program that needs to copy files around. I could read
> and write which would be inefficient and would time-stamp the copy. The
> module "os" has lots of operating system functions, but none that copies
> files I could make out reading the doc twice. The function "os.system
> ('copy file_name directory_name')" turns out doesn't do anything except
> flashing a DOS command window for half a second. So my question is: How
> can one copy files on the OS level?
>This simple question would surely have been asked many times before.
> Not to impose on anyone's patience I expect it can be answered between
> two sips of coffee.
> 
> Thanks very much

Did you take a look at the shutil-module?

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


Problem while using xml.dom.minidom

2009-10-26 Thread bhaskar jain
Hello all,

   I am using xml.dom.minidom for creating a SAML metadata file which is an
xml file.
   Code -

import xml.dom.minidom as md
doc = md.Document()

entity_descr = doc.createElement("EntityDescriptor")
doc.appendChild(entity_descr)
entity_descr.setAttribute('xmlns',
'urn:oasis:names:tc:SAML:2.0:metadata')
entity_descr.setAttribute('xmlns:saml',
'urn:oasis:names:tc:SAML:2.0:assertion')
entity_descr.setAttribute('xmlns:ds', '
http://www.w3.org/2000/09/xmldsig#')
# Get the entity_id from saml20_idp_settings
entity_descr.setAttribute('entityID', self.group['entity_id'])

idpssodescr = doc.createElement('IDPSSODescriptor')
idpssodescr.setAttribute('WantAuthnRequestsSigned', 'true')
idpssodescr.setAttribute('protocolSupportEnumeration',
'urn:oasis:names:tc:SAML:2.0:protocol')
entity_descr.appendChild(idpssodescr)

keydescr = doc.createElement('KeyDescriptor')
keydescr.setAttribute('use', 'signing')
idpssodescr.appendChild(keydescr)
keyinfo = doc.createElement('ds:KeyInfo')
keyinfo.setAttribute('xmlns:ds', 'http://www.w3.org/2000/09/xmldsig#')
keydescr.appendChild(keyinfo)
x509data = doc.createElement('ds:X509Data')
keyinfo.appendChild(x509data)


# check this part

s = "this is a cert  blah blah"
x509cert = doc.createElement('ds:X509Certificate')
cert = doc.createTextNode(s)
x509cert.appendChild(cert)
x509data.appendChild(x509cert)

sso = doc.createElement('SingleSignOnService')
sso.setAttribute('Binding',
'urn:oasis:names:tc:SAML:2.0:bindings:HTTP-Redirect')

sso.setAttribute('Location', 'http://googleapps/singleSignOn')
idpssodescr.appendChild(sso)

# Write the metadata file.
fobj = open('metadata.xml', 'w')
doc.writexml(fobj, "   ", "", "\n", "UTF-8")
fobj.close()


This produces -

   
   http://www.w3.org/2000/09/xmldsig#";
   xmlns:saml="urn:oasis:names:tc:SAML:2.0:assertion">
   
   
   http://www.w3.org/2000/09/xmldsig#";>
   
   
this is a cert  blah blah
   
   
   
   
   http:///singleSignOn"/>
   
   

Though the third-party library wants it as,


this is a cert blah blah

   


Have checked to ensure that there are no newlines etc but still get this
problem.
Have asked this -
http://stackoverflow.com/questions/1623607/escaping-and-in-xml-when-using-xml-dom-minidom



Thanks for your help.


Regards,
Bhaskar.
-- 
http://mail.python.org/mailman/listinfo/python-list


how to get os.system () call to cooperate on Windows

2009-10-26 Thread Anthra Norell
I have a Python program that needs to copy files around. I could read 
and write which would be inefficient and would time-stamp the copy. The 
module "os" has lots of operating system functions, but none that copies 
files I could make out reading the doc twice. The function "os.system 
('copy file_name directory_name')" turns out doesn't do anything except 
flashing a DOS command window for half a second. So my question is: How 
can one copy files on the OS level?
  This simple question would surely have been asked many times before. 
Not to impose on anyone's patience I expect it can be answered between 
two sips of coffee.


Thanks very much

Frederic

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


Re: Python GUI

2009-10-26 Thread eb303
On Oct 26, 3:53 am, Grant Edwards  wrote:
> On 2009-10-26, Philip Semanchuk  wrote:
>
>
>
> > On Oct 25, 2009, at 8:39 PM, Ronn Ross wrote:
>
> >> I need to create a gui for python. I'm looking for something that is
> >> easy to
> >> learn and cross platform. Any suggestions? If you have any good
> >> tutorials
> >> please send along. Thanks in advance.
>
> > wxPython (which wraps wxWidgets) is popular and IMO reasonably well
> > laid out.
>
> I wouldn't call wxPython easy to learn.  (It is, however, what
> I use when I need a cross-platform GUI.) IMO, Tkinter is much
> easier to learn. But, it doesn't use native widgets, so Tkinter
> apps look like Tkinter apps rather than like other native apps.

Not anymore: tcl/tk 8.5 now includes the ttk themed widget set, which
can be made to use native widgets by setting the proper theme.

> > I hear great things about PyQt (which wraps QT) but I haven't
> > used it. PySide is a new wrapper for QT that has generated a
> > lot of excitement but is still its infancy, I think.
>
> I've always intended to look into pyFLTK, but have never had
> time to do more than a simple "hello world" program.

Does FLTK support native widgets? Last time I looked, it didn't seem
to... But it was quite a long time ago.
-- 
http://mail.python.org/mailman/listinfo/python-list


why python cache the string > 256?

2009-10-26 Thread s7v7nislands
hi all:

test.py
#!/usr/bin/python
a = []
for i in xrange(100):
a.append('a'*500)


$python -i test.py #virt mem 514m in top output
>>del a   #virt mem 510m

why python cache these string?
In source, I see when object size > SMALL_REQUEST_THRESHOLD, python
would use malloc.
also use free() when string refcount == 0.

do I miss somethong?

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


Best way to configure a logger hierarchy (was Re: A new way to configure Python logging)

2009-10-26 Thread Jean-Michel Pichavant

Vinay Sajip wrote:

Wolodja Wentland  cl.uni-heidelberg.de> writes:

  

--

I usually register a logger 'foo' within the application and one logger
for each module in the package, so the resulting logger hierarchy will
look like this:

foo
 |__bar
 |__baz
 |__newt
|___witch

I set every loggers log level to DEBUG and use the respective logger in



You only need set foo's level to DEBUG and all of foo.bar, foo.baz etc.
will inherit that level. Setting the level explicitly on each logger is
not necessary, 


A little bit off topic, don't you just need to set the **root** logger 
debug level ?
I figured it out quite recently having problem configuring all my 
loggers with just one click:
I have an application importing modules, the application is not always 
aware of the logging support by the module. The only way to configure 
these modules loggers is by configuring the root logger.
If I'm not wrong, this mechanism should have been definitively  
described in the documentation within one the examples. The root logger 
being of little use (from user POV), it is easy to forget its existence. 
Actually it proved to me being very useful.


JM

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


Re: Pause a thread/ execfile()

2009-10-26 Thread Babloo
On Oct 26, 1:01 pm, Sean DiZazzo  wrote:
> On Oct 25, 11:58 pm, Babloo  wrote:
>
>
>
> > i have a small python application with GUI (frontend) which has
> > various functions. I have a "RUN" button which runs python scripts in
> > the background . It basically calls execfile() function internally
> > which runs in a thread ,  to run the python script .
>
> > I want to implement a "PAUSE" feature which would pause the running
> > python script . So do that i have to either pause the thread in which
> > execfile() runs or pause execfile itself .
>
> > When the user presses "RUN" again then the python script should resume
> > running .
>
> > Any ideas how to pause the thread / pause execfile() . Any other ideas
> > for the same would be helpful .
>
> > Thanks
>
> I think you can do that with a threading.event().  In the gui, create
> a new threading.event() and pass it in to the worker thread.  Set up
> your code in the worker so that on every iteration of "work", it
> checks to see if the event is set.  If it finds it set, then it
> sleeps, but keeps checking until the event is unset.  When unset
> again, it picks up and begins work again.
>
> In the gui, your pause button just sets and unsets the event, and the
> worker will find out and pause at the next iteration.
>
> Depending on what kind of work your worker thread is doing, it might
> be tough to structure the code so the event gets checked reasonably
> often.  Hope this helps.
>
> ~Sean
>
> PS.  Not sure this idea will hold up when using execfile()

Hi..
Thanks for the reply . Yes tried doing exactly what you have
suggested . i could show you the sample code .
But some how it doesn't work and main reason could be i am using
execfile() in the thread .
I was trying to set the event on the press of a button . It doesnt
pause the thread and instead keeps on executing .
Dont know what the problem could be ???

Sample code :-

$$$
import threading

class TestThread(threading.Thread):
"""
A sample thread class
"""

def __init__(self):
"""
Constructor, setting initial variables
"""
self._stopevent = threading.Event()
self._sleepperiod = 1.0

threading.Thread.__init__(self, name="TestThread")

def run(self):
"""
overload of threading.thread.run()
main control loop
"""
print "%s starts" % (self.getName(),)

count = 0
while not self._stopevent.isSet():
count += 1
print "loop %d" % (count,)
self._stopevent.wait(self._sleepperiod)

print "%s ends" % (self.getName(),)

def join(self,timeout=None):
"""
Stop the thread
"""
self._stopevent.set()
threading.Thread.join(self, timeout)

if __name__ == "__main__":
testthread = TestThread()
testthread.start()

import time
time.sleep(10.0)

testthread.join()

$


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


Re: Pause a thread/ execfile()

2009-10-26 Thread Babloo
On Oct 26, 1:11 pm, Saju Pillai  wrote:
> On 26/10/09 12:28 PM, Babloo wrote:
>
> > i have a small python application with GUI (frontend) which has
> > various functions. I have a "RUN" button which runs python scripts in
> > the background . It basically calls execfile() function internally
> > which runs in a thread ,  to run the python script .
>
> > I want to implement a "PAUSE" feature which would pause the running
> > python script . So do that i have to either pause the thread in which
> > execfile() runs or pause execfile itself .
>
> > When the user presses "RUN" again then the python script should resume
> > running .
>
> > Any ideas how to pause the thread / pause execfile() . Any other ideas
> > for the same would be helpful .
>
> Other ideas ? You could use job control signals if you are on unix. Try
> forking a child process instead of using a thread. Sending SIGSTOP to
> the forked child will stop/pause it, SIGCONT will resume it.
>
> -srp

Hi ,
Thanks for the reply .  I am on windows platform ... yeah if was on
linux things would have been easier !!
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Pause a thread/ execfile()

2009-10-26 Thread Saju Pillai

On 26/10/09 12:28 PM, Babloo wrote:

i have a small python application with GUI (frontend) which has
various functions. I have a "RUN" button which runs python scripts in
the background . It basically calls execfile() function internally
which runs in a thread ,  to run the python script .

I want to implement a "PAUSE" feature which would pause the running
python script . So do that i have to either pause the thread in which
execfile() runs or pause execfile itself .

When the user presses "RUN" again then the python script should resume
running .


Any ideas how to pause the thread / pause execfile() . Any other ideas
for the same would be helpful .


Other ideas ? You could use job control signals if you are on unix. Try
forking a child process instead of using a thread. Sending SIGSTOP to
the forked child will stop/pause it, SIGCONT will resume it.

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


Re: Pause a thread/ execfile()

2009-10-26 Thread Sean DiZazzo
On Oct 25, 11:58 pm, Babloo  wrote:
> i have a small python application with GUI (frontend) which has
> various functions. I have a "RUN" button which runs python scripts in
> the background . It basically calls execfile() function internally
> which runs in a thread ,  to run the python script .
>
> I want to implement a "PAUSE" feature which would pause the running
> python script . So do that i have to either pause the thread in which
> execfile() runs or pause execfile itself .
>
> When the user presses "RUN" again then the python script should resume
> running .
>
> Any ideas how to pause the thread / pause execfile() . Any other ideas
> for the same would be helpful .
>
> Thanks

I think you can do that with a threading.event().  In the gui, create
a new threading.event() and pass it in to the worker thread.  Set up
your code in the worker so that on every iteration of "work", it
checks to see if the event is set.  If it finds it set, then it
sleeps, but keeps checking until the event is unset.  When unset
again, it picks up and begins work again.

In the gui, your pause button just sets and unsets the event, and the
worker will find out and pause at the next iteration.

Depending on what kind of work your worker thread is doing, it might
be tough to structure the code so the event gets checked reasonably
often.  Hope this helps.

~Sean

PS.  Not sure this idea will hold up when using execfile()
-- 
http://mail.python.org/mailman/listinfo/python-list


Pause a thread/ execfile()

2009-10-26 Thread Babloo
i have a small python application with GUI (frontend) which has
various functions. I have a "RUN" button which runs python scripts in
the background . It basically calls execfile() function internally
which runs in a thread ,  to run the python script .

I want to implement a "PAUSE" feature which would pause the running
python script . So do that i have to either pause the thread in which
execfile() runs or pause execfile itself .

When the user presses "RUN" again then the python script should resume
running .


Any ideas how to pause the thread / pause execfile() . Any other ideas
for the same would be helpful .

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


handling PAMIE and lxml

2009-10-26 Thread elca

Hello,
i was open anther new thread ,old thread is too long.
first of all,i really appreciate other many people's help in this newsgroup.
im making webscraper now.
but still problem with my script source.
http://elca.pastebin.com/m52e7d8e0
i was upload my script in here.
so anybody can modify it.
main problem is , if you see line number 74 ,75 in my source,
you can see this line "thepage = urllib.urlopen(theurl).read()".
i want to change this line to work with Pamie not urllib.
if anyone help me,really appreciate.
thanks in advance.

Paul
-- 
View this message in context: 
http://www.nabble.com/handling-PAMIE-and-lxml-tp26055230p26055230.html
Sent from the Python - python-list mailing list archive at Nabble.com.

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


Re: how can i use lxml with win32com?

2009-10-26 Thread elca



motoom wrote:
> 
> elca wrote:
> 
>> http://news.search.naver.com/search.naver?sm=tab_hty&where=news&query=korea+times&x=0&y=0
>> that is korea portal site and i was search keyword using 'korea times'
>> and i want to scrap resulted to text name with 'blogscrap_save.txt'
> 
> Aha, now we're getting somewhere.
> 
> Getting and parsing that page is no problem, and doesn't need JavaScript 
> or Internet Explorer.
> 
> import urllib2
> import BeautifulSoup
> doc=urllib2.urlopen("http://news.search.naver.com/search.naver?sm=tab_hty&where=news&query=korea+times&x=0&y=0";)
> soup=BeautifulSoup.BeautifulSoup(doc)
> 
> 
> By analyzing the structure of that page you can see that the articles 
> are presented in an unordered list which has class "type01".  The 
> interesting bit in each list item is encapsulated in a  tag with 
> class "sh_news_passage".  So, to parse the articles:
> 
> ul=soup.find("ul","type01")
> for li in ul.findAll("li"):
>  dd=li.find("dd","sh_news_passage")
>  print dd.renderContents()
>  print
> 
> This example prints them, but you could also save them to a file (or a 
> database, whatever).
> 
> Greetings,
> 
> 
> 
> -- 
> "The ability of the OSS process to collect and harness
> the collective IQ of thousands of individuals across
> the Internet is simply amazing." - Vinod Valloppillil
> http://www.catb.org/~esr/halloween/halloween4.html
> -- 
> http://mail.python.org/mailman/listinfo/python-list
> 
> 


Hi, thanks for your help..
thread is too long, so i will open another new post.
thanks a lot

Paul
-- 
View this message in context: 
http://www.nabble.com/how-can-i-use-lxml-with-win32com--tp26044339p26055191.html
Sent from the Python - python-list mailing list archive at Nabble.com.

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