regular expressions

2010-04-15 Thread chaaana
hi..
im parsing the text file containing the details of the testcases
failed.From the file i wanted to obtain only the testcase names and
enter them in the excel sheet.

the pattern of the text file is:

FILE : NW_PTH_TFG6_SCEN_4_2_FIFO.c, LINE : 240 TEST FAIL to get entire:
32768 bytes
NW_PTH_TFG6_SCEN_4_2_FIFO.c 340 DATA NOT MATCHING, TEST FAIL
TEST FAIL SYSCALL_TEST_SCEN_4_1_ALL.c at line 355
FILE:US_TFG7_SCEN_4_1.c,LINE:189, Server side TEST FAIL
FAIL BREW_SCEN_4_1.c 219: can't mount
FAIL BREW_SCEN_4_1.c 121: can't umount
<< BREW_SCEN_4_1.c TEST FAIL errno:No such file or directory >>
<< BREW_SCEN_4_1.c TEST FAIL >> error:Invalid argument

i used the ' re module' and its function partition,but im facing
problem in obtaining only the testcase names..
if anyone know the answer please help me..
Thanks for ur help.

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


extract substring by regex from a text file

2010-04-15 Thread Alessio
Hi,

I'm facing the problem in the subject:
- I have a text file that I need to parse for producing a specifical
string (Json like) extracting some information (substring) in it;
- I created regural expressions capable to locate these substrings in
my txt file;

now I don't know how to continue. What is the best way to locate some
string in a file and output them (with print command or in another
file)?

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


Hi,Everyone: what's the most popular xml parser module on python?

2010-04-15 Thread Jo Chan
Hi, everyone~~~  I am new.
What is the most popular xml parser module used on python? Thanks for
answering...

-- 
--
Best Regards

陈松坚
信息科学与技术学院 中山大学 广州大学城 510006
Chen Songjian
School of Information Science & Technology
Sun Yat-sen(Zhongshan) University, Guangzhou Higher Education Mega Center,
China, 510006
Mobile: +86-137-6069-6137
Email:  csj...@gmail.com
-- 
http://mail.python.org/mailman/listinfo/python-list


test this maillist

2010-04-15 Thread 袁远松
I want to test how to use this maillist ,please reply to me,thank you !-- 
http://mail.python.org/mailman/listinfo/python-list


py2exe and msvcp90.dll

2010-04-15 Thread Alex Hall
Hi all,
I am still fighting with py2exe; I keep getting "error: msvcp90.dll:
no such file or directory" right after it says it is searching for
required dlls. I have followed the py2exe tutorial, though, and I am
not sure why it is not finding the dlls, which are in both
c:\windows\system32 and in mainFolder/dlls, where mainFolder is the
main folder of my project, containing setup.py. Here is my setup file:

from distutils.core import setup
import py2exe
from glob import glob
data_files=[("Microsoft.VC90.CRT", glob(r'c:\arm\dlls\*.*'))]
setup(data_files=data_files, console=['main.pyw'])

Of course, the location to glob is hard-coded. Also, I do not intend
this to have any console. Can I just omit the console argument? I
leave it in for now since the tutorial seems to indicate that such a
file is necessary, but I do not want to have one eventually. Thanks in
advance, as always! Oh, the entire source is at
http://www.gateway2somewhere.com/sw/sw.zip
as it usually is (and this time, I tested the link!).


-- 
Have a great day,
Alex (msg sent from GMail website)
mehg...@gmail.com; http://www.facebook.com/mehgcap
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Hi, Everyone: what's the most popular xml parser module on python?

2010-04-15 Thread Stefan Behnel

Jo Chan, 14.04.2010 15:28:

Hi, everyone~~~  I am new.
What is the most popular xml parser module used on python? Thanks for
answering...


Why do you want to know? Just out of curiosity, or are you looking for a 
tool that you can use to get a specific job done? If it's the latter, you 
may want to tell us what that job is, so that we can point you to a 
suitable tool.


Usually, parsing is only one part of a program that deals with XML.

Stefan

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


user rights and python com servers

2010-04-15 Thread sniffer
hi all,
i am facing a peculiar problem with a python com server i've developed
the com server runs fine in winxp  standalone systems but if the
system is part of a domain then until the logged in user is given
power user rights i am unable to register the dll using regsvr32 , a
similar problem i face on vista system here unless and untill the app
utilising the dll is run with admin privelleges the dll does not get
registered and does not function as a result.


any pointers on how to avoid this rights issue will be great also if
it is of some consequence i am using the python wmi module also in
this dll.

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


Re: Write web apps in Python?

2010-04-15 Thread Gilles Ganault
On Mon, 12 Apr 2010 05:37:54 -0700 (PDT), Luis M. González
 wrote:
>You should first investigate the different python web frameworks,
>choose one and then use the deployment options supported by your
>choice. These frameworks support several ways to deploy your apps,
>such as those you mentioned.

Thanks for the feedback. I wanted to have the big picture of the
different ways to write web applications in Python before checking the
different solutions.

So it looks like, unlike PHP, the prefered solution in Python is to
build a complete application as a long-running process, and either use
its embedded web server or configure a stand-alone web server to act
as reverse proxy using either FastCGI or WSGI to connect the two.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: msvcr90.dll is MIA?

2010-04-15 Thread Filip
Maybe this is a stupid question. I don't know, I don't use windows.
But what's so special about msvcr and visual studio compiler? Python
compiles fine with gcc under unixes, so is it a problem to compile
python interpreter with mingw and get rid of the proprietary runtime
dependecies? Or does the windows python port make heavy use of ms'
libs?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Hi, Everyone: what's the most popular xml parser module on python?

2010-04-15 Thread Shashwat Anand
BeautifulSoup

On Thu, Apr 15, 2010 at 1:39 PM, Stefan Behnel  wrote:

> Jo Chan, 14.04.2010 15:28:
>
>  Hi, everyone~~~  I am new.
>> What is the most popular xml parser module used on python? Thanks for
>> answering...
>>
>
> Why do you want to know? Just out of curiosity, or are you looking for a
> tool that you can use to get a specific job done? If it's the latter, you
> may want to tell us what that job is, so that we can point you to a suitable
> tool.
>
> Usually, parsing is only one part of a program that deals with XML.
>
> Stefan
>
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Hi, Everyone: what's the most popular xml parser module on python?

2010-04-15 Thread Stefan Behnel
Shashwat Anand, 15.04.2010 11:55:
> BeautifulSoup

The OP asked for an XML parser.

Stefan

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


Re: Hi, Everyone: what's the most popular xml parser module on python?

2010-04-15 Thread Shashwat Anand
BeatifulSoup can be used as one IMO

On Thu, Apr 15, 2010 at 3:50 PM, Stefan Behnel  wrote:

> Shashwat Anand, 15.04.2010 11:55:
> > BeautifulSoup
>
> The OP asked for an XML parser.
>
> Stefan
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Hi, Everyone: what's the most popular xml parser module on python?

2010-04-15 Thread Stefan Behnel

Shashwat Anand, 15.04.2010 12:29:

On Thu, Apr 15, 2010 at 3:50 PM, Stefan Behnel wrote:

Shashwat Anand, 15.04.2010 11:55:

BeautifulSoup


The OP asked for an XML parser.


BeatifulSoup can be used as one IMO


But it is not an XML parser according to the XML spec. So giving the 
impression that BeautifulSoup is a suitable tool to parse XML, and even 
presenting it under the headline of "the most popular xml parser module" is 
clearly misleading. For most tasks that involve XML as input, BeautifulSoup 
is not the right tool.


Stefan

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


Re: Write web apps in Python?

2010-04-15 Thread Bruno Desthuilliers

Gilles Ganault a écrit :

So it looks like, unlike PHP, the prefered solution in Python is to
build a complete application as a long-running process, and either use
its embedded web server or configure a stand-alone web server to act
as reverse proxy using either FastCGI or WSGI to connect the two.


Yeps. You'll find the same pattern with most general purpose programming 
languages, and specially OO ones.


The PHP execution model (mostly based on CGI FWIW) tends to be a bit 
unpractical for non-trivial applications since you have to rebuild the 
whole world for each and any incoming request, while with a long-running 
process, you load all your libs, parse your config etc only once.


Also, gateways like FastCGI or WSGI avoids being tied to a specific web 
server.

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


Re: Hi, Everyone: what's the most popular xml parser module on python?

2010-04-15 Thread Stefan Behnel
Jo Chan, 15.04.2010 10:52:
> I just want to get the content from a XML.

That's not a very specific description of what you want to do. What's "the
content"? The plain text content? Or do you care about the structure? And
what parts of the structure?


