Re: The Yield statement

2008-07-06 Thread inhahe

"Alex Bryan" <[EMAIL PROTECTED]> wrote in message 
news:[EMAIL PROTECTED]
> Okay, so i don't really understand the Yield thing and i know it is 
> useful. I've read a few things about it but it is all programming  jargon 
> and so basically it is hard for me to understand. So can anyone  give me a 
> description or link me to a site that has a good definition  and/or 
> examples of it? If you could I would really appreciate it.

Really short answer:

def f():
  yield 1
  yield 2
  yield 3

for x in f(): print x,
# should print 1 2 3

def f():
  for x in xrange(10):
yield x

for x in f(): print x,
# should print 0 1 2 3 4 5 6 7 8 9

note that this won't work;
def f():
  for x in xrange(10):
for y in xrange(10):
  yield (x,y)

yield just doesn't work right with multiple levels of loops. i had to 
discover that the hard way.



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


Re: re.search much slower then grep on some regular expressions

2008-07-06 Thread [EMAIL PROTECTED]
On Jul 5, 11:13 am, Mark Dickinson <[EMAIL PROTECTED]> wrote:
> Apparently, grep and Tcl convert a regex to a finite state machine.
...
> But not all PCREs can be converted to a finite state machine
...
> Part of the problem is a lack of agreement on what
> 'regular expression' means.   Strictly speaking, PCREs aren't
> regular expressions at all, for some values of the term
> 'regular expression'.  See
>
> http://en.wikipedia.org/wiki/Regular_expression

Formally, there's no lack of agreement that I'm aware of.  Anyone
formally defining it will use something along the lines of what
wikipedia specifies (with "Regular expressions in this sense can
express the regular languages, exactly the class of languages accepted
by finite state automata.").  Colloquially it's used to mean "any text-
matching scheme that looks vaguely like sed/grep regexes".

PCREs are certainly not "real" regular expressions, but they are
colloquially.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Python with Ecmascript

2008-07-06 Thread Daniel Fetchinson
>> Is there a way to do similar things on linux?
>
> I think no. Because these tech use COM. And COM don't exist under xxnux.
> But:
>   - look if XPCOM, or dBus) can help you
>   - search with the word "MOZLAB", who work a solution (plugin) for
> drive Firefox, from an external software.

Wow, mozlab is amazing!

Thanks,
Daniel
-- 
Psss, psss, put it down! - http://www.cafepress.com/putitdown
--
http://mail.python.org/mailman/listinfo/python-list


Re: The Yield statement

2008-07-06 Thread Mark Tolonen


"inhahe" <[EMAIL PROTECTED]> wrote in message 
news:[EMAIL PROTECTED]


"Alex Bryan" <[EMAIL PROTECTED]> wrote in message 
news:[EMAIL PROTECTED]
Okay, so i don't really understand the Yield thing and i know it is 
useful. I've read a few things about it but it is all programming  jargon 
and so basically it is hard for me to understand. So can anyone  give me 
a description or link me to a site that has a good definition  and/or 
examples of it? If you could I would really appreciate it.


Really short answer:

def f():
 yield 1
 yield 2
 yield 3

for x in f(): print x,
# should print 1 2 3

def f():
 for x in xrange(10):
   yield x

for x in f(): print x,
# should print 0 1 2 3 4 5 6 7 8 9

note that this won't work;
def f():
 for x in xrange(10):
   for y in xrange(10):
 yield (x,y)

yield just doesn't work right with multiple levels of loops. i had to 
discover that the hard way.


Huh?  Works fine:


def f():

...  for x in xrange(10):
...for y in xrange(10):
...  yield (x,y)
...

for x in f(): print x,

...
(0, 0) (0, 1) (0, 2) (0, 3) (0, 4) (0, 5) (0, 6) (0, 7) (0, 8) (0, 9) (1, 0) 
(1,
1) (1, 2) (1, 3) (1, 4) (1, 5) (1, 6) (1, 7) (1, 8) (1, 9) (2, 0) (2, 1) 
(2, 2)
(2, 3) (2, 4) (2, 5) (2, 6) (2, 7) (2, 8) (2, 9) (3, 0) (3, 1) (3, 2) (3, 
3) (3
, 4) (3, 5) (3, 6) (3, 7) (3, 8) (3, 9) (4, 0) (4, 1) (4, 2) (4, 3) (4, 4) 
(4, 5
) (4, 6) (4, 7) (4, 8) (4, 9) (5, 0) (5, 1) (5, 2) (5, 3) (5, 4) (5, 5) (5, 
6) (
5, 7) (5, 8) (5, 9) (6, 0) (6, 1) (6, 2) (6, 3) (6, 4) (6, 5) (6, 6) (6, 7) 
(6,
8) (6, 9) (7, 0) (7, 1) (7, 2) (7, 3) (7, 4) (7, 5) (7, 6) (7, 7) (7, 8) (7, 
9)
(8, 0) (8, 1) (8, 2) (8, 3) (8, 4) (8, 5) (8, 6) (8, 7) (8, 8) (8, 9) (9, 0) 
(9,

1) (9, 2) (9, 3) (9, 4) (9, 5) (9, 6) (9, 7) (9, 8) (9, 9)

-Mark

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


Re: Parsing MIME-encoded data in an HTTP request

2008-07-06 Thread Ron Garret
In article <[EMAIL PROTECTED]>,
 Michael Ströder <[EMAIL PROTECTED]> wrote:

> Ron Garret wrote:
> > In article <[EMAIL PROTECTED]>,
> >  Ron Garret <[EMAIL PROTECTED]> wrote:
> > 
> >> In article <[EMAIL PROTECTED]>,
> >>  Michael Ströder <[EMAIL PROTECTED]> wrote:
> >>
> >>> Ron Garret wrote:
>  I'm writing a little HTTP server and need to parse request content that 
>  is mime-encoded.  All the MIME routines in the Python standard library 
>  seem to have been subsumed into the email package, which makes this 
>  operation a little awkward.
> >>> How about using cgi.parse_multipart()?
> >>>
> >> Unfortunately cgi.parse_multipart doesn't handle nested multiparts, 
> >> which the requests I'm getting have.  You have to use a FieldStorage 
> >> object to do that, and that only works if you're actually in a cgi 
> >> environment, which I am not.  The server responds to these requests 
> >> directly.
> >>
> >> Anyway, thanks for the idea.
> > 
> > Hm, it actually seems to work if I manually pass in the outerboundary 
> > parameter and environ={'REQUEST_METHOD':'POST'}  That seems like the 
> > Right Answer.
> 
> I'm also using it to parse form parameters in a message body received by 
> POST.
> 
> CIao, Michael.

Just for the record, here's the incantation I ended up with:


class post_handler(BaseHTTPRequestHandler):
  def do_POST(self):
form = cgi.FieldStorage(fp=self.rfile, headers=self.headers,
environ={'REQUEST_METHOD':'POST'})
...


works like a charm.

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

Re: Elisp Lesson on file processing (make downloadable copy of a website)

