cannot execute binary file (Python 3.0.1)

2009-03-01 Thread cf29
Greetings,
On Mac OS 10.5.6, I updated Python to version 3.0.1.
When I want to run a py file, I get an error:
xxx:~ xxx$ cd '/Users/xxx/Documents/programmingPractice/' && '/usr/
local/bin/python'  '/Users/xxx/Documents/programmingPractice/
python_file.py'  && echo Exit status: $? && exit 1
-bash: /usr/local/bin/python: cannot execute binary file

This wasn't an issue with Python 2.6, please let me know how to solve
this problem.
Best regards
Charly
--
http://mail.python.org/mailman/listinfo/python-list


Re: cannot execute binary file (Python 3.0.1)

2009-03-01 Thread Chris Rebert
On Sun, Mar 1, 2009 at 12:04 AM, cf29  wrote:
> Greetings,
> On Mac OS 10.5.6, I updated Python to version 3.0.1.
> When I want to run a py file, I get an error:
> xxx:~ xxx$ cd '/Users/xxx/Documents/programmingPractice/' && '/usr/
> local/bin/python'  '/Users/xxx/Documents/programmingPractice/
> python_file.py'  && echo Exit status: $? && exit 1
> -bash: /usr/local/bin/python: cannot execute binary file
>
> This wasn't an issue with Python 2.6, please let me know how to solve
> this problem.

Detailing exactly how you upgraded Python would help immensely.

Cheers,
Chris

-- 
Follow the path of the Iguana...
http://rebertia.com
--
http://mail.python.org/mailman/listinfo/python-list


Re: ANN: updates to Python-by-example

2009-03-01 Thread Banibrata Dutta
very useful for an off-and-on, foo-bar programmer! i'm sure it'd have
something of value to more experienced programmers as well.

On Fri, Feb 27, 2009 at 7:27 PM, Rainy  wrote:

> Python-by-example http://pbe.lightbird.net/index.html";>http://
> pbe.lightbird.net has some new modules added: pickle, shelve,
> sqlite3, gzip, csv, configparser, optparse, logging. I also changed
> over to using excellent sphinx package to generate documentation, this
> will allow me to add pdf and windows help formats soon (I ran into
> some issues with that, actually). More modules coming soon, too! -AK
> --
> http://mail.python.org/mailman/listinfo/python-list
>



-- 
regards,
Banibrata
http://www.linkedin.com/in/bdutta
--
http://mail.python.org/mailman/listinfo/python-list


Re: cannot execute binary file (Python 3.0.1)

2009-03-01 Thread cf29
On Mar 1, 11:14 am, Chris Rebert  wrote:
> Detailing exactly how you upgraded Python would help immensely.
>
> Cheers,
> Chris