> I learn that there are two
> modules in python handling XML.(SAX and DOM)  Er, I just want to know if
> there is some open source tools for handling XML which is easier to use or
> has more powerful function.

Try xml.etree.ElementTree, it's certainly much easier to use than the two
above, and it's also in the stdlib. If you need more powerful features,
take a look at lxml.etree, which is a (mostly) compatible external package.


> By the way, besides  is there any great book for
> learning python?

That has been answered many times on this list. Check the archives, or look
through the book references at http://wiki.python.org

Stefan

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


Re: Windows installer of Python

2010-04-15 Thread moerchendiser2k3
Hm, I thought there will be installed something
like the Microsoft Redistributable 2008 Package to make Python run?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Tough sorting problem: or, I'm confusing myself

2010-04-15 Thread david jensen
On Apr 14, 6:06 pm, Raymond Hettinger  wrote:
> > I'm not sure a heap will help much, and at least to me,
> > doesn't improve readability.
>
> nlargest() should save quite a few comparisons and run much faster
> than sorted().
>
> Not sure what the readability issue is.  The phrase "nlargest(2,
> iterable)" does exactly what it says, finds the 2 largest elements
> from an iterable.  That makes the programmer's intent more clear than
> the slower, but semanticly equivalent form:  sorted(iterable)[:2].
>
> The running time for your algorithm can be very long, depending on the
> inputs.  Do you need an exact answer or can you approximate it with
> sampling random combinations (i.e. choose the best two scores out of
> 1 samples).
>
> Raymond


You are of course correct. I was running on lack of sleep. Thanks
again for having taken the time to help!
I need an exact answer, but don't anticipate 2**m or n to be huge so
even with e.g. m=10 and n=7 it should still be feasible. I can see how
sampling would become necessary if m is large though. Much larger, and
i'd have to think about optimizing the getValues function first
though.

thank you,
David
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: missing dll follow-up

2010-04-15 Thread Jonathan Hartley
Alex Hall wrote:
> The vcredist_x86 was, I thought, supposed to give me
> the dll, but it does not seem to have done so.

The installer puts the DLL in the directory C:\WINDOWS\WinSxS
(or at least it does for me, on WinXP) I shall update the py2exe
tutorial page to reflect this.

Under that dir, there are a lot of mangled directory names, and a
director called 'Manifests'. You can still discern the text
'Microsoft.VC90.CRT' and '9.0.21022.8' within the filenames of the DLL
dir and the manifest file that you want. I am no expert, but I think
if you are taking a copy of these to embed in your application, then
you can (must?) rename them to remove the mangling, as described on
the py2exe tutorial page.

If you still cannot find the DLL there, then try searching your
"Program Files" folder for a copy included with another application.
Several other Visual C/C++ applications include these runtime DLLs.
(eg. Console2 from sourceforge)

One other thing to keep in mind is that there is more than one version
of this DLL in the wild, all with the same filename. You absolutely
need the same version that Python 2.6 was compiled with, which is
9.0.21022.8. You can tell which version of the DLL you have got the
tooltip when hovering you mouse cursor over it. (also hovering over
the redistributable installer will tell you the same thing)

The original version of the redistributable installer does provide the
correct DLL version (this is the same thing as linked to above. This
is the English version):
http://www.microsoft.com/downloads/details.aspx?FamilyID=9b2da534-3e03-4391-8a4d-074b9f2bc1bf&displaylang=en

The SP1 version of the same installer provides a different version of
the DLL (but with the same filename). This will not work.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: missing dll follow-up

2010-04-15 Thread Jonathan Hartley
On Apr 15, 12:11 pm, Jonathan Hartley  wrote:
> Alex Hall wrote:
> > The vcredist_x86 was, I thought, supposed to give me
> > the dll, but it does not seem to have done so.
>
> The installer puts the DLL in the directory C:\WINDOWS\WinSxS
> (or at least it does for me, on WinXP) I shall update the py2exe
> tutorial page to reflect this.
>
> Under that dir, there are a lot of mangled directory names, and a
> director called 'Manifests'. You can still discern the text
> 'Microsoft.VC90.CRT' and '9.0.21022.8' within the filenames of the DLL
> dir and the manifest file that you want. I am no expert, but I think
> if you are taking a copy of these to embed in your application, then
> you can (must?) rename them to remove the mangling, as described on
> the py2exe tutorial page.
>
> If you still cannot find the DLL there, then try searching your
> "Program Files" folder for a copy included with another application.
> Several other Visual C/C++ applications include these runtime DLLs.
> (eg. Console2 from sourceforge)
>
> One other thing to keep in mind is that there is more than one version
> of this DLL in the wild, all with the same filename. You absolutely
> need the same version that Python 2.6 was compiled with, which is
> 9.0.21022.8. You can tell which version of the DLL you have got the
> tooltip when hovering you mouse cursor over it. (also hovering over
> the redistributable installer will tell you the same thing)
>
> The original version of the redistributable installer does provide the
> correct DLL version (this is the same thing as linked to above. This
> is the English 
> version):http://www.microsoft.com/downloads/details.aspx?FamilyID=9b2da534-3e0...
>
> The SP1 version of the same installer provides a different version of
> the DLL (but with the same filename). This will not work.

Oh, and, this is probably obvious and well-known, sorry if I'm
teaching grandmother to suck eggs here, but if you have rights to
distribute this DLL with your application, I understand this means
that you own a copy of Visual Studio, and a copy of the DLL and
manifest file can be found in the installed Visual Studio 'redist'
directory. If you don't have such a DLL in that directory (eg. if you
have the express edition) then you don't have legal right to
distribution it. Just so you know.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: missing dll follow-up

2010-04-15 Thread Jonathan Hartley
On Apr 15, 12:11 pm, Jonathan Hartley  wrote:
> The installer puts the DLL in the directory C:\WINDOWS\WinSxS
> (or at least it does for me, on WinXP) I shall update the py2exe
> tutorial page to reflect this.

Done. Final para of section 5.2.2 now reads:
"""
The installer puts a copy of the DLLs in the directory C:\WINDOWS
\WinSxS (XP), inside subdirectories with mangled names. The manifest
file is in the 'Manifests' subdirectory, again this will have a
mangled filename. You can still discern the text 'Microsoft.VC90.CRT'
and '9.0.21022.8' within the mangled file and directory names, to find
the files. It is possible to take a copy of these files and remove the
filename mangling, to embed them in your application as described in
5.2.1.
"""
Where section 5.2.1 begins, as it always has:
"""
If you do have the rights to redistribute MSVCR90.dll, there should be
a copy of it in your Visual Studio install, under VC\redist
\x86\Microsoft.VC90.CRT...
"""

http://www.py2exe.org/index.cgi/Tutorial#Step522
-- 
http://mail.python.org/mailman/listinfo/python-list


sqldict - You have a dict with unlimited capacity, what do you do? (it can store arbitrary objects too)

2010-04-15 Thread Krister Hedfors
sqldict - dict with sqlalchemy database-agnostic back-end

You can now create a dict out of arbitrary key/value columns of
any existing database table, in addition to ordinary dedicated
strict or auto-pickling sqldicts.

Basic use:
  $ easy_install sqldict
  $ easy_install sqlalchemy

  >>> from sqldict import sqldict
  >>> from sqlalchemy import *
  >>> #d0 = sqldict("mysql://user:p...@dbhost/dbname", "table0", create=1)
  >>> engine = create_engine("sqlite://")
  >>> d1 = sqldict(engine, "table1", create=1)
  >>> d2 = sqldict(engine, "table2", create=1, valtype=Integer)
  >>> contents = {"asd":123}
  >>> d1.update(contents)
  >>> d2.update(contents)
  >>> assert d1["asd"] == "123"
  >>> assert d2["asd"] == 123

Make dict from existing database table:

  >>> _ = engine.execute("create table asd (i integer, s varchar(50))")
  >>> _ = engine.execute("insert into asd values (42, 'gubbe')")
  >>> d3 = sqldict(engine, "asd", keycol="s", valcol="i")
  >>> d4 = sqldict(engine, "asd", keycol="i", valcol="s")
  >>> assert d3["gubbe"] == 42
  >>> assert d4[42] == "gubbe"

Key-val serializing and only val serializing sqldicts;
a's key column type is String, b's key column type is Integer.
The obvious use case for b is HUGE dicts where only integer
indexes are allowed:

  >>> a = sqldict(engine, "serty1", create=1, serialize=1)
  >>> b = sqldict(engine, "serty2", create=1, serialize=1, keytype=Integer)
  >>>
  >>> a[1] = (2,3)
  >>> assert a[1] == (2,3)
  >>> b[4] = (5,6)
  >>> assert b[4] == (5,6)

