Re: Object serialization: transfer from a to b (non-implemented code on b)
Andreas Löscher wrote: import types import marshal def a(): pass ... s=marshal.dumps(a.__code__) f=types.FunctionType(marshal.loads(s), {}) f function a at 0x7f6308a66de8 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 stdin, line 1, in module 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
Andrej Mitrovic andrej.mitrov...@gmail.com 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)
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?
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
Jim Byrnes wrote: div class=moz-text-flowed style=font-family: -moz-fixedI 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?
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. snip 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
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 term, ANSI.GREEN + hello 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. -- http://mail.python.org/mailman/listinfo/python-list
Re: cross-platform coloured text in terminal
On Apr 16, 10:28 am, Jonathan Hartley tart...@tartley.com 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 term, ANSI.GREEN + hello 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)
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?
Python 3.1.1 in Windows XP Prof: code filename=sum.v4.py language=Py3 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 ) ) /code To be thorough I tested the reaction to typing [Ctrl C] at the first prompt. It then displayed the first part of traceback output, output part=1 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): /output 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: output part=2 File C:\Documents and Settings\Alf\sum.v4.py, line 13, in module C:\Documents and Settings\Alf _ /output 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?
Alf P. Steinbach wrote: Python 3.1.1 in Windows XP Prof: code filename=sum.v4.py language=Py3 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 ) ) /code To be thorough I tested the reaction to typing [Ctrl C] at the first prompt. It then displayed the first part of traceback output, output part=1 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): /output 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: output part=2 File C:\Documents and Settings\Alf\sum.v4.py, line 13, in module C:\Documents and Settings\Alf _ /output 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?
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?
* MRAB: Alf P. Steinbach wrote: Python 3.1.1 in Windows XP Prof: code filename=sum.v4.py language=Py3 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 ) ) /code To be thorough I tested the reaction to typing [Ctrl C] at the first prompt. It then displayed the first part of traceback output, output part=1 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): /output 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: output part=2 File C:\Documents and Settings\Alf\sum.v4.py, line 13, in module C:\Documents and Settings\Alf _ /output 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: vsinfo '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). /vsinfo 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
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
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
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
On 04/15/10 02:03, Paul Rubin wrote: Raymond Hettinger pyt...@rcn.com 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?
* Alf P. Steinbach: * MRAB: Alf P. Steinbach wrote: Python 3.1.1 in Windows XP Prof: code filename=sum.v4.py language=Py3 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 ) ) /code To be thorough I tested the reaction to typing [Ctrl C] at the first prompt. It then displayed the first part of traceback output, output part=1 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): /output 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: output part=2 File C:\Documents and Settings\Alf\sum.v4.py, line 13, in module C:\Documents and Settings\Alf _ /output 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: vsinfo '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). /vsinfo 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: info 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 /info The tell-Bill box also reported more modules loaded than Visual Studio, but I think that has to do with the box itself: modules 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
Re: Download Visual Studio Express 2008 now
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
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?
* 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. url: 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
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?
* 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. url: 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 url: 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
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
On Apr 16, 10:48 am, Mark Hammond skippy.hamm...@gmail.com 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
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
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?
* 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 url: 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, url: 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
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 t...@probo.com 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 andrej.mitrov...@gmail.com 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
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
Jim Byrnes wrote: Dave Angel wrote: Jim Byrnes wrote: div class=moz-text-flowed style=font-family: -moz-fixedI 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
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) snip 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
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
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
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 ?
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?
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.snip 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
Hi Mark, On Apr 16, 3:16 am, Mark Hammond skippy.hamm...@gmail.com 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
In article 4bb92850$0$8827$c3e8...@news.astraweb.com, Steven D'Aprano st...@remove-this-cybersource.com.au 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
On Apr 16, 3:31 am, Tim Roberts t...@probo.com wrote: Andrej Mitrovic andrej.mitrov...@gmail.com 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
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?
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
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
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?
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
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) quote 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. /quote Malcolm -- http://mail.python.org/mailman/listinfo/python-list
Re: Merge two directories together
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
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 ?
On Apr 16, 11:18 am, pca pcarb...@yooper.be 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
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 ?
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
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
On Apr 3, 3:30 am, Alain Ketterlin al...@dpt-info.u-strasbg.fr 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?
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 url: 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, url: 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?
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
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?
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
On Fri, Apr 16, 2010 at 15:16, Terry Reedy tjre...@udel.edu 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
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 ?
On Apr 16, 8:28 pm, Stefan Behnel stefan...@behnel.de 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 ?
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
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
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
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
On Fri, Apr 16, 2010 at 3:01 PM, Mike Kent mrmak...@gmail.com 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
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?
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
En Thu, 15 Apr 2010 16:37:37 -0300, gert gert.cuyk...@gmail.com 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
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
On Fri, 16 Apr 2010 08:48:03 -0700, Aahz wrote: In article 4bb92850$0$8827$c3e8...@news.astraweb.com, Steven D'Aprano st...@remove-this-cybersource.com.au 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
On Fri, Apr 16, 2010 at 5:20 PM, Steven D'Aprano st...@remove-this-cybersource.com.au wrote: On Fri, 16 Apr 2010 08:48:03 -0700, Aahz wrote: In article 4bb92850$0$8827$c3e8...@news.astraweb.com, Steven D'Aprano st...@remove-this-cybersource.com.au 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
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 st...@remove-this-cybersource.com.au 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
* 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 st...@remove-this-cybersource.com.au 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++ ... code language=C++ #include assert.h int main() { int const i = 42; for( int i = 0; i 10; ++i ) { // blah blah } assert( i == 42 ); } /code 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. ... code language=Java 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 ); } } /code 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
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
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
[issue8416] python 2.6.5 documentation can't search
New submission from Santiago Gala sg...@apache.org: http://docs.python.org/release/2.6.5/search.html?q=regular+expression fails. It fails because http://docs.python.org/release/2.6.5/searchindex.js returns 404 NOT FOUND There are really two bugs here: * that the file is not there, and * that the page gives no clue that there is something broken inside IMO the second one is more important: the page stays forever with the Searching and the dots moving... I reported against build and Documentation as I'm not sure if the web site belongs here and where is the issue originating. -- assignee: georg.brandl components: Documentation messages: 103293 nosy: georg.brandl, sgala severity: normal status: open title: python 2.6.5 documentation can't search type: behavior versions: Python 2.6 ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue8416 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue4356] Add key argument to bisect module functions
Alex alex.gay...@gmail.com added the comment: Looks nice to me, however I wonder if there isn't some overlap with the requests to add a key= kwarg to heapq methods (and the discussion about adding a Heap class there). -- nosy: +alex ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue4356 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue7384] curses crash on FreeBSD
Jeroen Ruigrok van der Werven asmo...@in-nomine.org added the comment: For the record, this happens on FreeBSD 8 as well. It seems it is still the same bug as what I reported back in March 2009 on the Python-dev list. If you run the test stand-alone with ./python Lib/test/regrtest.py -uall test_curses it passes and prints 1 test OK. If you add something like test__all__ before it it will crash with a SIGSEGV: segmentation fault (core dumped). Mark's condensed test case switches to a SIGBUS, which is a bit different. Mark, did your initial backtrace look like this: #0 0x282e115e in memcpy () from /lib/libc.so.7 #1 0x282de375 in fwrite () from /lib/libc.so.7 #2 0x282de132 in fwrite () from /lib/libc.so.7 #3 0x28b7a1ca in putwin (win=0x28409640, filep=0x282f39f8) at /newusr/src/lib/ncurses/ncursesw/../../../contrib/ncurses/ncurses/base/lib_screen.c:132 #4 0x28d9b361 in PyCursesWindow_PutWin (self=0x28442ef0, args=0x2867f80c) at /home/asmodai/projects/python/Modules/_cursesmodule.c:1351 #5 0x080da60d in PyEval_EvalFrameEx (f=0x296d760c, throwflag=0) at Python/ceval.c:4013 #6 0x080db10e in PyEval_EvalFrameEx (f=0x296a948c, throwflag=0) at Python/ceval.c:4099 #7 0x080db10e in PyEval_EvalFrameEx (f=0x29692d8c, throwflag=0) at Python/ceval.c:4099 #8 0x080dc68b in PyEval_EvalCodeEx (co=0x297675c0, globals=0x2866bbdc, locals=0x2866bbdc, args=0x0, argcount=0, kws=0x0, kwcount=0, defs=0x0, defcount=0, closure=0x0) at Python/ceval.c:3253 #9 0x080dc7d7 in PyEval_EvalCode (co=0x297675c0, globals=0x2866bbdc, locals=0x2866bbdc) at Python/ceval.c:666 #10 0x080ef70c in PyImport_ExecCodeModuleEx ( name=0xbfbfd683 test.test_curses, co=0x297675c0, pathname=0xbfbfd223 /home/asmodai/projects/python/Lib/test/test_curses.py) -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue7384 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue8401] Strange behavior of bytearray slice assignment
Ezio Melotti ezio.melo...@gmail.com added the comment: Here is a proof of concept that fixes the problem. The doc of bytearray() says about its first arg: * If it is a string, you must also give the encoding [...]. * If it is an integer, the array will have that size and will be initialized with null bytes. * If it is an object conforming to the buffer interface, a read-only buffer of the object will be used to initialize the bytes array. * If it is an iterable, it must be an iterable of integers in the range 0 = x 256, which are used as the initial contents of the array. All these things except the string[1] and the integer seem OK to me while assigning to a slice, so in the patch I've special-cased ints to raise a TypeError (it fails already for unicode strings). [1]: note that string here means unicode string (the doc should probably be more specific about it.). Byte strings work fine, but for unicode strings there's no way to specify the encoding while doing ba[:] = u'ustring'. -- keywords: +patch stage: needs patch - unit test needed Added file: http://bugs.python.org/file16945/issue8401.diff ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue8401 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue8408] need console/pager module
anatoly techtonik techto...@gmail.com added the comment: It is not a bug, but a feature request. -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue8408 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue8408] need console/pager module
Changes by Ezio Melotti ezio.melo...@gmail.com: -- nosy: +ezio.melotti stage: - committed/rejected ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue8408 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue8401] Strange behavior of bytearray slice assignment
Eugene Kapun abacabadabac...@gmail.com added the comment: Empty string is an iterable of integers in the range 0 = x 256, so it should be allowed. all(isinstance(x, int) and 0 = x 256 for x in ) True bytearray()[:] = Traceback (most recent call last): File stdin, line 1, in module TypeError: string argument without an encoding -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue8401 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue8401] Strange behavior of bytearray slice assignment
Ezio Melotti ezio.melo...@gmail.com added the comment: Not really, chars are not ints and anyway the empty string fall in the first case. -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue8401 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue8417] bytes and bytearray constructors raise TypeError for very large ints
New submission from Eugene Kapun abacabadabac...@gmail.com: bytes(10) b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00' bytes(10 ** 100) Traceback (most recent call last): File stdin, line 1, in module TypeError: 'int' object is not iterable -- components: Interpreter Core messages: 103300 nosy: abacabadabacaba severity: normal status: open title: bytes and bytearray constructors raise TypeError for very large ints type: behavior versions: Python 3.1 ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue8417 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue1766304] improve xrange.__contains__
Changes by Eugene Kapun abacabadabac...@gmail.com: -- nosy: +abacabadabacaba ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue1766304 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue1766304] improve xrange.__contains__
Mark Dickinson dicki...@gmail.com added the comment: I suggest closing this: it's been implemented (for range) in Python 3.x, and I think it's too late for 2.x now. -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue1766304 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue8401] Strange behavior of bytearray slice assignment
Eugene Kapun abacabadabac...@gmail.com added the comment: Not really, chars are not ints Yes, however, empty string contains exactly zero chars. and anyway the empty string fall in the first case. Strings aren't mentioned in documentation of bytearray slice assignment. However, I think that bytearray constructor should accept empty string too, without an encoding, for consistency. -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue8401 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue8355] diff.py produce unified format by default
anatoly techtonik techto...@gmail.com added the comment: I am not convinced with -1 +1 argumentation. Can somebody properly summarize arguments behind the decision? Democracy is good, but it is a pity to see a technical proposal fail because of personal reasons. -- status: pending - open ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue8355 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue8417] bytes and bytearray constructors raise TypeError for very large ints
Changes by Ezio Melotti ezio.melo...@gmail.com: -- nosy: +ezio.melotti priority: - normal stage: - unit test needed versions: +Python 2.6, Python 2.7, Python 3.2 ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue8417 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue8355] diff.py produce unified format by default
anatoly techtonik techto...@gmail.com added the comment: I.e. if you put a -1 or +1 - put it with a short sentence that summarizes the key factor in your decision. There is no +0 or -0 that are used to give everybody else a hint about your feelings towards. For example: +1 - I use patch.py diff.py counterpart that accepts only unified diffs without any options, so it would be nice if diff.py generated unified diffs without any options as well -1 - I don't use diff.py to generate my diffs, I do not care that it is not a part of standard library, I know that it's output format is incompatible with unix diff(1) format, and I still want diff.py to generate incompatible context diffs by default, even though I could always generate them with -c option -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue8355 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue8413] String interpolation doesn't work with sys.version_info
Eric Smith e...@trueblade.com added the comment: This affects any type implemented as PyStructSequence. For example, sys.flags has the same behavior. -- components: +Interpreter Core -Library (Lib) priority: - normal type: - behavior ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue8413 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue8401] Strange behavior of bytearray slice assignment
Eugene Kapun abacabadabac...@gmail.com added the comment: __doc__ of bytearray says: bytearray(iterable_of_ints) - bytearray bytearray(string, encoding[, errors]) - bytearray bytearray(bytes_or_bytearray) - mutable copy of bytes_or_bytearray bytearray(memory_view) - bytearray So, unless an encoding is given, empty string should be interpreted as an iterable of ints. BTW, documentation and docstring should be made consistent with each other. -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue8401 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue7384] curses crash on FreeBSD
Mark Dickinson dicki...@gmail.com added the comment: Mark, did your initial backtrace look like this: No; the segfault was definitely happening in delwin rather than putwin. But I did see something like your backtrace when I tried to use ncurses from ports (installed in /usr/local) rather than the system ncurses. This was all on FreeBSD 8.0/amd64, by the way, running in a VM on Parallels. I got the same results both when working directly within the VM terminal, and when ssh'ing to the VM from an OS X Terminal. Maybe running this through Valgrind or something similar might show what's going on. (Though it's not clear from a quick google whether Valgrind works on FreeBSD.) -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue7384 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue7384] curses crash on FreeBSD
Stefan Krah stefan-use...@bytereef.org added the comment: Valgrind can be installed by: cd /usr/ports/devel/valgrind make install Then you can do (curses_test.py is your short test program): 1) valgrind --db-attach=yes --suppressions=Misc/valgrind-python.supp ./python curses_test.py 2) valgrind --suppressions=Misc/valgrind-python.supp ./python curses_test.py Valgrind finds invalid writes. The problem with 1) is that the terminal is in an unusable state, so controlling gdb isn't possible. The best thing is probably to use 2) and wade through the unformatted output starting here: ==12043== Invalid write of size 8 ==12043==at 0x27A71B7: getwin (in/li /libncursesw.so.8) ==12043==by 0x2A3EAAB: PyCurses_GetWin (_cursesmodule.c:1902) ==12043==by 0x4573FB: PyEval_EvalFrameEx (ceval.c:3833) ==12043== by 0x457DF9: PyEval_EvalCodeEx (ceval.c:3282) (I don't have time to do that right now, I might do it later.) -- nosy: +skrah ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue7384 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue762963] timemodule.c: Python loses current timezone
Grant Bowman grant...@gmail.com added the comment: Is there anything others like me can do to help get this fixed? -- nosy: +grantbow ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue762963 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue8299] Improve GIL in 2.7
David Beazley d...@dabeaz.com added the comment: I'm sorry, but even in the presence of fair locking, I still don't like this patch. The main problem is that it confuses fair locking with fair CPU use---something that this patch does not and can not achieve on any platform. The main problem is that everything is still based on the execution of interpreter ticks. However, interpreter ticks have wildly varying execution times dependent upon the code that's running. Thus, executing 1000 ticks might take significantly longer in one thread than another. Under a FIFO scheduler based on fair locking, the thread with the longer-running ticks is going to unfairly hog the GIL and the CPU. For example, if thread 1 takes 95 usec to execute 1000 ticks and thread 2 takes 5 usec to execute 1000 ticks, then thread 1 is going to end up hogging about 95% of the CPU cycles, starving thread 2. To me, that doesn't sound especially fair. It would be much better to have fairness where threads are guaranteed to get an equal time slice of CPU cycles regardless of how many ticks they're executing. In other words, it would be much better if the two threads above each got 50% of the CPU cycles. The only way you're ever going to be able to do that is to base thread scheduling on timing. The new GIL in Python 3 makes an effort to do this even though some issues are still being worked out with it. On a slightly unrelated note, I just tried some experiments on Linux with the GIL implemented as condition variables and with semaphores. I honestly didn't see any noticeable performance difference between the two versions. I also didn't see any kind of purported fair scheduling of threads using the semaphore version. Both versions exhibit the same performance problems as described in my GIL talk (albeit not to the same extreme as on OS-X). Based on my own reading of the pthreads source code (yes, I have looked), I can't really draw any conclusion about the fairness of semaphores. Under the covers, it's all based on futex locks (the f in futex referring to fast, not fair by the way). I know that the original paper on futexes has some experiments with fair lock scheduling, but I honestly don't know if that is being used in the Linux kernel or by pthreads. My understanding is that by default, futexes do not guarantee fairness. To know for certain with semaphor es, much more low-level investigation would be required. -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue8299 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue8413] String interpolation doesn't work with sys.version_info
Changes by Ezio Melotti ezio.melo...@gmail.com: -- nosy: +ezio.melotti stage: - unit test needed ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue8413 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue8299] Improve GIL in 2.7
David Beazley d...@dabeaz.com added the comment: I've attached a test fair.py that gives an example of the fair CPU scheduling issue. In this test, there are two threads, one of which has fast-running ticks, one of which has slow-running ticks. Here is their sequential performance (OS-X, Python 2.6): slow: 5.71 fast: 0.32 Here is their threaded performance (OS-X, Python 2.6.4): slow : 5.99 fast : 6.04(Notice : Huge jump in execution, unfair CPU) Here is their threaded performance using the Py3K New GIL: slow : 5.96 fast : 0.67(Notice : Fair CPU use--time only doubled) Using Linux with semaphores gives no benefit here. The fast code is stalled in the same way. For example: here are my Linux results (Ubuntu 8.10, Python-2.6.4, dual-core, using semaphores): Sequential: slow : 6.24 fast : 0.59 Threaded: slow : 6.40 fast : 6.69(even slower than the slow code!) -- Added file: http://bugs.python.org/file16946/fair.py ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue8299 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue2987] RFC2732 support for urlparse (IPv6 addresses)
Senthil Kumaran orsent...@gmail.com added the comment: Reverted the check-in made to 3.1 maint (in r80104). Features should not go in there. -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue2987 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue8410] Fix emulated lock to be 'fair'
Kristján Valur Jónsson krist...@ccpgames.com added the comment: Martin, it isn't the condition variable which is unfair, but how the constructed locking apparatus is unfair that is the problem. This lock is written by a Tim, whom I assume to be Tim Peters. I quote his comment: In general, if the bit can be acquired instantly, it is, else the pair is used to block the thread until the bit is cleared. 9 May 1994 t...@ksr.com Herein lies the problem. This is the behaviour of greedy or unfair mutexes, not that of fair semaphores. The lock is made 'free' and the just signaled thread has to _race_ to acquire it. Since the exact mechanics seem to be unclair to many, let me just step you through the series of events. 1) A has the lock, B is waiting for it. the bit is set. 2) A releases the lock: Clears the bit, signals the condition variable. 3) A tries to immediately reacquire the lock. Sees the bit cleared, sets it, and claims the lock. 4) B wakes up from the condition variable. Sees the bit set and goes back to sleep. It has lost the race to A. If the lock were based on a semaphore, the events would be different: 1) A has the semaphore, B is waiting for it, sem.value == 0 2) A releases (signals) the semaphore. B is made runnable. sem.value stays at 0 3) A tries to immediately reacquire the lock. Finds the sem.value at 0 and blocks. 4) B wakes up and executes, now the owner of the lock. sem.value stays at 0. This particular patch implements the latter behaviour by explicitly entering a handoff period. If you want, I can submit a different patch which emulates a semaphore perfectly. perhaps that is easier to understand, since semaphores are very familiar to people. The key difference between Tim's lock is that the semaphore hands off ownership to a particular waiting thread. The semaphore doesn't enter a state of free so that thread have to race to lock it. It is this race which is unfair and which the just-releasing lock almost always wins. If you are asking why would we want an unfair lock, then?, see issue 8299 where I point out some links that discuss unfair locks and their role in combating lock convoys. Antoine, if we have A, B, and C, all competing for the lock, at any one point, only one of the three has the lock. Say, A. The others are waiting on the condition variable. Condition variables are generally implemented in a fair manner, so that all threads that wait on it are woken up in a roughly FIFO manner. If not exactly, then at least in the long run. All of the threads have to enter the condition variable's wait queue to acquire the lock. Because of this, the lock is handed off to the threads in roughly the same order that they enter the condition variable´s wait state. If, in your example, C is waiting on the condition variable, then A and B, whenever they give up the lock, they will hand it off a single thread which is woken up, typcally the one at the head of the condition variable's internal queue. If the condition variable is implemented properly, there is no way that A and B can just flip-flop without C never being the thread to be woken up next. As so often, the proof is in the pudding. Try your ccprof.py script with the do_yield turned off. You can also implement an explicitly FIFO condition variable, as I did in issue 8299, if you don't trust the condition variable's own internal mechanism to treat its waiting threads fairly. -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue8410 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com