Thanks for your answer.
I installed the package in python-3.0.1-macosx2009-02-14.dmg
(downloaded from http://www.python.org/download/releases/3.0.1/) and
runed the Update Shell Profile.command situated in the Python 3.0
folder.

If I type python in the Terminal, it says: Python 3.0.1 (r301:69597,
Feb 14 2009, 19:03:52). So it seems that it is working properly.
If I use the Terminal and type: python myfile.py, it works as
expected.
The issue is when I want to run py file either with Python
Launcher.app or directly from BBEdit (the text editor i use). I get
the "cannot execute binary file" error.

In /usr/local/bin/ the python symbolic link is connected to Python v3

Charly http://cf29.com/
--
http://mail.python.org/mailman/listinfo/python-list


Re: file locking...

2009-03-01 Thread Nigel Rantor

bruce wrote:

Hi.

Got a bit of a question/issue that I'm trying to resolve. I'm asking
this of a few groups so bear with me.

I'm considering a situation where I have multiple processes running,
and each process is going to access a number of files in a dir. Each
process accesses a unique group of files, and then writes the group
of files to another dir. I can easily handle this by using a form of
locking, where I have the processes lock/read a file and only access
the group of files in the dir based on the  open/free status of the
lockfile.

However, the issue with the approach is that it's somewhat
synchronous. I'm looking for something that might be more
asynchronous/parallel, in that I'd like to have multiple processes
each access a unique group of files from the given dir as fast as
possible.


I don't see how this is synchronous if you have a lock per file. Perhaps 
you've missed something out of your description of your problem.



So.. Any thoughts/pointers/comments would be greatly appreciated. Any
 pointers to academic research, etc.. would be useful.


I'm not sure you need academic papers here.

One trivial solution to this problem is to have a single process 
determine the complete set of files that require processing then fork 
off children, each with a different set of files to process.


The parent then just waits for them to finish and does any 
post-processing required.


A more concrete problem statement may of course change the solution...

  n

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


Re: file locking...

2009-03-01 Thread koranthala
On Mar 1, 2:28 pm, Nigel Rantor  wrote:
> bruce wrote:
> > Hi.
>
> > Got a bit of a question/issue that I'm trying to resolve. I'm asking
> > this of a few groups so bear with me.
>
> > I'm considering a situation where I have multiple processes running,
> > and each process is going to access a number of files in a dir. Each
> > process accesses a unique group of files, and then writes the group
> > of files to another dir. I can easily handle this by using a form of
> > locking, where I have the processes lock/read a file and only access
> > the group of files in the dir based on the  open/free status of the
> > lockfile.
>
> > However, the issue with the approach is that it's somewhat
> > synchronous. I'm looking for something that might be more
> > asynchronous/parallel, in that I'd like to have multiple processes
> > each access a unique group of files from the given dir as fast as
> > possible.
>
> I don't see how this is synchronous if you have a lock per file. Perhaps
> you've missed something out of your description of your problem.
>
> > So.. Any thoughts/pointers/comments would be greatly appreciated. Any
> >  pointers to academic research, etc.. would be useful.
>
> I'm not sure you need academic papers here.
>
> One trivial solution to this problem is to have a single process
> determine the complete set of files that require processing then fork
> off children, each with a different set of files to process.
>
> The parent then just waits for them to finish and does any
> post-processing required.
>
> A more concrete problem statement may of course change the solution...
>
>    n

Using twisted might also be helpful.
Then you can avoid the problems associated with threading too.
--
http://mail.python.org/mailman/listinfo/python-list


Re: cannot execute binary file (Python 3.0.1)

2009-03-01 Thread Ned Deily
In article 
,
 cf29  wrote:
> On Mac OS 10.5.6, I updated Python to version 3.0.1.
> When I want to run a py file, I get an error:
> xxx:~ xxx$ cd '/Users/xxx/Documents/programmingPractice/' && '/usr/
> local/bin/python'  '/Users/xxx/Documents/programmingPractice/
> python_file.py'  && echo Exit status: $? && exit 1
> -bash: /usr/local/bin/python: cannot execute binary file
> 
> This wasn't an issue with Python 2.6, please let me know how to solve
> this problem.

It appears you are trying to run a python script by double-clicking on 
it and that Python Launcher.app is the default application associated 
with .py files.  The default setting in Python Launcher is to use the 
python linked to /use/local/bin/pythonw.  By default, the OS X 3.0.1 
installer does not install or modify the links in /usr/local/bin/, 
unlike 2.x installers.  That is a problem for Python Launcher.  Here are 
a few options, assuming you used the 3.0.1 python.org installer:

1. You can start up the installer again, choose Customize, and then 
select and install the "UNIX command-line tools" package.  
/usr/local/bin/pythonw will now point out at python 3.0.1 rather than 
python 2.6.

2. Launch Python Launcher and change its Preferences.  Python Launcher 
should be in the /Applications/Python 3.0 folder.  Select Preferences 
and in the Interpreter field enter the full path to python3.0, which is:
/Library/Frameworks/Python.framework/Versions/3.0/bin/python3.0

3. Use IDLE instead of Python Launcher to run scripts.  Just launch IDLE 
(it's also in /Applications/Python 3.0) and open the script file from 
IDLE's menu bar.  Or drag-drop the script onto the IDLE icon in the 
Dock.  If you want to be able to double-click on the file in the Finder, 
you'll need to change the default application associated with .py files.  
In a Finder window or the desktop select your python script file but 
don't double-click it.  Instead, choose the FInder's "Get Info" command 
and in the resulting Info window choose IDLE 3.0.1 in the "Open with" 
list.  To open all .py files with IDLE, if necessary click on the 
padlock in the lower right-hand corner of the Info window to 
authenticate, then click on the Change All.. button.

4. Run your scripts in a terminal window using python3.0 from the shell 
command line.  You can use the above path to execute python; it might 
help to create a shell alias for it.  Or double-click on the Update 
Shell Profile command in /Applications/Python 3.0 to cause python3.0 to 
be added to your shell PATH and then just type python3.0.

I would recommend either (or both) of the last two approaches.  You'll 
be better off avoiding Python Launcher.

-- 
 Ned Deily,
 n...@acm.org

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


Re: file locking...

2009-03-01 Thread Nigel Rantor

koranthala wrote:

On Mar 1, 2:28 pm, Nigel Rantor  wrote:

bruce wrote:

Hi.
Got a bit of a question/issue that I'm trying to resolve. I'm asking
this of a few groups so bear with me.
I'm considering a situation where I have multiple processes running,
and each process is going to access a number of files in a dir. Each
process accesses a unique group of files, and then writes the group
of files to another dir. I can easily handle this by using a form of
locking, where I have the processes lock/read a file and only access
the group of files in the dir based on the  open/free status of the
lockfile.
However, the issue with the approach is that it's somewhat
synchronous. I'm looking for something that might be more
asynchronous/parallel, in that I'd like to have multiple processes
each access a unique group of files from the given dir as fast as
possible.

I don't see how this is synchronous if you have a lock per file. Perhaps
you've missed something out of your description of your problem.


So.. Any thoughts/pointers/comments would be greatly appreciated. Any
 pointers to academic research, etc.. would be useful.

I'm not sure you need academic papers here.

One trivial solution to this problem is to have a single process
determine the complete set of files that require processing then fork
off children, each with a different set of files to process.

The parent then just waits for them to finish and does any
post-processing required.

A more concrete problem statement may of course change the solution...

   n


Using twisted might also be helpful.
Then you can avoid the problems associated with threading too.


No one mentioned threads.

I can't see how Twisted in this instance isn't like using a sledgehammer 
to crack a nut.


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


Re: cannot execute binary file (Python 3.0.1)

2009-03-01 Thread cf29
On Mar 1, 12:52 pm, Ned Deily  wrote:
> It appears you are trying to run a python script by double-clicking on
> it and that Python Launcher.app is the default application associated
> with .py files.  The default setting in Python Launcher is to use the
> python linked to /use/local/bin/pythonw.  By default, the OS X 3.0.1
> installer does not install or modify the links in /usr/local/bin/,
> unlike 2.x installers.  That is a problem for Python Launcher.  Here are
> a few options, assuming you used the 3.0.1 python.org installer:
>
> 1. You can start up the installer again, choose Customize, and then
> select and install the "UNIX command-line tools" package.  
> /usr/local/bin/pythonw will now point out at python 3.0.1 rather than
> python 2.6.
>
> --
>  Ned Deily,
>  n...@acm.org


Thank you Ned! The 1. did the trick.
Actually I was using the open menu of Python Launcher to open my
files. And now it works fine.
Usually I use to run python scripts from BBEdit itself and this is now
working as expected.
What a great place to find answers! Thanks again.
Charly
http://cf29.com/
--
http://mail.python.org/mailman/listinfo/python-list


Re: PIL's thumbnail function returns NoneType

2009-03-01 Thread Hrvoje Niksic
Mirat Can Bayrak  writes:

> Can you try it? it is about me or it is a bug?

Neither.  im.thumbnail() modifies the existing image object by
converting it to a thumbnail.  In Python such methods by convention
return None.

The documentation explicitly mentions that:

Also note that this function modifies the Image object in
place. If you need to use the full resolution image as well, apply
this method to a copy of the original image. This method returns
None.

> In [4]: thm = im.thumbnail((200,200))
>
> In [5]: type(thm)
> Out[5]: 

Instead of thm, simply keep using ihm.
--
http://mail.python.org/mailman/listinfo/python-list


PIL's thumbnail function returns NoneType

2009-03-01 Thread Mirat Can Bayrak
Can you try it? it is about me or it is a bug?

In [1]: import Image

In [2]: im = Image.open("r.png")

In [3]: type(im)
Out[3]: 

In [4]: thm = im.thumbnail((200,200))

In [5]: type(thm)
Out[5]: 


-- 
Mirat Can Bayrak 
--
http://mail.python.org/mailman/listinfo/python-list


Performance of Python 3

2009-03-01 Thread Kless
Does anybody has seen the performance of Python 3?
Respect to speed it's the last language together to Ruby 1.8, but Ruby
1.9 has a lot of better performance. :(


http://shootout.alioth.debian.org/u32q/benchmark.php?test=all&lang=all
--
http://mail.python.org/mailman/listinfo/python-list


Re: Performance of Python 3

2009-03-01 Thread Akira Kitada
Is this what you are looking for?
http://shootout.alioth.debian.org/u32q/benchmark.php?test=all&lang=python3&lang2=yarv&box=1


On Sun, Mar 1, 2009 at 10:04 PM, Kless  wrote:
> Does anybody has seen the performance of Python 3?
> Respect to speed it's the last language together to Ruby 1.8, but Ruby
> 1.9 has a lot of better performance. :(
>
>
> http://shootout.alioth.debian.org/u32q/benchmark.php?test=all&lang=all
> --
> http://mail.python.org/mailman/listinfo/python-list
>
--
http://mail.python.org/mailman/listinfo/python-list


Re: Performance of Python 3

2009-03-01 Thread Christian Heimes
Kless schrieb:
> Does anybody has seen the performance of Python 3?
> Respect to speed it's the last language together to Ruby 1.8, but Ruby
> 1.9 has a lot of better performance. :(

Python 3.0 is slower than Python 2.5 and 2.6. Lot's of code was added or
modified -- code that hasn't been optimized yet. Python 3's new io
library is much slower than the old file type but there will be an
optimized version in Python 3.1. The switch over to unicode is a minor
speed drain, too.

You can look forward for lots of interesting optimizations in Python 3.1
like threaded code (not to be confused with multi-threading) for the VM
on GCC platforms, 30bit digists for ints on 64bit platforms, C
optimization of the IO stack and more.

Christian

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


Re: Creating Zip file like java jar file

2009-03-01 Thread Steve Holden
zaheer.ag...@gmail.com wrote:
> On Mar 1, 1:32 am, "Gabriel Genellina"  wrote:
>> En Sat, 28 Feb 2009 16:51:04 -0200,  escribió:
>>
>>
>>
>>> On Feb 28, 11:33 pm, Lie Ryan  wrote:
 zaheer.ag...@gmail.com wrote:
> On Feb 28, 11:15 pm, "Gabriel Genellina" 
> wrote:
>> En Sat, 28 Feb 2009 14:34:15 -0200, 
 escribió:
>>> I want to create zip file equivalent to java jar file,I created a
 zip
>>> file of my sources and added some __main__.py
>>> it says __Main__.py not found in Copyproject.zip..?
>> __main__.py must exist in the root directory.
> What do you mean by root directory..?What is this directory in
> Windows..?You mean the top level folder of the project?in my case
> copyproject folder..?
 root directory is the topmost directory (imagine a tree, the root is
 where all the branches branched from), in this case the root directory
 is your copyproject main folder.
>>> I wonder, I do have the __main__.py  in the root directory,but still
>>> getting
>>> python.exe cannot find __main__.py in CopyProject.zip
>> The top of the tree inside the zip file. Depth zero. Not inside any
>> directory. Above anything else. Just a bare name.
>>
>> Open your zip using the zipfile module:
>>
>> import zipfile
>> z = zipfile.ZipFile("xxx.zip")
>> z.printdir()
>>
>> You should see a line starting with __main__.py *without* any / in it.
>>
>>> I used the following command
>>> python Copyproject.zip -m __main__.py --uploadFile and also tried with
>>> python Copyproject.zip --uploadFile
>> Use the second one.
>>
>>> both give me the same error , I can see the sys.path contains the
>>> project folder.
> 
>> --
>> Gabriel Genellina
> 
>> Uh? Which project folder? Isn't it in the .zip?
>>
>  Yeah I meant zip file.
> I can get to work but is it is not able to locate the packages,says
> import error cant find the package and module
> 
> here is my code
> 
> import sys
> import os.path as op
> sys.path.insert(0, op.join(op.dirname(op.abspath(__file__)),
> "somezip.zip"))
> 
> import zipfile
> z = zipfile.ZipFile("somezip.zip")
> z.printdir()
> 
> import some.storagepackage.somemodule
> print "upload"
> print "syspath",sys.path
> 
> #do something
> 
> should it not find the modules when the zip files is in sys.path..?

For this to work not only should your zipfile contain

some/storagepackage/somemodule.py, but some and some/storagepackage must
both contain __init__.py files to be recognized as packages.

Have you tried getting your imports working from the file store and then
 zipping up what works afterwards?

regards
 Steve
-- 
Steve Holden+1 571 484 6266   +1 800 494 3119
Holden Web LLC  http://www.holdenweb.com/

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


Characters aren't displayed correctly

2009-03-01 Thread Hussein B
Hey,
I'm retrieving records from MySQL database that contains non english
characters.
Then I create a String that contains HTML markup and column values
from the previous result set.
+
markup = u'''.'''
for row in rows:
 markup = markup + '' + row['id']
markup = markup + '
+
Then I'm sending the email according to this tip:
http://code.activestate.com/recipes/473810/
Well, the email contains ? characters for each non english ones.
Any ideas?
Ubuntu 8.04
Python 2.5.2
Evolution Mail Client
Thanks.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Bug report: ClientForm

2009-03-01 Thread Steve Holden
MRAB wrote:
> Muddy Coder wrote:
>> Hi Folks,
>>
>> As directed, I got ClientForm and played with it. It is cool! However,
>> I also found a bug:
>>
>> When it parses a form, if the VALUE of a field has not space, it works
>> very well. For example, if a dropdown list, there many options, such
>> as:
>>
>>  
>>
>> the value foo will be picked up for sure. But, if there is a space:
>>
>>  .
>>
> Values should be quoted, although you can omit the quotes if there
> aren't any spaces in the string:
> 
> 
> 
> You can see examples at http://wwwsearch.sourceforge.net/ClientForm/
> 
> 
> 
> As you can see, whitespace separates the name=value pairs.
> 
>> The *bar* will be missed out. I wish this bug can be fixed in near
>> future.
>>
> It's not a bug.

Or, if it is, it's a bug in the web page, not ClientForm!

regards
 Steve
-- 
Steve Holden+1 571 484 6266   +1 800 494 3119
Holden Web LLC  http://www.holdenweb.com/

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


Re: Creating Zip file like java jar file

2009-03-01 Thread Gabriel Genellina

En Sun, 01 Mar 2009 03:16:53 -0200,  escribió:


>> >>> I want to create zip file equivalent to java jar file,I created a
>> zip
>> >>> file of my sources and added some __main__.py
>> >>> it says __Main__.py not found in Copyproject.zip..?

I can get to work but is it is not able to locate the packages,says
import error cant find the package and module


Make it work *before* you attempt to zip the files. A complete session:

C:\TEMP>tree /a /f test_main_in_zip
Listado de rutas de carpetas para el volumen Cucho
El número de serie del volumen es 007A005F F4EC:16A9
C:\TEMP\TEST_MAIN_IN_ZIP
|   __main__.py
|
\---pkgA
foo.py
__init__.py


C:\TEMP>cd test_main_in_zip

C:\TEMP\test_main_in_zip>type __main__.py
#!/bin/env python

"""This script is the entry point
to the application"""

import sys
import pkgA.foo

def main():
  print "I'm main():"
  print "__name__", __name__
  print "__file__", __file__
  print "sys.path", sys.path[:3], "..."
  print
  pkgA.foo.bar()

main()

C:\TEMP\test_main_in_zip>type pkgA\__init__.py
print "I'm __init__.py"
print "__name__",__name__
print "__file__",__file__
print
C:\TEMP\test_main_in_zip>type pkgA\foo.py
def bar():
  print "I'm bar() inside foo.py:"
  print "__name__",__name__
  print "__file__",__file__
  print
C:\TEMP\test_main_in_zip>python __main__.py
I'm __init__.py
__name__ pkgA
__file__ C:\TEMP\test_main_in_zip\pkgA\__init__.py

I'm main():
__name__ __main__
__file__ __main__.py
sys.path ['C:\\TEMP\\test_main_in_zip',  
'c:\\apps\\python26\\python26.zip', 'c:\

\apps\\python26\\DLLs'] ...

I'm bar() inside foo.py:
__name__ pkgA.foo
__file__ C:\TEMP\test_main_in_zip\pkgA\foo.py


C:\TEMP\test_main_in_zip>zip anyname.zip __main__.py pkgA\*
  adding: __main__.py (196 bytes security) (deflated 40%)
  adding: pkgA/foo.py (196 bytes security) (deflated 40%)
  adding: pkgA/foo.pyc (196 bytes security) (deflated 41%)
  adding: pkgA/__init__.py (196 bytes security) (deflated 38%)
  adding: pkgA/__init__.pyc (196 bytes security) (deflated 29%)

C:\TEMP\test_main_in_zip>python anyname.zip
I'm __init__.py
__name__ pkgA
__file__ anyname.zip\pkgA\__init__.pyc

I'm main():
__name__ __main__
__file__ None
sys.path ['anyname.zip', 'c:\\apps\\python26\\python26.zip',  
'c:\\apps\\python26

\\DLLs'] ...

I'm bar() inside foo.py:
__name__ pkgA.foo
__file__ anyname.zip\pkgA\foo.pyc


--
Gabriel Genellina

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


Re: Performance of Python 3

2009-03-01 Thread Steve Holden
Kless wrote:
> Does anybody has seen the performance of Python 3?
> Respect to speed it's the last language together to Ruby 1.8, but Ruby
> 1.9 has a lot of better performance. :(
> 
I'm not sure what you think the speed of Ruby has to do with Python.
Unless, of course, you are simply trying to foment dischord.

Python 3.0 has a couple of performance issues, mostly the io subsystem.
The 3.1 release will address the most significant issues.

regards
 Steve
-- 
Steve Holden+1 571 484 6266   +1 800 494 3119
Holden Web LLC  http://www.holdenweb.com/

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


Is it possible to grab hidden code in ClientForm?

2009-03-01 Thread Muddy Coder
Hi Folks,

Nowadays some websites let users to fill in some so-called
verification code, and the tricky thing is that the CODE is delivered
from server with an image. For example:

  Refresh Image

When click Refresh Image, the CODE on the image changes. I wonder:
does the server really send a new image over to browser, or just send
a hidden code over? Is it possible to parse out such hidden code?

The other example is:




I did a few REFRESH on browser, and noticed the CODE changed. But,
when I viewed the HTML source code, the value "ahZsBmwyLGuf" remained
the same. What is the trick around here? That is why I am wondering
whether the server really keeps sending new images over, or just
sending new hidden codes over. If the trick is just keep sending
hidden codes over, there might be a chance of capturing the codes. Can
somebody help me out? Thanks a lot!


Muddy Coder





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


RE: Email Program

2009-03-01 Thread Thomas Raef
I totally agree. No sarcasm here.

> -Original Message-
> From: python-list-bounces+traef=ebasedsecurity@python.org
> [mailto:python-list-bounces+traef=ebasedsecurity@python.org] On
> Behalf Of Christian Heimes
> Sent: Saturday, February 28, 2009 8:24 PM
> To: python-list@python.org
> Subject: Re: Email Program
> 
> Thomas Raef wrote:
> > What a great response.
> 
> It's a correct, straight forward and short answer to the op's
question.
> 
> Christian
> 
> --
> http://mail.python.org/mailman/listinfo/python-list
--
http://mail.python.org/mailman/listinfo/python-list


Re: Creating Zip file like java jar file

2009-03-01 Thread zaheer . agadi
On Mar 1, 6:53 pm, "Gabriel Genellina"  wrote:
> En Sun, 01 Mar 2009 03:16:53 -0200,  escribió:
>
>
>
> >> >> >>> I want to create zip file equivalent to java jar file,I created a
> >> >> zip
> >> >> >>> file of my sources and added some __main__.py
> >> >> >>> it says __Main__.py not found in Copyproject.zip..?
> > I can get to work but is it is not able to locate the packages,says
> > import error cant find the package and module
>
> Make it work *before* you attempt to zip the files. A complete session:
>
> C:\TEMP>tree /a /f test_main_in_zip
> Listado de rutas de carpetas para el volumen Cucho
> El número de serie del volumen es 007A005F F4EC:16A9
> C:\TEMP\TEST_MAIN_IN_ZIP
> |   __main__.py
> |
> \---pkgA
>  foo.py
>  __init__.py
>
> C:\TEMP>cd test_main_in_zip
>
> C:\TEMP\test_main_in_zip>type __main__.py
> #!/bin/env python
>
> """This script is the entry point
> to the application"""
>
> import sys
> import pkgA.foo
>
> def main():
>print "I'm main():"
>print "__name__", __name__
>print "__file__", __file__
>print "sys.path", sys.path[:3], "..."
>print
>pkgA.foo.bar()
>
> main()
>
> C:\TEMP\test_main_in_zip>type pkgA\__init__.py
> print "I'm __init__.py"
> print "__name__",__name__
> print "__file__",__file__
> print
> C:\TEMP\test_main_in_zip>type pkgA\foo.py
> def bar():
>print "I'm bar() inside foo.py:"
>print "__name__",__name__
>print "__file__",__file__
>print
> C:\TEMP\test_main_in_zip>python __main__.py
> I'm __init__.py
> __name__ pkgA
> __file__ C:\TEMP\test_main_in_zip\pkgA\__init__.py
>
> I'm main():
> __name__ __main__
> __file__ __main__.py
> sys.path ['C:\\TEMP\\test_main_in_zip',
> 'c:\\apps\\python26\\python26.zip', 'c:\
> \apps\\python26\\DLLs'] ...
>
> I'm bar() inside foo.py:
> __name__ pkgA.foo
> __file__ C:\TEMP\test_main_in_zip\pkgA\foo.py
>
> C:\TEMP\test_main_in_zip>zip anyname.zip __main__.py pkgA\*
>adding: __main__.py (196 bytes security) (deflated 40%)
>adding: pkgA/foo.py (196 bytes security) (deflated 40%)
>adding: pkgA/foo.pyc (196 bytes security) (deflated 41%)
>adding: pkgA/__init__.py (196 bytes security) (deflated 38%)
>adding: pkgA/__init__.pyc (196 bytes security) (deflated 29%)
>
> C:\TEMP\test_main_in_zip>python anyname.zip
> I'm __init__.py
> __name__ pkgA
> __file__ anyname.zip\pkgA\__init__.pyc
>
> I'm main():
> __name__ __main__
> __file__ None
> sys.path ['anyname.zip', 'c:\\apps\\python26\\python26.zip',
> 'c:\\apps\\python26
> \\DLLs'] ...
>
> I'm bar() inside foo.py:
> __name__ pkgA.foo
> __file__ anyname.zip\pkgA\foo.pyc
>
> --
> Gabriel Genellin

> Make it work *before* you attempt to zip the files.
  Thanks a lot Gabriel, yes this works fine when I am running it
outside of zip.
when I say  python __main__.py --uploadfile  it works fine
I dont know what happens when I zip it.

And Steve: all of the packages have __init__.py inside them, I have
posted the tree structure of application if it helps.

C:\DOCUMENTS AND SETTINGS\ADMINISTRATOR\DESKTOP\PYTHNSTUF
\TestApplication
├───src
│   ├───network
│   │   ├───.svn
│   │   │   └───text-base
│   │   └───storage
│   │   └───.svn
│   │   └───text-base
│   ├───uc
│   │   └───some
│   │   └───extra
│   │   └───package
│   └───webdav
│   └───acp
└───test
└───.svn
└───text-base

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


Re: Characters aren't displayed correctly

2009-03-01 Thread Philip Semanchuk


On Mar 1, 2009, at 8:31 AM, Hussein B wrote:


Hey,
I'm retrieving records from MySQL database that contains non english
characters.
Then I create a String that contains HTML markup and column values
from the previous result set.
+
markup = u'''.'''
for row in rows:
markup = markup + '' + row['id']
markup = markup + '
+
Then I'm sending the email according to this tip:
http://code.activestate.com/recipes/473810/
Well, the email contains ? characters for each non english ones.
Any ideas?


There's so many places where this could go wrong and you haven't  
narrowed down the problem.


Are the characters stored in the database correctly?

Are they stored consistently (i.e. all using the same encoding, not  
some using utf-8 and others using iso-8859-1)?


What are you getting out of the database? Is it being converted to  
Unicode correctly, or at all?


Are you sure that the program you're using to view the email  
understands the encoding?


Isolate those questions one at a time. Add some debugging breakpoints.  
Ensure that you have what you think you have. You might not fix your  
problem, but you will make it much smaller and more specific.



Good luck
Philip



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


Re: Creating Zip file like java jar file

2009-03-01 Thread zaheer . agadi
On Mar 1, 7:40 pm, zaheer.ag...@gmail.com wrote:
> On Mar 1, 6:53 pm, "Gabriel Genellina"  wrote:
>
>
>
> > En Sun, 01 Mar 2009 03:16:53 -0200,  escribió:
>
> > >> >> >>> I want to create zip file equivalent to java jar file,I created a
> > >> >> zip
> > >> >> >>> file of my sources and added some __main__.py
> > >> >> >>> it says __Main__.py not found in Copyproject.zip..?
> > > I can get to work but is it is not able to locate the packages,says
> > > import error cant find the package and module
>
> > Make it work *before* you attempt to zip the files. A complete session:
>
> > C:\TEMP>tree /a /f test_main_in_zip
> > Listado de rutas de carpetas para el volumen Cucho
> > El número de serie del volumen es 007A005F F4EC:16A9
> > C:\TEMP\TEST_MAIN_IN_ZIP
> > |   __main__.py
> > |
> > \---pkgA
> >  foo.py
> >  __init__.py
>
> > C:\TEMP>cd test_main_in_zip
>
> > C:\TEMP\test_main_in_zip>type __main__.py
> > #!/bin/env python
>
> > """This script is the entry point
> > to the application"""
>
> > import sys
> > import pkgA.foo
>
> > def main():
> >print "I'm main():"
> >print "__name__", __name__
> >print "__file__", __file__
> >print "sys.path", sys.path[:3], "..."
> >print
> >pkgA.foo.bar()
>
> > main()
>
> > C:\TEMP\test_main_in_zip>type pkgA\__init__.py
> > print "I'm __init__.py"
> > print "__name__",__name__
> > print "__file__",__file__
> > print
> > C:\TEMP\test_main_in_zip>type pkgA\foo.py
> > def bar():
> >print "I'm bar() inside foo.py:"
> >print "__name__",__name__
> >print "__file__",__file__
> >print
> > C:\TEMP\test_main_in_zip>python __main__.py
> > I'm __init__.py
> > __name__ pkgA
> > __file__ C:\TEMP\test_main_in_zip\pkgA\__init__.py
>
> > I'm main():
> > __name__ __main__
> > __file__ __main__.py
> > sys.path ['C:\\TEMP\\test_main_in_zip',
> > 'c:\\apps\\python26\\python26.zip', 'c:\
> > \apps\\python26\\DLLs'] ...
>
> > I'm bar() inside foo.py:
> > __name__ pkgA.foo
> > __file__ C:\TEMP\test_main_in_zip\pkgA\foo.py
>
> > C:\TEMP\test_main_in_zip>zip anyname.zip __main__.py pkgA\*
> >adding: __main__.py (196 bytes security) (deflated 40%)
> >adding: pkgA/foo.py (196 bytes security) (deflated 40%)
> >adding: pkgA/foo.pyc (196 bytes security) (deflated 41%)
> >adding: pkgA/__init__.py (196 bytes security) (deflated 38%)
> >adding: pkgA/__init__.pyc (196 bytes security) (deflated 29%)
>
> > C:\TEMP\test_main_in_zip>python anyname.zip
> > I'm __init__.py
> > __name__ pkgA
> > __file__ anyname.zip\pkgA\__init__.pyc
>
> > I'm main():
> > __name__ __main__
> > __file__ None
> > sys.path ['anyname.zip', 'c:\\apps\\python26\\python26.zip',
> > 'c:\\apps\\python26
> > \\DLLs'] ...
>
> > I'm bar() inside foo.py:
> > __name__ pkgA.foo
> > __file__ anyname.zip\pkgA\foo.pyc
>
> > --
> > Gabriel Genellin
> > Make it work *before* you attempt to zip the files.
>
>   Thanks a lot Gabriel, yes this works fine when I am running it
> outside of zip.
> when I say  python __main__.py --uploadfile  it works fine
> I dont know what happens when I zip it.
>
> And Steve: all of the packages have __init__.py inside them, I have
> posted the tree structure of application if it helps.
>
> C:\DOCUMENTS AND SETTINGS\ADMINISTRATOR\DESKTOP\PYTHNSTUF
> \TestApplication
> ├───src
> │   ├───network
> │   │   ├───.svn
> │   │   │   └───text-base
> │   │   └───storage
> │   │   └───.svn
> │   │   └───text-base
> │   ├───uc
> │   │   └───some
> │   │   └───extra
> │   │   └───package
> │   └───webdav
> │   └───acp
> └───test
> └───.svn
> └───text-base

and also what it gives me when I Do, > python BRU.zip
some list of files
:
:
BRU/__init__.py2009-02-28
17:08:10  1
BRU/__main__.py2009-03-01
18:17:20  8
BRU/   2009-03-01 14:52:58
Traceback (most recent call last):
  File "C:\Python26\lib\runpy.py", line 121, in _run_module_as_main
"__main__", fname, loader, pkg_name)
  File "C:\Python26\lib\runpy.py", line 34, in _run_code
exec code in run_globals
  File "BRU.zip\__main__.py", line 18, in 
ImportError: No module named network.storage

I think I should I also mention I create this application using
ecliplse plugin

I appreciate your help Gabriella thanks  a lot,
--
http://mail.python.org/mailman/listinfo/python-list


Re: Performance of Python 3

2009-03-01 Thread Paul Rubin
Steve Holden  writes:
> I'm not sure what you think the speed of Ruby has to do with Python.

In the real world, people care about the relative speed of programs.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Proposed implementation for an Ordered Dictionary

2009-03-01 Thread Colin J. Williams

Michele Simionato wrote:

On Mar 1, 1:43 am, Paul Rubin  wrote:

"Colin J. Williams"  writes:


 # print [mydict[x] for x in sorted(mydict.keys)] Instance object
is not iterable

It was a typo.  Use:

print [mydict[x] for x in sorted(mydict.keys())]


Even better

print [mydict[x] for x in sorted(mydict)]


Both Paul Rubin and Michele Simionato 
produce the same result but neither

produces what was originally suggested:

def seqValues(self):
''' To return the values, with 
their keys, sorted by value. '''
v= [(it[1], it[0]) for it in 
self.items()]

v.sort()
return v

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


Iterator class to allow self-restarting generator expressions?

2009-03-01 Thread John O'Hagan
Inspired by some recent threads here about using classes to extend the 
behaviour of iterators, I'm trying to replace some some top-level functions 
aimed at doing such things with a class.

So far it's got a test for emptiness, a non-consuming peek-ahead method, and 
an extended next() which can return slices as well as the normal mode, but 
one thing I'm having a little trouble with is getting generator expressions 
to restart when exhausted. This code works for generator functions:

class Regen(object):
"""Optionally restart generator functions"""
def __init__(self, generator, options=None, restart=False):
self.gen = generator
self.options = options
self.gen_call = generator(options)
self.restart = restart

def __iter__(self):
return (self)

def next(self):
try:
return self.gen_call.next()
except StopIteration:
if self.restart:
self.gen_call = self.generator(self.options)
return self.gen_call.next()
else:
raise

used like this:

def gen():
for i in range(3):
yield i

reg = Regen(gen, restart=True)

I'd like to do the same for generator expressions, something like:

genexp = (i for i in range(3))

regenexp = Regen(genexp, restart=True)

such that regenexp would behave like reg, i.e. restart when exhausted (and 
would only raise StopIteration if it's actually empty). However because 
generator expressions aren't callable, the above approach won't work.

I suppose I could convert expressions to functions like:

def gen():
genexp = (i for i in range(3))
for j in genexp:
yield j

but that seems tautological.

Any clues or comments appreciated.

John

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


Re: file locking...

2009-03-01 Thread MRAB

bruce wrote:

Hi.

Got a bit of a question/issue that I'm trying to resolve. I'm asking this of
a few groups so bear with me.

I'm considering a situation where I have multiple processes running, and
each process is going to access a number of files in a dir. Each process
accesses a unique group of files, and then writes the group of files to
another dir. I can easily handle this by using a form of locking, where I
have the processes lock/read a file and only access the group of files in
the dir based on the  open/free status of the lockfile.

However, the issue with the approach is that it's somewhat synchronous. I'm
looking for something that might be more asynchronous/parallel, in that I'd
like to have multiple processes each access a unique group of files from the
given dir as fast as possible.

So.. Any thoughts/pointers/comments would be greatly appreciated. Any
pointers to academic research, etc.. would be useful.

You say "each process accesses a unique group of files". Does this mean 
that no two processes access the same file?


If yes, then why do you need locking?

If no, then could you lock, move the files into a work folder, and then 
unlock? (Remember that moving a file on the same volume (disk) should be 
a quick renaming.) There could be one work folder per process, although 
that isn't necessary because each process would know (or be told) which 
of the files in the work folder belonged to it.

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


Re: Static Map

2009-03-01 Thread KMCB
Andrew,

You are correct, that article was very beneficial.  It helped me
understand the stack, much better.

Thanks,

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


Re: Is it possible to grab hidden code in ClientForm?

2009-03-01 Thread Gabriel Genellina
En Sun, 01 Mar 2009 12:23:20 -0200, Muddy Coder   
escribió:



Nowadays some websites let users to fill in some so-called
verification code, and the tricky thing is that the CODE is delivered
from server with an image. For example:


  Refresh Image


When click Refresh Image, the CODE on the image changes. I wonder:
does the server really send a new image over to browser, or just send
a hidden code over? Is it possible to parse out such hidden code?


The server may asociate the expected value (CODE) to some session ID.  
Delivering a new image means a new value associated. No other changes are  
needed in the client side.


--
Gabriel Genellina

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


Re: Performance of Python 3

2009-03-01 Thread Stefan Behnel
Paul Rubin wrote:
> Steve Holden  writes:
>> I'm not sure what you think the speed of Ruby has to do with Python.
> 
> In the real world, people care about the relative speed of programs.

Fine, but the Shootout on Alioth isn't a particularly pythonic one. It
deals almost exclusively with computationally intensive tasks, i.e.
programs where any decent Python developer would either import Psyco or
speed up the code in Cython. As long as that gives you improvements of
100-1000 times almost for free, I wouldn't bother too much with changing
the platform just because someone shows me benchmark results of some code
that I absolutely don't need in my daily work.

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


Is it possible to grab hidden code in ClientForm?

2009-03-01 Thread rdmurray
Muddy Coder  wrote:
> Nowadays some websites let users to fill in some so-called
> verification code, and the tricky thing is that the CODE is delivered
> from server with an image. For example:
> 
>  >  Refresh Image
> 
> When click Refresh Image, the CODE on the image changes. I wonder:
> does the server really send a new image over to browser, or just send
> a hidden code over? Is it possible to parse out such hidden code?
> 
> The other example is:
> 
> 
> 
> 
> I did a few REFRESH on browser, and noticed the CODE changed. But,
> when I viewed the HTML source code, the value "ahZsBmwyLGuf" remained
> the same. What is the trick around here? That is why I am wondering
> whether the server really keeps sending new images over, or just
> sending new hidden codes over. If the trick is just keep sending
> hidden codes over, there might be a chance of capturing the codes. Can
> somebody help me out? Thanks a lot!

If there were some way for a program to extract the code from what
the server sent, then the whole point of using the Captcha (preventing
spam robots from posting) would be defeated.

--RDM

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


Re: Performance of Python 3

2009-03-01 Thread Isaac Gouy
On Mar 1, 8:10 am, Stefan Behnel  wrote:
> Paul Rubin wrote:
> > Steve Holden  writes:
> >> I'm not sure what you think the speed of Ruby has to do with Python.
>
> > In the real world, people care about the relative speed of programs.
>
> Fine, but theShootoutonAliothisn't a particularly pythonic one. It
> deals almost exclusively with computationally intensive tasks, i.e.
> programs where any decent Python developer would either import Psyco or
> speed up the code in Cython.

It deals exclusively with small programs in isolation as if they were
the bottleneck.


> As long as that gives you improvements of
> 100-1000 times almost for free, I wouldn't bother too much with changing
> the platform just because someone shows me benchmark results of some code
> that I absolutely don't need in my daily work.


What examples do you have of 1000x improvement?

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


Multiple separate py2exe executables and library.zip

2009-03-01 Thread The Dude
  Hello,

  Each invocation of py2exe creates an executable along with a number of
other files which need to be distributed with it, including library.zip. I
noticed that compiling different scripts creates different, and incompatible
library.zip-s. Suppose I need a directory that contains the result of
*separate* py2exe calls, then - how can there be a library.zip that fits
them all?

  Thanks & Bye,

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


Re: Iterator class to allow self-restarting generator expressions?

2009-03-01 Thread Mark Tolonen


"John O'Hagan"  wrote in message 
news:200903011520.29405.resea...@johnohagan.com...

Inspired by some recent threads here about using classes to extend the
behaviour of iterators, I'm trying to replace some some top-level 
functions

aimed at doing such things with a class.

So far it's got a test for emptiness, a non-consuming peek-ahead method, 
and

an extended next() which can return slices as well as the normal mode, but
one thing I'm having a little trouble with is getting generator 
expressions

to restart when exhausted. This code works for generator functions:


[snip code]

The Python help shows the Python-equivalent code (or go to the source) for 
things like itertools.islice and itertools.icycle, which sound like what you 
are re-implementing.  It looks like to handle generators icycle saves the 
items as they are generated in another list, then uses the list to generate 
successive iterations.


-Mark 



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


Re: Iterator class to allow self-restarting generator expressions?

2009-03-01 Thread Gabriel Genellina
En Sun, 01 Mar 2009 13:20:28 -0200, John O'Hagan   
escribió:



Inspired by some recent threads here about using classes to extend the
behaviour of iterators, I'm trying to replace some some top-level  
functions

aimed at doing such things with a class.

So far it's got a test for emptiness, a non-consuming peek-ahead method,  
and
an extended next() which can return slices as well as the normal mode,  
but
one thing I'm having a little trouble with is getting generator  
expressions

to restart when exhausted. This code works for generator functions:


[...]


I'd like to do the same for generator expressions, something like:

genexp = (i for i in range(3))

regenexp = Regen(genexp, restart=True)

such that regenexp would behave like reg, i.e. restart when exhausted  
(and

would only raise StopIteration if it's actually empty). However because
generator expressions aren't callable, the above approach won't work.


I'm afraid you can't do that. There is no way of "cloning" a generator:

py> g = (i for i in [1,2,3])
py> type(g)()
Traceback (most recent call last):
  File "", line 1, in 
TypeError: cannot create 'generator' instances
py> g.gi_code = code
Traceback (most recent call last):
  File "", line 1, in 
TypeError: readonly attribute
py> import copy
py> copy.copy(g)
Traceback (most recent call last):
...
TypeError: object.__new__(generator) is not safe, use generator.__new__()
py> type(g).__new__


You can do that with a generator function because it acts as a "generator  
factory", building a new generator when called. Even using the Python C  
API, to create a generator one needs a frame object -- and there is no way  
to create a frame object "on the fly" that I know of :(


py> import ctypes
py> PyGen_New = ctypes.pythonapi.PyGen_New
py> PyGen_New.argtypes = [ctypes.py_object]
py> PyGen_New.restype = ctypes.py_object
py> g = (i for i in [1,2,3])
py> g2 = PyGen_New(g.gi_frame)
py> g2.gi_code is g.gi_code
True
py> g2.gi_frame is g.gi_frame
True
py> g.next()
1
py> g2.next()
2

g and g2 share the same execution frame, so they're not independent. There  
is no easy way to create a new frame in Python:


py> type(g.gi_frame)()
Traceback (most recent call last):
  File "", line 1, in 
TypeError: cannot create 'frame' instances

One could try using PyFrame_New -- but that's way too magic for my taste...

--
Gabriel Genellina

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


Re: Creating Zip file like java jar file

2009-03-01 Thread zaheer . agadi
On Mar 1, 7:53 pm, zaheer.ag...@gmail.com wrote:
> On Mar 1, 7:40 pm, zaheer.ag...@gmail.com wrote:
>
>
>
> > On Mar 1, 6:53 pm, "Gabriel Genellina"  wrote:
>
> > > En Sun, 01 Mar 2009 03:16:53 -0200,  escribió:
>
> > > >> >> >>> I want to create zip file equivalent to java jar file,I created 
> > > >> >> >>> a
> > > >> >> zip
> > > >> >> >>> file of my sources and added some __main__.py
> > > >> >> >>> it says __Main__.py not found in Copyproject.zip..?
> > > > I can get to work but is it is not able to locate the packages,says
> > > > import error cant find the package and module
>
> > > Make it work *before* you attempt to zip the files. A complete session:
>
> > > C:\TEMP>tree /a /f test_main_in_zip
> > > Listado de rutas de carpetas para el volumen Cucho
> > > El número de serie del volumen es 007A005F F4EC:16A9
> > > C:\TEMP\TEST_MAIN_IN_ZIP
> > > |   __main__.py
> > > |
> > > \---pkgA
> > >  foo.py
> > >  __init__.py
>
> > > C:\TEMP>cd test_main_in_zip
>
> > > C:\TEMP\test_main_in_zip>type __main__.py
> > > #!/bin/env python
>
> > > """This script is the entry point
> > > to the application"""
>
> > > import sys
> > > import pkgA.foo
>
> > > def main():
> > >print "I'm main():"
> > >print "__name__", __name__
> > >print "__file__", __file__
> > >print "sys.path", sys.path[:3], "..."
> > >print
> > >pkgA.foo.bar()
>
> > > main()
>
> > > C:\TEMP\test_main_in_zip>type pkgA\__init__.py
> > > print "I'm __init__.py"
> > > print "__name__",__name__
> > > print "__file__",__file__
> > > print
> > > C:\TEMP\test_main_in_zip>type pkgA\foo.py
> > > def bar():
> > >print "I'm bar() inside foo.py:"
> > >print "__name__",__name__
> > >print "__file__",__file__
> > >print
> > > C:\TEMP\test_main_in_zip>python __main__.py
> > > I'm __init__.py
> > > __name__ pkgA
> > > __file__ C:\TEMP\test_main_in_zip\pkgA\__init__.py
>
> > > I'm main():
> > > __name__ __main__
> > > __file__ __main__.py
> > > sys.path ['C:\\TEMP\\test_main_in_zip',
> > > 'c:\\apps\\python26\\python26.zip', 'c:\
> > > \apps\\python26\\DLLs'] ...
>
> > > I'm bar() inside foo.py:
> > > __name__ pkgA.foo
> > > __file__ C:\TEMP\test_main_in_zip\pkgA\foo.py
>
> > > C:\TEMP\test_main_in_zip>zip anyname.zip __main__.py pkgA\*
> > >adding: __main__.py (196 bytes security) (deflated 40%)
> > >adding: pkgA/foo.py (196 bytes security) (deflated 40%)
> > >adding: pkgA/foo.pyc (196 bytes security) (deflated 41%)
> > >adding: pkgA/__init__.py (196 bytes security) (deflated 38%)
> > >adding: pkgA/__init__.pyc (196 bytes security) (deflated 29%)
>
> > > C:\TEMP\test_main_in_zip>python anyname.zip
> > > I'm __init__.py
> > > __name__ pkgA
> > > __file__ anyname.zip\pkgA\__init__.pyc
>
> > > I'm main():
> > > __name__ __main__
> > > __file__ None
> > > sys.path ['anyname.zip', 'c:\\apps\\python26\\python26.zip',
> > > 'c:\\apps\\python26
> > > \\DLLs'] ...
>
> > > I'm bar() inside foo.py:
> > > __name__ pkgA.foo
> > > __file__ anyname.zip\pkgA\foo.pyc
>
> > > --
> > > Gabriel Genellin
> > > Make it work *before* you attempt to zip the files.
>
> >   Thanks a lot Gabriel, yes this works fine when I am running it
> > outside of zip.
> > when I say  python __main__.py --uploadfile  it works fine
> > I dont know what happens when I zip it.
>
> > And Steve: all of the packages have __init__.py inside them, I have
> > posted the tree structure of application if it helps.
>
> > C:\DOCUMENTS AND SETTINGS\ADMINISTRATOR\DESKTOP\PYTHNSTUF
> > \TestApplication
> > ├───src
> > │   ├───network
> > │   │   ├───.svn
> > │   │   │   └───text-base
> > │   │   └───storage
> > │   │   └───.svn
> > │   │   └───text-base
> > │   ├───uc
> > │   │   └───some
> > │   │   └───extra
> > │   │   └───package
> > │   └───webdav
> > │   └───acp
> > └───test
> > └───.svn
> > └───text-base
>
> and also what it gives me when I Do, > python BRU.zip
> some list of files
> :
> :
> BRU/__init__.py2009-02-28
> 17:08:10  1
> BRU/__main__.py2009-03-01
> 18:17:20  8
> BRU/   2009-03-01 14:52:58
> Traceback (most recent call last):
>   File "C:\Python26\lib\runpy.py", line 121, in _run_module_as_main
> "__main__", fname, loader, pkg_name)
>   File "C:\Python26\lib\runpy.py", line 34, in _run_code
> exec code in run_globals
>   File "BRU.zip\__main__.py", line 18, in 
> ImportError: No module named network.storage
>
> I think I should I also mention I create this application using
> ecliplse plugin
>
> I appreciate your help Gabriella thanks  a lot,

Thanks a lot folks it is solved now,the problem  was I had to create a
zip file from the location where actual package declarations are there
and not from the top level directory  whatever I had.
I created zip file from the src directory of the my tree which had all
the packages as its next level contents and imports were

RE: file locking...

2009-03-01 Thread bruce
hi mrab..

to your question... no file is acquired by multiple processes. and yeah,
i've thought of copying the files to a separate dir for each child/client
process to work with.. and in all honesty, this is as fast as i can envision
at this time...



-Original Message-
From: python-list-bounces+bedouglas=earthlink@python.org
[mailto:python-list-bounces+bedouglas=earthlink@python.org]on Behalf
Of MRAB
Sent: Sunday, March 01, 2009 8:04 AM
To: python-list@python.org
Subject: Re: file locking...


bruce wrote:
> Hi.
>
> Got a bit of a question/issue that I'm trying to resolve. I'm asking this
of
> a few groups so bear with me.
>
> I'm considering a situation where I have multiple processes running, and
> each process is going to access a number of files in a dir. Each process
> accesses a unique group of files, and then writes the group of files to
> another dir. I can easily handle this by using a form of locking, where I
> have the processes lock/read a file and only access the group of files in
> the dir based on the  open/free status of the lockfile.
>
> However, the issue with the approach is that it's somewhat synchronous.
I'm
> looking for something that might be more asynchronous/parallel, in that
I'd
> like to have multiple processes each access a unique group of files from
the
> given dir as fast as possible.
>
> So.. Any thoughts/pointers/comments would be greatly appreciated. Any
> pointers to academic research, etc.. would be useful.
>
You say "each process accesses a unique group of files". Does this mean
that no two processes access the same file?

If yes, then why do you need locking?

If no, then could you lock, move the files into a work folder, and then
unlock? (Remember that moving a file on the same volume (disk) should be
a quick renaming.) There could be one work folder per process, although
that isn't necessary because each process would know (or be told) which
of the files in the work folder belonged to it.
--
http://mail.python.org/mailman/listinfo/python-list

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


Re: Creating Zip file like java jar file

2009-03-01 Thread Gabriel Genellina

En Sun, 01 Mar 2009 12:53:30 -0200,  escribió:

On Mar 1, 7:40 pm, zaheer.ag...@gmail.com wrote:

On Mar 1, 6:53 pm, "Gabriel Genellina"  wrote:
> En Sun, 01 Mar 2009 03:16:53 -0200,  escribió:

> >> >> >>> I want to create zip file equivalent to java jar file,I  
created a

> >> >> zip
> >> >> >>> file of my sources and added some __main__.py



  Thanks a lot Gabriel, yes this works fine when I am running it
outside of zip.
when I say  python __main__.py --uploadfile  it works fine
I dont know what happens when I zip it.

And Steve: all of the packages have __init__.py inside them, I have
posted the tree structure of application if it helps.

C:\DOCUMENTS AND SETTINGS\ADMINISTRATOR\DESKTOP\PYTHNSTUF
\TestApplication
├───src
│   ├───network
│   │   ├───.svn
│   │   │   └───text-base
│   │   └───storage
│   │   └───.svn
│   │   └───text-base
│   ├───uc
│   │   └───some
│   │   └───extra
│   │   └───package
│   └───webdav
│   └───acp
└───test
└───.svn
└───text-base


and also what it gives me when I Do, > python BRU.zip
some list of files
:
:
BRU/__init__.py2009-02-28
17:08:10  1
BRU/__main__.py2009-03-01
18:17:20  8


So the __main__.py is recognized and runs. That's good news. But I see  
*another* __main__.py listed that should not exist, in a directory BRU.  
Are you sure you tested using the *outer* __main__.py? And what is that  
__init__.py?


Test in *another* directory, not your development environment, and remove  
all those extra artifacts like .svn directories and such that you're not  
going to deploy, I presume.



Traceback (most recent call last):
  File "C:\Python26\lib\runpy.py", line 121, in _run_module_as_main
"__main__", fname, loader, pkg_name)
  File "C:\Python26\lib\runpy.py", line 34, in _run_code
exec code in run_globals
  File "BRU.zip\__main__.py", line 18, in 
ImportError: No module named network.storage


I see "network" inside "src" in your directory tree. For something like  
"ipmort network.storage" to work, "src" must be in the import path used by  
Python (sys.path).



I appreciate your help Gabriella thanks  a lot,


My name is *Gabriel* and I'm male...

--
Gabriel Genellina

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


Re: Multiple separate py2exe executables and library.zip

2009-03-01 Thread Patrick Mullen
On Sun, Mar 1, 2009 at 8:35 AM, The Dude  wrote:
>   Hello,
>
>   Each invocation of py2exe creates an executable along with a number of
> other files which need to be distributed with it, including library.zip. I
> noticed that compiling different scripts creates different, and incompatible
> library.zip-s. Suppose I need a directory that contains the result of
> *separate* py2exe calls, then - how can there be a library.zip that fits
> them all?
>
>   Thanks & Bye,
>
>   TD
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>
>

You can unpack each zip and then create one that has everything.  A
better option might be to work one of the executables to include all
of the stuff, and then use its library.zip.  Sometimes I have done
this, by making an extra .py file which imports all of my other files.
 When I build the exe for this one, it will create the library.zip,
and I just ignore the .exe.  (In your build step you run this last).

There might be better ways, but with py2exe I generally hack around
problems and make my build process a bit more involved. (Often even
calling out command line programs to do some of the work).
--
http://mail.python.org/mailman/listinfo/python-list


RE: file locking...

2009-03-01 Thread bruce
hi nigel...

using any kind of file locking process requires that i essentially have a
gatekeeper, allowing a single process to enter, access the files at a
time...

i can easily setup a file read/write lock process where a client app
gets/locks a file, and then copies/moves the required files from the initial
dir to a tmp dir. after the move/copy, the lock is released, and the client
can go ahead and do whatever with the files in the tmp dir.. thie process
allows multiple clients to operate in a psuedo parallel manner...

i'm trying to figure out if there's a much better/faster approach that might
be available.. which is where the academic/research issue was raised..

the issue that i'm looking at is analogous to a FIFO, where i have lots of
files being shoved in a dir from different processes.. on the other end, i
want to allow mutiple client processes to access unique groups of these
files as fast as possible.. access being fetch/gather/process/delete the
files. each file is only handled by a single client process.

thanks..



-Original Message-
From: python-list-bounces+bedouglas=earthlink@python.org
[mailto:python-list-bounces+bedouglas=earthlink@python.org]on Behalf
Of Nigel Rantor
Sent: Sunday, March 01, 2009 2:00 AM
To: koranthala
Cc: python-list@python.org
Subject: Re: file locking...


koranthala wrote:
> On Mar 1, 2:28 pm, Nigel Rantor  wrote:
>> bruce wrote:
>>> Hi.
>>> Got a bit of a question/issue that I'm trying to resolve. I'm asking
>>> this of a few groups so bear with me.
>>> I'm considering a situation where I have multiple processes running,
>>> and each process is going to access a number of files in a dir. Each
>>> process accesses a unique group of files, and then writes the group
>>> of files to another dir. I can easily handle this by using a form of
>>> locking, where I have the processes lock/read a file and only access
>>> the group of files in the dir based on the  open/free status of the
>>> lockfile.
>>> However, the issue with the approach is that it's somewhat
>>> synchronous. I'm looking for something that might be more
>>> asynchronous/parallel, in that I'd like to have multiple processes
>>> each access a unique group of files from the given dir as fast as
>>> possible.
>> I don't see how this is synchronous if you have a lock per file. Perhaps
>> you've missed something out of your description of your problem.
>>
>>> So.. Any thoughts/pointers/comments would be greatly appreciated. Any
>>>  pointers to academic research, etc.. would be useful.
>> I'm not sure you need academic papers here.
>>
>> One trivial solution to this problem is to have a single process
>> determine the complete set of files that require processing then fork
>> off children, each with a different set of files to process.
>>
>> The parent then just waits for them to finish and does any
>> post-processing required.
>>
>> A more concrete problem statement may of course change the solution...
>>
>>n
>
> Using twisted might also be helpful.
> Then you can avoid the problems associated with threading too.

No one mentioned threads.

I can't see how Twisted in this instance isn't like using a sledgehammer
to crack a nut.

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

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


Re: Multiple separate py2exe executables and library.zip

2009-03-01 Thread Gabriel Genellina
En Sun, 01 Mar 2009 14:35:01 -0200, The Dude   
escribió:



  Each invocation of py2exe creates an executable along with a number of
other files which need to be distributed with it, including library.zip.  
I
noticed that compiling different scripts creates different, and  
incompatible

library.zip-s. Suppose I need a directory that contains the result of
*separate* py2exe calls, then - how can there be a library.zip that fits
them all?


Just list all targets in a single setup call:

from distutils.core import setup
import py2exe
setup(console=['foo.py','bar.py'],
  windows=['baz.py'])

If you can't, note that all those library.zip aren't "incompatibles", they  
contain only the required modules for each target. You may obtain the  
union of them all and use that as the single library.zip.


--
Gabriel Genellina

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


Re: file locking...

2009-03-01 Thread Gabriel Genellina
En Sun, 01 Mar 2009 15:39:56 -0200, bruce   
escribió:


the issue that i'm looking at is analogous to a FIFO, where i have lots  
of
files being shoved in a dir from different processes.. on the other end,  
i

want to allow mutiple client processes to access unique groups of these
files as fast as possible.. access being fetch/gather/process/delete the
files. each file is only handled by a single client process.


I still fail to see why do you need any locking. Could you provide a  
concrete example?


Suppose I have 26 processes, each one handles files starting with a  
certain letter. This example fits your description perfectly, and no  
locking is needed at all.


--
Gabriel Genellina

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


Re: Iterator class to allow self-restarting generator expressions?

2009-03-01 Thread Chris Rebert
On Sun, Mar 1, 2009 at 8:54 AM, Gabriel Genellina
 wrote:
> En Sun, 01 Mar 2009 13:20:28 -0200, John O'Hagan 
> escribió:
>
>> Inspired by some recent threads here about using classes to extend the
>> behaviour of iterators, I'm trying to replace some some top-level
>> functions
>> aimed at doing such things with a class.
>>
>> So far it's got a test for emptiness, a non-consuming peek-ahead method,
>> and
>> an extended next() which can return slices as well as the normal mode, but
>> one thing I'm having a little trouble with is getting generator
>> expressions
>> to restart when exhausted. This code works for generator functions:
>
> [...]
>
>> I'd like to do the same for generator expressions, something like:
>>
>> genexp = (i for i in range(3))
>>
>> regenexp = Regen(genexp, restart=True)
>>
>> such that regenexp would behave like reg, i.e. restart when exhausted (and
>> would only raise StopIteration if it's actually empty). However because
>> generator expressions aren't callable, the above approach won't work.
>
> I'm afraid you can't do that. There is no way of "cloning" a generator:

Really? What about itertools.tee()? Sounds like it'd do the job,
albeit with some caveats.
http://docs.python.org/library/itertools.html#itertools.tee

Cheers,
Chris

-- 
Follow the path of the Iguana...
http://rebertia.com
--
http://mail.python.org/mailman/listinfo/python-list


RE: file locking...

2009-03-01 Thread bruce
Hi Gabriel.

Except in my situation.. the client has no knowledge of the filenaming
situation, and i might have 1000s of files... think of the FIFO, first in,
first out.. so i'm loking for a fast solution that would allow me to create
groups of say, 500 files, that get batched and processed by the client
app...

so in this situation, the client needs to access the files, group the files,
copy/move the files, process the files...

rather than "lock" the dir for the entire process listed above, the app
could lock the dir/files for the initial access/copy/move process.. and then
release, allowing other client processes to more quickly access the files..
but i'm wondering if there's a faster approach...

thanks


-Original Message-
From: python-list-bounces+bedouglas=earthlink@python.org
[mailto:python-list-bounces+bedouglas=earthlink@python.org]on Behalf
Of Gabriel Genellina
Sent: Sunday, March 01, 2009 9:50 AM
To: python-list@python.org
Subject: Re: file locking...


En Sun, 01 Mar 2009 15:39:56 -0200, bruce 
escribió:

> the issue that i'm looking at is analogous to a FIFO, where i have lots
> of
> files being shoved in a dir from different processes.. on the other end,
> i
> want to allow mutiple client processes to access unique groups of these
> files as fast as possible.. access being fetch/gather/process/delete the
> files. each file is only handled by a single client process.

I still fail to see why do you need any locking. Could you provide a
concrete example?

Suppose I have 26 processes, each one handles files starting with a
certain letter. This example fits your description perfectly, and no
locking is needed at all.

--
Gabriel Genellina

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

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


Re: Iterator class to allow self-restarting generator expressions?

2009-03-01 Thread Gabriel Genellina
En Sun, 01 Mar 2009 15:51:07 -0200, Chris Rebert   
escribió:

On Sun, Mar 1, 2009 at 8:54 AM, Gabriel Genellina
 wrote:
En Sun, 01 Mar 2009 13:20:28 -0200, John O'Hagan  


escribió:


Inspired by some recent threads here about using classes to extend the
behaviour of iterators, I'm trying to replace some some top-level
functions
aimed at doing such things with a class.



I'm afraid you can't do that. There is no way of "cloning" a generator:


Really? What about itertools.tee()? Sounds like it'd do the job,
albeit with some caveats.
http://docs.python.org/library/itertools.html#itertools.tee


It doesn't clone the generator, it just stores the generated objects in a  
temporary array to be re-yielded later.


--
Gabriel Genellina

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


Re: file locking...

2009-03-01 Thread Nigel Rantor


Hi Bruce,

Excuse me if I'm a little blunt below. I'm ill grumpy...

bruce wrote:

hi nigel...

using any kind of file locking process requires that i essentially have a
gatekeeper, allowing a single process to enter, access the files at a
time...


I don't beleive this is a necessary condition. That would only be the 
case if you allowed yourself a single lock.



i can easily setup a file read/write lock process where a client app
gets/locks a file, and then copies/moves the required files from the initial
dir to a tmp dir. after the move/copy, the lock is released, and the client
can go ahead and do whatever with the files in the tmp dir.. thie process
allows multiple clients to operate in a psuedo parallel manner...

i'm trying to figure out if there's a much better/faster approach that might
be available.. which is where the academic/research issue was raised..


I'm really not sure why you want to move the files around. Here are two 
different approaches from the one I initially gave you that deals 
perfectly well with a directory where files are constantly being added.


In both approaches we are going to try and avoid using OS-specific 
locking mechanisms, advisory locking, flock etc. So it should work 
everywhere as long as you also have write access to the filesystem 
you're on.



Approach 1 - Constant Number of Processes

This requires no central manager but for every file lock requires a few 
OS calls.


Start up N processes with the same working directory WORK_DIR.

Each process then follows this algorithm:

- sleep for some small random period.

- scan the WORK_DIR for a FILE that does not have a corresponding LOCK_FILE

- open LOCK_FILE in append mode and write our PID into it.

- close LOCK_FILE

- open LOCK_FILE

- read first line from LOCK_FILE and compare to our PID

- if the PID we just read from the LOCK_FILE matches ours then we may 
process the corresponding FILE otherwise another process beat us to it.


- repeat

After processing a file completely you can remove it and the lockfile at 
the same time.


As long as filenames follow some pattern then you can simply say that 
the LOCK_FILE for FILE is called FILE.lock


e.g.

WORK_DIR  : /home/wiggly/var/work
FILE  : /home/wiggly/var/work/data_2354272.dat
LOCK_FILE : /home/wiggly/var/work/data_2354272.dat.lock


Approach 2 - Managed Processes

Here we have a single main process that spawns children. The children 
listen for filenames on a pipe that the parent has open to them.


The parent constantly scans the WORK_DIR for new files to process and as 
it finds one it sends that filename to a child process.


You can either be clever about the children and ensure they tell the 
parent when they're free or just pass them work in a round-robin fashion.


I hope the two above descriptions make sense, let me know if they don't.

   n



the issue that i'm looking at is analogous to a FIFO, where i have lots of
files being shoved in a dir from different processes.. on the other end, i
want to allow mutiple client processes to access unique groups of these
files as fast as possible.. access being fetch/gather/process/delete the
files. each file is only handled by a single client process.

thanks..



-Original Message-
From: python-list-bounces+bedouglas=earthlink@python.org
[mailto:python-list-bounces+bedouglas=earthlink@python.org]on Behalf
Of Nigel Rantor
Sent: Sunday, March 01, 2009 2:00 AM
To: koranthala
Cc: python-list@python.org
Subject: Re: file locking...


koranthala wrote:

On Mar 1, 2:28 pm, Nigel Rantor  wrote:

bruce wrote:

Hi.
Got a bit of a question/issue that I'm trying to resolve. I'm asking
this of a few groups so bear with me.
I'm considering a situation where I have multiple processes running,
and each process is going to access a number of files in a dir. Each
process accesses a unique group of files, and then writes the group
of files to another dir. I can easily handle this by using a form of
locking, where I have the processes lock/read a file and only access
the group of files in the dir based on the  open/free status of the
lockfile.
However, the issue with the approach is that it's somewhat
synchronous. I'm looking for something that might be more
asynchronous/parallel, in that I'd like to have multiple processes
each access a unique group of files from the given dir as fast as
possible.

I don't see how this is synchronous if you have a lock per file. Perhaps
you've missed something out of your description of your problem.


So.. Any thoughts/pointers/comments would be greatly appreciated. Any
 pointers to academic research, etc.. would be useful.

I'm not sure you need academic papers here.

One trivial solution to this problem is to have a single process
determine the complete set of files that require processing then fork
off children, each with a different set of files to process.

The parent then just waits for them to finish and does any
post-processing required.

A more concrete prob

Re: Email Program

2009-03-01 Thread Tino Wildenhain

J wrote:

Is it possible to make a GUI email program in Python that stores
emails, composes, ect?


Yes this is possible.

Regards
Tino



smime.p7s
Description: S/MIME Cryptographic Signature
--
http://mail.python.org/mailman/listinfo/python-list


Re: file locking...

2009-03-01 Thread Gabriel Genellina
En Sun, 01 Mar 2009 16:11:41 -0200, Nigel Rantor   
escribió:

bruce wrote:



i can easily setup a file read/write lock process where a client app
gets/locks a file, and then copies/moves the required files from the  
initial
dir to a tmp dir. after the move/copy, the lock is released, and the  
client
can go ahead and do whatever with the files in the tmp dir.. thie  
process

allows multiple clients to operate in a psuedo parallel manner...


I'm really not sure why you want to move the files around. Here are two  
different approaches from the one I initially gave you that deals  
perfectly well with a directory where files are constantly being added.


This is a third approach - simpler than Bruce's.
Each process chooses any file and tries to rename/move it onto a different  
directory. Rename is an atomic operation (at least on POSIX) so no locks  
are required. If the rename fails, choose another file and try again.


--
Gabriel Genellina

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


Re: Performance of Python 3

2009-03-01 Thread Thorsten Kampe
* Isaac Gouy (Sun, 1 Mar 2009 08:27:05 -0800 (PST))
> On Mar 1, 8:10 am, Stefan Behnel  wrote:
> > Paul Rubin wrote:
> > > Steve Holden  writes:
> > >> I'm not sure what you think the speed of Ruby has to do with Python.
> >
> > > In the real world, people care about the relative speed of programs.
> >
> > Fine, but theShootoutonAliothisn't a particularly pythonic one. It
> > deals almost exclusively with computationally intensive tasks, i.e.
> > programs where any decent Python developer would either import Psyco or
> > speed up the code in Cython.
> 
> It deals exclusively with small programs in isolation as if they were
> the bottleneck.

Right. But they aren't. So people who draw any conclusions from that 
like "C++ is faster than C" or "Ruby is slower than Python" or "Python 
is 30 times slower than C" draw the wrong conclusions.

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


Re: OTish: convince the team to drop VBScript

2009-03-01 Thread Thorsten Kampe
* Carl Banks (Sat, 28 Feb 2009 20:09:03 -0800 (PST))
> On Feb 28, 7:10 pm, Shane Geiger  wrote:
> > >> The company does use Python on rare occasions. It all comes down to
> > >> the prejudices and habits of one of the programmers. His only argument
> > >> I can't counter -because I don't see the problem- is that "Python
> > >> modules cause problems for updates to customer's installations".
> >
> > This is purely an argument from ignorance, a logical fallacy.
> 
> I don't think it's an argument at all.
Exactly. In the "Python modules cause problems for updates to customer's 
installations" there is a "because ..." missing...

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


Re: Performance of Python 3

2009-03-01 Thread Stefan Behnel
Isaac Gouy wrote:
> On Mar 1, 8:10 am, Stefan Behnel wrote:
>> As long as that gives you improvements of
>> 100-1000 times almost for free, I wouldn't bother too much with changing
>> the platform just because someone shows me benchmark results of some code
>> that I absolutely don't need in my daily work.
> 
> What examples do you have of 1000x improvement?

We hear that from time to time on the Cython mailing list. Here's a recent
example of a user who reported an 80 times speed-up before we helped in
getting the code straight, which brought another factor of 20.

http://permalink.gmane.org/gmane.comp.python.cython.devel/4619

Speed-ups in the order of several hundred times are not uncommon for
computing intensive tasks and large data sets when you move from Python to
Cython, as it generates very optimised C code.

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


Re: TypeErrors

2009-03-01 Thread Benjamin Kaplan
On Sun, Mar 1, 2009 at 1:50 PM, Sean Novick  wrote:

> Here is the bit of code my error was refering to:
> class phonedb:
>
> some definitons...
>
> def lookup(self, string):
> list = []
> for key in self.shelve.keys():
> e = self.shelve[key]
> if cmp(e, string) == 0:
> list.append(e)
> return(list)
>
> where would it tell me to return an int?
>
>
cmp(e, string) is actually just a shortcut for e.__cmp__(string). Again, you
should almost never directly call cmp. First of all, newer code should
implement the __eq__ method for this, not cmp. Also, you should just use "if
e == string" instead of cmp or eq. This isn't java- Python has operator
overloading (though it isn't quite as flexible as C++).
--
http://mail.python.org/mailman/listinfo/python-list


Script in /usr/bin doesn't see my packages

2009-03-01 Thread Filip Gruszczyński
I have used distutils to install a python package and a script, that
runs a program. Everything seemed ok, when I run interpreter I can
import stuff, that I have just installed. But when I run script that
was installed into /usr/bin it can't import anything. This happens
also with my test scripts: i put an import statement there and run
them (they are outside of development directory) and they import stuff
just the way they should. But when I put them into /usr/bin they stop.
Could anyone help me on this?

-- 
Filip Gruszczyński
--
http://mail.python.org/mailman/listinfo/python-list


Re: file locking...

2009-03-01 Thread zugnush
You could do something like this so that  every process will know if
the file "belongs" to it without prior coordination, it  means a lot
of redundant hashing though.

In [36]: import md5

In [37]: pool = 11

In [38]: process = 5

In [39]: [f for f in glob.glob('*') if int(md5.md5(f).hexdigest(),16)
% pool == process ]
Out[39]:
--
http://mail.python.org/mailman/listinfo/python-list


Re: TypeErrors

2009-03-01 Thread Christian Heimes
Benjamin Kaplan wrote:

> cmp(e, string) is actually just a shortcut for e.__cmp__(string).

FYI, cmp(e, string) does a lot more than just calling e.__cmp__(string).
Check out Objects/object.c:do_cmp()

Christian

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


Re: file locking...

2009-03-01 Thread Nigel Rantor

zugnush wrote:

You could do something like this so that  every process will know if
the file "belongs" to it without prior coordination, it  means a lot
of redundant hashing though.

In [36]: import md5

In [37]: pool = 11

In [38]: process = 5

In [39]: [f for f in glob.glob('*') if int(md5.md5(f).hexdigest(),16)
% pool == process ]
Out[39]:


You're also relying on the hashing being perfectly distributed, 
otherwise some processes aren't going to be performing useful work even 
though there is useful work to perform.


In other words, why would you rely on a scheme that limits some 
processes to certain parts of the data? If we're already talking about 
trying to get away without some global lock for synchronisation this 
seems to go against the original intent of the problem...


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


Re: urllib2 httplib.BadStatusLine exception while opening a page on an Oracle HTTP Server

2009-03-01 Thread ak
which website have you tested it on ?
My tests were basically on https://www.orange.sk and http://www.orange.sk
(the first fails, and not the second one, which led me to think
there's a bug in python's SSL implementation for this particular web
server) (Oracle) with python 2.5



On Feb 19, 1:57 pm, O Peng  wrote:
> I'm running into a similar problem with the BadStatusLine.
> The source code for httplib.py in the problem is as follows:
>
> class HTTPResponse:
>     ...
>     def _read_status(self):
>         line = self.fp.readline()
>         ...
>         if not line:
>             # Presumably, the server closed the connection before
>             # sending a valid response.
>             raise BadStatusLine(line)
>
> However, I found that right before the 'raise BadStatusLine(line)'
> when I ran the following:
>
> restOfResponse = self.fp.read()
> print restOfResponse
>
> restOfResponse is NOT empty.  In fact, when I run self.fp.read() at
> the beginning of the begin() function, it is not empty at all.
> This leads me to believe there is a bug with the self.fp.readline()
> (socket._fileobject.readline()) function.  For me it only fails
> sometimes.
>
> This behavior is only observed on Windows, Python 2.5.  Running it on
> Mac OS X, Python 2.5 yielded no problems.
>
> On Jan 19, 3:48 pm, ak  wrote:
>
> > On Jan 19, 10:00 pm, ak  wrote:
>
> > > Hi everyone,
>
> > > I have a problem withurllib2on this particular url, hosted on an
> > > Oracle HTTP Server
>
> > >http://www.orange.sk/eshop/sk/portal/catalog.html?type=post&subtype=p...
>
> > > which gets 302 redirected 
> > > tohttps://www.orange.sk/eshop/sk/catalog/post/phones.html,
> > > after setting a cookie through the Set-Cookie header field in the 302
> > > reply. This works fin with firefox.
>
> > > However, withurllib2and the following code snippet, it doesn't work
>
> > > 
> > > import cookiejar
> > > importurllib2
>
> > > cookiejar = cookielib.LWPCookieJar()
> > > opener =urllib2.build_opener(urllib2.HTTPCookieProcessor(cookiejar))
> > > url = 'http://www.orange.sk/eshop/sk/portal/catalog.html?
> > > type=post&subtype=phone&null'
> > > req =urllib2.Request(url, None)
> > > s=opener.open(req)
> > > 
>
> > > Traceback (most recent call last):
> > >   File "", line 1, in 
> > >   File "/usr/lib/python2.5/urllib2.py", line 387, in open
> > >     response = meth(req, response)
> > >   File "/usr/lib/python2.5/urllib2.py", line 498, in http_response
> > >     'http', request, response, code, msg, hdrs)
> > >   File "/usr/lib/python2.5/urllib2.py", line 419, in error
> > >     result = self._call_chain(*args)
> > >   File "/usr/lib/python2.5/urllib2.py", line 360, in _call_chain
> > >     result = func(*args)
> > >   File "/usr/lib/python2.5/urllib2.py", line 582, in http_error_302
> > >     return self.parent.open(new)
> > >   File "/usr/lib/python2.5/urllib2.py", line 381, in open
> > >     response = self._open(req, data)
> > >   File "/usr/lib/python2.5/urllib2.py", line 399, in _open
> > >     '_open', req)
> > >   File "/usr/lib/python2.5/urllib2.py", line 360, in _call_chain
> > >     result = func(*args)
> > >   File "/usr/lib/python2.5/urllib2.py", line 1115, in https_open
> > >     return self.do_open(httplib.HTTPSConnection, req)
> > >   File "/usr/lib/python2.5/urllib2.py", line 1080, in do_open
> > >     r = h.getresponse()
> > >   File "/usr/lib/python2.5/httplib.py", line 928, in getresponse
> > >     response.begin()
> > >   File "/usr/lib/python2.5/httplib.py", line 385, in begin
> > >     version, status, reason = self._read_status()
> > >   File "/usr/lib/python2.5/httplib.py", line 349, in _read_status
> > >     raise BadStatusLine(line)
> > > httplib.BadStatusLine
>
> > > Trying the redirected url directly doesn't work either (trying with
> > > Firefox will give an HTML error page, as the cookie is not set yet,
> > > but trying withurllib2gives the same exception as previously,
> > > whereas it should return the HTML error page)
> > > This works correctly on other urls on this website 
> > > (http(s)://www.orange.sk).
>
> > > Am I doing anything wrong or is this a bug inurllib2?
>
> > > -- ak
>
> > Actually, I was wrong on the last point, this does *not* work 
> > onhttps://www.orange.sk(butdoes onhttp://www.orange.sk). IMHO, this
> > means eitherurllib2or the server misimplemented HTTPS.
>
> > Here's some output with debuglevel=1 :
>
> > >>> opener.open(urllib2.Request('http://www.orange.sk/', None, headers))
>
> > reply: 'HTTP/1.1 200 OK\r\n'
> > header: Date: Mon, 19 Jan 2009 21:44:03 GMT
> > header: Server: Oracle-Application-Server-10g/10.1.3.1.0 Oracle-HTTP-
> > Server
> > header: Set-Cookie:
> > JSESSIONID=0a19055a30d630c427bda71d4e26a37ca604b9f590dc.e3eNaNiRah4Pe3aSch8 
> > Sc3yOc40;
> > path=/web
> > header: Expires: Mon, 19 Jan 2009 21:44:13 GMT
> > header: Surrogate-Control: max-age="10"
> > header: Content-Type: text/html; charset=ISO-8859-2
> > header: X-Cache: MISS fromwww.orange.sk
> > header: Connecti

Re: Characters aren't displayed correctly

2009-03-01 Thread J. Clifford Dyer
On Sun, 2009-03-01 at 09:51 -0500, Philip Semanchuk wrote:
> On Mar 1, 2009, at 8:31 AM, Hussein B wrote:
> 
> > Hey,
> > I'm retrieving records from MySQL database that contains non english
> > characters.
> > Then I create a String that contains HTML markup and column values
> > from the previous result set.
> > +
> > markup = u'''.'''
> > for row in rows:
> > markup = markup + '' + row['id']
> > markup = markup + '
> > +
> > Then I'm sending the email according to this tip:
> > http://code.activestate.com/recipes/473810/
> > Well, the email contains ? characters for each non english ones.
> > Any ideas?
> 
> There's so many places where this could go wrong and you haven't  
> narrowed down the problem.
> 
> Are the characters stored in the database correctly?
> 
> Are they stored consistently (i.e. all using the same encoding, not  
> some using utf-8 and others using iso-8859-1)?
> 
> What are you getting out of the database? Is it being converted to  
> Unicode correctly, or at all?
> 
> Are you sure that the program you're using to view the email  
> understands the encoding?
> 
> Isolate those questions one at a time. Add some debugging breakpoints.  
> Ensure that you have what you think you have. You might not fix your  
> problem, but you will make it much smaller and more specific.
> 
> 
> Good luck
> Philip
> 
> 

Let me add to that checklist:

Are you sure the email you are creating has the encoding declared
properly in the headers?

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

Cheers,
Cliff


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


Re: PIL's thumbnail function returns NoneType

2009-03-01 Thread Terry Reedy

Hrvoje Niksic wrote:

Mirat Can Bayrak  writes:


Can you try it? it is about me or it is a bug?


Neither.  im.thumbnail() modifies the existing image object by
converting it to a thumbnail.  In Python such methods by convention
return None.

The documentation explicitly mentions that:

Also note that this function modifies the Image object in
place. If you need to use the full resolution image as well, apply
this method to a copy of the original image. This method returns
None.


Indeed, the purpose of returning None is to remind that the method does 
mutation in place.






In [4]: thm = im.thumbnail((200,200))

In [5]: type(thm)
Out[5]: 


Instead of thm, simply keep using ihm.
--
http://mail.python.org/mailman/listinfo/python-list



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


Re: Iterator class to allow self-restarting generator expressions?

2009-03-01 Thread Terry Reedy

John O'Hagan wrote:
Inspired by some recent threads here about using classes to extend the 
behaviour of iterators, I'm trying to replace some some top-level functions 
aimed at doing such things with a class.


So far it's got a test for emptiness, a non-consuming peek-ahead method, and 
an extended next() which can return slices as well as the normal mode, but 
one thing I'm having a little trouble with is getting generator expressions 
to restart when exhausted. This code works for generator functions:


class Regen(object):
"""Optionally restart generator functions"""
def __init__(self, generator, options=None, restart=False):
self.gen = generator


Your 'generator' parameter is actually a generator function -- a 
function that created a generator when called.



self.options = options


Common practice would use 'args' instead of 'options'.


self.gen_call = generator(options)


If the callable takes multiple args, you want '*options' (or *args) 
instead of 'options'.


That aside, your 'gen_call' parameter is actually a generator -- a 
special type of iterator (uncallable object with __next__ (3.0) method).


It is worthwhile keeping the nomenclature straight.  As you discovered, 
generator expressions create generators, not generator functions.  Other 
than being given the default .__name__ attribute '', there is 
otherwise nothing special about their result.  So I would not try to 
treat them specially.  Initializing a Regen instance with *any* 
generator (or other iterator) will fail.


On the other hand, your Regen instances could be initialized with *any* 
callable that produces iterators, including iterator classes.  So you 
might as well call the parameters iter_func and iterator.


In general, for all iterators and not just generators, reiteration 
requires a new iterator, either by duplicating the original or by saving 
the values in a list and iterating through that.


Terry Jan Reedy

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


Re: TypeErrors

2009-03-01 Thread Scott David Daniels

Dennis Lee Bieber wrote:

...  Even this looks strange, since all list will contain is a copy of
string for each occurrence of string in the values of shelve!
Furthermore, the only use for the key is to obtain the value -- the key
is never returned for later use... so...

def lookup(self, needle):
cnt = 0
for hay in self.shelve.values():
if hay == needle:   cnt += 1
return cnt

No need to go through keys() (presuming the documentation of shelve
is correct, and all dictionary methods work), and the return value is an
integer (if one really needs a list of duplicates, then 


return [needle] * cnt


OK, but you could do better:

def lookup(self, needle):
return self.shelve.values().count(needle)

or:
def lookup(self, needle):
return self.shelve.values().count(needle) * [needle]

depending on the needed result (until values starts returning an
iterator).

--Scott David Daniels
scott.dani...@acm.org

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


Re: Performance of Python 3

2009-03-01 Thread Isaac Gouy
On Mar 1, 11:15 am, Thorsten Kampe  wrote:
> * Isaac Gouy (Sun, 1 Mar 2009 08:27:05 -0800 (PST))
>
> > On Mar 1, 8:10 am, Stefan Behnel  wrote:
> > > Paul Rubin wrote:
> > > > Steve Holden  writes:
> > > >> I'm not sure what you think the speed of Ruby has to do with Python.
>
> > > > In the real world, people care about the relative speed of programs.
>
> > > Fine, but theShootoutonAliothisn't a particularly pythonic one. It
> > > deals almost exclusively with computationally intensive tasks, i.e.
> > > programs where any decent Python developer would either import Psyco or
> > > speed up the code in Cython.
>
> > It deals exclusively with small programs in isolation as if they were
> > the bottleneck.
>
> Right. But they aren't.

They aren't except when they are!


> So people who draw any conclusions from that
> like "C++ is faster than C" or "Ruby is slower than Python" or "Python
> is 30 times slower than C" draw the wrong conclusions.
>
> Thorsten

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


Re: Performance of Python 3

2009-03-01 Thread Isaac Gouy
On Mar 1, 11:24 am, Stefan Behnel  wrote:
> Isaac Gouy wrote:
> > On Mar 1, 8:10 am, Stefan Behnel wrote:
> >> As long as that gives you improvements of
> >> 100-1000 times almost for free, I wouldn't bother too much with changing
> >> the platform just because someone shows me benchmark results of some code
> >> that I absolutely don't need in my daily work.
>
> > What examples do you have of 1000x improvement?
>
> We hear that from time to time on the Cython mailing list. Here's a recent
> example of a user who reported an 80 times speed-up before we helped in
> getting the code straight, which brought another factor of 20.
>
> http://permalink.gmane.org/gmane.comp.python.cython.devel/4619
>
> Speed-ups in the order of several hundred times are not uncommon for
> computing intensive tasks and large data sets when you move from Python to
> Cython, as it generates very optimised C code.
>
> Stefan


"Now only the def line and the return line are using Python..." ;-)
--
http://mail.python.org/mailman/listinfo/python-list


Reason why co_filename is no longer interned?

2009-03-01 Thread David Christian
In 2005, when the ast branch was merged to head, compile.c

when setting the filename for the code object,
PyString_InternFromString was replaced with PyString_FromString.

http://svn.python.org/view?view=rev&revision=39758

This means that where before, you could rely that
.func_code.co_filename == .func_code.co_filename

Does anyone know whether this change was purposeful?
--
http://mail.python.org/mailman/listinfo/python-list


Re: Reason why co_filename is no longer interned?

2009-03-01 Thread Benjamin Peterson
David Christian  gmail.com> writes:
> This means that where before, you could rely that
> .func_code.co_filename == .func_code.co_filename

Regardless of the change's intentionality, you should never rely on that
behavior! Interned strings are an implementation detail even at the C level.




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


Re: Reason why co_filename is no longer interned?

2009-03-01 Thread Chris Rebert
On Sun, Mar 1, 2009 at 5:03 PM, David Christian
 wrote:
> In 2005, when the ast branch was merged to head, compile.c
>
> when setting the filename for the code object,
> PyString_InternFromString was replaced with PyString_FromString.
>
> http://svn.python.org/view?view=rev&revision=39758
>
> This means that where before, you could rely that
> .func_code.co_filename == .func_code.co_filename

Are you sure you don't instead mean `is` rather than == ?

Cheers,
Chris

-- 
Shameless self-promotion:
http://blog.rebertia.com
--
http://mail.python.org/mailman/listinfo/python-list


Re: Reason why co_filename is no longer interned?

2009-03-01 Thread Benjamin Peterson
2009/3/1 David Christian :
> On Sun, Mar 1, 2009 at 8:15 PM, Benjamin Peterson  wrote:
>> David Christian  gmail.com> writes:
>>> This means that where before, you could rely that
>>> .func_code.co_filename == .func_code.co_filename
>>
>> Regardless of the change's intentionality, you should never rely on that
>> behavior! Interned strings are an implementation detail even at the C level.
>>
>
> Hi Benjamin,
> Thanks for your response.
>
> The code in question is in a tracing function for coverage - running
> for every line in the python code and an extra strcmp for every line
> of python code is expensive.

When you're testing for coverage, is performance really an issue?
Other coverage libraries do this in Python.

>
> And I'm not relying the files being equal, just taking advantage of it
> when it's the case.  The code looks like this:
>
> if(frame->f_code->co_filename == last_filename \
>   || !strcmp(PyString_AS_STRING(frame->f_code->co_filename),
>                  last_filename))
> {
>   < cache-hit!  Use latest coverage object.  >
> }
> else {
>   < cache miss.  Do dictionary lookup of coverage object by filename >
> }
>
> In the code I've looked at, cache hits happen 90+% of the time, which
> means I save a dictionary lookup.  In 2.4, I don't even have to do the
> strcmp, which means that running your code w/ coverage enabled is
> really not that much of a slowdown at all.
>
> Obviously, even with the strcmp, this manner of recording coverage
> data is much faster than running coverage in python, but I was
> wondering if this was a purposeful change or just something that
> happened by accident as part of a larger change.

Well, you could look through the logs of the ast-branch its self.



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


Re: Iterator class to allow self-restarting generator expressions?

2009-03-01 Thread John O'Hagan
On Sun, 1 Mar 2009, Mark Tolonen wrote:
> "John O'Hagan"  wrote in message
> news:200903011520.29405.resea...@johnohagan.com...
>
> > Inspired by some recent threads here about using classes to extend the
> > behaviour of iterators, I'm trying to replace some some top-level
> > functions
> > aimed at doing such things with a class.
> >
> > So far it's got a test for emptiness, a non-consuming peek-ahead method,
> > and
> > an extended next() which can return slices as well as the normal mode,
> > but one thing I'm having a little trouble with is getting generator
> > expressions
> > to restart when exhausted. This code works for generator functions:
>
> [snip code]
>
> The Python help shows the Python-equivalent code (or go to the source) for
> things like itertools.islice and itertools.icycle, which sound like what
> you are re-implementing.  It looks like to handle generators icycle saves
> the items as they are generated in another list, then uses the list to
> generate successive iterations.
>

Thanks for your reply Mark; I've looked at the itertools docs (again, this 
time I understood more of it!), but because the generators in question 
produce arbitrarily many results (which i should have mentioned), it would 
not always be practical to hold them all in memory. 

So I've used a "buffer" instance attribute in my iterator class, which only 
holds as many items as are required by the peek(), next() and __nonzero__() 
methods, in order to minimize memory use (come to think of it, I should add a 
clear() method as well...).  

But the islice() function looks very useful and could replace some code in my  
generator functions, as could some of the ingenious recipes at the end of the 
itertools chapter. It's always good to go back to the docs!

As for restarting the iterators, it seems from other replies that I must use 
generator function calls rather than expressions in order to do that.

Thanks,

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


imaplib fetch message flags

2009-03-01 Thread Rich Healey
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

Hi List,

I'm using an example of an imap client I found with google as a
framework for a more fullfeatured imap client.

They use the line:

 f = self.M.fetch(num, '(BODY[HEADER.FIELDS (SUBJECT FROM)])')

To retrieve the Subject: and From: fields from the message. I'm curious
about how to get the imap flags attached to the message, I can't find
this anywhere. The documentation suggests that it's merely some flag as
part of the `message_parts' argument to IMAP4{,_SSL}.fetch() method, but
what I cannot find. I've tried
(BODY[HEADER.FIELDS (SUBJECT FROM FLAGS)])
but it doesn't have the desired result.

I'm sure I'm missing something obvious.

Thanks in advance

Richo
- --
Rich Healey - iTReign  \.''`.   / healey.r...@gmail.com
Developer / Systems Admin   \  : :' :  /healey.r...@itreign.com
AIM: richohealey33   \ `. `'  / ri...@psych0tik.net
MSN: bitchohea...@hotmail.com \  `-  / richohea...@hellboundhackers.org
-BEGIN PGP SIGNATURE-
Version: GnuPG v1.4.9 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iEYEARECAAYFAkmrWBwACgkQLeTfO4yBSAepWACdHufITez2lL78KgRY9D/WUN9y
V3UAn12rdLxG6nKv1mfIxUeSywpEQk94
=RLfw
-END PGP SIGNATURE-
--
http://mail.python.org/mailman/listinfo/python-list


Re: Python won't run

2009-03-01 Thread dkiekow
On Feb 23, 5:01 pm, Ned Deily  wrote:
> [Again, please reply-all to the list, don't send private email!]
>
> On Feb 23, 2009, at 14:03 , kevin hayes wrote:
>
>
>
> > Ned, system log didn't do anything when I tried to open IDLE. However, this
> > is what's in the console.log. does this tell you anything?
>
> > Unhandled server exception!
> > Thread: SockThread
> > Client Address:  ('127.0.0.1', 8833)
> > Request:  
> > Traceback (most recent call last):
> >   File
> > "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/SocketServ 
> > er.
> > py", line 281, in _handle_request_noblock
> >     self.process_request(request, client_address)
> >   File
> > "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/SocketServ 
> > er.
> > py", line 307, in process_request
> >     self.finish_request(request, client_address)
> >   File
> > "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/SocketServ 
> > er.
> > py", line 320, in finish_request
> >     self.RequestHandlerClass(request, client_address, self)
> >   File
> > "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/idlelib/rp 
> > c.p
> > y", line 503, in __init__
> >     SocketServer.BaseRequestHandler.__init__(self, sock, addr, svr)
> >   File
> > "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/SocketServ 
> > er.
> > py", line 615, in __init__
> >     self.handle()
> >   File
> > "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/idlelib/ru 
> > n.p
> > y", line 256, in handle
> >     import IOBinding
> >   File
> > "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/idlelib/IO 
> > Bin
> > ding.py", line 12, in 
> >     import tempfile
> >   File
> > "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/tempfile.p 
> > y",
> >  line 34, in 
> >     from random import Random as _Random
> >   File "random.py", line 3, in 
> >     import rand      # handy random-number functions
> > ImportError: No module named rand
>
> > *** Unrecoverable, server exiting!
>
> [...]
>
> It looks like you have a file named random.py in your Documents
> directory.  IDLE.app adds ~/Documents to the front of sys.path, python's
> search path for modules.   Your random.py is being found before the
> standard library module, random, causing the idle server process to
> abort.  Rename your random.py* and all should be well for both 2.5 and
> 2.6.
>
> One could argue that IDLE.app should be smarter about situations like
> this.  It would be good to open an issue about this on the python
> tracker:
>    http://bugs.python.org/
>
> --
>   Ned Deily
>   n...@acm.org -- []
>
> --
>  Ned Deily,
>  n...@acm.org

I just downloaded the os x installer (2.5) and followed the
instructions in the wiki to install IDLE. When I double click the icon
it bounces, but nothing happens. From the command line python -m
idlelib.idle -n brings up a python terminal window. I tried searching
for random.py and did not find it. System I'm using is 10.5.6 on a
MacPro.
--
http://mail.python.org/mailman/listinfo/python-list


Re: imaplib fetch message flags

2009-03-01 Thread Rich Healey
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

Rich Healey wrote:
> Hi List,
> 
> I'm using an example of an imap client I found with google as a
> framework for a more fullfeatured imap client.
> 
> They use the line:
> 
>  f = self.M.fetch(num, '(BODY[HEADER.FIELDS (SUBJECT FROM)])')
> 
> To retrieve the Subject: and From: fields from the message. I'm curious
> about how to get the imap flags attached to the message, I can't find
> this anywhere. The documentation suggests that it's merely some flag as
> part of the `message_parts' argument to IMAP4{,_SSL}.fetch() method, but
> what I cannot find. I've tried
> (BODY[HEADER.FIELDS (SUBJECT FROM FLAGS)])
> but it doesn't have the desired result.
> 
> I'm sure I'm missing something obvious.
> 
> Thanks in advance
> 
> Richo
Found my own solution.

Anyone interested I found the info I needed on:

http://www.devshed.com/c/a/Python/Python-Email-Libraries-part-2-IMAP/3/
- --
Rich Healey - iTReign  \.''`.   / healey.r...@gmail.com
Developer / Systems Admin   \  : :' :  /healey.r...@itreign.com
AIM: richohealey33   \ `. `'  / ri...@psych0tik.net
MSN: bitchohea...@hotmail.com \  `-  / richohea...@hellboundhackers.org
-BEGIN PGP SIGNATURE-
Version: GnuPG v1.4.9 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iEYEARECAAYFAkmrXS8ACgkQLeTfO4yBSAdoYwCfU2UWL3mseIz/kQIUXWCxyBAc
ExkAoL0WYh7uu7A3cFP/bmjFONviAFgh
=mCa4
-END PGP SIGNATURE-
--
http://mail.python.org/mailman/listinfo/python-list


Re: imaplib fetch message flags

2009-03-01 Thread Gabriel Genellina
En Mon, 02 Mar 2009 01:53:00 -0200, Rich Healey   
escribió:



I'm using an example of an imap client I found with google as a
framework for a more fullfeatured imap client.

They use the line:

 f = self.M.fetch(num, '(BODY[HEADER.FIELDS (SUBJECT FROM)])')

To retrieve the Subject: and From: fields from the message. I'm curious
about how to get the imap flags attached to the message, I can't find
this anywhere. The documentation suggests that it's merely some flag as
part of the `message_parts' argument to IMAP4{,_SSL}.fetch() method, but
what I cannot find. I've tried
(BODY[HEADER.FIELDS (SUBJECT FROM FLAGS)])
but it doesn't have the desired result.


Try moving FLAGS out of the parenthesis (inside the outermost parenthesis):

(FLAGS BODY[HEADER.FIELDS (SUBJECT FROM)])

RFC1730  defines IMAP4 and isn't  
hard to read.


--
Gabriel Genellina

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


Re: Python won't run

2009-03-01 Thread Benjamin Kaplan
On Sun, Mar 1, 2009 at 10:52 PM,  wrote:

> On Feb 23, 5:01 pm, Ned Deily  wrote:
> > [Again, please reply-all to the list, don't send private email!]
> >
> > On Feb 23, 2009, at 14:03 , kevin hayes wrote:
> >
> >
> >
> > > Ned, system log didn't do anything when I tried to open IDLE. However,
> this
> > > is what's in the console.log. does this tell you anything?
> >
> > > Unhandled server exception!
> > > Thread: SockThread
> > > Client Address:  ('127.0.0.1', 8833)
> > > Request:  
> > > Traceback (most recent call last):
> > >   File
> > >
> "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/SocketServ
> er.
> > > py", line 281, in _handle_request_noblock
> > > self.process_request(request, client_address)
> > >   File
> > >
> "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/SocketServ
> er.
> > > py", line 307, in process_request
> > > self.finish_request(request, client_address)
> > >   File
> > >
> "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/SocketServ
> er.
> > > py", line 320, in finish_request
> > > self.RequestHandlerClass(request, client_address, self)
> > >   File
> > >
> "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/idlelib/rp
> c.p
> > > y", line 503, in __init__
> > > SocketServer.BaseRequestHandler.__init__(self, sock, addr, svr)
> > >   File
> > >
> "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/SocketServ
> er.
> > > py", line 615, in __init__
> > > self.handle()
> > >   File
> > >
> "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/idlelib/ru
> n.p
> > > y", line 256, in handle
> > > import IOBinding
> > >   File
> > >
> "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/idlelib/IO
> Bin
> > > ding.py", line 12, in 
> > > import tempfile
> > >   File
> > >
> "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/tempfile.p
> y",
> > >  line 34, in 
> > > from random import Random as _Random
> > >   File "random.py", line 3, in 
> > > import rand  # handy random-number functions
> > > ImportError: No module named rand
> >
> > > *** Unrecoverable, server exiting!
> >
> > [...]
> >
> > It looks like you have a file named random.py in your Documents
> > directory.  IDLE.app adds ~/Documents to the front of sys.path, python's
> > search path for modules.   Your random.py is being found before the
> > standard library module, random, causing the idle server process to
> > abort.  Rename your random.py* and all should be well for both 2.5 and
> > 2.6.
> >
> > One could argue that IDLE.app should be smarter about situations like
> > this.  It would be good to open an issue about this on the python
> > tracker:
> >http://bugs.python.org/
> >
> > --
> >   Ned Deily
> >   n...@acm.org -- []
> >
> > --
> >  Ned Deily,
> >  n...@acm.org
>
> I just downloaded the os x installer (2.5) and followed the
> instructions in the wiki to install IDLE. When I double click the icon
> it bounces, but nothing happens. From the command line python -m
> idlelib.idle -n brings up a python terminal window. I tried searching
> for random.py and did not find it. System I'm using is 10.5.6 on a
> MacPro.



Someone should probably update that Wiki page. It's really outdated. Ignore
everything that's on there right now.
Just download the Python 2.6.1 installer from the main python download page
and install it. It will automatically create a Python 2.6 folder in
Applications with IDLE in it.


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


Can CleintForm work with webbrowser?

2009-03-01 Thread Muddy Coder
Hi Folks,

ClientForm is cool at grabbing and parsing stuff from server, I like
it. After the stuff parsed, and even filled values for the Controls, I
popped up an idea of displaying what I had done with webbrowser. Look
at the code:

import ClientForm
import urllib2
import webbrowser

request = urllib2.Request(url)
response = urllib2.urlopen(request)
forms = ClientForm.ParseResponse(response, backwards_compat=False)
...parsing and filling forms

# now I want to display the forms I modified, with webbrowser
webbrowser.open_new_tab (???)

??? is supposed to be a url. But this moment I want to display the
form I filled. Obviously webbrowser takes url as argument rather than
a form.  Is there other options to do this? Somebody can help? Thanks!


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


Re: Can CleintForm work with webbrowser?

2009-03-01 Thread Chris Rebert
On Sun, Mar 1, 2009 at 9:36 PM, Muddy Coder  wrote:
> Hi Folks,
>
> ClientForm is cool at grabbing and parsing stuff from server, I like
> it. After the stuff parsed, and even filled values for the Controls, I
> popped up an idea of displaying what I had done with webbrowser. Look
> at the code:
>
> import ClientForm
> import urllib2
> import webbrowser
>
> request = urllib2.Request(url)
> response = urllib2.urlopen(request)
> forms = ClientForm.ParseResponse(response, backwards_compat=False)
> ...parsing and filling forms
>
> # now I want to display the forms I modified, with webbrowser
> webbrowser.open_new_tab (???)
>
> ??? is supposed to be a url. But this moment I want to display the
> form I filled. Obviously webbrowser takes url as argument rather than
> a form.  Is there other options to do this? Somebody can help? Thanks!

You could run a local HTTP server in another Python process/thread
using SimpleHTTPServer
(http://docs.python.org/library/simplehttpserver.html) and have it
serve the modified webpage you produce. Then you could call webbrowser
with a localhost address corresponding to the HTTP server you're
running.

Cheers,
Chris

-- 
Shameless self-promotion:
http://blog.rebertia.com
--
http://mail.python.org/mailman/listinfo/python-list


Re: Python won't run

2009-03-01 Thread Ned Deily
In article 
,
 dkie...@gmail.com wrote:
> On Feb 23, 5:01 pm, Ned Deily  wrote:
> > On Feb 23, 2009, at 14:03 , kevin hayes wrote:
> > > Ned, system log didn't do anything when I tried to open IDLE. However, 
> > > this
> > > is what's in the console.log. does this tell you anything?
> >
> > > Unhandled server exception!
> > > Thread: SockThread
> > > Client Address:  ('127.0.0.1', 8833)
> > > Request:  
> > > Traceback (most recent call last):
> > >   File
> > > "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/SocketSer
> > > v er.
> > > py", line 281, in _handle_request_noblock
> > >     self.process_request(request, client_address)
> > >   File
> > > "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/SocketSer
> > > v er.
> > > py", line 307, in process_request
> > >     self.finish_request(request, client_address)
> > >   File
> > > "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/SocketSer
> > > v er.
> > > py", line 320, in finish_request
> > >     self.RequestHandlerClass(request, client_address, self)
> > >   File
> > > "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/idlelib/r
> > > p c.p
> > > y", line 503, in __init__
> > >     SocketServer.BaseRequestHandler.__init__(self, sock, addr, svr)
> > >   File
> > > "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/SocketSer
> > > v er.
> > > py", line 615, in __init__
> > >     self.handle()
> > >   File
> > > "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/idlelib/r
> > > u n.p
> > > y", line 256, in handle
> > >     import IOBinding
> > >   File
> > > "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/idlelib/I
> > > O Bin
> > > ding.py", line 12, in 
> > >     import tempfile
> > >   File
> > > "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/tempfile.
> > > p y",
> > >  line 34, in 
> > >     from random import Random as _Random
> > >   File "random.py", line 3, in 
> > >     import rand      # handy random-number functions
> > > ImportError: No module named rand
> >
> > > *** Unrecoverable, server exiting!
> >
> > [...]
> >
> > It looks like you have a file named random.py in your Documents
> > directory.  IDLE.app adds ~/Documents to the front of sys.path, python's
> > search path for modules.   Your random.py is being found before the
> > standard library module, random, causing the idle server process to
> > abort.  Rename your random.py* and all should be well for both 2.5 and
> > 2.6.
> I just downloaded the os x installer (2.5) and followed the
> instructions in the wiki to install IDLE. When I double click the icon
> it bounces, but nothing happens. From the command line python -m
> idlelib.idle -n brings up a python terminal window. I tried searching
> for random.py and did not find it. System I'm using is 10.5.6 on a
> MacPro.

It's clear from the traceback above that the standard library random.py 
file is not being imported.  That file is here:

/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/random.py

There is nothing like "import rand # handy random-number functions" in 
it.  And the path reported is "random.py", not 
"/Library/Frameworks.../random.py".  IDLE.app changes its working 
directory to the Documents directory in your home directory so that path 
is what one would expect for a file from there.

The most likely culprit is in your ~/Documents folder.  That would 
explain why all versions of IDLE are being affected.

A Google seach for that string turns up this:

Does that ring any bells for you?

How about a Spotlight search for "handy random-number functions"?  

Something else to check is environment variable settings.  What does 
this produce in a terminal shell?:
   env | grep PYTHON

And try temporarily disabling the IDLE preferences files:
   mv ~/.idlerc ~/.idlerc-disabled

If you are seeing the same behavior with multiple versions of IDLE, make 
sure the Console output for each is similar to that above.

-- 
 Ned Deily,
 n...@acm.org

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


Re: Email Program

2009-03-01 Thread Ralf Schoenian

J wrote:

Is it possible to make a GUI email program in Python that stores
emails, composes, ect?


Hi,

yes, it is possible. There are modules in the standard library like 
email, smtplib and poplib. A gui can be written in wxPython, pyQT, pyGTK 
or tkinter. There are many more toolkits but these are the big ones.
Actually, ff you want to see an Python email client in action have a 
look at Chandler: http://chandlerproject.org/ it's written in wxPython.


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


unziping a file in python..

2009-03-01 Thread David Lyon

It might seem a simple question.. but how does one programmaticaly unzip a
file in python?

In version 2.6 and above.. the zipfile module has an extractall method. But
it isn't available in 2.5 or below.

Any cross version, cross-platform answers welcome.

Any answers specific to win32 also welcome...

David

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


Re: Email Program

2009-03-01 Thread Paul McGuire
On Feb 28, 7:56 pm, J  wrote:
> Is it possible to make a GUI email program in Python that stores
> emails, composes, ect? Also, could I create my own programming
> language in Python? What are Pythons limits, or is this just a waste
> of my time to learn it.

This "waste of my time" phrase is a telling one - I guess your age to
be in the 12-15 range.  I would suggest that you are not necessarily
in the best position to know what is or is not a waste of your time to
learn.

Imagine you are a baby and want to grow up to be a runner.  Is it a
waste of time to learn to crawl, and then to walk?  Is it a waste of
time to learn human nutrition, fitness, hydration?  Is it a waste of
time to learn the discipline of diet and practice?

Is it a waste of time to learn something that may not pertain to your
personal occupational goal, but may make you a more interesting, or
philosophical, or thoughtful, or creative person?

I'm not sure that we are the best judges as to whether Python is a
waste of your time to learn.  In general, I would say it is not a
waste of *anyone's* time to learn Python, but a lot depends on whether
the student is actually inspired by some inner curiosity and
creativity.  If Python instruction is simply being shoved down their
throat, then yes, it probably is a waste of their time, and their
instructor's, and their fellow students' who may be more motivated to
actually learn the subject.

As to your question of whether Python can be used to write an e-mail
client, or to create a programming language, I assure you both are
possible.  But also, given your unfamiliarity with Python, both are
well beyond your skills for some time yet, and you are nowhere near
reaching any of Python's limits any time soon.  You will have to spend
a lot of time learning and practicing a number of design and
development skills before you reach that point.  Whether that is a
"waste" of time or not is up to you.

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


Re: Email Program

2009-03-01 Thread Paul Rubin
Paul McGuire  writes:
> As to your question of whether Python can be used to write an e-mail
> client, or to create a programming language, I assure you both are
> possible.  But also, given your unfamiliarity with Python, both are
> well beyond your skills for some time yet, and you are nowhere near
> reaching any of Python's limits any time soon.  

Mitch Kapor (of Lotus 1-2-3 fame) spent a lot of money hiring 
very sharp Python programmers to write an email client called
Chandler, but from what I understand, progress so far has been
disappointing, at least in part for performance reasons.
--
http://mail.python.org/mailman/listinfo/python-list


Re: unziping a file in python..

2009-03-01 Thread Steven D'Aprano
On Mon, 02 Mar 2009 01:00:54 -0500, David Lyon wrote:

> It might seem a simple question.. but how does one programmaticaly unzip
> a file in python?


A quick and dirty solution would be something like this:

zf = zipfile.ZipFile('Archive.zip')
for name in zf.namelist():
open(name, 'w').write(zf.read(name))




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


Re: Can CleintForm work with webbrowser?

2009-03-01 Thread Diez B. Roggisch

Muddy Coder schrieb:

Hi Folks,

ClientForm is cool at grabbing and parsing stuff from server, I like
it. After the stuff parsed, and even filled values for the Controls, I
popped up an idea of displaying what I had done with webbrowser. Look
at the code:

import ClientForm
import urllib2
import webbrowser

request = urllib2.Request(url)
response = urllib2.urlopen(request)
forms = ClientForm.ParseResponse(response, backwards_compat=False)
...parsing and filling forms

# now I want to display the forms I modified, with webbrowser
webbrowser.open_new_tab (???)

??? is supposed to be a url. But this moment I want to display the
form I filled. Obviously webbrowser takes url as argument rather than
a form.  Is there other options to do this? Somebody can help? Thanks!


I don't think that ClientForm supports this out of the box, as "filling 
out a form" probably means something very different in terms of internal 
representation for a browser and ClientForm. But *if* you can get it to 
spit out the HTML, you can open the browser and point it to  a file copy 
of your html.


But you'd need to rewrite all resource links first, to point absolutly 
to the host the page came from.


All in all I don't think this is the road to success. If you really want 
something like this, learn how to code an extension to firefox that does 
this. Or use e.g. selenium + selenium server to remote control firefox 
through python.


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