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

2010-04-16 Thread Gabriel Rossetti

Andreas Löscher wrote:

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

  

Yes, it works, thank you,
Gabriel
--
http://mail.python.org/mailman/listinfo/python-list


Re: Updated License Term Agreement for VC Redistributable in VS 2008 SP1

2010-04-16 Thread Tim Roberts
Andrej Mitrovic  wrote:
>
>I don't think this license agreement change involves the express
>editions, which are free. Correct me if I'm wrong here?

The license agreement change fixes a problem that was accidentally
introduced by Visual Studio 2008 SP1.  The redistributable package that can
be downloaded directly from Microsoft (which you would use if you had the
Express Edition) has the right license to begin with.  It never had the
restriction.

http://msdn.microsoft.com/en-us/library/ms235299.aspx

Microsoft's intent is that you be able to distribute the non-debug runtimes
with any applications built with Visual Studio.  They are evil, but not
arbitrarily malicious.
-- 
Tim Roberts, t...@probo.com
Providenza & Boekelheide, Inc.
-- 
http://mail.python.org/mailman/listinfo/python-list


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

2010-04-16 Thread Tim Golden

On 16/04/2010 01:39, News123 wrote:

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?


Look at the object's .Properties_ attribute, eg:

print [p.Name for p in itm.Properties_]

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


Re: Globally override built-in print function?

2010-04-16 Thread Peter Otten
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:

Assigning a new function to the global print name affects only print() calls 
within your script, not the REPL. You have to redirect the latter and make 
sure that it is actually used instead of the print statement.

The easiest way I see to achieve that would be:

py.runsource("from __future__ import print_function")
py.runsource("from __main__ import printhook as print")

Peter

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


Re: How to run program in Linux

2010-04-16 Thread Dave Angel

Jim Byrnes wrote:
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


Presumably you're also new to mailing lists.

At an absolute minimum when you describe an error, PASTE the error 
message, complete with traceback, into your message.  As it stands, I'm 
left wondering which key on your keyboard can possibly "not exist."  
Perhaps it's a non-ASCII code, and you're getting some encoding error.  
That's a common discrepancy between running from a terminal and running 
from some GUI.


Even better is to specify the version of Python this program is 
presumably written in, and what Linux distro. Then you say it's a GUI 
program, so you should specify which GUI library you're using.


Now if I do a bunch of guessing, I might come up with the likelihood 
that your "Nautilus" is supplying a different current directory than the 
one the script is located in.  You can find that out by looking at:

   os.path.abspath(os.curdir)

But of course how you print that depends on what GUI package you're running.

DaveA


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


Re: Globally override built-in print function?

2010-04-16 Thread Lie Ryan
On 04/16/10 12:17, 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.  
> 
>>
>>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?

No, the benefit of 'from __future__ import print_function' is for easing
transition to python 3. The ability to replace print globally only works
in python 3, after applying the change Robert Kern and turning raw_input
to input, the code works in python 3:

lier...@compaq ~/junks $ python3 printhook.py
Python 3.1.2 (r312:79147, Apr 16 2010, 16:58:34)
[GCC 4.3.4]
linux2
Type "help", "copyright", "credits" or "license" for more info.
>>> print(32)
printhook(): 32

Note that assigning to __builtins__.print is different from assigning to
print. With the latter, you shadowed the print function in
__builtins__.print by putting your own print in the global namespace
(which in python really means module-level); while with the former
you're switching print in the interpreter level, the true global namespace.


### 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(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


cross-platform coloured text in terminal

2010-04-16 Thread Jonathan Hartley
Hi,

It irks me that I know of no simple cross-platform way to print
colored terminal text from Python.

As I understand it, printing ANSI escape codes (as wrapped nicely by
module termcolor and others) works on Macs and *nix, but only works on
Windows if one has installed the ANSI.SYS device driver, which most
users have not. However, on Windows, there is an alternative method,
which is to make win32 calls via ctypes.

I'd like to try and unite these different implementations under a
single cross-platform API. Has this been done already? I understand
that the detailed capabilities of the two implementations (eg. dim/
bright colors) might not map neatly, but at least for simple colored
text, it should be OK.

I'm playing with ideas of what API to expose. My favourite one is to
simply embed ANSI codes in the stream to be printed. Then this will
work as-is on Mac and *nix. To make it work on Windows, printing could
be done to a file0-like object which wraps stdout:


class ColorStream(object):

def __init__(self, wrapped):
self.wrapped = wrapped

def write(self, text):
# magic goes here
self.wrapped.write(text)

def __getattr__(self, name):
return getattr(self.wrapped, name)

term = ColorTerm(sys.stdout)
print 

Re: cross-platform coloured text in terminal

2010-04-16 Thread Jonathan Hartley
On Apr 16, 10:28 am, Jonathan Hartley  wrote:
> Hi,
>
> It irks me that I know of no simple cross-platform way to print
> colored terminal text from Python.
>
> As I understand it, printing ANSI escape codes (as wrapped nicely by
> module termcolor and others) works on Macs and *nix, but only works on
> Windows if one has installed the ANSI.SYS device driver, which most
> users have not. However, on Windows, there is an alternative method,
> which is to make win32 calls via ctypes.
>
> I'd like to try and unite these different implementations under a
> single cross-platform API. Has this been done already? I understand
> that the detailed capabilities of the two implementations (eg. dim/
> bright colors) might not map neatly, but at least for simple colored
> text, it should be OK.
>
> I'm playing with ideas of what API to expose. My favourite one is to
> simply embed ANSI codes in the stream to be printed. Then this will
> work as-is on Mac and *nix. To make it work on Windows, printing could
> be done to a file0-like object which wraps stdout:
>
> class ColorStream(object):
>
>     def __init__(self, wrapped):
>         self.wrapped = wrapped
>
>     def write(self, text):
>         # magic goes here
>         self.wrapped.write(text)
>
>     def __getattr__(self, name):
>         return getattr(self.wrapped, name)
>
> term = ColorTerm(sys.stdout)
> print <
> The idea being that in place of 'magic goes here', there will be code
> that, on Windows, searches 'text' for ANSI escape codes, strips them
> from the text, and converts them into the appropriate win32 calls.
>
> For extra nasty magic, either the module or the user of the module
> could wrap sys.stdout globally:
>
> sys.stdout = ColoredStream(sys.stdout)
>
> Then print statements in the user's code would simply be:
>
> print ANSI.GREEN + "hello"
>
> and this would work on all platforms.
>
> No doubt there are many problems with these ideas. I would love to
> hear about them. Many thanks.


Sorry, I forgot to mention: The reason I like this idea is that, in
theory, all existing libraries like termcolor will then work,
unmodified, on all platforms.
-- 
http://mail.python.org/mailman/listinfo/python-list


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

2010-04-16 Thread Daniel Fetchinson
> I am trying to serialize a function, class, etc and transfer it, have it
> unserialized and used.

You might want to look at pyro: http://pyro.sourceforge.net/ and also
picloud: http://www.picloud.com/

HTH,
Daniel



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


Can anyone reproduce this crash?

2010-04-16 Thread Alf P. Steinbach

Python 3.1.1 in Windows XP Prof:



def number_from_user( prompt ):
while True:
spec = input( prompt )
try:
return float( spec )
except ValueError:
s = "Sorry, '{}' is not a valid number spec. Try e.g. '3.14'."
print( s.format( spec ) )
print()

print( "This program computes the sum of two numbers A and B." )
print()
a = number_from_user( "Number A, please: " )
b = number_from_user( "Number B, please: " )
sum = a + b
print()
print( "{} + {} = {}".format( a, b, sum ) )



To be thorough I tested the reaction to typing [Ctrl C] at the first prompt. It 
then displayed the first part of traceback output,




C:\Documents and Settings\Alf> sum.v4.py
This program computes the sum of two numbers A and B.

Number A, please: Traceback (most recent call last):



and seemingly hung for, I don't know, 20 seconds?, whereupon Microsoft's "Please 
tell Bill Gates about it" box popped up; the interpreter had crashed.


Regretfully declining the offer to tell Bill Gates, and this I don't quite 
understand, possibly buffer thing?, one more line of output then appeared:




  File "C:\Documents and Settings\Alf\sum.v4.py", line 13, in 

C:\Documents and Settings\Alf> _



In a normal traceback there are four more lines.

I thought I'd report this so I tried it several times more but unable to 
reproduce: instead of above hang + crash + truncated traceback the complete 
expected traceback appeared and the program terminated properly.


Can anyone reproduce?


Cheers,

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


Re: Can anyone reproduce this crash?

2010-04-16 Thread MRAB

Alf P. Steinbach wrote:

Python 3.1.1 in Windows XP Prof:



def number_from_user( prompt ):
while True:
spec = input( prompt )
try:
return float( spec )
except ValueError:
s = "Sorry, '{}' is not a valid number spec. Try e.g. '3.14'."
print( s.format( spec ) )
print()

print( "This program computes the sum of two numbers A and B." )
print()
a = number_from_user( "Number A, please: " )
b = number_from_user( "Number B, please: " )
sum = a + b
print()
print( "{} + {} = {}".format( a, b, sum ) )



To be thorough I tested the reaction to typing [Ctrl C] at the first 
prompt. It then displayed the first part of traceback output,




C:\Documents and Settings\Alf> sum.v4.py
This program computes the sum of two numbers A and B.

Number A, please: Traceback (most recent call last):



and seemingly hung for, I don't know, 20 seconds?, whereupon Microsoft's 
"Please tell Bill Gates about it" box popped up; the interpreter had 
crashed.


Regretfully declining the offer to tell Bill Gates, and this I don't 
quite understand, possibly buffer thing?, one more line of output then 
appeared:




  File "C:\Documents and Settings\Alf\sum.v4.py", line 13, in 

C:\Documents and Settings\Alf> _



In a normal traceback there are four more lines.

I thought I'd report this so I tried it several times more but unable to 
reproduce: instead of above hang + crash + truncated traceback the 
complete expected traceback appeared and the program terminated properly.


Can anyone reproduce?


I also have Python 3.1.1 on Windows XP Professional, but it doesn't
crash for me!

Does it happen every time?
--
http://mail.python.org/mailman/listinfo/python-list


Re: Can anyone reproduce this crash?

2010-04-16 Thread Lie Ryan
On 04/16/10 21:29, MRAB wrote:
> Alf P. Steinbach wrote:
>> I thought I'd report this so I tried it several times more but unable
>> to reproduce: instead of above hang + crash + truncated traceback the
>> complete expected traceback appeared and the program terminated properly.
>>
>> Can anyone reproduce?
>>
> I also have Python 3.1.1 on Windows XP Professional, but it doesn't
> crash for me!
> 
> Does it happen every time?