2008-07-06 Thread [EMAIL PROTECTED]
In this week i wrote a emacs program and tutorial that does archiving
a website for offline reading.
(See http://xahlee.org/emacs/make_download_copy.html )

In the process, i ran into a problem with the unix “cp” utility. I've
been a  unix admin for Solaris during 1998-2004. Even the first time i
learned about cp, i noticed some pecularity. But only today, i thought
about it and wrote it out exactly what's going on.

Here's a excerpt from my emacs tutorial above regarding the issue.
--

Copying a bunch of directories seems a trivial operation, but it
actually took me a couple hours to arrive at the final code, due to
the exact requirement of directory paths, and the unix “cp” tool's
lack of precision and flexibility.

Originally, i thought the code would be something simple like several
“(shell-command (concat "cp -R " fromDir " " toDir))”, one for each
source dir, where fromDir and toDir are full paths. However, it turns
out the problem is slightly more complex.

Suppose the source dir is “/Users/xah/web/emacs” and dest dir is “/
Users/xah/web/diklo/xahtut/emacs” and i want all branches under the
source dir copied into the dest dir.

If you do “cp -R /Users/xah/web/emacs /Users/xah/web/diklo/xahtut/
emacs” with both xahtut and xahtut/emacs doesn't exist, then this
error results: “cp: /Users/xah/web/diklo/xahtut/emacs: No such file or
directory”.

If you do “cp -R /Users/xah/web/emacs /Users/xah/web/diklo/xahtut/
emacs” with xahtut/emacs exists, then you got “/Users/xah/web/diklo/
xahtut/emacs/emacs”, which is not what i want.

If you do “cp -R /Users/xah/web/emacs /Users/xah/web/diklo/xahtut”
with xahtut doesn't exist, it results in all branches of emacs in
xahtut, which is wrong.

Only when you do “cp -R /Users/xah/web/emacs /Users/xah/web/diklo/
xahtut” with xahtut exists, you get the correct result with the new
dir “/Users/xah/web/diklo/xahtut/emacs” having all branches of the
original dir.

So, the solution is to first create all the parent dirs of the dest
dir, but without the dest dir node itself. Then, do a cp to the first
parent of dest dir.

Directories are abstractly a tree. Copying directories is like
grafting a tree from one branch into another branch. To begin, we are
given two spec: the source node and a destination node. The source
node by definition is a existing node (i.e. existing dir or file),
otherwise the copying won't make sense. However, the destination spec
can be a node that doesn't exist, or its parents doesn't exist, or
several levels of parents doesn't exist. When the destination spec has
missing nodes, we can consider creating them as part of the grafting
process, or we can consider it as a error.

The unix “cp” tool's behavior is mathematically inconsistent. When the
destination node exist, the source node will become new children of
destination node. When the destination node does not exist (but its
parent exists), “cp” will create the node, and copy only the children
of the source node to it. When the destination node doesn't exist and
its parent doesn't exist neither, then “cp” considers it a error.

---
Related readings:

• The Nature of the “Unix Philosophy”
http://xahlee.org/UnixResource_dir/writ/unix_phil.html

  Xah
∑ http://xahlee.org/

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

Re: Discover Islam - The Fastest Growing Religion in the World !

2008-07-06 Thread kylefarthing
On Jul 1, 4:51 pm, ah <[EMAIL PROTECTED]> wrote:
> Correct your information about Islam
> ,
> The Misunderstood Religion
>
>   When you are ready_ you can enter this place!!!
>  http://sultan.org

all u muslim liers get your facts stright
According to the Carnegie Endowment for International Peace, the World
Christian Database as of 2007 estimated the six fastest growing
religions of the world to be Islam (1.84%), the Bahá'í Faith (1.7%),
Sikhism (1.62%), Jainism (1.57%), Hinduism (1.52%), and Christianity
(1.32%). High birth rates were cited as the reason for the growth.
[13]

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


Re: pythoncom InternetExplorer.Application don't work in vista || firefox pythoncom ?

2008-07-06 Thread gcmartijn
On 5 jul, 15:27, Terry Reedy <[EMAIL PROTECTED]> wrote:
> [EMAIL PROTECTED] wrote:
> > H!
>
> > I using a script that opens a internet page in a small window (what I
> > can control)
> > In XP everything was working fine, but now I'm using Vista with IE7
> > and this is what happends now:
>
> > First a small window opens at the postion x0 y0 (like I want) but then
> > IE thinks "Hey lets open a other main window too".
> > And that window opens the url 'http://www.google.nl'
>
> Perhaps on XP you changed the IE homepage to about:blank.  On your Vista
> machine, it is set to Google, perhaps by the manufacturer (for a fee).
> Try changing it.

Nope when its about:blank I get that google page (because I say that
in the script)
--
http://mail.python.org/mailman/listinfo/python-list


Re: Freesoftware for auto/intelligent code completing in Python

2008-07-06 Thread Ali Servet Dönmez
On Jul 4, 12:56 am, "Python Nutter" <[EMAIL PROTECTED]> wrote:
> If you guys can get your head out of IDE land, you'll find iPython
> does a fantastic job at introspection and Auto-completion, you can
> launch shell commands and editors and when done saving be back in the
> iPython shell, save memory/variable space to disk so you can come back
> the next day and continue off where you were. It puts IDEs to shame.

I have quick tried iPython and autocomplete seems to work pretty
decently, even if it's not same as in a GUI. Thank you very much for
your advice.

Could you let me know how do work with .py files in iPython please?

> If you can't get your Windows-centric IDE need eliminated, then Wing
> IDE 101 will not auto-complete, its been deliberately disabled to
> force students (hence 101) to memorize python/function names.
>
> Komodo Edit is a free download and will Auto-complete.

Yes, Komodo Edit works well too... Thanks.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Freesoftware for auto/intelligent code completing in Python

2008-07-06 Thread Ali Servet Dönmez
On Jul 4, 7:10 am, Yu-Xi Lim <[EMAIL PROTECTED]> wrote:
> Ali Servet Dönmez wrote:
>
> > I tried code come completion options in Emacs for Python, but none of
> > them was satisfactory to me. I'd be glad to hear how did your friend
> > get it work though.
>
> Perhaps it would help to say what ways the completion in Emacs was not
> satisfactory?

I simply couldn't manage to get it work.

> FWIW, it should be possible to get IPython-type completion in Emacs, but
> I hadn't managed that yet :( Refactoring, too. Both involve Pymacs but
> I've had limited success with that.

Yeah, that's what I'm talking about.

> As for PyDev (I know you said "No" to this already), the main problem I
> have with PyDev/Eclipse is the woefully underpowered editor (compared to
> Emacs), and poor indentation logic. On the plus side, refactoring works
> pretty well. So why not PyDev?

I tried PyDev with Eclipse too and it's an aweful environment to me.
Auto-completion was a total failure too...

> I'm just wondering, you insist on Free/Libre software solutions, and say
> the ones you tried don't work for you. Why not "use the source" and fix
> them so they work your way? ;) To quote you: "how hard it could be be
> writing a freesoftware which would automatically/intelligently auto
> complete Python code?"

Yes Yu-Xi Lim, you are right. Let me quote my self here: "I made my
mind
and I could volunteer to make this happen as thesis project for my
incoming graduation in the next year."
--
http://mail.python.org/mailman/listinfo/python-list


Re: pythoncom InternetExplorer.Application don't work in vista || firefox pythoncom ?

2008-07-06 Thread gcmartijn
On 5 jul, 14:14, "Méta-MCI \(MVP\)" <[EMAIL PROTECTED]>
wrote:
> Hi!
>
> Your code run OK for me (Vista Ultimate).
> This other version run also OK :
>
> def webbrowser(url=None):
>     import win32com.client, time
>
>     ie=win32com.client.Dispatch('InternetExplorer.Application')    
>     while ie.Busy==True:
>         time.sleep(0.125)
>     ie.Top = 0
>     ie.Left = 0
>     ie.Height = 400
>     ie.Width = 400
>     ie.AddressBar = False
>     ie.MenuBar  = False
>     ie.Resizable = False
>     ie.StatusBar = False
>     ie.ToolBar = False
>     ie.Visible = 1
>     return ie
>
> w = webbrowser()
> w.Navigate('http://www.google.nl')
>
> @-salutations
> --
> Michel Claveau

I use your script now but I'm still getting 2 windows I uploaded a
screenshot how it looks.
1 at the background my window (but that is loading nothing)
1 at on top with the site http://www.google.nl (because that is in the
script)

http://img376.imageshack.us/img376/5506/capturess8.jpg
--
http://mail.python.org/mailman/listinfo/python-list


Re: Freesoftware for auto/intelligent code completing in Python

2008-07-06 Thread Ali Servet Dönmez
On Jul 4, 7:31 am, Jeroen Ruigrok van der Werven <[EMAIL PROTECTED]
nomine.org> wrote:
> -On [20080630 23:51], Ali Servet Dönmez ([EMAIL PROTECTED]) wrote:
>
> >This could be an extension, a plugin, an Emacs mode, a new editor or
> >even a brand new huge all-fancy IDE, I don't care, but what am I
> >missing here?
>
> Vim's omnicomplete (CTRL-X CTRL-O).
>
> See :help omnifunc within vim.
>
> --
> Jeroen Ruigrok van der Werven  / asmodai
> イェルーン ラウフロック ヴァン デル ウェルヴェンhttp://www.in-nomine.org/|http://www.rangaku.org/| 
> GPG: 2EAC625B
> Don't always think in a straight line...