Have fun!
/Krister Hedfors
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: extract substring by regex from a text file

2010-04-15 Thread Neil Cerutti
On 2010-04-15, Alessio  wrote:
> Hi,
>
> I'm facing the problem in the subject:
> - I have a text file that I need to parse for producing a specifical
> string (Json like) extracting some information (substring) in it;
> - I created regural expressions capable to locate these substrings in
> my txt file;
>
> now I don't know how to continue. What is the best way to locate some
> string in a file and output them (with print command or in another
> file)?

grep

Or: show your work.

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


A question about the posibility of raise-yield in Python

2010-04-15 Thread Дамјан Георгиевски
I'm writing this as a complete newbie (on the issue), so don't be 
surprised if it's the stupidest idea ever.

I was wondering if there was ever a discusision in the python community 
on a 'raise-yield' kind-of combined expression. I'd like to know if it 
was proposed/rejected/discussed/not-decided yet??


A 'raise-yield' expression would break the flow of a program just like 
an exception, going up the call stack until it would be handled, but 
also like yield it would be possible to continue the flow of the program 
from where it was raise-yield-ed.

This would be usefull for example in event based frameworks, they could 
just replace socket.* and similar, normally blocking, modules/functions 
with it's own 'raise-yield' enabled ones.

Then you could just take any normal imperative code that calls normal 
library networking code (say smtplib, poplib or httplib) nad run it in a 
event framework.
The normal xxxlib calls at some point would get to the now non-blocking, 
event based socket write/read, break the flow back to the event 
framework, and when it finishes the event framework would continue the 
normal flow of the program past the raise-yield.