I believe Alf said it happened once only and he himself cannot reproduce it.

btw, Alf, did you happen to Ctrl+C multiple times? Perhaps the timing of
your interrupt happened exactly at the moment where it confused the
interpreter. Possibly the second interrupt got received when the first
interrupt was just part way printing the traceback.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Can anyone reproduce this crash?

2010-04-16 Thread Alf P. Steinbach

* MRAB:

Alf P. Steinbach wrote:

Python 3.1.1 in Windows XP Prof:



def number_from_user( prompt ):
while True:
spec = input( prompt )
try:
return float( spec )
except ValueError:
s = "Sorry, '{}' is not a valid number spec. Try e.g. 
'3.14'."

print( s.format( spec ) )
print()

print( "This program computes the sum of two numbers A and B." )
print()
a = number_from_user( "Number A, please: " )
b = number_from_user( "Number B, please: " )
sum = a + b
print()
print( "{} + {} = {}".format( a, b, sum ) )



To be thorough I tested the reaction to typing [Ctrl C] at the first 
prompt. It then displayed the first part of traceback output,




C:\Documents and Settings\Alf> sum.v4.py
This program computes the sum of two numbers A and B.

Number A, please: Traceback (most recent call last):



and seemingly hung for, I don't know, 20 seconds?, whereupon 
Microsoft's "Please tell Bill Gates about it" box popped up; the 
interpreter had crashed.


Regretfully declining the offer to tell Bill Gates, and this I don't 
quite understand, possibly buffer thing?, one more line of output then 
appeared:




  File "C:\Documents and Settings\Alf\sum.v4.py", line 13, in 

C:\Documents and Settings\Alf> _



In a normal traceback there are four more lines.

I thought I'd report this so I tried it several times more but unable 
to reproduce: instead of above hang + crash + truncated traceback the 
complete expected traceback appeared and the program terminated properly.


Can anyone reproduce?


I also have Python 3.1.1 on Windows XP Professional, but it doesn't
crash for me!

Does it happen every time?


No, that's the problem, I'm unable to reproduce consistently or nearly at all.

It just happened again (that's the second time), and this time I chose "Debug", 
firing up Visual Studio 2003 as the Just-In-Time debugger. However, and this has 
/never/ happened before, Visual Studio did not manage to catch the process state 
and reported the program as terminated.


Here's the contents of the Visual Studio output pane:



'python.exe': Loaded 'C:\Program Files\cpython\python31\python.exe', No symbols 
loaded.

'python.exe': Loaded 'C:\WINDOWS\SYSTEM32\ntdll.dll', No symbols loaded.
'python.exe': Loaded 'C:\WINDOWS\SYSTEM32\kernel32.dll', No symbols loaded.
'python.exe': Loaded 'C:\WINDOWS\SYSTEM32\python31.dll', No symbols loaded.
'python.exe': Loaded 'C:\WINDOWS\SYSTEM32\user32.dll', No symbols loaded.
'python.exe': Loaded 'C:\WINDOWS\SYSTEM32\gdi32.dll', No symbols loaded.
'python.exe': Loaded 'C:\WINDOWS\SYSTEM32\advapi32.dll', No symbols loaded.
'python.exe': Loaded 'C:\WINDOWS\SYSTEM32\rpcrt4.dll', No symbols loaded.
'python.exe': Loaded 'C:\WINDOWS\SYSTEM32\shell32.dll', No symbols loaded.
'python.exe': Loaded 'C:\WINDOWS\SYSTEM32\msvcrt.dll', No symbols loaded.
'python.exe': Loaded 'C:\WINDOWS\SYSTEM32\shlwapi.dll', No symbols loaded.
'python.exe': Loaded 
'C:\WINDOWS\WinSxS\x86_Microsoft.VC90.CRT_1fc8b3b9a1e18e3b_9.0.30729.1_x-ww_6f74963e\msvcr90.dll', 
No symbols loaded.

'python.exe': Loaded 'C:\WINDOWS\SYSTEM32\imm32.dll', No symbols loaded.
'python.exe': Loaded 
'C:\WINDOWS\WinSxS\x86_Microsoft.Windows.Common-Controls_6595b64144ccf1df_6.0.2600.2982_x-ww_ac3f9c03\comctl32.dll', 
No symbols loaded.

'python.exe': Loaded 'C:\WINDOWS\SYSTEM32\comctl32.dll', No symbols loaded.
'python.exe': Loaded 'C:\WINDOWS\SYSTEM32\version.dll', No symbols loaded.
'python.exe': Loaded 'C:\WINDOWS\SYSTEM32\apphelp.dll', No symbols loaded.
The thread 'Win32 Thread' (0xd54) has exited with code -1073740777 (0xc417).
The program '[3292] python.exe: Native' has exited with code -1073740777 
(0xc417).




The error code 0xc417 is some custom one, not a standard Windows code.

The crash address reported by the tell-Bill box was a low one with four zeroes 
at front, but I didn't note it because that box doesn't support copy to 
clipboard and I was sure I'd get it in Visual Studio, which I didn't.


Is there any DLL above that shouldn't be there, like malware (it's the only 
thing I can think of, a program shouldn't retain state between invocations)?



Cheers,

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


Re: Download Visual Studio Express 2008 now

2010-04-16 Thread Lie Ryan
On 04/13/10 06:36, Martin v. Loewis wrote:
> Microsoft has just released Visual Studio 2010, along with its free (of
> charge) Express edition. Following a tradition, they are likely to
> withdraw support and availability for VS 2008 Express some time in the
> future.

If only Python could do that, just pull the plug out and not offer
archaic versions for download. If that has been the tradition all along
probably people would be rushing to download Python 3 when it's hot and
porting all their code in fear of using a no longer supported compiler
instead of complaining how they're still using python 1.5 and now
there's python 3.0 breaking compatibility.

I guess I'm glad that whatever python program I wrote now would still be
easily runnable with no change in twenty years or so.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Download Visual Studio Express 2008 now

2010-04-16 Thread Robin Becker

On 12/04/2010 21:36, Martin v. Loewis wrote:
..


If you are planning to build Python extension modules in the next five
years, I recommend that you obtain a copy of VS Express, just in case
Microsoft removes it from their servers. As mentioned, it's free of
charge. When downloading it for later use, it's probably best to get the
offline ISO image release, available from

http://www.microsoft.com/express/Downloads/#2008-All

..

Is it sufficient to download just the setup program vcsetup.exe or do people 
need to obtain the offline iso which presumably has the full content in it.

--
Robin Becker

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


Re: Download Visual Studio Express 2008 now

2010-04-16 Thread Lie Ryan
On 04/16/10 22:09, Robin Becker wrote:
> On 12/04/2010 21:36, Martin v. Loewis wrote:
> ...
>>
>> If you are planning to build Python extension modules in the next five
>> years, I recommend that you obtain a copy of VS Express, just in case
>> Microsoft removes it from their servers. As mentioned, it's free of
>> charge. When downloading it for later use, it's probably best to get the
>> offline ISO image release, available from
>>
>> http://www.microsoft.com/express/Downloads/#2008-All
> ...
> 
> Is it sufficient to download just the setup program vcsetup.exe or do
> people need to obtain the offline iso which presumably has the full
> content in it.

As I remember it when installing VS Excpress a few years back, the thin
installer is just a download manager so you should get the full
installer if you want to insure yourself from Microsoft pulling the plug
out.
-- 
http://mail.python.org/mailman/listinfo/python-list


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

2010-04-16 Thread Lie Ryan
On 04/15/10 02:03, Paul Rubin wrote:
> Raymond Hettinger  writes:
>> 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].
> 
> I think you meant
> 
>sorted(iterable, reverse=True)[:2]


or sorted(iterable)[-2:]
-- 
http://mail.python.org/mailman/listinfo/python-list



Re: Can anyone reproduce this crash?

2010-04-16 Thread Alf P. Steinbach

* Alf P. Steinbach:

* MRAB:

Alf P. Steinbach wrote:

Python 3.1.1 in Windows XP Prof:



def number_from_user( prompt ):
while True:
spec = input( prompt )
try:
return float( spec )
except ValueError:
s = "Sorry, '{}' is not a valid number spec. Try e.g. 
'3.14'."

print( s.format( spec ) )
print()

print( "This program computes the sum of two numbers A and B." )
print()
a = number_from_user( "Number A, please: " )
b = number_from_user( "Number B, please: " )
sum = a + b
print()
print( "{} + {} = {}".format( a, b, sum ) )



To be thorough I tested the reaction to typing [Ctrl C] at the first 
prompt. It then displayed the first part of traceback output,




C:\Documents and Settings\Alf> sum.v4.py
This program computes the sum of two numbers A and B.

Number A, please: Traceback (most recent call last):



and seemingly hung for, I don't know, 20 seconds?, whereupon 
Microsoft's "Please tell Bill Gates about it" box popped up; the 
interpreter had crashed.


Regretfully declining the offer to tell Bill Gates, and this I don't 
quite understand, possibly buffer thing?, one more line of output 
then appeared:




  File "C:\Documents and Settings\Alf\sum.v4.py", line 13, in 

C:\Documents and Settings\Alf> _



In a normal traceback there are four more lines.

I thought I'd report this so I tried it several times more but unable 
to reproduce: instead of above hang + crash + truncated traceback the 
complete expected traceback appeared and the program terminated 
properly.


Can anyone reproduce?


I also have Python 3.1.1 on Windows XP Professional, but it doesn't
crash for me!

Does it happen every time?


No, that's the problem, I'm unable to reproduce consistently or nearly 
at all.