Jeroen, your advice might be *the solution* to the problem; but I'm
not really into using Vi(m). Thank your very much anyway!
--
http://mail.python.org/mailman/listinfo/python-list

Re: Not necessarily related to python Web Crawlers

2008-07-06 Thread subeen
On Jul 5, 2:31 pm, [EMAIL PROTECTED] wrote:
> Hi
> Does anyone here have a good recommendation for an open source crawler
> that I could get my hands on? It doesn't have to be python based. I am
> interested in learning how crawling works. I think python based
> crawlers will ensure a high degree of flexibility but at the same time
> I am also torn between looking for open source crawlers in python vs C
> ++ because the latter is much more efficient(or so I heard. I will be
> crawling on very cheap hardware.)
>
> I am definitely open to suggestions.
>
> Thx

You can check my python blog. There are some tips and codes on
crawlers.
http://love-python.blogspot.com/

regards,
Subeen
http://love-python.blogspot.com/
--
http://mail.python.org/mailman/listinfo/python-list


Re: Freesoftware for auto/intelligent code completing in Python

2008-07-06 Thread Ali Servet Dönmez
On Jul 4, 8:58 am, Aspersieman <[EMAIL PROTECTED]> wrote:
> Jeroen Ruigrok van der Werven wrote:> -On [20080630 23:51], Ali Servet Dönmez 
> ([EMAIL PROTECTED]) wrote:
>
> >> This could be an extension, a plugin, an Emacs mode, a new editor or
> >> even a brand new huge all-fancy IDE, I don't care, but what am I
> >> missing here?
>
> > Vim's omnicomplete (CTRL-X CTRL-O).
>
> > See :help omnifunc within vim.
>
> I find Vim with ctags, omnicomplete and calltip support the BEST I've
> tried so far. And I've tried many.
>
> Here's a tutorial on setting this up.
>    http://blog.sontek.net/2008/05/11/python-with-a-modular-ide-vim/
>
> Regards
>
> Nicol
>
> --
>
> The three things to remember about Llamas:
> 1) They are harmless
> 2) They are deadly
> 3) They are made of lava, and thus nice to cuddle.

Oh my, that thing seems to work! I didn't try it my self, but checked
out the URL you've mentioned. I think I've been unfair to Yu-Xi Lim
before... Thank you.
--
http://mail.python.org/mailman/listinfo/python-list


Re: conflict between multiple installs of python (linux)

2008-07-06 Thread [EMAIL PROTECTED]
Is some problems with 2.5 i see something on internet (ex: ctypes )
So i try to install 2.5.1 for pyglet1.1, but not work with ctypes .
So ctypes lib is on the path lib's !?
But python2.6 work with ctypes.
The python2.5 and 2.6 have been installed with same command:
python setup.py install
If you see my code :

 python2.5
Python 2.5.1 (r251:54863, Jul  4 2008, 14:55:17)
[GCC 4.3.1] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import ctypes
Traceback (most recent call last):
  File "", line 1, in 
  File "/usr/local/lib/python2.5/ctypes/__init__.py", line 10, in

from _ctypes import Union, Structure, Array
ImportError: No module named _ctypes
>>> import pyglet
Traceback (most recent call last):
  File "", line 1, in 
  File "/usr/local/lib/python2.5/site-packages/pyglet/__init__.py",
line 69, in 
_require_ctypes_version('1.0.0')
  File "/usr/local/lib/python2.5/site-packages/pyglet/__init__.py",
line 64, in _require_ctypes_version
import ctypes
  File "/usr/local/lib/python2.5/ctypes/__init__.py", line 10, in

from _ctypes import Union, Structure, Array
ImportError: No module named _ctypes
>>>

python (default python )
Python 2.6b1 (r26b1:64398, Jul  4 2008, 15:57:20)
[GCC 4.3.1] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import ctypes
>>> import pyglet
>>> print pyglet.version
1.1beta2
>>>


Try python 2.6
To see the path this is some code:

import sys
print sys.path
print sys.prefix
print sys.prefix

Have a nice day !

On Jul 5, 10:04 pm, casevh <[EMAIL PROTECTED]> wrote:
> On Jul 5, 11:09 am, david <[EMAIL PROTECTED]> wrote:
>
>
>
> > You learn something new every day:
>
> > On my ubuntu, update-manager is supposed to use the python2.5
> > installed on /usr/bin. Well, I had subsequently installed a whole
> > bunch of stuff in /usr/local (/usr/local/bin/python and /usr/local/lib/
> > python2.5 etc), which I have happily been using for development for a
> > year. I had thought that the two pythons were completely independent.
>
> > Well, I was wrong. When /usr/bin/python2.5 runs, *by default*, it
> > adds /usr/local/lib/python2.5 to its sys path - and apparently there
> > are things in /usr/local which are inconsistent with those at /usr
> > (not suprising).
>
> > I have fixed the problem - but I had to modify the actual update-
> > manager .py file itself. At the beginning, I set the sys.path in
> > python *explicitly* to not include the /usr/local stuff.
>
> > But this is clearly a kludge. My question: how do I keep the Ubuntu
> > python stuff at /usr/bin/python2.5 from adding /usr/local/lib/
> > python2.5 to the import search path in a clean and global way? I
> > really want both pythons completely isolated from one another!
>
> > Thankyou.
>
> Python's path is build by site.py. In the file /usr/lib/python2.5/
> site.py, look for the line "prefixes.insert(0, '/usr/local')" and
> comment it out. That should do it.
>
> casevh

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


Re: multi-platform browser embedding

2008-07-06 Thread Diez B. Roggisch

Joe P. Cool schrieb:

I fiddled a little with pyGTK and was quite happy to discover
gtkMozEmbed because I want to write an application for Linux and
Windows with a powerful browser widget. Unfortunatly I couldnt find a
way to make gtkMozEmbed work on Windows. Are there alternatives? I'm
lazy so I prefer to download binaries for Windows :) but I don't mind
building from source as long as I can use MinGW/Msys and avoid an
incalculable odyssey through cryptic compiler errors and makefile
surgery. Thanks in advance for your hints.


If you can switch to Qt4, it embeds WebKit on all platforms.

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


Python / WxPython error message

2008-07-06 Thread Keith Bailey

Dear All,

Any help on this would be hugely appreciated.

I have had a Python programme written for me, but when I try to run it, 
I get the following error message:


/*Traceback (most recent call last):
 File "iTeddyConverter.py", line 3, in 
 File "zipextimporter.pyc", line 82, in load_module
 File "iTeddyConverterPanel.pyc", line 4, in 
 File "zipextimporter.pyc", line 98, in load_module
ImportError: MemoryLoadLibrary failed loading win32file.pyd*/

I hav etrawled through the net trying to find a resolution but nothing 
works.  I tried putting the DLL msvcp71.dll in the system32 folder but 
that made no difference. Please help if you can.


Thanks

Keith


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


Hands-on HTML Table Parser/Matrix?

2008-07-06 Thread robert
Often I want to extract some web table contents. Formats are 
mostly static, simple text & numbers in it, other tags to be 
stripped off. So a simple & fast approach would be ok.


What of the different modules around is most easy to use, stable, 
up-to-date, iterator access or best matrix-access (without need 
for callback functions,classes.. for basic tasks)?



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


Re: Hands-on HTML Table Parser/Matrix?

2008-07-06 Thread Tim Cook
There are couple of HTML examples using Pyparsing here:

http://pyparsing.wikispaces.com/Examples


--Tim
 
On Sun, 2008-07-06 at 14:40 +0200, robert wrote:
> Often I want to extract some web table contents. Formats are 
> mostly static, simple text & numbers in it, other tags to be 
> stripped off. So a simple & fast approach would be ok.
> 
> What of the different modules around is most easy to use, stable, 
> up-to-date, iterator access or best matrix-access (without need 
> for callback functions,classes.. for basic tasks)?
> 
> 
> Robert
> --
> http://mail.python.org/mailman/listinfo/python-list
-- 
Timothy Cook, MSc
Health Informatics Research & Development Services
LinkedIn Profile:http://www.linkedin.com/in/timothywaynecook 
Skype ID == timothy.cook 
**
*You may get my Public GPG key from  popular keyservers or   *
*from this link http://timothywayne.cook.googlepages.com/home*
**


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