-- 
дамјан ((( http://damjan.softver.org.mk/ )))

When you do things right, people won't be sure if you did anything at 
all.

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


Re: Object serialization: transfer from a to b (non-implemented code on b)

2010-04-15 Thread Gabriel Rossetti

Andreas Löscher wrote:

Am Mittwoch, den 14.04.2010, 11:33 +0200 schrieb Gabriel Rossetti:
  

Paul Rubin wrote:


Gabriel Rossetti  writes:
  
  

I am trying to serialize a function, class, etc and transfer it



You mean the actual code?  You have to use marshal rather than pickle,
the Python versions have to be the same at both ends, and you better
have some kind of authenticated transport to stop malicious code from
getting accepted and run by the receiving end.
  
  
Yes, but I wasn't able to marshal/unmarshal them correctly as shown in 
my examples



The marshal module can be used to dump the Code of an Function (or
anything else), like you have done. If you have the Code, you can
reconstruct the function.

  

import types
import marshal
def a(): pass

... 
  

s=marshal.dumps(a.__code__)
f=types.FunctionType(marshal.loads(s), {})
f



  


What version of python do you have? If I try your code above I get :

>>> import types
>>> import marshal
>>> def a(): pass
...
>>> s=marshal.dumps(a.__code__)
Traceback (most recent call last):
 File "", line 1, in 
AttributeError: 'function' object has no attribute '__code__'



The second parameter is the global scoop of the function.

If you want to marshal a class, things get a little more complicated,
because these consist of many code objects and you also need the code 
to assemble them together.


There are two easy ways I can think of right now:

1.
Send the string of the code you want to transfer:
  

s="""class A: pass"""



and then:
  

exec(s) in globals()



2.
Encapsule the stuff you want to send in a function.


Best,
Andreas

  

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


Re: Hi, Everyone: what's the most popular xml parser module on python?

2010-04-15 Thread Jo Chan
On Thu, Apr 15, 2010 at 6:52 PM, Stefan Behnel  wrote:

> Jo Chan, 15.04.2010 10:52:
> > I just want to get the content from a XML.
>
> That's not a very specific description of what you want to do. What's "the
> content"? The plain text content? Or do you care about the structure? And
> what parts of the structure?
>
>
> > I learn that there are two
> > modules in python handling XML.(SAX and DOM)  Er, I just want to know if
> > there is some open source tools for handling XML which is easier to use
> or
> > has more powerful function.
>
> Try xml.etree.ElementTree, it's certainly much easier to use than the two
> above, and it's also in the stdlib. If you need more powerful features,
> take a look at lxml.etree, which is a (mostly) compatible external package.
>
>
> > By the way, besides  is there any great book for
> > learning python?
>
> That has been answered many times on this list. Check the archives, or look
> through the book references at http://wiki.python.org
>
> Stefan
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>



-- 
--
Best Regards

陈松坚
信息科学与技术学院 中山大学 广州大学城 510006
Chen Songjian
School of Information Science & Technology
Sun Yat-sen(Zhongshan) University, Guangzhou Higher Education Mega Center,
China, 510006
Mobile: +86-137-6069-6137
Email:  csj...@gmail.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Hi, Everyone: what's the most popular xml parser module on python?

2010-04-15 Thread Jo Chan
I want to say I just have to deal with some regular text input (the input
file is as XML format) so I need to read all the nodes out and get what they
are.

Thanks for your great help though. I should have made my point clearer. :)

On Thu, Apr 15, 2010 at 6:52 PM, Stefan Behnel  wrote:

> Jo Chan, 15.04.2010 10:52:
> > I just want to get the content from a XML.
>
> That's not a very specific description of what you want to do. What's "the
> content"? The plain text content? Or do you care about the structure? And
> what parts of the structure?
>
>
> > I learn that there are two
> > modules in python handling XML.(SAX and DOM)  Er, I just want to know if
> > there is some open source tools for handling XML which is easier to use
> or
> > has more powerful function.
>
> Try xml.etree.ElementTree, it's certainly much easier to use than the two
> above, and it's also in the stdlib. If you need more powerful features,
> take a look at lxml.etree, which is a (mostly) compatible external package.
>
>
> > By the way, besides  is there any great book for
> > learning python?
>
> That has been answered many times on this list. Check the archives, or look
> through the book references at http://wiki.python.org
>
> Stefan
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>



-- 
--
Best Regards

陈松坚
信息科学与技术学院 中山大学 广州大学城 510006
Chen Songjian
School of Information Science & Technology
Sun Yat-sen(Zhongshan) University, Guangzhou Higher Education Mega Center,
China, 510006
Mobile: +86-137-6069-6137
Email:  csj...@gmail.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: C-style static variables in Python?

2010-04-15 Thread Albert van der Horst
In article ,
Steve Holden   wrote:
>Terry Reedy wrote:
>> On 4/1/2010 6:34 PM, kj wrote:
>>>
>>>
>>> When coding C I have often found static local variables useful for
>>> doing once-only run-time initializations.  For example:
>>>
>>> int foo(int x, int y, int z) {
>>>
>>>static int first_time = TRUE;
>>>static Mongo *mongo;
>>>if (first_time) {
>>>  mongo = heavy_lifting_at_runtime();
>>>  first_time = FALSE;
>>>}
>>>
>>>return frobnicate(mongo, x, y, z);
>>
>> Global var or class or closure such as below (obviously untested ;=):
>>
>> make_foo()
>>   mongo = heavy_lifting_at_runtime();
>>   def _(x,y,z):
>> return frobnicate(mongo, x, y, z)
>>   return _
>> foo = make_foo
>
>I suspect you mean
>
>foo = make_foo()
>
>> del make_foo # to make sure it is *never* called again ;
>>
>> Now you only have foo with a hard-to-access private object and no
>> first_time checks when you call it.
>>
>> Terry Jan Reedy
>>
>I don't think I'd ever want to use such an obscure technique in a
>program. You might want to consider using functools.wraps to make sure
>that the foo function looks right.

Imagine that heavy_lifting is only ever used here and uses 4 Gbyte of core.
Suddenly deleting those function objects seems the right thing to do,
instead of an obscure technique.
(I'm not sure the Python compiler could take advantage of this,
I know I could in my Forth compiler, under circumstances.)

>
>regards
> Steve
>--
>Steve Holden   +1 571 484 6266   +1 800 494 3119

Groetjes Albert

--
-- 
Albert van der Horst, UTRECHT,THE NETHERLANDS
Economic growth -- being exponential -- ultimately falters.
alb...@spe&ar&c.xs4all.nl &=n http://home.hccnet.nl/a.w.m.van.der.horst

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


pylint bugs day #2 tomorrow

2010-04-15 Thread Sylvain Thénault
Hi there,

just a quick note to remind pylint felows that we will hold
the second pylint bugs day tomorrow, from about 8am to 18pm
UTC+2. See you on our jabber forum or in our paris office!

-- 
Sylvain Thénault   LOGILAB, Paris (France)
Formations Python, Debian, Méth. Agiles: http://www.logilab.fr/formations
Développement logiciel sur mesure:   http://www.logilab.fr/services
CubicWeb, the semantic web framework:http://www.cubicweb.org

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


Re: lambda with floats

2010-04-15 Thread Albert van der Horst
In article <3790faeb-ae4c-4b45-b0a6-41cb32e46...@k13g2000yqe.googlegroups.com>,
Patrick Maupin   wrote:
>On Apr 6, 11:10=A0pm, Patrick Maupin  wrote:
>> On Apr 6, 11:04=A0pm, Patrick Maupin  wrote:
>>
>>
>>
>> > On Apr 6, 10:16=A0pm, monkeys paw  wrote:
>>
>> > > I have the following acre meter which works for integers,
>> > > how do i convert this to float? I tried
>>
>> > > return float ((208.0 * 208.0) * n)
>>
>> > > =A0>>> def s(n):
>> > > ... =A0 =A0 return lambda x: (208 * 208) * n
>> > > ...
>> > > =A0>>> f =3D s(1)
>> > > =A0>>> f(1)
>> > > 43264
>> > > =A0>>> 208 * 208
>> > > 43264
>> > > =A0>>> f(.25)
>> > > 43264
>>
>> > Not sure why you are returning a lambda (which is just a function that
>> > does not have a name) from an outer function.
>>
>> > A function that does this multiplication would simply be:
>>
>> > def s(n):
>> > =A0 =A0 return 208.0 * 208.0 * n
>>
>> > Regards,
>> > Pat
>>
>> I realized I didn't show the use. =A0A bit different than what you were
>> doing:
>>
>> >>> def s(n):
>>
>> ... =A0 =A0 return 208.0 * 208.0 * n
>> ...>>> s(1)
>> 43264.0
>> >>> s(0.5)
>> 21632.0
>> >>> s(3)
>>
>> 129792.0
>>
>> I'm not sure exactly what you mean by "acre meter" though; this
>> returns the number of square feet in 'n' acres.
>>
>> Regards,
>> Pat
>
>I should stop making a habit of responding to myself, BUT.  This isn't
>quite an acre in square feet.  I just saw the 43xxx and assumed it
>was, and then realized it couldn't be, because it wasn't divisible by
>10.  (I used to measure land with my grandfather with a 66 foot long
>chain, and learned at an early age that an acre was 1 chain by 10
>chains, or 66 * 66 * 10 =3D 43560 sqft.)
>That's an exact number, and 208 is a poor approximation of its square
>root.

208 = 2^6 * 13^2

66 = 2 * 3 * 11

Now I understand why the state of Wisconsin wants to drop out of
the USA and join the EU ;-)

>
>Regards,
>Pat

Groetjes Albert

--
-- 
Albert van der Horst, UTRECHT,THE NETHERLANDS
Economic growth -- being exponential -- ultimately falters.
alb...@spe&ar&c.xs4all.nl &=n http://home.hccnet.nl/a.w.m.van.der.horst

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


Re: Object serialization: transfer from a to b (non-implemented code on b)

2010-04-15 Thread Andreas Löscher
>  import types
>  import marshal
>  def a(): pass
>  
> > ... 
> >   
>  s=marshal.dumps(a.__code__)
>  f=types.FunctionType(marshal.loads(s), {})
>  f
>  
> > 
> >   
> 
> What version of python do you have? If I try your code above I get :
> 
>  >>> import types
>  >>> import marshal
>  >>> def a(): pass
> ...
>  >>> s=marshal.dumps(a.__code__)
> Traceback (most recent call last):
>   File "", line 1, in 
> AttributeError: 'function' object has no attribute '__code__'
> 

I used Version 2.6 for this. __code__ is just an alias for func_code.

>>> def a(): pass
...
>>> s=marshal.dumps(a.func_code)

This should allways work, unless the implementation of the function
object changes. (I have tested it under 2.4, 2.5 and 2.6, but it should
also work in further versions)

Best,
Andreas

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


Re: regular expressions

2010-04-15 Thread Terry Reedy

On 4/15/2010 2:57 AM, chaaana wrote:

hi..
im parsing the text file containing the details of the testcases
failed.From the file i wanted to obtain only the testcase names and
enter them in the excel sheet.

the pattern of the text file is:

FILE : NW_PTH_TFG6_SCEN_4_2_FIFO.c, LINE : 240 TEST FAIL to get entire:
32768 bytes
NW_PTH_TFG6_SCEN_4_2_FIFO.c 340 DATA NOT MATCHING, TEST FAIL
TEST FAIL SYSCALL_TEST_SCEN_4_1_ALL.c at line 355
FILE:US_TFG7_SCEN_4_1.c,LINE:189, Server side TEST FAIL
FAIL BREW_SCEN_4_1.c 219: can't mount
FAIL BREW_SCEN_4_1.c 121: can't umount
<<  BREW_SCEN_4_1.c TEST FAIL errno:No such file or directory>>
<<  BREW_SCEN_4_1.c TEST FAIL>>  error:Invalid argument


I do not see any consistent pattern in the above lines.
What output do you see from filtering them?


i used the ' re module' and its function partition,but im facing
problem in obtaining only the testcase names..


If I could not write a satisfactory re, I would be tempted to write 
explicit code to process the lines, possibly defining appropriate search 
states.


Terry Jan Reedy

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


Re: Write web apps in Python?

2010-04-15 Thread Gilles Ganault
On Thu, 15 Apr 2010 12:41:56 +0200, Bruno Desthuilliers
 wrote:
>The PHP execution model (mostly based on CGI FWIW) tends to be a bit 
>unpractical for non-trivial applications since you have to rebuild the 
>whole world for each and any incoming request, while with a long-running 
>process, you load all your libs, parse your config etc only once.

Apart from the ease of having the application run at all times, I'd be
curious to read about an application that was written in PHP and then
a long-running process and see if performance improved.

Regardless, Python has an easier syntax, so AFAIC, that's already a
good enough reason to use this to write web apps.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: A question about the posibility of raise-yield in Python

2010-04-15 Thread Terry Reedy

On 4/15/2010 9:34 AM, Дамјан Георгиевски wrote:

I'm writing this as a complete newbie (on the issue), so don't be
surprised if it's the stupidest idea ever.

I was wondering if there was ever a discusision in the python community
on a 'raise-yield' kind-of combined expression. I'd like to know if it
was proposed/rejected/discussed/not-decided yet??



The idea of resumable exceptions has been discussed and so far rejected. 
I presume the cost in complication of both the language and 
implementations is seen as too high.



A 'raise-yield' expression would break the flow of a program just like
an exception, going up the call stack until it would be handled, but
also like yield it would be possible to continue the flow of the program
from where it was raise-yield-ed.

This would be usefull for example in event based frameworks, they could
just replace socket.* and similar, normally blocking, modules/functions
with it's own 'raise-yield' enabled ones.

Then you could just take any normal imperative code that calls normal
library networking code (say smtplib, poplib or httplib) nad run it in a
event framework.
The normal xxxlib calls at some point would get to the now non-blocking,
event based socket write/read, break the flow back to the event
framework, and when it finishes the event framework would continue the
normal flow of the program past the raise-yield.



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


Re: py2exe and msvcp90.dll

2010-04-15 Thread Gaicitadie
On 4月15日, 下午12时19分, Alex Hall  wrote:
> Hi all,
> I am still fighting with py2exe; I keep getting "error: msvcp90.dll:
> no such file or directory" right after it says it is searching for
> required dlls. I have followed the py2exe tutorial, though, and I am
> not sure why it is not finding the dlls, which are in both
> c:\windows\system32 and in mainFolder/dlls, where mainFolder is the
> main folder of my project, containing setup.py. Here is my setup file:
>
> from distutils.core import setup
> import py2exe
> from glob import glob
> data_files=[("Microsoft.VC90.CRT", glob(r'c:\arm\dlls\*.*'))]
> setup(data_files=data_files, console=['main.pyw'])
>
> Of course, the location to glob is hard-coded. Also, I do not intend
> this to have any console. Can I just omit the console argument? I
> leave it in for now since the tutorial seems to indicate that such a
> file is necessary, but I do not want to have one eventually. Thanks in
> advance, as always! Oh, the entire source is 
> athttp://www.gateway2somewhere.com/sw/sw.zip
> as it usually is (and this time, I tested the link!).
>
> --
> Have a great day,
> Alex (msg sent from GMail website)
> mehg...@gmail.com;http://www.facebook.com/mehgcap

you can use python2.5
-- 
http://mail.python.org/mailman/listinfo/python-list


Urllib2 urlopen and read - difference

2010-04-15 Thread koranthala
Hi,
   Suppose I am doing the following:
req = urllib2.urlopen('http://www.python.org')
data = req.read()

   When is the actual data received? is it done by the first line? or
is it done only when req.read() is used?
  My understanding is that when urlopen is done itself, we would have
received all the data, and req.read() just reads it from the file
descriptor.
  But, when I read the source code of pylot, it mentioned the
following:
resp = opener.open(request)  # this sends the HTTP request
and returns as soon as it is done connecting and sending
connect_end_time = self.default_timer()
content = resp.read()
req_end_time = self.default_timer()

Here, it seems to suggest that the data is received only after you do
resp.read(), which made me all confused.

If someone could help me out, it would be much helpful.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: regular expressions

2010-04-15 Thread Tim Chase

On 04/15/2010 11:05 AM, Terry Reedy wrote:

On 4/15/2010 2:57 AM, chaaana wrote:

hi..
im parsing the text file containing the details of the testcases
failed.From the file i wanted to obtain only the testcase names and
enter them in the excel sheet.

the pattern of the text file is:

FILE : NW_PTH_TFG6_SCEN_4_2_FIFO.c, LINE : 240 TEST FAIL to get entire:
32768 bytes
NW_PTH_TFG6_SCEN_4_2_FIFO.c 340 DATA NOT MATCHING, TEST FAIL
TEST FAIL SYSCALL_TEST_SCEN_4_1_ALL.c at line 355
FILE:US_TFG7_SCEN_4_1.c,LINE:189, Server side TEST FAIL
FAIL BREW_SCEN_4_1.c 219: can't mount
FAIL BREW_SCEN_4_1.c 121: can't umount
<<   BREW_SCEN_4_1.c TEST FAIL errno:No such file or directory>>
<<   BREW_SCEN_4_1.c TEST FAIL>>   error:Invalid argument


I do not see any consistent pattern in the above lines.
What output do you see from filtering them?


My guess is that it's the "FILE:...LINE:..." line(s) that the OP 
is interested in, in which case one could do something like


  r = re.compile(r'^FILE\s*:\s*(.*?),\s*LINE\s*:\s*(\d+)')
  for line in file('input.txt'):
m = r.match(line)
if m:
  print m.group(1), m.group(2)

Alternatively, if you're in the regexp-avoiding camp, you might 
be able to get away with


  LINE_BIT = ', LINE : '
  for line in file('input.txt'):
if line.startswith('FILE :') and LINE_BIT in line:
  leader, _ = line.split(LINE_BIT, 1)
  _, fname = leader.split(":", 1)
  fname = fname.strip()
  print repr(fname)

but that relies on the LINE_BIT remaining constant (the 
"LINE:189" doesn't have spaces where the first "LINE : 240" does 
have extra spaces; and the same with the extra spaces around the 
"FILE" portion).


-tkc




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


Re: Urllib2 urlopen and read - difference

2010-04-15 Thread J. Cliff Dyer
On Thu, 2010-04-15 at 11:25 -0700, koranthala wrote:
> Hi,
>Suppose I am doing the following:
> req = urllib2.urlopen('http://www.python.org')
> data = req.read()
> 
>When is the actual data received? is it done by the first line? or
> is it done only when req.read() is used?
>   My understanding is that when urlopen is done itself, we would have
> received all the data, and req.read() just reads it from the file
> descriptor.
>   But, when I read the source code of pylot, it mentioned the
> following:
> resp = opener.open(request)  # this sends the HTTP request
> and returns as soon as it is done connecting and sending
> connect_end_time = self.default_timer()
> content = resp.read()
> req_end_time = self.default_timer()
> 
> Here, it seems to suggest that the data is received only after you do
> resp.read(), which made me all confused.
> 
> If someone could help me out, it would be much helpful.

My understanding (please correct me if I'm wrong), is that when you call
open, you send a request to the server, and get a response object back.
The server immediately begins sending data (you can't control when they
send it, once you've requested it).  When you call read() on your
response object, it reads all the data it has already received, and if
that amount of data isn't sufficient to handle your read call, it blocks
until it has enough.

So your opener returns as soon as the request is sent, and read() blocks
if it doesn't have enough data to handle your request.

Cheers,
Cliff

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


Re: Urllib2 urlopen and read - difference

2010-04-15 Thread J. Cliff Dyer
On Thu, 2010-04-15 at 11:25 -0700, koranthala wrote:
> Hi,
>Suppose I am doing the following:
> req = urllib2.urlopen('http://www.python.org')
> data = req.read()
> 
>When is the actual data received? is it done by the first line? or
> is it done only when req.read() is used?
>   My understanding is that when urlopen is done itself, we would have
> received all the data, and req.read() just reads it from the file
> descriptor.
>   But, when I read the source code of pylot, it mentioned the
> following:
> resp = opener.open(request)  # this sends the HTTP request
> and returns as soon as it is done connecting and sending
> connect_end_time = self.default_timer()
> content = resp.read()
> req_end_time = self.default_timer()
> 
> Here, it seems to suggest that the data is received only after you do
> resp.read(), which made me all confused.
> 
> If someone could help me out, it would be much helpful.

My understanding (please correct me if I'm wrong), is that when you call
open, you send a request to the server, and get a response object back.
The server immediately begins sending data (you can't control when they
send it, once you've requested it).  When you call read() on your
response object, it reads all the data it has already received, and if
that amount of data isn't sufficient to handle your read call, it blocks
until it has enough.

So your opener returns as soon as the request is sent, and read() blocks
if it doesn't have enough data to handle your request.

Cheers,
Cliff


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


feature request for a wget -r like implementation in python3

2010-04-15 Thread gert
So I can make a recursive http download script
My goal is a one click instruction to install and launch my project
http://code.google.com/p/appwsgi/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Suppress output to stdout/stderr in InteractiveInterpreter

2010-04-15 Thread Dave W.
> > I thought I could get away with importing print_function
> > from __future__ ... but my re-pointed print function never gets
> > called.

> -snip-

> >def __enter__(self):
> >print = self.printhook

> That redefines the print function local to __enter__.  You need to
> change the global value of print.

Thanks for the clue.  I had actually tried using 'global print' in
the __enter__ function, but it broke my tests even worse so I
figured I must not need it. :-} After your reply, I went back and
discovered that everything was actually working fine with 'global'
in place---except my automated tests break.  So I just have a little
mystery to solve regarding how execution using nose differs from
running the app manually.

> from contextlib import contextmanager

Hey, thanks for that gem!  I didn't know about this clever little
module---really useful!
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: py2exe and msvcp90.dll

2010-04-15 Thread Joaquin Abian
On Apr 15, 6:19 am, Alex Hall  wrote:
> Hi all,
> I am still fighting with py2exe; I keep getting "error: msvcp90.dll:
> no such file or directory" right after it says it is searching for
> required dlls. I have followed the py2exe tutorial, though, and I am
> not sure why it is not finding the dlls, which are in both
> c:\windows\system32 and in mainFolder/dlls, where mainFolder is the
> main folder of my project, containing setup.py. Here is my setup file:
>
> from distutils.core import setup
> import py2exe
> from glob import glob
> data_files=[("Microsoft.VC90.CRT", glob(r'c:\arm\dlls\*.*'))]
> setup(data_files=data_files, console=['main.pyw'])
>
> Of course, the location to glob is hard-coded. Also, I do not intend
> this to have any console. Can I just omit the console argument? I
> leave it in for now since the tutorial seems to indicate that such a
> file is necessary, but I do not want to have one eventually. Thanks in
> advance, as always! Oh, the entire source is 
> athttp://www.gateway2somewhere.com/sw/sw.zip
> as it usually is (and this time, I tested the link!).
>
> --
> Have a great day,
> Alex (msg sent from GMail website)
> mehg...@gmail.com;http://www.facebook.com/mehgcap


Did you already checked 
http://stackoverflow.com/questions/323424/py2exe-fails-to-generate-an-executable
and the links there?.

I am a heavy user of py2exe in winxp with python2.5. It works great
producing single executables  with matplotlib, wxpython, and others.

Please report if you get your problem fixed. Sure will be helpful for
everybody

Luck

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


python wia and RegisterEvent

2010-04-15 Thread gelonida
Hi,

I'd like to register an event in order to be informed, whenever a
Windows WIA device is connected or disconnected.

In python I can use WIA devices, but I don't know how to register
events

I have existing C# code, which works and looks like.

   class MgrHandlerClass
{
public void devManager_OnEvent(string eventID, string
deviceID, string itemID)
{} // her emy handler code

public void addhandler(DeviceManager manager)
{
Console.WriteLine("adding handler!");
manager.OnEvent += new
WIA._IDeviceManagerEvents_OnEventEventHandler(
devManager_OnEvent);
}

static void Main(string[] args)
{

MgrHandlerClass mgrhndlr;
mgrhndlr = new MgrClass();
DeviceManager manager;

 manager = new DeviceManagerClass();
 
manager.RegisterEvent(WIA.EventID.wiaEventDeviceConnected, "*");
 
manager.RegisterEvent(WIA.EventID.wiaEventDeviceDisconnected, "*");
 mgrhndlr.addhandler(manager);
// wait for callbacks or do other stuff
}


Now in python I'm stuck

import win32com.client
import wia_defs # created with makepy.py
manager = win32com.client.Dispatch("WIA.DeviceManager")
mgrhndlr = MgrClass()
manager.RegisterEvent(EventID=constants.wiaEventDeviceConnected,DeviceID=u'*')
manager.RegisterEvent(EventID=constants.wiaEventDeviceDisconnected,DeviceID=u'*')
mgrhndlr.addhandler(manager)


class MgrHandlerClass:
def OnEvent(self, EventID=defaultNamedNotOptArg,
DeviceID=defaultNamedNotOptArg, ItemID=defaultNamedNotOptArg):
print "Called back with (%s) (%s) (%s)" %
(EventID,DeviceID,ItemID)

def addhandler(self,manager):
# here I'm stuck :-(
# the following line doesn't work as it seems, that manager
does not have attr
# onevent
 
manager.OnEvent.append( 
WIA._IDeviceManagerEvents_OnEventEventHandler(self.OnEvent) )



The autogenerated file contains:
class IDeviceManager(DispatchBaseClass):
CLSID = IID('{73856D9A-2720-487A-A584-21D5774E9D0F}')
coclass_clsid = IID('{E1C5D730-7E97-4D8A-9E42-BBAE87C2059F}')

def RegisterEvent(self, EventID=defaultNamedNotOptArg,
DeviceID=u'*'):
"""Registers the specified EventID for the specified DeviceID. 
If
DeviceID is "*" then OnEvent will be called whenever the event
specified occurs for any device. Otherwise, OnEvent will only be
called if the event specified occurs on the device specified."""
return self._ApplyTypes_(2, 1, (24, 32), ((8, 1), (8, 49)),
u'RegisterEvent', None,EventID
, DeviceID)



but I do not know where to place (how to create the function)
OnEvent()


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


Re: Windows installer of Python

2010-04-15 Thread Martin v. Loewis
moerchendiser2k3 wrote:
> Hm, I thought there will be installed something
> like the Microsoft Redistributable 2008 Package to make Python run?

No, the Python installer integrates the Microsoft Merge Module for the
Visual Studio Runtime Dynamic Link Libraries. That removes the need to
install the Microsoft Redistributable Package.

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


Re: ctypes question

2010-04-15 Thread Brendan Miller
On Wed, Apr 14, 2010 at 12:12 PM, Mark Dickinson  wrote:
> On Apr 14, 7:09 pm, Brendan Miller  wrote:
>> I'm using python 2.5.2.
>>
>> I have a ctypes function with argtypes like this:
>>
>> _create_folder.argyptes = [c_void_p, c_int]
>
> Is that line a cut-and-paste?  If so, try 'argtypes' instead of
> 'argyptes'.  :)

Woops! Well, nice to know that ctypes works as I expect.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Suppress output to stdout/stderr in InteractiveInterpreter

2010-04-15 Thread Dave W.
> After your reply, I went back and
> discovered that everything was actually working fine with 'global'
> in place 

Oops, I lied.  It still doesn't work.  It doesn't seem possible (or
at least not easy) to *globally* override the built-in print
function.  The best I've managed to do is override it for the
current module.

Think I'll start a new post with the subject: "Globally override
built-in print function?"
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: py2exe and msvcp90.dll

2010-04-15 Thread Waldemar Osuch
On Apr 14, 10:19 pm, Alex Hall  wrote:
> Hi all,
> I am still fighting with py2exe; I keep getting "error: msvcp90.dll:
> no such file or directory" right after it says it is searching for
> required dlls. I have followed the py2exe tutorial, though, and I am
> not sure why it is not finding the dlls, which are in both
> c:\windows\system32 and in mainFolder/dlls, where mainFolder is the
> main folder of my project, containing setup.py. Here is my setup file:
>
> from distutils.core import setup
> import py2exe
> from glob import glob
> data_files=[("Microsoft.VC90.CRT", glob(r'c:\arm\dlls\*.*'))]
> setup(data_files=data_files, console=['main.pyw'])
>
> Of course, the location to glob is hard-coded. Also, I do not intend
> this to have any console. Can I just omit the console argument? I
> leave it in for now since the tutorial seems to indicate that such a
> file is necessary, but I do not want to have one eventually. Thanks in
> advance, as always! Oh, the entire source is 
> athttp://www.gateway2somewhere.com/sw/sw.zip
> as it usually is (and this time, I tested the link!).
>
> --
> Have a great day,
> Alex (msg sent from GMail website)
> mehg...@gmail.com;http://www.facebook.com/mehgcap

Did you see http://www.py2exe.org/index.cgi/Tutorial#Step52 ?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Suppress output to stdout/stderr in InteractiveInterpreter

2010-04-15 Thread Robert Kern

On 2010-04-15 17:54 PM, Dave W. wrote:

 After your reply, I went back and
discovered that everything was actually working fine with 'global'
in place


Oops, I lied.  It still doesn't work.  It doesn't seem possible (or
at least not easy) to *globally* override the built-in print
function.  The best I've managed to do is override it for the
current module.

Think I'll start a new post with the subject: "Globally override
built-in print function?"


Don't bother. Replacing sys.stdout is the right thing to do. It won't interfere 
with the C++ streams but it will take care of some potential Python output that 
does not go through the print() function.


--
Robert Kern

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

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


Globally override built-in print function?

2010-04-15 Thread Dave W.
I naively thought I could capture output from exec()'ed print
invocations by (somehow) overriding 'print' globally.  But this
seems not to be possible.  Or at least not easy:

c:\d>test.py
Python 2.6.2 (r262:71605, Apr 14 2009, 22:40:02) [MSC v.1500 32 bit
(Intel)] win32
Type "help", "copyright", "credits" or "license" for more info.
>>> print("Hello?")
Hello?
>>>

My custom print function isn't being called (see code below),
I guess because its only being overridden in the current module?
Is there some way to make InteractiveInterpreter/exec use my print
function, or is this simply not possible?

--

### File test.py ###
from __future__ import print_function
import sys
from code import InteractiveInterpreter
from contextlib import contextmanager

def printhook(*args):
sys.stdout.write("printhook(): {0}\n".format(repr(args[0])))

@contextmanager
def global_printhook(printhook):
global print
print = printhook
yield
print = __builtins__.print

py = InteractiveInterpreter()

if not hasattr(sys, "ps1"): sys.ps1 = ">>> "
if not hasattr(sys, "ps2"): sys.ps2 = "... "

banner = ("Python %s\n%s\n" % (sys.version, sys.platform) +
  'Type "help", "copyright", "credits" or "license" '
  'for more info.\n')

sys.stdout.write(banner)
sys.stdout.write(sys.ps1)
while True:
try:
with global_printhook(printhook):
result = py.runsource(raw_input())
if result is None:
sys.stdout.write(sys.ps2)
elif result is True:
py.runcode(result)
except EOFError:
break
else:
sys.stdout.write(sys.ps1)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Globally override built-in print function?

2010-04-15 Thread Robert Kern

On 2010-04-15 18:08 PM, Dave W. wrote:

I naively thought I could capture output from exec()'ed print
invocations by (somehow) overriding 'print' globally.  But this
seems not to be possible.  Or at least not easy:

c:\d>test.py
Python 2.6.2 (r262:71605, Apr 14 2009, 22:40:02) [MSC v.1500 32 bit
(Intel)] win32
Type "help", "copyright", "credits" or "license" for more info.

print("Hello?")

Hello?




My custom print function isn't being called (see code below),
I guess because its only being overridden in the current module?
Is there some way to make InteractiveInterpreter/exec use my print
function, or is this simply not possible?

--

### File test.py ###
from __future__ import print_function
import sys
from code import InteractiveInterpreter
from contextlib import contextmanager

def printhook(*args):
 sys.stdout.write("printhook(): {0}\n".format(repr(args[0])))

@contextmanager
def global_printhook(printhook):
 global print
 print = printhook
 yield
 print = __builtins__.print


  old_print = __builtins__.print
  __builtins__.print = printhook
  yield
  __builtins__.print = old_print

But you really should replace sys.stdout and sys.stderr instead.

--
Robert Kern

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

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


how to get elements of a com object (wmi log events)

2010-04-15 Thread News123
Just having  a short question:

I found a code snippet, that fetches windows event logs via a wmi query.

import win32com.client

strComputer = "."
objWMIService = win32com.client.Dispatch("WbemScripting.SWbemLocator")
objSWbemServices = objWMIService.ConnectServer(strComputer,"root\cimv2")
colItems = objSWbemServices.ExecQuery("Select * from Win32_NTLogEvent")

for i,itm in enumerate(colItems):
entry =( itm.TimeGenerated,itm.TimeWritten,
itm.Category,itm.CategoryString,itm.ComputerName,
itm.Data,itm.EventCode,itm.EventIdentifier,
itm.EventType,itm.InsertionStrings,itm.LogFile,
   itm.Message,itm.RecordNumber,
   itm.SourceName,itm.Type,itm.User)
print entry

Asumming I would not have no documentation, I would be too lazy to
lookup or to type all this code.

Would there be any way to query the list of members
( TimeGenerated , TimeWritten, . . . ) of variable itm?


thanks upfront



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


py2exe saga continues...

2010-04-15 Thread Alex Hall
Hi all,
I started a new thread as I already have several out there, all
talking about basically the same thing. After re-visiting a
StackOverflow post, thanks to the person who gave me that link, I
tossed msvcp90.dll and msvcr90.dll (I use wx) into c:\python26\dlls
and it now compiles! I think I kept thinking that all I needed was to
have the dll files in *my own program folder*. I now have an exe file
which, after doing more globbing of a configuration file and some
other dlls I need, does exactly what I wanted it to do. I now have a
couple questions so I can fine-tune this:
1. Is there a way to start with no command line window popping up? My
main script is a pyw, but it still shows a dos window when the
generated .exe file is clicked. Leaving out the "console" parameter of
setup, though, results in no .exe file at all, so I had to put it
back. I want what I have heard called a "silent startup", where the
program starts but it does not pop up anything. My users will know
because I will speak a message, but I want to dump the dos window.

2. Is there a way to put the exe in a higher-level dir, then put all
the pyd, dll, zip, and other files into a subdirectory so the .exe is
not mixed in with all these files that most users will not care about?
Thank you for all your help over the last few days!!

-- 
Have a great day,
Alex (msg sent from GMail website)
mehg...@gmail.com; http://www.facebook.com/mehgcap
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: msvcr90.dll is MIA?

2010-04-15 Thread Neil Hodgson
Filip:
> But what's so special about msvcr and visual studio compiler? Python
> compiles fine with gcc under unixes, so is it a problem to compile
> python interpreter with mingw and get rid of the proprietary runtime
> dependecies?

   MinGW uses an older version of Microsoft's runtime MSVCRT.DLL. While
MSVCRT.DLL is present in all commonly used versions of Windows, the
particular version varies and, unless you have licensed an older version
of Visual C++, you probably do not have the right to redistribute it.

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


Re: user rights and python com servers

2010-04-15 Thread Mark Hammond

On 15/04/2010 6:05 PM, sniffer wrote:

hi all,
i am facing a peculiar problem with a python com server i've developed
the com server runs fine in winxp  standalone systems but if the
system is part of a domain then until the logged in user is given
power user rights i am unable to register the dll using regsvr32 , a
similar problem i face on vista system here unless and untill the app
utilising the dll is run with admin privelleges the dll does not get
registered and does not function as a result.


This is a "feature" of Vista and later - you must have elevated 
permissions to write to the place in the registry where "global" COM 
objects are stored.  By default, the standard win32com registration code 
will attempt to elevate and register if necessary.


Note that it is also possible in theory to register COM objects just for 
a single user, but while win32com doesn't support that directly it 
shouldn't be hard to support this with a few changes to 
win32com\server\register.py


HTH,

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


Re: py2exe saga continues...

2010-04-15 Thread Mark Hammond

On 16/04/2010 10:52 AM, Alex Hall wrote:

1. Is there a way to start with no command line window popping up? My
main script is a pyw, but it still shows a dos window when the
generated .exe file is clicked. Leaving out the "console" parameter of
setup, though, results in no .exe file at all, so I had to put it
back. I want what I have heard called a "silent startup", where the
program starts but it does not pop up anything. My users will know
because I will speak a message, but I want to dump the dos window.


You probably want to use the 'windows=' option instead of the 'console=' 
option (or both if you like - in which case you probably also need to 
specify a 'dest_base' value for one of them.



2. Is there a way to put the exe in a higher-level dir, then put all
the pyd, dll, zip, and other files into a subdirectory so the .exe is
not mixed in with all these files that most users will not care about?
Thank you for all your help over the last few days!!


I *think* that if you specify the 'zipfile' param to include a directory 
portion then all libs will be stored in that same dir.  Eg, spambayes 
includes:


  zipfile = "lib/spambayes.modules",

which causes the .zip file to be named as specified, but all the .pyd 
files also wind up in the 'lib' directory.  Use of the 'dest_base' param 
causes all executables to be placed in a 'bin' directory, so we have 2 
separate dirs holding things.  Spambayes has a complicated setup file 
which may offer some insights - find the spambayes source at sourceforge 
then look for the spambayes/spambayes/windows/py2exe/setup_all.py file 
for inspiration...


HTH,

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


Re: python wia and RegisterEvent

2010-04-15 Thread Mark Hammond

On 16/04/2010 7:15 AM, gelonida wrote:

Hi,

I'd like to register an event in order to be informed, whenever a
Windows WIA device is connected or disconnected.

In python I can use WIA devices, but I don't know how to register
events

I have existing C# code, which works and looks like.

class MgrHandlerClass
 {
 public void devManager_OnEvent(string eventID, string
deviceID, string itemID)
 {} // her emy handler code

 public void addhandler(DeviceManager manager)
 {
 Console.WriteLine("adding handler!");
 manager.OnEvent += new
WIA._IDeviceManagerEvents_OnEventEventHandler(
 devManager_OnEvent);
 }

 static void Main(string[] args)
 {

 MgrHandlerClass mgrhndlr;
 mgrhndlr = new MgrClass();
 DeviceManager manager;

  manager = new DeviceManagerClass();

manager.RegisterEvent(WIA.EventID.wiaEventDeviceConnected, "*");

manager.RegisterEvent(WIA.EventID.wiaEventDeviceDisconnected, "*");
  mgrhndlr.addhandler(manager);
 // wait for callbacks or do other stuff
 }


Now in python I'm stuck

import win32com.client
import wia_defs # created with makepy.py
manager = win32com.client.Dispatch("WIA.DeviceManager")
mgrhndlr = MgrClass()
manager.RegisterEvent(EventID=constants.wiaEventDeviceConnected,DeviceID=u'*')
manager.RegisterEvent(EventID=constants.wiaEventDeviceDisconnected,DeviceID=u'*')
mgrhndlr.addhandler(manager)


class MgrHandlerClass:
 def OnEvent(self, EventID=defaultNamedNotOptArg,
DeviceID=defaultNamedNotOptArg, ItemID=defaultNamedNotOptArg):
 print "Called back with (%s) (%s) (%s)" %
(EventID,DeviceID,ItemID)

 def addhandler(self,manager):
 # here I'm stuck :-(
 # the following line doesn't work as it seems, that manager
does not have attr
 # onevent

manager.OnEvent.append( 
WIA._IDeviceManagerEvents_OnEventEventHandler(self.OnEvent) )


The model used by pywin32 is more "low level" than that exposed by some 
of the MS languages.  You probably need something closer to:



 class MgrHandlerClass:
  def OnEvent(self, EventID=defaultNamedNotOptArg, ...):
  print "Called back with ..."


manager = win32com.client.DispatchWithEvents("WIA.DeviceManager", 
MgrHandlerClass)

manager.RegisterEvent(EventID=constants.wiaEventDeviceConnected,DeviceID=u'*')
manager.RegisterEvent(EventID=constants.wiaEventDeviceDisconnected,DeviceID=u'*')

And magically your OnEvent should be called when the event happens. 
Googling for 'DispatchWithEvents' might find some good hits for more 
information.


HTH,

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


Re: py2exe saga continues...

2010-04-15 Thread alex23
Alex Hall  wrote:
> I started a new thread as I already have several out there, all
> talking about basically the same thing.

Would you mind not doing that and sticking to the one thread to talk
about an issue, preferably one with a subject that actually describes
the question? Every time you start a new thread, you make it harder
for those helping you to keep track of the situation, as well as
annoying those who chose to ignore the original post. Keeping all of
your posts in one large related thread is a better fit for the way
newsreaders & email clients work.

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


Re: feature request for a wget -r like implementation in python3

2010-04-15 Thread alex23
On Apr 16, 5:37 am, gert  wrote:
> So I can make a recursive http download script
> My goal is a one click instruction to install and launch my 
> projecthttp://code.google.com/p/appwsgi/

Here's Guido's take on wget:

import sys, urllib
def reporthook(*a): print a
for url in sys.argv[1:]:
 i = url.rfind('/')
 file = url[i+1:]
 print url, "->", file
 urllib.urlretrieve(url, file, reporthook)

If you extend this, you can offer an easy-download-and-run python
script that does the installation you want.

But why duplicate existing effort? Why not pip[1]?

1: http://pypi.python.org/pypi/pip
-- 
http://mail.python.org/mailman/listinfo/python-list


How to run program in Linux

2010-04-15 Thread Jim Byrnes
I am just learning Python and am new to Linux so I am probably doing 
something to trip myself up.  I am trying to run an example GUI program 
that fetches a record from a database.  All the files are in the same 
folder.


The program runs but its results vary depending on how I started it.  If 
I run it from the terminal or Idle, I enter a key and the program 
fetches the proper record.  If I run it from Nautilis or a panel 
launcher, I enter the proper key and I get an error message saying the 
key does not exist.


I am assuming that I am having path issues but don't know how to correct it.

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


Re: Globally override built-in print function?

2010-04-15 Thread Dave W.
> > I naively thought I could capture output from exec()'ed print
> > invocations by (somehow) overriding 'print' globally.  But this
> > seems not to be possible.  

>
>old_print = __builtins__.print
>__builtins__.print = printhook
>yield
>__builtins__.print = old_print

I'm pretty sure this is semantically equivalent to my original code,
but I gave it a try anyway.  FWIW, it doesn't work, either. :-}

> But you really should replace sys.stdout and sys.stderr instead.

I'm starting to believe it, but... I thought that one of the
benefits of making print a function was that it *could* be globally
replaced. So far I've had no luck injecting a custom print
replacement into other modules.  Is this really not possible?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: py2exe saga continues...

2010-04-15 Thread Alex Hall
On 4/15/10, Mark Hammond  wrote:
> On 16/04/2010 10:52 AM, Alex Hall wrote:
>> 1. Is there a way to start with no command line window popping up? My
>> main script is a pyw, but it still shows a dos window when the
>> generated .exe file is clicked. Leaving out the "console" parameter of
>> setup, though, results in no .exe file at all, so I had to put it
>> back. I want what I have heard called a "silent startup", where the
>> program starts but it does not pop up anything. My users will know
>> because I will speak a message, but I want to dump the dos window.
>
> You probably want to use the 'windows=' option instead of the 'console='
> option (or both if you like - in which case you probably also need to
> specify a 'dest_base' value for one of them.
Yes, that did it!
>
>> 2. Is there a way to put the exe in a higher-level dir, then put all
>> the pyd, dll, zip, and other files into a subdirectory so the .exe is
>> not mixed in with all these files that most users will not care about?
>> Thank you for all your help over the last few days!!
>
> I *think* that if you specify the 'zipfile' param to include a directory
> portion then all libs will be stored in that same dir.  Eg, spambayes
> includes:
>
>zipfile = "lib/spambayes.modules",
>
> which causes the .zip file to be named as specified, but all the .pyd
> files also wind up in the 'lib' directory.  Use of the 'dest_base' param
> causes all executables to be placed in a 'bin' directory, so we have 2
> separate dirs holding things.
I found that setting zipfile to None gets rid of an unnecessary (as
far as I can tell) .zip file; specifying another name did not do
anything, though it did not give me an error either.
> Spambayes has a complicated setup file
> which may offer some insights - find the spambayes source at sourceforge
> then look for the spambayes/spambayes/windows/py2exe/setup_all.py file
> for inspiration...

Oddly, I set the --bundle flag to 1, then 2, but in both cases my
program had a memory error. When the bundle flag was left out, I have
no errors and things work as expected. In either case, though, I get a
dist folder of nearly 21mb in size, much larger than I ever imagined!
I use wx, wmi, win32con, and ctypes (and other libs, but they are
small). Is there any way of optimizing things so that I can get the
overall size down some?
>
> HTH,
Yes, it helped a lot.
>
> Mark.
>


-- 
Have a great day,
Alex (msg sent from GMail website)
mehg...@gmail.com; http://www.facebook.com/mehgcap
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Download Visual Studio Express 2008 now

2010-04-15 Thread Neil Hodgson
Martin v. Loewis:

> Python 2.6, 2.7, and 3.1 are all built with that release (i.e. 2008).
> Because of another long tradition, Python extension modules must be
> built with the same compiler version (more specifically, CRT version) as
> Python itself. So to build extension modules for any of these releases,
> you need to have a copy of VS 2008 or VS 2008 Express.

   Is it too late for Python 2.7 to update to using Visual Studio 2010?
It is going to be much easier for people to find and install the current
version of VS than the previous. There is still more than 2 months left
before 2.7 is planned to be released.

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


Re: user rights and python com servers

2010-04-15 Thread sniffer
On Apr 16, 6:01 am, Mark Hammond  wrote:
> On 15/04/2010 6:05 PM, sniffer wrote:
>
> > hi all,
> > i am facing a peculiar problem with a python com server i've developed
> > the com server runs fine in winxp  standalone systems but if the
> > system is part of a domain then until the logged in user is given
> > power user rights i am unable to register the dll using regsvr32 , a
> > similar problem i face on vista system here unless and untill the app
> > utilising the dll is run with admin privelleges the dll does not get
> > registered and does not function as a result.
>
> This is a "feature" of Vista and later - you must have elevated
> permissions to write to the place in the registry where "global" COM
> objects are stored.  By default, the standard win32com registration code
> will attempt to elevate and register if necessary.
>
> Note that it is also possible in theory to register COM objects just for
> a single user,while win32com doesn't support that directly it
> shouldn't be hard to support this with a few changes to
> win32com\server\register.py
>
> HTH,
>
> Mark

Thanks Mark,
 just one question does the explanation given above by you also apply
to winxp systems in a domain,if so then what is the minimum level of
user rights required for the com server to run without hiccups.

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


Re: Suppress output to stdout/stderr in InteractiveInterpreter

2010-04-15 Thread Dave W.
> > Think I'll start a new post with the subject: "Globally override
> > built-in print function?"

> Don't bother. Replacing sys.stdout is the right thing to do. It
> won't interfere with the C++ streams...
-snip-

I'm not so certain. Won't the C++ host app share the same
stdin/stdout/stderr file descriptors with the embedded Python
interpreter?  So there's at least the *potential* for a background
C++ thread dedicated to processing Python commands (which redirect
stdout) to interfere with, say, the main thread's log statements to
stdout.  Seems like I could wind up with log statements in my
interpreter results.

As it happens, the background thread for processing incoming
commands from the remote REPL currently just queues those commands
to be executed in the main thread, so there's no contention.  But
this makes some 'interesting' things possible using the remote
console:

c:\pt\celoverus\scripts>remote_console.py 192.168.1.10
Python 2.6.2 [IG REPL]
>>> from time import sleep
>>> sleep(100)

Because this is executed in the main app thread's context, it hangs
the host app forever.  Kind of a perfect DoS attack.  Not that
security is a big deal for this particular app. I'm more worried
about not being able to perform debugging tasks like this:

>>> while True:
...   for obj in engine.get_objects():
... if obj.collides_with(engine.get_object(OWNSHIP)
...print("'{0}' hit the ownship".format(obj.name))
...   time.sleep(5.0)

Currently, this would hang the app forever, too.  Moving the
execution of remote Python commands into a low-priority background
thread would allow the host app to keep running in this case.

Anyway, that's why I've got this mild obsession with finding a way
to capture output from the interpreter *without* redirecting
stdout...
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: user rights and python com servers

2010-04-15 Thread Mark Hammond

On 16/04/2010 2:40 PM, sniffer wrote:

Thanks Mark,
  just one question does the explanation given above by you also apply
to winxp systems in a domain,


Yeah - IIRC, domain users can't change much of the registry by default, 
primarily as they aren't in the 'administrators' or 'power user' groups 
by default like local users are - but it all depends on various security 
policies and attributes of each user.



if so then what is the minimum level of
user rights required for the com server to run without hiccups.


Any user can *run* the server - just not all can register it.  To 
register it, the user needs the ability to write to the 
HKEY_CLASSES_ROOT hive in the registry.  This is the same problem 
forcing may installation programs to insist on being run as an 
administrator even if the program itself doesn't need to be.


Cheers,

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