It just happened again (that's the second time), and this time I chose 
"Debug", firing up Visual Studio 2003 as the Just-In-Time debugger. 
However, and this has /never/ happened before, Visual Studio did not 
manage to catch the process state and reported the program as terminated.


Here's the contents of the Visual Studio output pane:



'python.exe': Loaded 'C:\Program Files\cpython\python31\python.exe', No 
symbols loaded.

'python.exe': Loaded 'C:\WINDOWS\SYSTEM32\ntdll.dll', No symbols loaded.
'python.exe': Loaded 'C:\WINDOWS\SYSTEM32\kernel32.dll', No symbols loaded.
'python.exe': Loaded 'C:\WINDOWS\SYSTEM32\python31.dll', No symbols loaded.
'python.exe': Loaded 'C:\WINDOWS\SYSTEM32\user32.dll', No symbols loaded.
'python.exe': Loaded 'C:\WINDOWS\SYSTEM32\gdi32.dll', No symbols loaded.
'python.exe': Loaded 'C:\WINDOWS\SYSTEM32\advapi32.dll', No symbols loaded.
'python.exe': Loaded 'C:\WINDOWS\SYSTEM32\rpcrt4.dll', No symbols loaded.
'python.exe': Loaded 'C:\WINDOWS\SYSTEM32\shell32.dll', No symbols loaded.
'python.exe': Loaded 'C:\WINDOWS\SYSTEM32\msvcrt.dll', No symbols loaded.
'python.exe': Loaded 'C:\WINDOWS\SYSTEM32\shlwapi.dll', No symbols loaded.
'python.exe': Loaded 
'C:\WINDOWS\WinSxS\x86_Microsoft.VC90.CRT_1fc8b3b9a1e18e3b_9.0.30729.1_x-ww_6f74963e\msvcr90.dll', 
No symbols loaded.

'python.exe': Loaded 'C:\WINDOWS\SYSTEM32\imm32.dll', No symbols loaded.
'python.exe': Loaded 
'C:\WINDOWS\WinSxS\x86_Microsoft.Windows.Common-Controls_6595b64144ccf1df_6.0.2600.2982_x-ww_ac3f9c03\comctl32.dll', 
No symbols loaded.

'python.exe': Loaded 'C:\WINDOWS\SYSTEM32\comctl32.dll', No symbols loaded.
'python.exe': Loaded 'C:\WINDOWS\SYSTEM32\version.dll', No symbols loaded.
'python.exe': Loaded 'C:\WINDOWS\SYSTEM32\apphelp.dll', No symbols loaded.
The thread 'Win32 Thread' (0xd54) has exited with code -1073740777 
(0xc417).
The program '[3292] python.exe: Native' has exited with code -1073740777 
(0xc417).




The error code 0xc417 is some custom one, not a standard Windows code.

The crash address reported by the tell-Bill box was a low one with four 
zeroes at front, but I didn't note it because that box doesn't support 
copy to clipboard and I was sure I'd get it in Visual Studio, which I 
didn't.


I managed to crash it a third time. Same problem with JIT debugging, but this 
time I noted manually some info from the tell-Bill box:




AppName: python.exe
AppVer: 0.0.0.0
ModName: msvcr90.dll
ModVer: 9.0.30729.1
Offset: 00068389

(Error Report Contents)
Code: 0xc417
Address: 0x78588389



The tell-Bill box also reported more modules loaded than Visual Studio, but I 
think that has to do with the box itself:




Module 1   python.exe
Module 2   ntdll.dll
Module 3   kernel32.dll
Module 4   python31.dll
Module 5   USER32.dll
Module 6   GDI32.dll
Module 7   ADVAPI32.dll
Module 7   RPCRT4.dll
Module 9   SHELL32.dll
Module 10  msvcrt.dll
Module 11  SHLWAPI.dll
Module 12  MSVCR90.dll
Module 13  IMM32.dll
Module 14  comctl32.dll  (FileVer 6.0:2900.2982)
Module 15  comctl32.dll  (FileVer 5.82:2900.2982)
Module 16  faultrep.dll
Module 17  VERSION.dll
Module 18  USERENV.dll
Module 19  WINSTA.dll
Module 20  NETAPI32.dll
Module 2

Re: Download Visual Studio Express 2008 now

2010-04-16 Thread Brian Blais

On Apr 12, 2010, at 16:36 , Martin v. Loewis wrote:


If you are planning to build Python extension modules in the next five
years, I recommend that you obtain a copy of VS Express


Am I missing something here?  I have heard this before, but I have  
built extension modules many times under windows (using Cython) and  
never once used a MS product.  I've just had to change a distutils  
config file to use a different compiler (mingw32, directions here:  
http://docs.cython.org/src/tutorial/appendix.html).  It seems to work  
fine.  What is the basis of this claim that you need MS Visual Studio  
to do it?




bb
--
Brian Blais
bbl...@bryant.edu
http://web.bryant.edu/~bblais
http://bblais.blogspot.com/



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


unexpected output from difflib.SequenceMatcher

2010-04-16 Thread Vlastimil Brom
Hi all,
Once in a while I happen to stumble on some not expected behaviour of
difflib.SequenceMatcher, in this case I hopefully managed to replicate
it on an illustrative sample text.
Both strings differ in a minimal way, each having one extra character
in a "strategic" position, which seems to meet some pathological case
for difflib.
Instead of just reporting the insertion and deletion of these single
characters (which works well for most cases - with most other
positions of the differing characters), the output of the
SequenceMatcher decides to delete a large part of the string in
between the differences and to insert the almost same text after that.
I didn't find any mentions of such cases in the documentation and,
honestly, I wasn't able to follow the sourcecode of difflib to make i
t clearer, hence I would like to ask for some hints.
Can this behaviour be avoided or worked around in some way? (I thought
about repeatedly trying sequence matcher on replaced parts, but this
doesn't help, if there is an insertion and deletion in the opcodes).
Or is this maybe some inherent possibility of the algorithm, which
cannot be dealt with reasonably?

The attached code simply prints the results of the comparison with the
respective tags, and substrings. No junk function is used.
I get the same results on Python 2.5.4, 2.6.5, 3.1.1 on windows XPp SP3.

Thanks in advance for any hints,
Regards,
   vbr

#

#! Python
# -*- coding: utf-8 -*-

import difflib

# txt_a - extra character A at index 196
txt_a = "Chapman: *I* don't know - Mr Wentworth just told me to come
in here and say that there was trouble at the mill, that's all - I
didn't expect a kind of Spanish Inquisition.[jarring chord] Ximinez:
ANobody expects the Spanish Inquisition! Our chief weapon is
surprise...surprise and fear...fear and surprise Our two weapons
are fear and surprise...and ruthless efficiency Our *three*
weapons are fear, surprise, and ruthless efficiency...and an almost
fanatical devotion to the Pope Our *four*...no... *Amongst* our
weapons Amongst our weaponry...are such elements as fear,
surprise I'll come in again."

# txt_b - extra character B at index 525
txt_b = "Chapman: *I* don't know - Mr Wentworth just told me to come
in here and say that there was trouble at the mill, that's all - I
didn't expect a kind of Spanish Inquisition.[jarring chord] Ximinez:
Nobody expects the Spanish Inquisition! Our chief weapon is
surprise...surprise and fear...fear and surprise Our two weapons
are fear and surprise...and ruthless efficiency Our *three*
weapons are fear, surprise, and ruthless efficiency...and an almost
fanatical devotion to the Pope Our *four*...no... *Amongst* our
Bweapons Amongst our weaponry...are such elements as fear,
surprise I'll come in again."

seq_match = difflib.SequenceMatcher(None, txt_a, txt_b)
print ("\n".join("%7s a[%d:%d] (%s) b[%d:%d] (%s)" % (tag, i1, i2,
txt_a[i1:i2], j1, j2, txt_b[j1:j2]) for tag, i1, i2, j1, j2 in
seq_match.get_opcodes()))


difflib_test_inq.py
Description: Binary data
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Can anyone reproduce this crash?

2010-04-16 Thread Alf P. Steinbach

* Alf P. Steinbach:



> [About baffling almost not reproducible interpreter crash on Ctrl C]

The error code 0xc417 is some custom one, not a standard Windows code.


Sorry, I was wrong about that, just that the MS ErrLook utility didn't find it.

http://social.msdn.microsoft.com/Forums/en-US/vsdebug/thread/2d0577ec-562a-498d-af66-0177a3f2e52c>


says it's


  STATUS_INVALID_CRUNTIME_PARAMETER
  #An invalid parameter was passed to a C runtime function.


defined in [ntstatus.h].


Cheers,

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


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

2010-04-16 Thread Lie Ryan
On 04/16/10 02:30, Terry Reedy wrote:
> 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.
> 

I once proposed a similar construct a couple of years ago (it was also
one of my first post in this group)
http://groups.google.com/group/comp.lang.python/browse_thread/thread/ac62e0fe69304c6f/ec95518c16e8b9dc?q

And also, in the last few weeks (or so), there was a thread in
python-ideas mailing list proposing "yieldfrom":

yieldfrom iterable

is equivalent to:

for n in iterable:
yield n

which is practically the same as what I was and raise-yield is
proposing. The difference being that SoftException/raise-yield silently
re-raise the exception, while yieldfrom is an explicit re-raise.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Can anyone reproduce this crash?

2010-04-16 Thread Alf P. Steinbach

* Alf P. Steinbach:

* Alf P. Steinbach:



 > [About baffling almost not reproducible interpreter crash on Ctrl C]
The error code 0xc417 is some custom one, not a standard Windows 
code.


Sorry, I was wrong about that, just that the MS ErrLook utility didn't 
find it.


http://social.msdn.microsoft.com/Forums/en-US/vsdebug/thread/2d0577ec-562a-498d-af66-0177a3f2e52c> 



says it's


  STATUS_INVALID_CRUNTIME_PARAMETER
  #An invalid parameter was passed to a C runtime function.


defined in [ntstatus.h].


Found a another bug discussion with

  * same exception,
0xc417 STATUS_INVALID_CRUNTIME_PARAMETER

  * same address,
0x78588389

  * almost same Python version,
namely Py3,

  * almost same context,
namely occurring when program terminates,

at

  http://www.mail-archive.com/pyinstal...@googlegroups.com/msg01564.html>

Can I report a bug with so little information  --  not generally reproducible, 
but hey, someone else has seen something nearly identical?



Cheers,

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


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

2010-04-16 Thread Peter Otten
david jensen wrote:

> Hi all,
> 
> I'm trying to find a good way of doing the following:
> 
> Each n-tuple in combinations( range( 2 ** m ), n ) has a corresponding
> value n-tuple (call them "scores" for clarity later). I'm currently
> storing them in a dictionary, by doing:
> 
> 
> res={}
> for i in itertools.combinations( range( 2**m ) , n):
> res[ i ] = getValues( i )# getValues() is computationally
> expensive
> 
> 
> For each (n-1)-tuple, I need to find the two numbers that have the
> highest scores versus them. I know this isn't crystal clear, but
> hopefully an example will help: with m=n=3:
> 
> Looking at only the (1, 3) case, assuming:
> getValues( (1, 2, 3) ) == ( -200, 125, 75 )# this contains the
> highest "other" score, where 2 scores 125
> getValues( (1, 3, 4) ) == ( 50, -50, 0 )
> getValues( (1, 3, 5) ) == ( 25, 300, -325 )
> getValues( (1, 3, 6) ) == ( -100, 0, 100 )# this contains the
> second-highest, where 6 scores 100
> getValues( (1, 3, 7) ) == ( 80, -90, 10  )
> getValues( (1, 3, 8) ) == ( 10, -5, -5 )
> 
> I'd like to return ( (2, 125), (6, 100) ).
> 
> The most obvious (to me) way to do this would be not to generate the
> res dictionary at the beginning, but just to go through each
> combinations( range( 2**m), n-1) and try every possibility... this
> will test each combination n times, however, and generating those
> values is expensive. [e.g. (1,2,3)'s scores will be generated when
> finding the best possibilities for (1,2), (1,3) and (2,3)]
> 
> What I'm doing now is ugly, and i think is where i'm confusing myself:
> 
> 
> best2={}
> for i in itertools.combinations( range( 2**m), n-1):
> scorelist=[]
> for j in range( 2**m ):
> if j not in i:
> k=list(i)
> k.append(j)
> k=tuple(sorted(k))#gets the key for looking up the
> scores in res
> scorelist.append((j,res[k][k.index(j)]))
> best2[i]=sorted(scorelist,key=lambda x: -x[1])[:2]
> 
> 
> Am I missing an obviously better way?

After some tinkering I came up with

def calculate(getvalues):
best2 = defaultdict(list)
for t in combinations(range(2**m), n):
values = getvalues(t)
for i, k in enumerate(t):
best2[t[:i] + t[i+1:]].append((k, values[i]))
return dict((k, nlargest(2, v, key=itemgetter(1))) for k, v in 
best2.iteritems())

which is concise but slower than your code with Raymond's improvements. I 
then tried inlining the nlargest() operation:

def calculate_inlined(getvalues):
best2 = {}
for t in combinations(range(2**m), n):
values = getvalues(t)
for i, k in enumerate(t):
key = t[:i] + t[i+1:]
value = values[i]
if key not in best2:
best2[key] = [(k, value), (None, None)]
else:
a, b = best2[key]
if value > a[1]:
best2[key] = [(k, value), a]
elif value > b[1]:
best2[key] = [a, (k, value)]
return best2

This gives a speed boost (I measured with m=n=5) but is both messy and 
brittle. I've got a hunch that there is a better way; I just don't see it at 
the moment...

Peter


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


Re: user rights and python com servers

2010-04-16 Thread sniffer
On Apr 16, 10:48 am, Mark Hammond  wrote:
> 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

Thanks Mark for all your help
-- 
http://mail.python.org/mailman/listinfo/python-list


question about list extension

2010-04-16 Thread J
Ok... I know pretty much how .extend works on a list... basically it
just tacks the second list to the first list... like so:

>>> lista=[1]
>>> listb=[2,3]
>>> lista.extend(listb)
>>> print lista;
[1, 2, 3]

what I'm confused on is why this returns None:

>>> lista=[1]
>>> listb=[2,3]
>>> print lista.extend(listb)
None
>>> print lista
[1, 2, 3]

So why the None? Is this because what's really happening is that
extend() and append() are directly manipulating the lista object and
thus not actuall returning a new object?

Even if that assumption of mine is correct, I would have expected
something like this to work:

>>> lista=[1]
>>> listb=[2,3]
>>> print (lista.extend(listb))
None

The reason this is bugging me right now is that I'm working on some
code.  My program has a debugger class that takes a list as it's only
(for now) argument.  That list, is comprised of messages I want to
spit out during debug, and full output from system commands being run
with Popen...

So the class looks something like this:

class debugger():
def printout(self,info):
for line in info:
print "DEBUG: %s" % line


and later on, it get's called like this

meminfo = Popen('cat
/proc/meminfo',shell=True,stdout=PIPE).communicate[0].splitlines()

if debug:
debugger.printout(meminfo)

easy enough

BUT, what if I have several lists I want to pass on multiple lists...

So changing debugger.printout() to:

   def printout(self,*info):

lets me pass in multiple lists... and I can do this:

   for tlist in info:
   for item in tlist:
print item

which works well...

So, what I'm curious about, is there a list comprehension or other
means to reduce that to a single line?

I tried this, which didn't work because I'm messing up the syntax, somehow:

def func(*info)
print [ i for tlist in info for i in tlist ]

so can someone help me understand a list comprehension that will turn
those three lines into on?

It's more of a curiosity thing at this point...  and not a huge
difference in code... I was just curious about how to make that work.

Cheers,

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


Merge two directories together

2010-04-16 Thread Keith Hughitt
Suppose you have two file-trees with common sub-directories but
different files that you want to merge together, e.g.

/test/
/test/a/
/test/a/file1

/test2/
/test2/a/
/test2/a/file2

You can easily merge the directories in Linux using the "cp" command:

cp -r test/* test2/

While Python provides some helpful methods for moving files and
directories around (shutil.move, shutil.copytree, etc), none of them
seem to be able to merge two directories.

I've looked around some on Google for an alternative to calling cp
directly, but so far no luck.

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


Re: Can anyone reproduce this crash?

2010-04-16 Thread Alf P. Steinbach

* Alf P. Steinbach:


Found a another bug discussion with

  * same exception,
0xc417 STATUS_INVALID_CRUNTIME_PARAMETER

  * same address,
0x78588389

  * almost same Python version,
namely Py3,

  * almost same context,
namely occurring when program terminates,

at

  http://www.mail-archive.com/pyinstal...@googlegroups.com/msg01564.html>


Can I report a bug with so little information  --  not generally 
reproducible, but hey, someone else has seen something nearly identical?


OK, I did, http://bugs.python.org/issue8418>.


Cheers,

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


Re: Updated License Term Agreement for VC Redistributable in VS 2008 SP1

2010-04-16 Thread python
Hi Tim,

> The license agreement change fixes a problem that was accidentally introduced 
> by Visual Studio 2008 SP1. The redistributable package that can
be downloaded directly from Microsoft (which you would use if you had
the Express Edition) has the right license to begin with. It never had
the
restriction. http://msdn.microsoft.com/en-us/library/ms235299.aspx.
Microsoft's intent is that you be able to distribute the non-debug
runtimes with any applications built with Visual Studio. 

Original poster here. Thanks for your insight!

> They are evil, but not arbitrarily malicious.

:)

Regards,
Malcolm


- Original message -
From: "Tim Roberts" 
To: python-list@python.org
Date: Fri, 16 Apr 2010 00:31:35 -0700
Subject: Re: Updated License Term Agreement for VC Redistributable in VS
2008   SP1

Andrej Mitrovic  wrote:
>
>I don't think this license agreement change involves the express
>editions, which are free. Correct me if I'm wrong here?

The license agreement change fixes a problem that was accidentally
introduced by Visual Studio 2008 SP1.  The redistributable package that
can
be downloaded directly from Microsoft (which you would use if you had
the
Express Edition) has the right license to begin with.  It never had the
restriction.

http://msdn.microsoft.com/en-us/library/ms235299.aspx

Microsoft's intent is that you be able to distribute the non-debug
runtimes
with any applications built with Visual Studio.  They are evil, but not
arbitrarily malicious.
-- 
Tim Roberts, t...@probo.com
Providenza & Boekelheide, Inc.
-- 
http://mail.python.org/mailman/listinfo/python-list

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


Re: question about list extension

2010-04-16 Thread Bruno Desthuilliers

J a écrit :

Ok... I know pretty much how .extend works on a list... basically it
just tacks the second list to the first list... like so:


lista=[1]
listb=[2,3]
lista.extend(listb)
print lista;

[1, 2, 3]

what I'm confused on is why this returns None:



So why the None? Is this because what's really happening is that
extend() and append() are directly manipulating the lista object and
thus not actuall returning a new object?


Exactly.


Even if that assumption of mine is correct, I would have expected
something like this to work:


lista=[1]
listb=[2,3]
print (lista.extend(listb))

None


So what ? It JustWork(tm). list.extend returns None, so "None" is 
printed !-)



(snip)


So changing debugger.printout() to:

   def printout(self,*info):

lets me pass in multiple lists... and I can do this:

   for tlist in info:
   for item in tlist:
print item

which works well...

So, what I'm curious about, is there a list comprehension or other
means to reduce that to a single line?


Why do you think the above code needs to be "reduced to a single line" ? 
 What's wrong with this snippet ???




It's more of a curiosity thing at this point...  and not a huge
difference in code... I was just curious about how to make that work.


Uh, ok.

What about:

from itertools import chain

def printout(*infos):
   print "\n".join("%s" % item for item in chain(*infos))


HTH


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


Re: How to run program in Linux

2010-04-16 Thread Dave Angel

Jim Byrnes wrote:

Dave Angel wrote:

Jim Byrnes wrote:

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


Presumably you're also new to mailing lists.


Not really.


At an absolute minimum when you describe an error, PASTE the error
message, complete with traceback, into your message. As it stands, I'm
left wondering which key on your keyboard can possibly "not exist."
Perhaps it's a non-ASCII code, and you're getting some encoding error.
That's a common discrepancy between running from a terminal and running
from some GUI.


The error was generated by the program, not Python.  The 'key' I was 
referring to was a dictionary type key, not a physical one on the 
keyboard.



Even better is to specify the version of Python this program is
presumably written in, and what Linux distro. Then you say it's a GUI
program, so you should specify which GUI library you're using.


Python 2.6,  Ubuntu 9.10,  tkinter


Now if I do a bunch of guessing, I might come up with the likelihood
that your "Nautilus" is supplying a different current directory than the
one the script is located in. You can find that out by looking at:
os.path.abspath(os.curdir)


OK, thanks.  If that is the case how do I correct it?


But of course how you print that depends on what GUI package you're
running.

DaveA



Regards,  Jim



You forgot to include the list in your reply.  Try using reply-all instead.

If you determine that the current directory is your problem, and that 
Nautilus isn't setting it the way you'd like, then you may have to 
resort to other ways to identify the other files you mention.  Easiest 
way might be to use the __file__ attribute of each module, which gives 
its complete path.  So your code in the main script could do something 
like  (untested):

 target = os.path.dirname(__file__)
 os.chdir(target)

Better is usually to ignore current directory, and passed the desired 
directory name into whatever function is going to use it.


HTH,

DaveA

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


Re: question about list extension

2010-04-16 Thread Lie Ryan
On 04/16/10 23:41, J wrote:
> Ok... I know pretty much how .extend works on a list... basically it
> just tacks the second list to the first list... like so:
> 
 lista=[1]
 listb=[2,3]
 lista.extend(listb)
 print lista;
> [1, 2, 3]
> 
> what I'm confused on is why this returns None:
> 
 lista=[1]
 listb=[2,3]
 print lista.extend(listb)
> None
 print lista
> [1, 2, 3]
> 
> So why the None? Is this because what's really happening is that
> extend() and append() are directly manipulating the lista object and
> thus not actuall returning a new object?

In python every function that does not explicitly returns a value or use
a bare return returns None. So:

def foo():
pass
def bar():
return

print foo()
print bar()

you can say that returning None is python's equivalent to void return
type in other languages.

> Even if that assumption of mine is correct, I would have expected
> something like this to work:
> 
 lista=[1]
 listb=[2,3]
 print (lista.extend(listb))
> None

Why would these has to be different?
print None
print (None)



> So, what I'm curious about, is there a list comprehension or other
> means to reduce that to a single line?

from itertools import chain
def printout(*info):
print '\n'.join(map(str, chain(*info)))

or using generator comprehension

from itertools import chain
def printout(*info):
print '\n'.join(str(x) for x in chain(*info))
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Download Visual Studio Express 2008 now

2010-04-16 Thread Robert Kern

On 2010-04-16 07:30 AM, Brian Blais wrote:

On Apr 12, 2010, at 16:36 , Martin v. Loewis wrote:


If you are planning to build Python extension modules in the next five
years, I recommend that you obtain a copy of VS Express


Am I missing something here? I have heard this before, but I have built
extension modules many times under windows (using Cython) and never once
used a MS product. I've just had to change a distutils config file to
use a different compiler (mingw32, directions here:
http://docs.cython.org/src/tutorial/appendix.html). It seems to work
fine. What is the basis of this claim that you need MS Visual Studio to
do it?


Most extensions will work okay when compiled with mingw32. However, mingw32 is 
still based on MSVCRT6.dll as its C runtime. You would get errors whenever a 
FILE* pointer crosses over the boundary. distutils will tell it to link with the 
CRT that Python is currently built with, but some of the headers aren't up to 
date for that CRT, so some C++ extensions will not work (a command C++ operation 
triggers a table lookup in a static table defined in the CRT, but it differs in 
size between versions).


--
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


Re: question about list extension

2010-04-16 Thread J. Cliff Dyer
On Sat, 2010-04-17 at 00:37 +1000, Lie Ryan wrote:
> On 04/16/10 23:41, J wrote:

> > So, what I'm curious about, is there a list comprehension or other
> > means to reduce that to a single line?
> 
> from itertools import chain
> def printout(*info):
> print '\n'.join(map(str, chain(*info)))
> 
> or using generator comprehension
> 
> from itertools import chain
> def printout(*info):
> print '\n'.join(str(x) for x in chain(*info))


It's even easier if you don't need to modify lista.  

print lista + listb


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


Re: Suppress output to stdout/stderr in InteractiveInterpreter

2010-04-16 Thread Robert Kern

On 2010-04-16 00:42 AM, Dave W. wrote:

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.


No. Changing the object that the name sys.stdout refers to does not swap out the 
underlying file descriptors.



Anyway, that's why I've got this mild obsession with finding a way
to capture output from the interpreter *without* redirecting
stdout...


Not possible. Many things write directly to sys.stdout/sys.stderr.

--
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


Reactive programming in Python ?

2010-04-16 Thread pca
Dear all,

Could “reactive programming” still increase the productivity and joy
of Python programming?  I’d like to hear your thoughts on the idea
that object-oriented “programming by formula”, as in a spreadsheet,
would simplify our work, because we would not have to worry about the
sequence of program execution anymore.

In fact, I have seeded an open-source project, Yoopf, that enables
programming by formula within Python, with the goal of dramatically
accelerating the development of the model view in the MVC model.
Declarative-style programming has accelerated the development of the
presentation layer (with HTML, CSS) and the Database layer (with SQL),
so why not take advantage of it for the Business Logic layer too?

You can find more information on this project at www.yoopf.org.  Your
comments are more than welcome!

Best regards,
P. Carbonnelle
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Globally override built-in print function?

2010-04-16 Thread Robert Kern

On 2010-04-15 21:17 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.




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.


Not at all. Declaring "global print" then assigning to "print" simply changes 
what the module's "print" variable refers to. Other modules are unaffected. 
"Global" variables aren't truly global; they are actually local to the module. 
You need to replace it in the __builtins__ because that's where everyone else 
gets it.



FWIW, it doesn't work, either. :-}


Right. Lie answered why. I didn't pay attention and thought you were already 
using Python 3.


--
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


Re: python wia and RegisterEvent

2010-04-16 Thread gelonida
Hi Mark,

On Apr 16, 3:16 am, Mark Hammond  wrote:
> On 16/04/2010 7:15 AM,gelonidawrote:
>
> 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.
>

I'm still stuck. Please look at following code snippet.
I tried to reduce it to the absolute minimum.
running under WinXP and python 2.6.4


import win32com.client,pythoncom,time

defaultNamedNotOptArg=pythoncom.Empty
wiaEventDeviceConnected   =u'{A28BBADE-64B6-11D2-
A231-00C04FA31809}' # from enum EventID

class MgrHandlerClass: # doesn't work either
def OnEvent(self, EventID=defaultNamedNotOptArg,
DeviceID=defaultNamedNotOptArg, ItemID=defaultNamedNotOptArg):
print "Called back with ..."

manager = win32com.client.DispatchWithEvents("WIA.DeviceManager",
MgrHandlerClass)
manager.RegisterEvent(EventID=wiaEventDeviceConnected,DeviceID=u'*')

while True:
print "sleep"
time.sleep(10)

When I plug / unplug a USB WIA device nothing shows up.
My C# implementation prints messages on wiaEventDeviceConnected /
wiaEventDeviceDisconnected events if I register them.

What am I missing?

Should MgrHandlerClass inherit from some kind of default class?


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


Re: Incorrect scope of list comprehension variables

2010-04-16 Thread Aahz
In article <4bb92850$0$8827$c3e8...@news.astraweb.com>,
Steven D'Aprano   wrote:
>
>Nevertheless, it is a common intuition that the list comp variable should 
>*not* be exposed outside of the list comp, and that the for-loop variable 
>should. Perhaps it makes no sense, but it is very common -- I've never 
>heard of anyone being surprised that the for-loop variable is exposed, 
>but I've seen many people surprised by the fact that list-comps do expose 
>their loop variable.

I've definitely seen people surprised by the for-loop behavior.
-- 
Aahz (a...@pythoncraft.com)   <*> http://www.pythoncraft.com/

"It is easier to optimize correct code than to correct optimized code."
--Bill Harlan
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Updated License Term Agreement for VC Redistributable in VS 2008 SP1

2010-04-16 Thread CM
On Apr 16, 3:31 am, Tim Roberts  wrote:
> Andrej Mitrovic  wrote:
>
> >I don't think this license agreement change involves the express
> >editions, which are free. Correct me if I'm wrong here?
>
> The license agreement change fixes a problem that was accidentally
> introduced by Visual Studio 2008 SP1.  The redistributable package that can
> be downloaded directly from Microsoft (which you would use if you had the
> Express Edition) has the right license to begin with.  It never had the
> restriction.
>
> http://msdn.microsoft.com/en-us/library/ms235299.aspx
>
> Microsoft's intent is that you be able to distribute the non-debug runtimes
> with any applications built with Visual Studio.  They are evil, but not
> arbitrarily malicious.

Just to be clear:  are you saying that if one has Visual Studio 2008
Express Edition (the free one), one then has the right to redistribute
the necessary dlls for using py2exe to make working Python 2.6
executables?

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


Re: Suppress output to stdout/stderr in InteractiveInterpreter

2010-04-16 Thread Dave W.
>>> Don't bother. Replacing sys.stdout is the right thing to do. It
>>> won't interfere with the C++ streams...

>> I'm not so certain. Won't the C++ host app share the same
>> stdin/stdout/stderr file descriptors with the embedded Python
>> interpreter?

> No. Changing the object that the name sys.stdout refers to does
> not swap out the underlying file descriptors.

Whoa--that's a bombshell.  I guess I shouldn't have assumed that
this was the case, but it seemed so 'obvious'.  Glad I was wrong,
since it makes like much, much easier.  Thank you!

[xref "Globally override built-in print function?"]
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Globally override built-in print function?

2010-04-16 Thread Dave W.
>>> 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.
>
> Not at all. Declaring "global print" then assigning to "print"
> simply changes what the module's "print" variable refers to. Other
> modules are unaffected.  "Global" variables aren't truly global;
> they are actually local to the module.  You need to replace it in
> the __builtins__ because that's where everyone else gets it.
>
> > FWIW, it doesn't work, either. :-}
>
> Right. Lie answered why. I didn't pay attention and thought you
> were already using Python 3.

Thanks, Robert and Lie for the considered and informative responses.
Getting feedback like this from people who really understand
Python's internals is invaluable.  Sounds like redirecting
stdout/stderr is the way to go.  (Especially given that they're not
the 'real' stdout/stderr---that was news to me!)

[xref "Suppress output to stdout/stderr in InteractiveInterpreter"]
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: cross-platform coloured text in terminal

2010-04-16 Thread Lie Ryan
On 04/16/10 19:28, Jonathan Hartley wrote:
> I'm playing with ideas of what API to expose. My favourite one is to
> simply embed ANSI codes in the stream to be printed. Then this will
> work as-is on Mac and *nix. To make it work on Windows, printing could
> be done to a file0-like object which wraps stdout:

The problem with that is you're simply reinventing ANSI.SYS device driver.

An alternative API is you could override .__add__(), like so (completely
untested):

class Color(object):
   def __init__(self, color):
   self.color =  map_the_color(color)
   self.string = ""
   def __add__(self, string):
   self.string += string
   return self
   def __str__(self):
   if terminal_can_do_ansi_color:
   return ansicolorescape(self.string, self.color)
   elif windows:
   syscalltocolor(self.color)
   print self.string
   syscalltocolor(reset the color)
   return ""

GREEN = Color('green')
print GREEN + "Great" + "Good"

you can even go a bit further and allow chained calls (again, completely
untested, but you get the idea):

class Color(object):
   def __init__(self, color):
   self.color =  map_the_color(color)
   self.stack = []
   def __add__(self, string):
   if isinstance(string, Color):
   # not a string, chain the calls
   self.stack.append((string.color, []]))
   else:
   # a string,
   self.stack[-1][1].append(string)
   return self
   def __radd__(self, string):
   self.stack.append([self.default, string])
   return self

   def __str__(self):
   if ansi_capable:
   return colorescape(format, string)
   elif windows:
   for format, string in self.stack:
   syscalltocolor(color)
   print string
   return ""

GREEN = Color('green')
RED = Color('red')

print "Fairly" + GREEN + "Great" + RED + "Poor"

or something like that, and you will have an API that works
transparently on all platforms. The downside is that you cannot call
str(GREEN + "foo") on windows.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Updated License Term Agreement for VC Redistributable in VS 2008 SP1

2010-04-16 Thread Lie Ryan
On 04/15/10 06:38, pyt...@bdurham.com wrote:
> Alex,
> 
>> I do not see anything about redistribution, only installation, unless I am 
>> missing something?
> 
> I read "installation" to mean the same as "redistribution" in the
> context of this article. Perhaps I'm wrong?
> 

Does it makes sense to be able to install a library in other's computer,
but not redistribute it? Hmm... I'll have to consult a lawyer.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Globally override built-in print function?

2010-04-16 Thread J. Cliff Dyer
On Fri, 2010-04-16 at 09:50 -0700, Dave W. wrote:
> >>> 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.
> >
> > Not at all. Declaring "global print" then assigning to "print"
> > simply changes what the module's "print" variable refers to. Other
> > modules are unaffected.  "Global" variables aren't truly global;
> > they are actually local to the module.  You need to replace it in
> > the __builtins__ because that's where everyone else gets it.
> >
> > > FWIW, it doesn't work, either. :-}
> >
> > Right. Lie answered why. I didn't pay attention and thought you
> > were already using Python 3.
> 
> Thanks, Robert and Lie for the considered and informative responses.
> Getting feedback like this from people who really understand
> Python's internals is invaluable.  Sounds like redirecting
> stdout/stderr is the way to go.  (Especially given that they're not
> the 'real' stdout/stderr---that was news to me!)
> 
> [xref "Suppress output to stdout/stderr in InteractiveInterpreter"]

It's good to remember that names in python are just names.  The objects
that have the names "sys.stdout" and "sys.stderr" are the real deal, but
when you assign a file object to them, you are not actually
"redirecting" anything.  You are assigning a name (sys.stdout) to a
different file object.  The old object still points to STDOUT, but
sys.stdout no longer refers to that object as long as your assignment
remains in scope.

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


Re: Updated License Term Agreement for VC Redistributable in VS 2008 SP1

2010-04-16 Thread python
Lie,

> Does it makes sense to be able to install a library in other's computer, but 
> not redistribute it? Hmm... I'll have to consult a lawyer.

See Tim Robert's response (I can't remember which Python mailing list)


The license agreement change fixes a problem that was accidentally
introduced by Visual Studio 2008 SP1. The redistributable package that
can be downloaded directly from Microsoft (which you would use if you
had the Express Edition) has the right license to begin with. It never
had the restriction.

http://msdn.microsoft.com/en-us/library/ms235299.aspx

Microsoft's intent is that you be able to distribute the non-debug
runtimes with any applications built with Visual Studio. They are evil,
but not arbitrarily malicious.


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


Re: Merge two directories together

2010-04-16 Thread Steven Howe

Think about using the subprocess module. There are calls made just for
your. Notably (using command pydoc subprrocess.call) :
-
subprocess.call = call(*popenargs, **kwargs)
Run command with arguments.  Wait for command to complete, then
return the returncode attribute.

The arguments are the same as for the Popen constructor.  Example:

retcode = call(["ls", "-l"])
-


Steven Howe


On 04/16/2010 06:48 AM, Keith Hughitt wrote:

Suppose you have two file-trees with common sub-directories but
different files that you want to merge together, e.g.

/test/
/test/a/
/test/a/file1

/test2/
/test2/a/
/test2/a/file2

You can easily merge the directories in Linux using the "cp" command:

cp -r test/* test2/

While Python provides some helpful methods for moving files and
directories around (shutil.move, shutil.copytree, etc), none of them
seem to be able to merge two directories.

I've looked around some on Google for an alternative to calling cp
directly, but so far no luck.

Any ideas?
   


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


Re: Updated License Term Agreement for VC Redistributable in VS 2008 SP1

2010-04-16 Thread Lie Ryan
On 04/17/10 03:40, pyt...@bdurham.com wrote:
> Lie,
> 
>> Does it makes sense to be able to install a library in other's computer, but 
>> not redistribute it? Hmm... I'll have to consult a lawyer.
> 
> See Tim Robert's response (I can't remember which Python mailing list)
> 

I was responding to Alex Hall's comment (and your subsequent reply)

"""
pyt...@bdurham.com wrote:
> Alex Hall wrote:
>> I do not see anything about redistribution, only
>> installation, unless I am missing something?
> I read "installation" to mean the same as "redistribution" in the
> context of this article. Perhaps I'm wrong?
"""

it appears to me *if* someone had written an EULA that allows
installation on other machine but not redistributing it, they must be
fairly insane (in this case, Microsoft isn't insane enough to write such
EULA for their VC).
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Reactive programming in Python ?

2010-04-16 Thread Mike Kent
On Apr 16, 11:18 am, pca  wrote:
> Dear all,
>
> Could “reactive programming” still increase the productivity and joy
> of Python programming?  I’d like to hear your thoughts on the idea
> that object-oriented “programming by formula”, as in a spreadsheet,
> would simplify our work, because we would not have to worry about the
> sequence of program execution anymore.
>
> In fact, I have seeded an open-source project, Yoopf, that enables
> programming by formula within Python, with the goal of dramatically
> accelerating the development of the model view in the MVC model.
> Declarative-style programming has accelerated the development of the
> presentation layer (with HTML, CSS) and the Database layer (with SQL),
> so why not take advantage of it for the Business Logic layer too?
>
> You can find more information on this project atwww.yoopf.org.  Your
> comments are more than welcome!
>
> Best regards,
> P. Carbonnelle

The requested URL /www.yoopf.org was not found on this server.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Merge two directories together

2010-04-16 Thread Dave W.
> While Python provides some helpful methods for moving files and
> directories around (shutil.move, shutil.copytree, etc), none of
> them seem to be able to merge two directories.
-snip-
> Any ideas?

It's not pretty, but you could hack up the original copytree()
source so it ignores errors from the makedirs() call.  Then it
should work more-or-less like 'cp -r'.  This isn't ideal, because
'OSError' is thrown, which could mean that the dir already exists
(okay), or it could be a 'real' error, like the current user doesn't
have permission to write to the destination. (See 'XXX' in the code
below.)

Better would be to match on the error string and only ignore the
'directory exists' error.  Unfortunately, the error messages do
vary per-platform.  Here's what I see under Windows when the
directory already exists:

WindowsError: [Error 183] Cannot create a file when that file
already exists: 'test2'

and under CentOS:

OSError: [Errno 17] File exists: 'test2'

The code below seems to work under both Linux and Windows; but I
didn't really test it much, so handle with care.  :-}

--

def copytree(src, dst, symlinks=False, ignore=None):
import os
from shutil import copy2, copystat, Error

names = os.listdir(src)
if ignore is not None:
ignored_names = ignore(src, names)
else:
ignored_names = set()

try:
os.makedirs(dst)
except OSError, exc:
# XXX - this is pretty ugly
if "file already exists" in exc[1]:  # Windows
pass
elif "File exists" in exc[1]:# Linux
pass
else:
raise

errors = []
for name in names:
if name in ignored_names:
continue
srcname = os.path.join(src, name)
dstname = os.path.join(dst, name)
try:
if symlinks and os.path.islink(srcname):
linkto = os.readlink(srcname)
os.symlink(linkto, dstname)
elif os.path.isdir(srcname):
copytree(srcname, dstname, symlinks, ignore)
else:
copy2(srcname, dstname)
# XXX What about devices, sockets etc.?
except (IOError, os.error), why:
errors.append((srcname, dstname, str(why)))
# catch the Error from the recursive copytree so that we can
# continue with other files
except Error, err:
errors.extend(err.args[0])
try:
copystat(src, dst)
except WindowsError:
# can't copy file access times on Windows
pass
except OSError, why:
errors.extend((src, dst, str(why)))
if errors:
raise Error, errors
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Reactive programming in Python ?

2010-04-16 Thread Stefan Behnel
pca, 16.04.2010 17:18:
> In fact, I have seeded an open-source project, Yoopf, that enables
> programming by formula within Python, with the goal of dramatically
> accelerating the development of the model view in the MVC model.

Looks like the example on the main page would work better with the "any"
builtin than with the "sum" builtin.

Stefan

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


Re: Download Visual Studio Express 2008 now

2010-04-16 Thread Martin v. Löwis
Brian Blais wrote:
> On Apr 12, 2010, at 16:36 , Martin v. Loewis wrote:
> 
>> If you are planning to build Python extension modules in the next five
>> years, I recommend that you obtain a copy of VS Express
> 
> Am I missing something here?  I have heard this before, but I have built
> extension modules many times under windows (using Cython) and never once
> used a MS product.

It's fine if your package supports being compiled with Mingw32. A lot of
source code can't be compiled this way, either because gcc doesn't
support some of the MS extensions (in particular wrt. COM), or because
Mingw32 doesn't provide the header files (in particular wrt. C++), or
because linking with a library is necessary that uses the MSVC mangling,
not the g++ one (again, for C++).

Code written in Cython should work fine with gcc indeed.

> It seems to
> work fine.  What is the basis of this claim that you need MS Visual
> Studio to do it?

Just try building Mark Hammond's Win32 extensions or PythonWin with
Mingw32 to see for yourself.

Regards,
Martin

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


Re: Incorrect scope of list comprehension variables

2010-04-16 Thread Raymond Hettinger
On Apr 3, 3:30 am, Alain Ketterlin 
wrote:
> Hi all,
>
> I've just spent a few hours debugging code similar to this:
>
> d = dict()
> for r in [1,2,3]:
>     d[r] = [r for r in [4,5,6]]
> print d
>
> THe problem is that the "r" in d[r] somehow captures the value of the
> "r" in the list comprehension, and somehow kills the loop interator. The
> (unexpected) result is {6: [4, 5, 6]}. Changing r to s inside the list
> leads to the correct (imo) result.
>
> Is this expected? Is this a known problem? Is it solved in newer
> versions?

It is the intended behavior in 2.x.  The theory was that a list
comprehension would have the same effect as if it had been unrolled
into a regular for-loop.

In 3.x, Guido changed his mind and the induction variable is hidden.
The theory is that some folks (like you) expect the variable to be
private and that is what we already do with generator expressions.

There's no RightAnswer(tm), just our best guess as to what is the most
useful behavior for the most number of people.

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


Re: Can anyone reproduce this crash?

2010-04-16 Thread Terry Reedy

On 4/16/2010 9:50 AM, Alf P. Steinbach wrote:

* Alf P. Steinbach:


Found a another bug discussion with

* same exception,
0xc417 STATUS_INVALID_CRUNTIME_PARAMETER

* same address,
0x78588389

* almost same Python version,
namely Py3,

* almost same context,
namely occurring when program terminates,

at

http://www.mail-archive.com/pyinstal...@googlegroups.com/msg01564.html>

Can I report a bug with so little information -- not generally
reproducible, but hey, someone else has seen something nearly identical?


OK, I did, http://bugs.python.org/issue8418>.


Good report. I might have just dismissed this as a random windows bug ;-).

Terry Jan Reedy

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


distutils examples?

2010-04-16 Thread TomF
I'm packaging up a program with distutils and I've run into problems 
trying to get setup.py right.  It's not a standalone package; it's a 
script plus modules, data files and documentation.  I've been over the 
distutils documentation but I'm having trouble getting the package_data 
and data_files correct.


Is there a repository of distutils examples somewhere that I can look at?
The documentation is not particularly instructive for me.

Thanks,
-Tom

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


Re: question about list extension

2010-04-16 Thread Terry Reedy

On 4/16/2010 9:41 AM, J wrote:

Ok... I know pretty much how .extend works on a list... basically it
just tacks the second list to the first list... like so:


lista=[1]
listb=[2,3]
lista.extend(listb)
print lista;

[1, 2, 3]


This shows right here that lista is extended in place. If you are not 
convinced, print(id(lista)) before and after.



what I'm confused on is why this returns None:


lista=[1]
listb=[2,3]
print lista.extend(listb)

None


It is conventional in Python (at least the stdlib) that methods that 
mutate mutable objects 'in-place' return None to clearly differentiate 
them from methods that return new objects. There are pluses and minuses 
but such it is.


Terry Jan Reedy

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


Re: distutils examples?

2010-04-16 Thread Philip Semanchuk


On Apr 16, 2010, at 3:12 PM, TomF wrote:

I'm packaging up a program with distutils and I've run into problems  
trying to get setup.py right.  It's not a standalone package; it's a  
script plus modules, data files and documentation.  I've been over  
the distutils documentation but I'm having trouble getting the  
package_data and data_files correct.


Is there a repository of distutils examples somewhere that I can  
look at?

The documentation is not particularly instructive for me.


Hi Tom,
I don't know of a dedicated repository of distutils examples, but  
there's so many packages out there that it's sure that someone's  
already done what you're trying to do. If you can find that package  
(easier said than done, I know) then you have a working example.


THat's the main way I've been learning how to write setup.py files. I  
also find the distutils documentation somewhat opaque.



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


Re: question about list extension

2010-04-16 Thread J
On Fri, Apr 16, 2010 at 15:16, Terry Reedy  wrote:
> On 4/16/2010 9:41 AM, J wrote:
>>
>> Ok... I know pretty much how .extend works on a list... basically it
>> just tacks the second list to the first list... like so:
>>
> lista=[1]
> listb=[2,3]
> lista.extend(listb)
> print lista;
>>
>> [1, 2, 3]
>
> This shows right here that lista is extended in place. If you are not
> convinced, print(id(lista)) before and after.

Thanks for the explanations, everyone...

I was just a bit confused about how .extend was working... I
originally thought that it returned a new object and linked lista to
that, but I realize that it directly manipulates the list object
instead...

I'm not sure why I got that idea stuck in my head, but it was there,
so I asked :)
-- 
http://mail.python.org/mailman/listinfo/python-list


getting a string as the return value from a system command

2010-04-16 Thread Catherine Moroney

Hello,

I want to call a system command (such as uname) that returns a string,
and then store that output in a string variable in my python program.

What is the recommended/most-concise way of doing this?

I could always create a temporary file, call the "subprocess.Popen"
module with the temporary file as the stdout argument, and then
re-open that temporary file and read in its contents.  This seems
to be awfully long way of doing this, and I was wondering about 
alternate ways of accomplishing this task.


In pseudocode, I would like to be able to do something like:
hostinfo = subprocess.Popen("uname -srvi") and have hostinfo
be a string containing the result of issuing the uname command.

Thanks for any tips,

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


Re: Reactive programming in Python ?

2010-04-16 Thread pca
On Apr 16, 8:28 pm, Stefan Behnel  wrote:
> pca, 16.04.2010 17:18:
>
> > In fact, I have seeded an open-source project, Yoopf, that enables
> > programming by formula within Python, with the goal of dramatically
> > accelerating the development of the model view in the MVC model.
>
> Looks like the example on the main page would work better with the "any"
> builtin than with the "sum" builtin.
>
> Stefan

Stefan,

I'm not sure what you mean.  The example formula in the main page of
http://www.yoopf.org calculates the total amount of an order as the
sum of the amount of each order line: why the 'any' ?

By the way, Mike is right.  The URL should be http://www.yoopf.org
(not http://www.google.com/www.yoopf.org)  Sorry for that.

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


Re: Reactive programming in Python ?

2010-04-16 Thread Stefaan Himpe



You can find more information on this project at www.yoopf.org.  Your
comments are more than welcome!


Is this something similar to trellis?
http://pypi.python.org/pypi/Trellis

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


Re: getting a string as the return value from a system command

2010-04-16 Thread Robert Kern

On 2010-04-16 14:06 PM, Catherine Moroney wrote:

Hello,

I want to call a system command (such as uname) that returns a string,
and then store that output in a string variable in my python program.

What is the recommended/most-concise way of doing this?

I could always create a temporary file, call the "subprocess.Popen"
module with the temporary file as the stdout argument, and then
re-open that temporary file and read in its contents. This seems
to be awfully long way of doing this, and I was wondering about
alternate ways of accomplishing this task.


p = subprocess.Popen(['uname', '-srvi'], stdout=subprocess.PIPE,
stderr=subprocess.PIPE)
stdout, stderr = p.communicate()

--
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


Re: getting a string as the return value from a system command

2010-04-16 Thread Catherine Moroney

Robert Kern wrote:

On 2010-04-16 14:06 PM, Catherine Moroney wrote:

Hello,

I want to call a system command (such as uname) that returns a string,
and then store that output in a string variable in my python program.

What is the recommended/most-concise way of doing this?

I could always create a temporary file, call the "subprocess.Popen"
module with the temporary file as the stdout argument, and then
re-open that temporary file and read in its contents. This seems
to be awfully long way of doing this, and I was wondering about
alternate ways of accomplishing this task.


p = subprocess.Popen(['uname', '-srvi'], stdout=subprocess.PIPE,
stderr=subprocess.PIPE)
stdout, stderr = p.communicate()



Thanks, I knew there had to be a more elegant way of doing that.

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


SEC apparently about to mandate Python for a particular financial use

2010-04-16 Thread Mike Kent
http://jrvarma.wordpress.com/2010/04/16/the-sec-and-the-python/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: SEC apparently about to mandate Python for a particular financial use

2010-04-16 Thread Chris Rebert
On Fri, Apr 16, 2010 at 3:01 PM, Mike Kent  wrote:
> SEC apparently about to mandate Python for a particular financial use
> http://jrvarma.wordpress.com/2010/04/16/the-sec-and-the-python/

See thread from 5 days ago:
http://mail.python.org/pipermail/python-list/2010-April/1241578.html

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


Re: Download Visual Studio Express 2008 now

2010-04-16 Thread 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?

Most definitely. They have switched *again* the way they distribute the
CRT, so major changes to packaging and distutils would be required.

> 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.

It took us about two years to accommodate the CRT change. This time, it
will be easier, but nowhere near 2 months. I'm skeptical that the switch
to VS 2010 will be ready for 3.2.

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


Re: What license/copyright text to include and where to include it when selling a commercial Python based application?

2010-04-16 Thread Martin v. Loewis
> 1. What Python license text/copyright text should I place in our
> printed user manual?
> 
> 2. What Python license text/copyright text should I include in
> our online documentation?
> 
> 3. What Python license text/copyright text should I include in
> product's license text file?
> 
> 4. What Python license text/copyright text should I include in
> application's splash screen and about dialog boxes?

IANAL, and you should really ask your own lawyer.

However, the relevant clause seems to be clause 2, which requires you to
retain a copy of the license "in Python alone or in any derivative
version prepared by Licensee".

IIUC, your product will be a derivative version (ask your lawyer whether
that's a correct assessment). Then, the only requirement is to have a
copy of the license in the derivative work, i.e. in the software
installation. No need to include it in the manual, the online
documentation, or the splash screen. Putting it into the product's
license text file might be appropriate, as might be putting it next to it.

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


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

2010-04-16 Thread Gabriel Genellina

En Thu, 15 Apr 2010 16:37:37 -0300, gert  escribió:


[a wget -r like implementation in python3]
So I can make a recursive http download script


What about calling wget itself? subprocess.call(['wget',...])


--
Gabriel Genellina

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


Re: SEC apparently about to mandate Python for a particular financial use

2010-04-16 Thread Gnarlodious
"technology as a regulatory tool", what a concept! Pretty impressive
change we can believe in. Here's hoping open-source human-readable
computer programs become the standard for verifiable elections and all
sorts of financial uses. Otherwise, computers will end up being used
to defraud the populace rather than to serve it.

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


Re: Incorrect scope of list comprehension variables

2010-04-16 Thread Steven D'Aprano
On Fri, 16 Apr 2010 08:48:03 -0700, Aahz wrote:

> In article <4bb92850$0$8827$c3e8...@news.astraweb.com>, Steven D'Aprano 
>  wrote:
>>
>>Nevertheless, it is a common intuition that the list comp variable
>>should *not* be exposed outside of the list comp, and that the for-loop
>>variable should. Perhaps it makes no sense, but it is very common --
>>I've never heard of anyone being surprised that the for-loop variable is
>>exposed, but I've seen many people surprised by the fact that list-comps
>>do expose their loop variable.
> 
> I've definitely seen people surprised by the for-loop behavior.

What programming languages were they used to (if any)?

I don't know of any language that creates a new scope for loop variables, 
but perhaps that's just my ignorance...


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


Re: Incorrect scope of list comprehension variables

2010-04-16 Thread Chris Rebert
On Fri, Apr 16, 2010 at 5:20 PM, Steven D'Aprano
 wrote:
> On Fri, 16 Apr 2010 08:48:03 -0700, Aahz wrote:
>> In article <4bb92850$0$8827$c3e8...@news.astraweb.com>, Steven D'Aprano
>>  wrote:
>>>Nevertheless, it is a common intuition that the list comp variable
>>>should *not* be exposed outside of the list comp, and that the for-loop
>>>variable should. Perhaps it makes no sense, but it is very common --
>>>I've never heard of anyone being surprised that the for-loop variable is
>>>exposed, but I've seen many people surprised by the fact that list-comps
>>>do expose their loop variable.
>>
>> I've definitely seen people surprised by the for-loop behavior.
>
> What programming languages were they used to (if any)?
>
> I don't know of any language that creates a new scope for loop variables,
> but perhaps that's just my ignorance...

Well, technically it's the idiomatic placement of the loop variable
declaration rather than the loop construct itself, but:

//Written in Java
//Can trivially be changed to C99 or C++
for (int i = 0; i < array.length; i++)
{
// code
}
// variable 'i' no longer accessible

//Using a for-each loop specific to Java
for (ItemType item : array)
{
// code
}
// variable 'item' no longer accessible

Cheers,
Chris
--
http://blog.rebertia.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Incorrect scope of list comprehension variables

2010-04-16 Thread MRAB

Steven D'Aprano wrote:

On Fri, 16 Apr 2010 08:48:03 -0700, Aahz wrote:

In article <4bb92850$0$8827$c3e8...@news.astraweb.com>, Steven D'Aprano 
 wrote:

Nevertheless, it is a common intuition that the list comp variable
should *not* be exposed outside of the list comp, and that the for-loop
variable should. Perhaps it makes no sense, but it is very common --
I've never heard of anyone being surprised that the for-loop variable is
exposed, but I've seen many people surprised by the fact that list-comps
do expose their loop variable.

I've definitely seen people surprised by the for-loop behavior.


What programming languages were they used to (if any)?

I don't know of any language that creates a new scope for loop variables, 
but perhaps that's just my ignorance...



The programming language Ada comes to mind (the variable exists only
within the body of the loop and is read-only like a constant), so yes,
that's just your ignorance. ;-)
--
http://mail.python.org/mailman/listinfo/python-list


Re: Incorrect scope of list comprehension variables

2010-04-16 Thread Alf P. Steinbach

* Steven D'Aprano:

On Fri, 16 Apr 2010 08:48:03 -0700, Aahz wrote:

In article <4bb92850$0$8827$c3e8...@news.astraweb.com>, Steven D'Aprano 
 wrote:

Nevertheless, it is a common intuition that the list comp variable
should *not* be exposed outside of the list comp, and that the for-loop
variable should. Perhaps it makes no sense, but it is very common --
I've never heard of anyone being surprised that the for-loop variable is
exposed, but I've seen many people surprised by the fact that list-comps
do expose their loop variable.

I've definitely seen people surprised by the for-loop behavior.


What programming languages were they used to (if any)?

I don't know of any language that creates a new scope for loop variables, 
but perhaps that's just my ignorance...


MRAB has mentioned Ada, let me mention C++ ...



#include 

int main()
{
int const   i = 42;

for( int i = 0; i < 10; ++i )
{
// blah blah
}
assert( i == 42 );
}



Java and C# take a slightly different approach where code analogous to the above 
won't compile. But it's still a nested scope. E.g. ...





class App
{
static public void main( String[] args )
{
for( int i = 0; i < 10; ++i )
{
// blah blah
}

// Uncomment statement below to get compilation error:
//System.out.println( i );
}
}



So, yes, considering Ada, C++, Java and C#  --  and so on. ;-)


Cheers & hth.,

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


Re: getting a string as the return value from a system command

2010-04-16 Thread Larry Hudson

Catherine Moroney wrote:

Hello,

I want to call a system command (such as uname) that returns a string,
and then store that output in a string variable in my python program.

What is the recommended/most-concise way of doing this?

I could always create a temporary file, call the "subprocess.Popen"
module with the temporary file as the stdout argument, and then
re-open that temporary file and read in its contents.  This seems
to be awfully long way of doing this, and I was wondering about 
alternate ways of accomplishing this task.


In pseudocode, I would like to be able to do something like:
hostinfo = subprocess.Popen("uname -srvi") and have hostinfo
be a string containing the result of issuing the uname command.

Thanks for any tips,

Catherine


import os
txt = os.popen("uname -srvi")
hostinfo = txt.readline()

Or if the command outputs a number of lines (such as 'ls'),
use txt.readlines() to put the result into a list of strings.

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


Elise Mooney reports on Channel 9 about Maths Worldwide and the fraud that it is

2010-04-16 Thread Ms. Hyde
Link: http://www.petitiononline.com/mwwabuse/petition.html (as
reported by Elise Mooney from Channel 9)

I wish to raise this topic of Rob and Kim Hyde and their experience
they stated publicly on Channel Nine's A Current Affair. Now they are
caring loving parents, and for them to even THINK about going on
television just demonstrates to you how far/extreme the ethical
conduct of Mathemagic (now known as Maths Worldwide) has gone. And the
thing is, they just DONT learn from their lesson. As you already know,
Mathemagic bankrupt under the hands of the very professionally inept
hands of Gary Rosenberg. His name is already disgraced as it was
featured in a major newspaper publication: he's a nobody, he should be
shunned in our society, and that's what bankrupt law is meant to do.

Now as to this new respawning of Mathemagic as Maths Worldwide, they
are completely and utterly ridiculous under the Trade Practices Act.
Not only do they not act in good faith, but in no way could you even
suggest that such a firm which has had this PAST< should you EVER
consider buying from again.

Now I read another person analogizing the conduct of Maths Worldwide
to that of child pedophiles. Now so not to be defamatory, I'm going to
analyze this matter in good faith. Being a pedophile means you have a
sexual perversion in which children are the preferred sexual object.
Obviously, there is no statement of fact that Maths Worldwide
personell have sexually molested little children (and I don't make
that inference). But I understand the analogy to financial abuse.
Abuse comes in many ways, verbal abuse, really, any sort of abuse
towards kids isn't okay. Financially targetting little children, is
just SICK, and it should be jailable in our society. I don't care what
your view is in life, you have got to have mental problems to do
something like that, serious psychological issues. You need to go to
see a psychiatrist if you do something like that. It is a failure of
our market to address it otherwise.

If I were you, I would immediately write to your local MP, guys, this
is our CHILDREN's stake at future.

We CANNOT let this sort of scam stay around.

With over 4 million customers, this is the BIGGEST scam in Australia
since the Nigerian scams.

And I called the ACCC, and they said they couldn't do a thing.

Why?

Because Mathemagic went into bankruptcy.

And then there is the issue about the allegedly 'fiesty red haired
porn star Director' (I'm not sure how accurate it is since it is a
forum post, of Western Australia subsidiary apparently). But, I
wouldn't be surprised. Look at her on YouTube, she's not reliable,
nothing about that business is trustable. The brand name of that
company is so damaged, I don't think it could be damaged it any
further. I don't think they even took action against Channel 9's a
Current Affair because they knew how much of a RIP they were.



Maths Worldwide is at it again, trying to find a fiesty red female,
who looks like she walked out of a pornographic movie, with the
following sales pitch. I've included it below, but just a few
comments:
- She looks nothing like a teacher, just ANOTHER sales agent, the same
people we know (and hate) who ripped off little children just as
pedophiles touch little kids inappropriately. It's called CHILD ABUSE
when you're abusing children's finances
- They are trying to get testimonies from people by selling it at
$390, didn't the web site say it's now costing $650? Which one is it?
- Why the hell are they still called Australian Institute of Maths? I
thought this fraud owned by Gary Rosenberg was shut down??? Now
renamed Maths Worldwide? So mathemagic is the same thing as Maths
Worldwide then? What's happening?
- Why aren't any names given? If you have a consultant come in your
house, ask their name and post it on here. THEIR FULL NAME. - Even at
$400... they're still charging $31 a week for 12 weeks - what a RIPP
OFF. stil trying to enter parents into contracts. ripping people -
they're at it again.
Anyway, here is the copy of the advert:
"Hi, and thanks for your time. We at Maths Worldwide are dedicated
educationalists who have a genuine interest in improving the standard
of childrens edcuation here in the greatest country of the world,
Australia. We believe that education is power, and power creates
opportunity. We want all our chidlren to make the most of their
opportunity. During the past year or so, you allowed an education
consultant representing the Australian Institute of Maths [You're
shitting me, they're still using that name???] enter your home, to
demonstrate the mathemagic computer tutor. During the time spent in
your house, your children would have conducted a diagnostic test, to
see how they were going with udnerstanding maths. Remember that? It
was almost a reflection of your children's report card. Well just as a
refresher, why do some chidlren perform very poorly at school? And
excel once they go to work? Just because they 

Re: Reactive programming in Python ?

2010-04-16 Thread Stefan Behnel

pca, 16.04.2010 22:02:

On Apr 16, 8:28 pm, Stefan Behnel wrote:

pca, 16.04.2010 17:18:


In fact, I have seeded an open-source project, Yoopf, that enables
programming by formula within Python, with the goal of dramatically
accelerating the development of the model view in the MVC model.


Looks like the example on the main page would work better with the "any"
builtin than with the "sum" builtin.


I'm not sure what you mean.  The example formula in the main page of
http://www.yoopf.org calculates the total amount of an order as the
sum of the amount of each order line: why the 'any' ?


I guess I misinterpreted the phrase "only when one of its order line has 
been added or deleted" as meaning that a change to any of the amounts would 
trigger an event. It wasn't clear to me that the example actually presented 
a calculation that would be evaluated based on that event.


You might want to give potential users a better idea of what this tool 
does. Neither your announcement nor the homepage made that clear to me.


Stefan

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


Re: Striving for PEP-8 compliance

2010-04-16 Thread Gregory Ewing

Steven D'Aprano wrote:

On Wed, 14 Apr 2010 22:10:28 +0200, Hans Mulder wrote:



Anybody who invents another brace-delimited language should be beaten.
You always end up with a big problem trying to make sure the braces are
consistent with the program logic.


Anybody who invents another programming language should be beaten. You
always end up with a big problem trying to make sure the program logic
is consistent with the customers's needs :-(



Anyone who invents another program should be beaten. You always end up 
with a big problem trying to make sure the program logic is consistent 
with what the customer thinks they need.


Anyone who takes on new customers should be beaten. You always end up
with a big problem trying to make sure that what the customer thinks
they need is what they actually need.

--
Greg

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


Re: getting a string as the return value from a system command

2010-04-16 Thread CHEN Guang
> Catherine Moroney wrote:
>> Hello,
>> 
>> I want to call a system command (such as uname) that returns a string,
>> and then store that output in a string variable in my python program.
>> 
>> What is the recommended/most-concise way of doing this?
>> 
>> I could always create a temporary file, call the "subprocess.Popen"
>> module with the temporary file as the stdout argument, and then
>> re-open that temporary file and read in its contents.  This seems
>> to be awfully long way of doing this, and I was wondering about 
>> alternate ways of accomplishing this task.
>> 
>> In pseudocode, I would like to be able to do something like:
>> hostinfo = subprocess.Popen("uname -srvi") and have hostinfo
>> be a string containing the result of issuing the uname command.
>> 
>> Thanks for any tips,
>> 
>> Catherine
> 
> import os
> txt = os.popen("uname -srvi")
> hostinfo = txt.readline()
> 
> Or if the command outputs a number of lines (such as 'ls'),
> use txt.readlines() to put the result into a list of strings.
> 
>  -=- Larry -=-
> 
os.popen3()  gives not only result but also error prompt (in case an error or 
warning happens)
stdin,stdout,stderr  =  os.popen3('uname -srvi')
resultText = stdout.read()
errorText = stderr.read()
For more examples of os.popen3() please look at source code of PythoidC 
(http://pythoidc.googlecode.com or http://pythoidc.sf.net )-- 
http://mail.python.org/mailman/listinfo/python-list