Re: Recursive wildcard file search

2008-07-06 Thread Simon Brunning
2008/7/4 Gerhard Häring <[EMAIL PROTECTED]>:
> Robert Dailey wrote:
>> Is there a way to perform a recursive file search using wildcards in
>> python 3.0b1? [...]
>
> glob.glob() or glob.iglob().

glob's not recursive AFAIK. This recipe probably still works under
Pythion 3K, though:



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


Hi there! I need what is probably a very basic lesson in events....

2008-07-06 Thread furby
I am teaching myself Python... I'm nowhere near even intermediate
level yet, so treat me like an idiot. I am using Boa Constructor on
Ubuntu 8.04 if that helps. Here is what I have right now :

I am plying with reading a URL (An RSS feed to be exact) and
displaying it inside a HTMLWindow. I have that part working - It shows
the title as a link and displays the description next to it. What I
want to do is trap the mouseclick on the link and use that to grab
just the text that is on the site. Right now, if I click on it, the
HTML window control takes me to the site and doesn't really show the
site very well, since it doesn't seem to do CSS. That's okay - I just
want to display the text How do I trap the mouse clicking on the
link?

I know that HTMLwindow has a "OnLinkClicked" event - I can see it in
the docs for that control. But it seems that Boa Constructor doesn't
expose that event in it's frame designer How do I code a event
that fires off instead of the default event?

I don't know if I am being clear enough, so if not just tell me what I
should say... Liek I said, I am a newbie right now.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Python with Ecmascript

2008-07-06 Thread [EMAIL PROTECTED]
On 6 Čec, 07:02, Tim Roberts <[EMAIL PROTECTED]> wrote:
> "[EMAIL PROTECTED]" <[EMAIL PROTECTED]> wrote:
>
> >for my Python application (Windows platform) to be standards
> >compliant, I need to embbed Ecmascript(Javascript) interpreter - I
> >need to execute plugins written in this language.
>
> What standard are you hoping to comply with?  I mean, what kind of a
> program is this?
> --
> Tim Roberts, [EMAIL PROTECTED]
> Providenza & Boekelheide, Inc.

Thats for our speech recognition server - it should executed "tags"
with Javascript code embbeded in some XML grammar format.

I personally does not like COM solution. I prefer some simple library
but may be it is just a hope. I will look to PyQT library and to
Mozilla scripting engine, but I think that this one can get
unnecessarily difficult.

Does anyone work or use something similar?

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


Re: Hands-on HTML Table Parser/Matrix?

2008-07-06 Thread robert

Tim Cook wrote:
 
On Sun, 2008-07-06 at 14:40 +0200, robert wrote:
Often I want to extract some web table contents. Formats are 
mostly static, simple text & numbers in it, other tags to be 
stripped off. So a simple & fast approach would be ok.


What of the different modules around is most easy to use, stable, 
up-to-date, iterator access or best matrix-access (without need 
for callback functions,classes.. for basic tasks)?



> There are couple of HTML examples using Pyparsing here:
>
> http://pyparsing.wikispaces.com/Examples
>
>

hm - nothing special with HTML tables.

Meanwhile:

I dislike "ClientTable" (file centric, too much parsing errors in 
real world).


"TableParse" works. Very simple&fast 70-liner regexp->matrix and 
strip/clean/HTML-entities conversion. Fast success hands-on. 
Doesn't separate nested tables and such complexities consciously - 
but works though for simple hands-on tasks in real world.



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


Re: Hands-on HTML Table Parser/Matrix?

2008-07-06 Thread Sebastian "lunar" Wiesner
robert <[EMAIL PROTECTED]>:

> Often I want to extract some web table contents. Formats are
> mostly static, simple text & numbers in it, other tags to be
> stripped off. So a simple & fast approach would be ok.
> 
> What of the different modules around is most easy to use, stable,
> up-to-date, iterator access or best matrix-access (without need
> for callback functions,classes.. for basic tasks)?

Not more than a handful of lines with lxml.html:

def htmltable2matrix(table):
"""Converts a html table to a matrix.

:param table:  The html table element
:type table:  An lxml element
"""
matrix = []
for row in table:
matrix.append([e.text_content() for e in row])
return matrix



-- 
Freedom is always the freedom of dissenters.
  (Rosa Luxemburg)
--
http://mail.python.org/mailman/listinfo/python-list


Re: Nested generator caveat

2008-07-06 Thread Mark Wooding
Dieter Maurer <[EMAIL PROTECTED]> wrote:

> I met the following surprising behaviour

[code moved until later...]

> The apparent reason is that the free variables in nested generator
> definitions are not bound (to a value) at invocation time but only at
> access time.

No.  This is about the difference between binding and assignment.
Unfortunately, Python doesn't have explicit syntax for doing the former.

Here's what's actually going on in your generator.

 def gen0():
> ...   for i in range(3):
> ... def gen1():
> ...   yield i
> ... yield i, gen1()

The function gen0 contains a yield statement; it's therefore a
generator.  It contains an assignment to a variable i (in this case,
it's implicit in the `for' loop).  So, on entry to the code, a fresh
location is allocated, and the variable i is bound to it.

The function gen1 contains a yield statement too, so it's also a
generator.  It contains a free reference to a variable i, so it shares
the binding in the outer scope.

Here's the important part: the for loop works by assigning to the
location named by i each time through.  It doesn't rebind i to a fresh
location.  So each time you kick gen1, it produces the current value of
i at that time.  So...

 for i,g in gen0(): print i, g.next()
> 0 0
> 1 1
> 2 2

Here, the for loop in gen0 is suspended each iteration while we do some
printing.  So the variable i (in gen0) still matches the value yielded
by gen0.

But...

 for i,g in list(gen0()): print i, g.next()
> 0 2
> 1 2
> 2 2

Here, gen0 has finished all of its iterations before we start kicking
any of the returned generators.  So the value of i in gen0 is 2 (the
last element of range(3)).

> Almost surely, the same applies to all locally defined functions
> with free variables.
> This would mean that locally defined functions with free
> variables are very risky in generators.

It means that you must be careful about the difference between binding
and assignment when dealing with closures of whatever kind.

Here's an example without involving nested generators.

def gen():
  for i in xrange(3):
yield lambda: i
for f in gen(): print f()
for f in list(gen()): print f()

To fix the problem, you need to arrange for something to actually rebind
a variable around your inner generator on each iteration through.  Since
Python doesn't have any mechanism for controlling variable binding other
than defining functions, that's what you'll have to do.

def genfix():
  for i in xrange(3):
def bind(i):
  def geninner():
yield i
  return geninner()
yield i, bind(i)

shows the general pattern, but since a generator has the syntactic form
of a function anyway, we can fold the two together.

def genfix2():
  for i in xrange(3):
def geninner(i):
  yield i
yield i, geninner(i)

Yes, this is cumbersome.  A `let' statement would help a lot.  Or
macros. ;-)

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


Re: re.search much slower then grep on some regular expressions

2008-07-06 Thread Mark Wooding
Sebastian "lunar" Wiesner <[EMAIL PROTECTED]> wrote:

> I just wanted to illustrate, that the speed of the given search is somehow
> related to the complexity of the engine.  
>
> Btw, other pcre implementation are as slow as Python or "grep -P".  I tried
> a sample C++-code using pcre++ (a wrapper around libpcre) and saw it
> running equally long.

So some other implementations are equally poor.  I note that Perl itself
handles this case very quickly, as does Edi Weitz's CL-PPCRE library.

Yes, Perl-compatible `regular expressions' are more complicated than
POSIX extended regular expressions; but that doesn't mean that you have
to implement them in a dumb way.  Indeed, it stands to reason that
expressions describing truly regular languages can be matched using the
same old algorithms that grep uses.

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


Problem with subprocess.Popen wget within a thread

2008-07-06 Thread Mathieu Prevot
Hi

it seems the script (A) finishes before the downloading ends, and the
(B) version doesn't (wanted behavior) ... this is unexpected. What
happens ?


(A) 
class vid(threading.Thread):
def __init__(self):
threading.Thread.__init__(self)
def download(self):
self.cmd = 'wget
ftp://ftp.freebsd.org/pub/FreeBSD/releases/i386/ISO-IMAGES/7.0/7.0-RELEASE-i386-bootonly.iso'
self.child = subprocess.Popen(self.cmd.split())
def run(self):
self.download()

def main():
w = vid()
w.start()
w.join()

(B) 
class vid(threading.Thread):
def __init__(self):
threading.Thread.__init__(self)
def download(self):
self.cmd = 'wget
ftp://ftp.freebsd.org/pub/FreeBSD/releases/i386/ISO-IMAGES/7.0/7.0-RELEASE-i386-bootonly.iso'
self.child = subprocess.Popen(self.cmd.split(), 
stderr=subprocess.PIPE)
def run(self):
self.download()
self.child.stderr.readlines()

def main():
w = vid()
w.start()
w.join()

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


Re: re.search much slower then grep on some regular expressions

2008-07-06 Thread Sebastian "lunar" Wiesner
Mark Wooding <[EMAIL PROTECTED]>:

> Sebastian "lunar" Wiesner <[EMAIL PROTECTED]> wrote:
> 
>> I just wanted to illustrate, that the speed of the given search is
>> somehow related to the complexity of the engine.
>>
>> Btw, other pcre implementation are as slow as Python or "grep -P".  I
>> tried a sample C++-code using pcre++ (a wrapper around libpcre) and saw
>> it running equally long.
> 
> So some other implementations are equally poor.  I note that Perl itself
> handles this case very quickly, as does Edi Weitz's CL-PPCRE library.

I don't know about the latter, but perl doesn't use any smart algorithm, it
just heavily relies on memoization to gain speed.

This makes perl perform poorly in other situations, as mentioned in the
paper cited by Mark Dickinson:

# perl -e '("a" x 10) =~ /^(ab?)*$/;'
zsh: segmentation fault  perl -e '("a" x 10) =~ /^(ab?)*$/;'

In Python on the other, this pattern works fine, at the cost of performance
losses on other patterns.

It'd be interesting to know, how CL-PPCRE performs here (I don't know this
library).

> Yes, Perl-compatible `regular expressions' are more complicated than
> POSIX extended regular expressions; but that doesn't mean that you have
> to implement them in a dumb way. Indeed, it stands to reason that
> expressions describing truly regular languages can be matched using the 
> same old algorithms that grep uses. 

I completely agree.  I'd just believe, that the combination of some finite
state machine for "classic" expressions with some backtracking code is
terribly hard to implement.  But I'm not an expert in this, probably some
libraries out there already do this.  In this case, it'd be time to give
pythons re engine a more sophisticated implementation ;)

-- 
Freedom is always the freedom of dissenters.
  (Rosa Luxemburg)
--
http://mail.python.org/mailman/listinfo/python-list


Re: Problem with subprocess.Popen wget within a thread

2008-07-06 Thread Sebastian "lunar" Wiesner
Mathieu Prevot <[EMAIL PROTECTED]>:

> it seems the script (A) finishes before the downloading ends, and the
> (B) version doesn't (wanted behavior) ... this is unexpected. What
> happens ?

"readlines" blocks, until the pipe is closed, which usually happens, if the
process dies.  

On the other hand, spawned processes are usually asynchronous, you have to
explicitly _wait_ for them.  And you're not waiting for it in example A.

Anyway, the _proper_ way to wait for a child process is ... guess what ...
the "wait" method of the Popen object ;)


-- 
Freedom is always the freedom of dissenters.
  (Rosa Luxemburg)
--
http://mail.python.org/mailman/listinfo/python-list


how are strings immutable in python?

2008-07-06 Thread ssecorp
>>> h = "aja baja"
>>> h += 'e'
>>> h
'aja bajae'
>>>

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


Re: how are strings immutable in python?

2008-07-06 Thread Peter Otten
ssecorp wrote:

 h = "aja baja"
 h += 'e'
 h
> 'aja bajae'


The inplace-add operator doesn't mutate the lvalue, it just rebinds it:

>>> a = b = "foo"
>>> id(a)
47643036142016
>>> a += "bar"
>>> id(a), a
(47643036142064, 'foobar')
>>> id(b), b
(47643036142016, 'foo')

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


Re: re.search much slower then grep on some regular expressions

2008-07-06 Thread Terry Reedy



Sebastian "lunar" Wiesner wrote:


I completely agree.  I'd just believe, that the combination of some finite
state machine for "classic" expressions with some backtracking code is
terribly hard to implement.  But I'm not an expert in this, probably some
libraries out there already do this.  In this case, it'd be time to give
pythons re engine a more sophisticated implementation ;)


One thing to remember in making comparisons is that Python moved to its 
own implementation to support unicode as well as extended ascii (bytes 
in 3.0).  Does grep do that?  Has pcre, which Python once used, been 
upgraded to do that?


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


Re: how are strings immutable in python?

2008-07-06 Thread Mel
ssecorp wrote:
 h = "aja baja"
 h += 'e'
 h
> 'aja bajae'

What Peter said, or, to put it another way:

Python 2.5.2 (r252:60911, Apr 21 2008, 11:12:42)
[GCC 4.2.3 (Ubuntu 4.2.3-2ubuntu7)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> a = b = "aja baja"
>>> a += "e"
>>> print a
aja bajae
>>> print b
aja baja

Mutability/immutability makes a difference in programs when different
symbols (or container items) share a value.


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


Re: how are strings immutable in python?

2008-07-06 Thread Terry Reedy



Peter Otten wrote:

ssecorp wrote:


h = "aja baja"
h += 'e'
h

'aja bajae'


The inplace-add operator doesn't mutate the lvalue, it just rebinds it:


In Python, neither '=' nor members of the 'op=' family are operators.
They all mark *assignment* or *augmented assignment* statements that 
*all* bind objects to targets.


Augmented assignments are, rather obviously, restricted to binding one 
object to one target.  For 'x op= y', if the object originally bound to 
x is mutable, the arithmetic operation part of the augmented assignment 
can (should) be implemented by an inplace __i__ special method 
that (normally, but not necessarily) mutates and returns self to be 
rebound.  Otherwise, the interpreter calls the normal  
special method  (if it exits) that returns a new object to be bound.


Thus, '+=' is neither an operator nor is the indicated operation 
necessarily inplace.


Immutable built-in classes do not have __i__ methods.  So given 
that name h is bound to a string,

  h += 'e'
has exactly the same effect as
  h = h + 'e'
which has exactly the same effect as
  h = h.__add__('e')
The same is true for immutable instances of other built-in classes.


Terry Jan Reedy

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


Re: how are strings immutable in python?

2008-07-06 Thread ssecorp
so if strings were mutable and i did
a = b = "foo"
and then did
a += "bar"
then a and b would be foobar?
--
http://mail.python.org/mailman/listinfo/python-list


interpretation of special characters in Python

2008-07-06 Thread TP
Hi everybody,

I am new to Python, I try to understand how Python treats special
characters. For example, if I execute the following line in a shell
console, I obtain a colored string:

$ python -c "print '\033[30;44m foo \033[0m'"

So, it works.
Some time ago, I have made a lot of shell variables with all possible colors
(with shell functions executed each time I launch a new shell). For
example:

$ echo -e $esc$ColorBlackOnDarkblue foo $esc$ColorReset

gives the same result than the python command above.
To know the corresponding non-interpreted characters, I can use the -n
option of echo:

$ echo -n $esc$ColorBlackOnDarkblue foo $esc$ColorReset
\033[30;44m foo \033[0m

So, it is exactly the string above, as expected.

My problem arises when it comes to get these shell variables ( $esc,
$ColorBlackOnDarkblue, $ColorReset) in a Python script, with os.environ, in
the following 5-line script:

import os
Color = os.environ['ColorBlackOnDarkblue']
ColorReset = os.environ['ColorReset']
Esc = os.environ['esc']
print '%s%s%s%s%s' % (Esc, Color, " foo ", Esc, ColorReset)

Run this script color.py, but after having defined these shell variables in
a shell:

$ export esc="\033"
$ export ColorBlackOnDarkblue="[30;44m"
$ export ColorReset="[0m"

When I execute the Python script, I do not obtain any special character
interpretation in Python:

$ python color.py
\033[30;44m foo \033[0m

Why? What is the problem? Is there any solution?
I really want to get my shell color variables.

Thanks a lot

-- 
TP (Tribulations Parallèles)

"Allez, Monsieur, allez, et la foi vous viendra." (D'Alembert).
--
http://mail.python.org/mailman/listinfo/python-list


Re: re.search much slower then grep on some regular expressions

2008-07-06 Thread Mark Wooding
Sebastian "lunar" Wiesner <[EMAIL PROTECTED]> wrote:

> # perl -e '("a" x 10) =~ /^(ab?)*$/;'
> zsh: segmentation fault  perl -e '("a" x 10) =~ /^(ab?)*$/;'

(Did you really run that as root?)

> It'd be interesting to know, how CL-PPCRE performs here (I don't know this
> library).

Stack overflow condition. :-(

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


Very weird bug!

2008-07-06 Thread ssecorp
I was looking into currying and

Python 2.5.2 (r252:60911, Feb 21 2008, 13:11:45) [MSC v.1310 32 bit
(Intel)] on win32
Type "copyright", "credits" or "license()" for more information.


Personal firewall software may warn about the connection IDLE
makes to its subprocess using this computer's internal loopback
interface.  This connection is not visible on any external
interface and no data is sent to or received from the Internet.


IDLE 1.2.2
>>> h = "aja baja"
>>> h += 'e'
>>> h
'aja bajae'
>>> h = h+'a'
>>> h
'aja bajaea'
>>> a = b = "foo"
>>> a
'foo'
>>> b
'foo'
>>> a==b
True
>>> id(a)
35018400
>>> id(b)
35018400
>>> a += "bar"
>>> id(a),a
(35110112, 'foobar')
>>> id(b),b
(35018400, 'foo')
>>> fac

Traceback (most recent call last):
  File "", line 1, in 
fac
NameError: name 'fac' is not defined
>>> factorial

Traceback (most recent call last):
  File "", line 1, in 
factorial
NameError: name 'factorial' is not defined
>>> import math
>>> math

>>> math.factorial

Traceback (most recent call last):
  File "", line 1, in 
math.factorial
AttributeError: 'module' object has no attribute 'factorial'
>>> math.fac

Traceback (most recent call last):
  File "", line 1, in 
math.fac
AttributeError: 'module' object has no attribute 'fac'
>>> dir(math)
['__doc__', '__name__', 'acos', 'asin', 'atan', 'atan2', 'ceil',
'cos', 'cosh', 'degrees', 'e', 'exp', 'fabs', 'floor', 'fmod',
'frexp', 'hypot', 'ldexp', 'log', 'log10', 'modf', 'pi', 'pow',
'radians', 'sin', 'sinh', 'sqrt', 'tan', 'tanh']
>>> pow

>>> tan

Traceback (most recent call last):
  File "", line 1, in 
tan
NameError: name 'tan' is not defined
>>> math.tan

>>> def build(a,b):
return a+b

>>> build(5,4)
(5, 4)
>>> def build(x,y):
a=x+y
return a

>>> build(5,4)
9
>>> def b(n, p):
return n + p

>>> b(1, 10)
11
>>> def b(n,p):
return n+p

>>> b(5,2)
7
>>> def build(x,y):
return a+b

>>> build(5,4)

Traceback (most recent call last):
  File "", line 1, in 
build(5,4)
  File "", line 2, in build
return a+b
TypeError: cannot concatenate 'str' and 'function' objects
>>> def build(x,y):
yreturn x+

SyntaxError: invalid syntax
>>> def build(x,y):
return x+y

>>> build(5,4)
9
>>> def build(a,b):
return a+b

>>> build(5,4)
9
>>>




wtf was this in the middle!?

>>> def build(a,b):
return a+b

>>> build(5,4)
(5, 4)
--
http://mail.python.org/mailman/listinfo/python-list


Re: how are strings immutable in python?

2008-07-06 Thread Mark Tolonen


"ssecorp" <[EMAIL PROTECTED]> wrote in message 
news:[EMAIL PROTECTED]

so if strings were mutable and i did
a = b = "foo"
and then did
a += "bar"
then a and b would be foobar?


This can be demonstrated with a list of characters, which *is* mutable:


a = b = list('foo')
a += list('bar')
a

['f', 'o', 'o', 'b', 'a', 'r']

b

['f', 'o', 'o', 'b', 'a', 'r']

--Mark

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


Re: pythoncom InternetExplorer.Application don't work in vista || firefox pythoncom ?

2008-07-06 Thread M�ta-MCI (MVP)

H...  I have a similary problem, in another circumstances.
It's often a problem of configuration of IE (for news customers).  But, 
it is not easy, because IE has many parameters.


Good luck!

Michel Claveau

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


Re: how are strings immutable in python?

2008-07-06 Thread ssecorp
so why would you ever want mutability?


seems very counterintuitive and unreliable.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Using poplib to parse headers - Thank You All!

2008-07-06 Thread Jean-Claude Neveu

Tim Roberts wrote:

You've received some very confusing advice in this thread.  Alex had the
right answer, but I want to expand it a bit.

[...]

poplib.retr gives you a string.  You need to hand that string to the email
module, and you do that using "email.message_from_string".


This is just to thank Tim, Alex, and everyone who posted for their 
help in getting this to work. It's been more than a month since you 
answered my question and I've been having to focus on other things. 
Last week, I finally got back to this task and your answers helped me 
get it working.


To save time for future people who might have the same question, I'm 
posting a basic script for reading mail from a POP server and passing 
the email message to the Python email library for parsing. I'm new to 
Python (but experienced in other languages) so please feel free to 
tell me if any of my syntax is clumsy, or if I did something the 
difficult way when Python has an easier or more efficient way to do 
it. I hope this will be useful for the archives.


#
import getpass, poplib, email

# Set up the connection to the POP server
popconnection = poplib.POP3('mail.blah.com')
popconnection.user('user-name-goes-here')
popconnection.pass_('password-goes-here')

# Find out how many messages are waiting
numMessages = len(popconnection.list()[1])

# Iterate through the messages
for i in range(numMessages):

# retr will be called three times for each email message in the j loop below.
#
# The first call will return a string telling you how many bytes (i.e., octets)
# are in the message. The string will look like this: OK  octets
# (where  is the total number of bytes in the message).
#
# The second call will return a list containing the elements of the message.
#
# The third call will return an integer containing the total number of
# bytes in the message

for j in popconnection.retr(i+1):

# We are interested only in the contents of the list. And we need to put the
# list contents into a string, because that is what 
message_from_string expects.

# We must also be sure to put a line break at the end of the substring that
# represents each list element, as message_from_string relies on line breaks
# to parse the email message. The k loop below builds the string from the list.
if type(j) == list:
numElements = len(j)
outString = ""
   for k in range(numElements):
outString += j[k]
outString += '\n'
message = email.message_from_string(outString)

# Now that we have got the contents of the email into an email object, we can
# access the logical elements of the email at will, in any order. The call to
# get_payload() is to retrieve the body of the message.
print message['Subject']
print message['From']
print message.get_payload()

# Strictly speaking, all we need to do on quitting is to disconnect, 
but in some

# applications it would be a good idea to delete the email from the server.
popconnection.quit()



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


RE: how are strings immutable in python?

2008-07-06 Thread Delaney, Timothy (Tim)
ssecorp wrote:

> so why would you ever want mutability?
> 
> 
> seems very counterintuitive and unreliable.

Because immutability imposes a lot of restrictions and performance
characteristics that mutable objects don't have. For example, compare
building up a list and a tuple element-by-element (using the most
appropriate methods for each):

a = []
b = ()

for i in range(10):
a.append(i)
b += (i,)

The list can simply grow its memory space and assign the new element.
OTOH, we need to create two new tuples each time (the one containing the
new element, and the one which is a concatenation of the old elements
plus the new element). The old tuple and the temporary tuple then get
thrown away.

Even if you optimise away the temporary 1-tuple (which python doesn't)
the need to allocate a new tuple every time and copy the old elements to
it results in much worse time and memory usage.

There are optimisations that can be done if the compiler/runtime system
can determine that there is only one reference to the immutable object
(python now does this in some cases for string concatenation), but in
general you cannot rely on this and have to assume that the worst case
applies.

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


ANN: python-ldap-2.3.5

2008-07-06 Thread Michael Ströder

Find a new release of python-ldap:

  http://python-ldap.sourceforge.net/

python-ldap provides an object-oriented API to access LDAP directory
servers from Python programs. It mainly wraps the OpenLDAP 2.x libs for
that purpose. Additionally it contains modules for other LDAP-related
stuff (e.g. processing LDIF, LDAPURLs and LDAPv3 schema).


Released 2.3.5 2008-07-06

Changes since 2.3.4:

Lib/
* Fixed methods ldap.cidict.__contains__() and
  ldap.schema.models.Entry.__contains__()
* FWIW method LDAPObject.cancel_s() returns a result now
* Fixed ldap.schema.models.NameForm: Class attribute oc is now
  of type string, not tuple to be compliant with RFC 4512
--
http://mail.python.org/mailman/listinfo/python-list


mirroring files and data via http

2008-07-06 Thread Steve Potter
I'm working on a project to create a central administration interface
for several websites located on different physical servers.

You can think of the websites as a blog type application. My
administration application will be used to create new blog posts with
associated media (images, etc..)

So I am thinking to setting up a script on each of the sites to "phone
home" once per day and download any new posts and media files.

I am thinking of transmitting the post data in an xml format that
could then be decoded an recorded into the database on the slave
site.   Are there any easy ways to encode a python dictionary to and
from xml?

For the media files I am thinking that the administration interface
would also provide an xml file with a list of all of the media files
required along with an http path to retrieve them and a checksum of
some sort to verify that they were downloaded correctly.

Basically I am trying to figure out if anything already exists to
perform some of these functions or if I have to make them from
scratch.  I know none of it should be too hard, but I hate to re-
invent the wheel.

Thanks,

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


Re: mirroring files and data via http

2008-07-06 Thread Matt Nordhoff
Steve Potter wrote:
> I'm working on a project to create a central administration interface
> for several websites located on different physical servers.
> 
> You can think of the websites as a blog type application. My
> administration application will be used to create new blog posts with
> associated media (images, etc..)
> 
> So I am thinking to setting up a script on each of the sites to "phone
> home" once per day and download any new posts and media files.
> 
> I am thinking of transmitting the post data in an xml format that
> could then be decoded an recorded into the database on the slave
> site.   Are there any easy ways to encode a python dictionary to and
> from xml?
> 
> For the media files I am thinking that the administration interface
> would also provide an xml file with a list of all of the media files
> required along with an http path to retrieve them and a checksum of
> some sort to verify that they were downloaded correctly.
> 
> Basically I am trying to figure out if anything already exists to
> perform some of these functions or if I have to make them from
> scratch.  I know none of it should be too hard, but I hate to re-
> invent the wheel.
> 
> Thanks,
> 
> Steven Potter

It sounds like JSON would be perfect for this. For working with it in
Python, the simplejson module is popular:


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


GUI Programming by hand not code with Python Code

2008-07-06 Thread jayjaygibbs
Is their a program that lets you design a GUI by hand (like gambas)
not by code (like wxpython) but the commands are in python?

A program similar to gambas or vb

Gambas with python code instead of gambas code would be perfect.

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


can't start IDLE 2.6 in Windows Vista

2008-07-06 Thread Mensanator
Python 2.6b1 installed ok on my XP laptop but not my Vista desktop.

First I got a strange application log error:

Activation context generation failed for
"C:\Python\Dlls\_socket.pyd".
Error in manifest or policy file
"C:\Python26\DLLs\Microsoft.VC90.CRT.MANIFEST"
on line 12. The value
"..\msvcr90.dll"
of attribute "name" in element
"urn:schemas-microsoft-com:asm.v1^file" is invalid.

Oddly, It IS valid. Poking around, I changed the name in the
manifest from "..\msvcr90.dll" to "msvcr90.dll" and copied
the .dll from the parent directory.

This stopped the app;ication error log messages.

In Googling around, I found the suggestion to do

python lib\idlelib\idle.py -n

which gives me this error:

Traceback (most recent call last):
  File "lib\idlelib\idle.py", line 21, in 
idlelib.PyShell.main()
  File "C:\Python26\lib\idlelib\PyShell.py", line 1382, in main
root = Tk(className="Idle")
  File "C:\Python26\lib\lib-tk\Tkinter.py", line 1647, in __init__
self.tk = _tkinter.create(screenName, baseName, className,
interactive, wantobjects, useTk, sync, use)
_tkinter.TclError: Can't find a usable init.tcl in the following
directories:
C:/Python26/lib/tcl8.5 C:/lib/tcl8.5 C:/lib/tcl8.5 C:/library C:/
library C:/tcl8.5.2/library C:/tcl8.5.2/library

And, just like the previous error, the file DOES exist

 Directory of C:\Python26\tcl\tcl8.5

06/12/2008  06:07 PM24,808 init.tcl

But I note that the suggested places it looked have a forward slash
instead
of a the backward slash used by Windows. Is this why the file can't be
found?
I would try changing it but can't figure out where to look.
--
http://mail.python.org/mailman/listinfo/python-list


Re: GUI Programming by hand not code with Python Code

2008-07-06 Thread Jason Scheirer
On Jul 6, 7:33 pm, [EMAIL PROTECTED] wrote:
> Is their a program that lets you design a GUI by hand (like gambas)
> not by code (like wxpython) but the commands are in python?
>
> A program similar to gambas or vb
>
> Gambas with python code instead of gambas code would be perfect.
>
> Thanks in advance

Glade for GTK, wxGlade for wxPython.
--
http://mail.python.org/mailman/listinfo/python-list


Re: GUI Programming by hand not code with Python Code

2008-07-06 Thread Victor Noagbodji
> Is their a program that lets you design a GUI by hand (like gambas)
> not by code (like wxpython) but the commands are in python?
>
> A program similar to gambas or vb
>
> Gambas with python code instead of gambas code would be perfect.
>
> Thanks in advance

Check out the Designer program that comes with PyQt.

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


Re: mirroring files and data via http

2008-07-06 Thread Steve Potter
On Jul 6, 8:19 pm, Matt Nordhoff <[EMAIL PROTECTED]> wrote:
> Steve Potter wrote:
> > I'm working on a project to create a central administration interface
> > for several websites located on different physical servers.
>
> > You can think of the websites as a blog type application. My
> > administration application will be used to create new blog posts with
> > associated media (images, etc..)
>
> > So I am thinking to setting up a script on each of the sites to "phone
> > home" once per day and download any new posts and media files.
>
> > I am thinking of transmitting the post data in an xml format that
> > could then be decoded an recorded into the database on the slave
> > site.   Are there any easy ways to encode a python dictionary to and
> > from xml?
>
> > For the media files I am thinking that the administration interface
> > would also provide an xml file with a list of all of the media files
> > required along with an http path to retrieve them and a checksum of
> > some sort to verify that they were downloaded correctly.
>
> > Basically I am trying to figure out if anything already exists to
> > perform some of these functions or if I have to make them from
> > scratch.  I know none of it should be too hard, but I hate to re-
> > invent the wheel.
>
> > Thanks,
>
> > Steven Potter
>
> It sounds like JSON would be perfect for this. For working with it in
> Python, the simplejson module is popular:
>
> 
> --

Matt,

You are correct JSON would be much easier to deal with than xml.  That
takes care of several of the problems.

Now it really just comes down to the file transfer from one server to
the other and a verification of some sort that the file transfer was
not corrupt.  Is there a python module that takes care of file
downloads and verification?

Thanks,

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


Re: interpretation of special characters in Python

2008-07-06 Thread Peter Pearson
On Sun, 06 Jul 2008 23:42:26 +0200, TP <[EMAIL PROTECTED]> wrote:
>
> $ python -c "print '\033[30;44m foo \033[0m'"
[writes an escape sequence to stdout]

> $ echo -e $esc$ColorBlackOnDarkblue foo $esc$ColorReset
[also writes an escape sequence to stdout]

> $ echo -n $esc$ColorBlackOnDarkblue foo $esc$ColorReset
> \033[30;44m foo \033[0m

[snip, shuffle]
> $ export esc="\033"
> $ export ColorBlackOnDarkblue="[30;44m"
> $ export ColorReset="[0m"
>
> import os
> Color = os.environ['ColorBlackOnDarkblue']
> ColorReset = os.environ['ColorReset']
> Esc = os.environ['esc']
> print '%s%s%s%s%s' % (Esc, Color, " foo ", Esc, ColorReset)
[snip]
> $ python color.py
> \033[30;44m foo \033[0m

The string "\033" is 4 characters long. Your shell variable
"esc" is 4 characters long.  Your Python program prints
those four characters.  You want it to re-interpret those 4
characters into a single escape character.

One of this group's regular participants can (I hope) tell
us three breathtakingly elegant ways to do that.  I'm sorry
I can't.

When you run echo, it recognizes the 4-character "esc" as a
convention for representing a single character, and performs
the re-interpretation for you.  When you tell python
"print '\033[30;44m foo \033[0m'", python interprets
the "\033" as a single character.

-- 
To email me, substitute nowhere->spamcop, invalid->net.
--
http://mail.python.org/mailman/listinfo/python-list


VNC capture in python

2008-07-06 Thread Astan Chee

Hi,
I was wondering if I can do a capture of a VNC screen in python. Kinda 
like this http://search.cpan.org/~lbrocard/Net-VNC-0.35/lib/Net/VNC.pm

but without opening a VNC window or doing a screen capture.
Thanks for any suggestions

--
"Formulations of number theory: Complete, Consistent, Non-trivial. Choose two."


Animal Logic
http://www.animallogic.com

Please think of the environment before printing this email.

This email and any attachments may be confidential and/or privileged. If you 
are not the intended recipient of this email, you must not disclose or use the 
information contained in it. Please notify the sender immediately and delete 
this document if you have received it in error. We do not guarantee this email 
is error or virus free.



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


Re: how are strings immutable in python?

2008-07-06 Thread Martin v. Löwis
> so why would you ever want mutability?
> 
> 
> seems very counterintuitive and unreliable.

For lists, mutability is fairly natural.

Suppose you have a function f that copies
some items from one list to another. You write it
as

def f(src, dst):
for x in src:
if condition(x):
dst.append(x)

If dst was immutable, an .append method could not
be defined (since it modifies the list itself), so
you would have to write

dst = dst + [x]

However, that would only modify the local variable
dst in the function f - the parameter of the caller
of f would not get modified.

The same holds for many other operations on lists.
You can pass very complex data structures around
(lists of lists of dictionaries etc), and have functions
modify the lists, rather than creating new ones.

For example, to change a two-dimensional matrix
(which is a list of lists), you can write

   M[10][11] = 3.14

whereas with immutable lists, you would have to write

   M_10_new = M[10][:11] + [3.14] + [M10][12:]
   M = M[:10] + [M_10_new] + M[11:]

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


Re: interpretation of special characters in Python

2008-07-06 Thread TP
Dennis Lee Bieber wrote:

> Off-hand, I'd probably try first with:
> 
> csi = "\033["
> 
> and then define your
> 
> colorblackondarkblue = $csi"30;44m"

Thanks for your answer.
I have tried this slight modification, but it does not change anything on my
terminal.


-- 
TP (Tribulations Parallèles)

"Allez, Monsieur, allez, et la foi vous viendra." (D'Alembert).
--
http://mail.python.org/mailman/listinfo/python-list


Re: interpretation of special characters in Python

2008-07-06 Thread TP
Peter Pearson wrote:

Thanks for your answer.

> When you run echo, it recognizes the 4-character "esc" as a
> convention for representing a single character, and performs
> the re-interpretation for you.  When you tell python
> "print '\033[30;44m foo \033[0m'", python interprets
> the "\033" as a single character.

So, the python print command *can* interpret these 4-character as a single
character. It would be odd if there were no possibility to do the same
thing when the characters are (i) stored in a python variable, or (ii) come
from the environment variables. Does anybody know any way to re-interpret a
string in Python? I have tried to play with "eval" (as in bash), but it
does not yield anything.

-- 
TP (Tribulations Parallèles)

"Allez, Monsieur, allez, et la foi vous viendra." (D'Alembert).
--
http://mail.python.org/mailman/listinfo/python-list


Re: Very weird bug!

2008-07-06 Thread Terry Reedy

ssecorp wrote:

Python 2.5.2 (r252:60911, Feb 21 2008, 13:11:45) [MSC v.1310 32 bit
wtf was this in the middle!?


def build(a,b):

return a+b


build(5,4)

(5, 4)


I have exactly the same build on Windows and get the expected 9.

Try it again.

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


extended setattr()

2008-07-06 Thread Rotlaus
2 weeks ago i asked for a etended getattr() which worked really fine,
but now i would love to have a extended setattr() as well.

Lets assume i have some classes:

class A(object):
def __init__(self):
self.B = B()

class B(object):
def __init__(self):
self.C = C()

class C(object):
def __init__(self, foo='', bar=''):
self.foo = foo
self.bar = bar

and now i wanna do something like this:

a=A()
ext_setattr(a, 'B.C', ('a', 'b'))

Is this possible? It would also be nice if the attributes would be
created if they not exist, always implying that
objectname==objecttype.

Kind regards,

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


Re: Nested generator caveat

2008-07-06 Thread marek . rocki
Excellent explanation by Mark Wooding. I would only like to add that
the standard pythonic idiom in such cases seems to be the (ab)use of a
default argument to the function, because these get evaluated at the
definition time:
def gen0():
for i in range(3):
def gen1(i = i):
yield i
yield i, gen1()
--
http://mail.python.org/mailman/listinfo/python-list


error in SimpleXMLRPCServer

2008-07-06 Thread vaibhav pol
hi,
   I create a SimpleXMLRPCServer script which execute the command on server
and return the result.
 code is below



accessList=(
   'test.org'
)




class Server(SimpleXMLRPCServer.SimpleXMLRPCServer):
def __init__(self,*args):

SimpleXMLRPCServer.SimpleXMLRPCServer.__init__(self,(args[0],args[1]))

def server_bind(self):
self.socket.setsockopt(socket.SOL_SOCKET,
socket.SO_REUSEADDR, 1)
SimpleXMLRPCServer.SimpleXMLRPCServer.server_bind(self)


def verify_request(self,request, client_address):
if client_address[0] in accessList:
return 1
else:
return 0

class xmlrpc_registers:
def __init__(self):
self.python_string = string

def clientfun(self,argument):
try:
   cmd = argument
   (stdin,stdout,stderr)=popen3(cmd)
   stdin.close()
   value2=stdout.read()
   value3=stderr.read()
   stdout.close()
   stderr.close()
   output = {"stdout":value2,"stderr": value3}
   return output


if __name__ == "__main__":
if (len(sys.argv) == 3):
try :
servername=sys.argv[1]
portnumber=int(sys.argv[2])
server = Server(servername,portnumber)
server.register_instance(xmlrpc_registers())
server.serve_forever()
except Exception,e:
print "Root service  is shutting down .."
print str(e)
else:
   print "Please provide <\"hostname or ip\"> <\"portnumber\">"


this server side code i run in background using nohup
from client when i  call function it execute fine but after some time when i
call it gives following error




and server program killed.



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

Validation in plone

2008-07-06 Thread Sallu
Hi all and one,
How to do server side validation in plone? please help me its very
urgent. i created a validator.py file where i wrote a script for
'special character are not allowed' and calling that script in
movie.py its working fine by validators = ('splcharvalid',), and when
i wrote another script for email validation and want to call in same
field like
validators = ('emailvalid',), and i am calling like this
validators = ('splcharvalid',),('emailvalid',), but its not working
even i wrote like this too
validators = ('splcharvalid','emailvalid',),  but its too not
working.. could you please help mr to resolve this problem or may tell
me another way to do validation in plone..

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


Re: Python with Ecmascript

2008-07-06 Thread alex23
On Jul 7, 12:31 am, "[EMAIL PROTECTED]"
<[EMAIL PROTECTED]> wrote:
> I personally does not like COM solution. I prefer some simple library
> but may be it is just a hope.

Have you looked at the module 'python-spidermonkey'? It apparently
"allows for the implementation of Javascript classes, objects and
functions in Python, as well as the evaluation and calling of
Javascript scripts and functions".

http://code.google.com/p/python-spidermonkey/
--
http://mail.python.org/mailman/listinfo/python-list