[ANN] Release 0.61.4 of Task Coach
Hi all, Release 0.61.4 of Task Coach is a bug-fix release that hopefully fixes the following issues: * Make Task Coach work with Python 2.5. * Cancel reminders when marking a task completed. * Unchecking a reminder would cause an exception. * Column resizing is now less jumpy. * MSVCP71.DLL was missing from the Windows distribution. * Marking a task completed while completed tasks are hidden wouldn't immediately hide the completed task. * The category filter was not applied correctly on launch; showing categories as filtered but not hiding the associated tasks. * Turning on filtering for a category didn't mark the task file as changed. In addition, RPM and Debian distributions of Task Coach are now available. What is Task Coach? Task Coach is a simple task manager that allows for hierarchical tasks, i.e. tasks in tasks. Task Coach is open source (GPL) and is developed using Python and wxPython. You can download Task Coach from: http://www.taskcoach.org https://sourceforge.net/projects/taskcoach/ In addition to the source distribution, packaged distributions are available for Windows XP, Mac OSX, and Linux (Debian and RPM format). Note that Task Coach is alpha software, meaning that it is wise to back up your task file regularly, and especially when upgrading to a new release. Cheers, Frank -- http://mail.python.org/mailman/listinfo/python-announce-list Support the Python Software Foundation: http://www.python.org/psf/donations.html
py2exe 0.6.6 released
py2exe 0.6.6 released = py2exe is a Python distutils extension which converts Python scripts into executable Windows programs, able to run without requiring a Python installation. Console and Windows (GUI) applications, Windows NT services, exe and dll COM servers are supported. Changes in 0.6.6: * Better support for Python 2.5. * Experimental support for 64-bit builds of Python on win64. * Better ISAPI support. * New samples for ISAPI and COM servers. * Support for new command-line styles when building Windows services. Changes in 0.6.5: * Fixed modulefinder / mf related bugs introduced in 0.6.4. This will be most evident when working with things like win32com.shell and xml.xpath. * Files no longer keep read-only attributes when they are copied as this was causing problems with the copying of some MS DLLs. Changes in 0.6.4: * New skip-archive option which copies the Python bytecode files directly into the dist directory and subdirectories - no archive is used. * An experimental new custom-boot-script option which allows a boot script to be specified (e.g., --custom-boot-script=cbs.py) which can do things like installing a customized stdout blackhole. See py2exe's boot_common.py for examples of what can be done. The custom boot script is executed during startup of the executable immediately after boot_common.py is executed. * Thomas Heller's performance improvements for finding needed modules. * Mark Hammond's fix for thread-state errors when a py2exe created executable tries to use a py2exe created COM DLL. Changes in 0.6.3: * First release assembled by py2exe's new maintainer, Jimmy Retzlaff. Code changes in this release are from Thomas Heller and Gordon Scott. * The dll-excludes option is now available on the command line. It was only possible to specify that in the options argument to the setup function before. The dll-excludes option can now be used to filter out dlls like msvcr71.dll or even w9xpopen.exe. * Fix from Gordon Scott: py2exe crashed copying extension modules in packages. Changes in 0.6.2: * Several important bugfixes: - bundled extensions in packages did not work correctly, this made the wxPython single-file sample fail with newer wxPython versions. - occasionally dlls/pyds were loaded twice, with very strange effects. - the source distribution was not complete. - it is now possible to build a debug version of py2exe. Changes in 0.6.1: * py2exe can now bundle binary extensions and dlls into the library-archive or the executable itself. This allows to finally build real single-file executables. The bundled dlls and pyds are loaded at runtime by some special code that emulates the Windows LoadLibrary function - they are never unpacked to the file system. This part of the code is distributed under the MPL 1.1, so this license is now pulled in by py2exe. * By default py2exe now includes the codecs module and the encodings package. * Several other fixes. Homepage: http://www.py2exe.org Download from the usual location: http://sourceforge.net/project/showfiles.php?group_id=15583 Enjoy, Jimmy -- http://mail.python.org/mailman/listinfo/python-announce-list Support the Python Software Foundation: http://www.python.org/psf/donations.html
Re: Progress Box or Bar in Windows
Not that I want to suggest a completely different solution; however, I have used: http://www.averdevelopment.com/python/EasyDialogs.html to add simple file open dialogs, message boxes, and progress bars to many of my scripts. You may want to have a look at it. It's easy to install and really simple to use. tubby wrote: Hi guys, I have a Python script that I've prettied-up for Windows users by adding things like shell.SHBrowseForFolder and win32gui.MessageBox, etc. In short, it looks like this: 1. Pretty window where user can browse for folder. (instead of typing path into cmd prompt) 2. win32gui.MessageBox informing user the script will now begin. 3. 4. win32gui.MessageBox informing user the script has finished. I left 3 blank. This is where I'd like to use some sort of progress indicator (a box that says 'processing 3 of 30 files... 4 of 30, etc' or a progress bar that moves across the screen as the script does its job. Any ideas on how to do this quickly and easily (less than 20 lines of code)? I'd prefer to stick with the win32 extensions, but I'd be willing to use TK too if that would be simpler... and it looks like TK would be much simpler :) Thanks! -- http://mail.python.org/mailman/listinfo/python-list
Re: a question on python dict
[Tim Peters] You should also note that copying a dict key or value (no matter of what type) consists in its entirety of copying one machine address (a 4- or 8-byte pointer, depending on platform). [Lawrence D'Oliveiro] Actually, no. It also consists of updating reference counts as well. Not in context: dict resizing is refcount-neutral, and the CPython implementation of dict resizing exploits that (quite directly in 2.5; indirectly before 2.5). It's not just that refcounts end up the same /across/ dict resizing, it's that they're not changed internally either for the duration of the resizing operation. -- http://mail.python.org/mailman/listinfo/python-list
Re: python , Boost and straight (but complex) C code
On Sun, 31 Dec 2006 01:01:29 +0100, Christophe Cavalaria [EMAIL PROTECTED] wrote: Osiris wrote: On Sat, 30 Dec 2006 13:19:28 -0800, Erik Max Francis [EMAIL PROTECTED] wrote: Osiris wrote: I have these pieces of C-code (NOT C++ !!) I want to call from Python. I found Boost. I have MS Visual Studio 2005 with C++. is this the idea: I write the following C source file: #include iostream #include stdafx.h namespace { // Avoid cluttering the global namespace. iostream and namespaces are both most definitely C++ features, not C. yes, but C can be compiled with a C++ compiler, One can put C code in C++ source Boost should not complain... should it ? Boost text is all about C++.. so... C should not be a problem... Not all C code can be compiled by a C++ compiler. And anyway, this is definitively NOT C code. ok ok, but the examples of the application of boost only show how to do C++. So I followed those examples and try to embed my C code in the framework of the examples... Which seems not to be without merit, because my example here compiles ok, but the linking into a DLL goes wrong, looking at the log. I told VC where the boost libs are, and still -- http://mail.python.org/mailman/listinfo/python-list
Re: Question concerning this list
In [EMAIL PROTECTED], Thomas Ploch wrote: Alright, my prof said '... to process documents written in structural markup languages using regular expressions is a no-no.' (Because of nested Elements? Can't remember) So I think he wants us to use regexes to learn them. He is pointing to HTMLParser though. Problem is that much of the HTML in the wild is written in a structured markup language but it's in many cases broken. If you just search some words or patterns that appear somewhere in the documents then regular expressions are good enough. If you want to actually *parse* HTML from the wild better use the BeautifulSoup_ parser. .. _BeautifulSoup: http://www.crummy.com/software/BeautifulSoup/ You are probably right. For me it boils down to these problems: - Implementing a stack for large queues of documents which is faster than list.pop(index) (Is there a lib for this?) If you need a queue then use one: take a look at `collections.deque` or the `Queue` module in the standard library. Ciao, Marc 'BlackJack' Rintsch -- http://mail.python.org/mailman/listinfo/python-list
Re: DOS, UNIX and tabs
In [EMAIL PROTECTED], Paul McNett wrote: Did you try to open your code files with another editor, which has a different length for tabulator chars? It would look quite ugly, I guess... Actually, no. Everyone can choose their own number of spaces-per-tab and it'll look right, as long as everyone uses a monospace font. You never tried that with tabs plus additional spaces to line up e.g. arguments that are broken across lines, right? And there are a number of environments where you can't change the length of a tab like email or terminals where code will be displayed from time to time for example as diffs from a version control system. Ciao, Marc 'BlackJack' Rintsch -- http://mail.python.org/mailman/listinfo/python-list
Re: python , Boost and straight (but complex) C code
On Sat, 30 Dec 2006 23:35:22 +0200, Roman Yakovenko [EMAIL PROTECTED] wrote: On 12/30/06, Osiris [EMAIL PROTECTED] wrote: Visual C++ build log at: http://213.10.133.192/BuildLog.htm It is better to ask Boost.Python related questions on it mailing list: http://mail.python.org/mailman/listinfo/c++-sig/ You should add to the link line boost_python.lib, thus you will eliminate unresolved reference symbol errors. If you did not build Boost.Python next page( http://boost.org/libs/python/doc/building.html ) contains pretty good explanation how to do this. That explanation I find confusing: To build boost_python, use Boost.Build...: Where is boost.build and what is it ? in my D:\boost\libs\python\build there is no boost.build... in D:\boost there is a build-boost.jam file Is that it ? I have a D:\boost\libs\python\build\bin-stage\boost_python.dll (204kB size) and a D:\boost\libs\python\build\bin-stage\boost_build.lib (163 KB) I made them with Visual Studio... I made a bjam, it is in C:\ In D:\boost\libs\python\build there are a bin_stage and a VisualStudio folder , the files jamfile jamfile.v2 python_v1.zip Is it so, that I can build the boost_python.dll and lib, either with bjam OR with VisualStudio C++ ? Why are all those other folders there in d:\boost ? people, regression, tools, status etc ? What do I do with d:\boost\boost ? a lot of headers there... what are all these folders in d:\boost\libs\ ? In short: it's all rather confusing I think it must be like this: To use my C/C++ code with Python, add some stuff in the C/C++ source and compile it into a DLL, that must be combined with some boost-DLL to make it accessible to Python 2.4. Therefore I need a boost DLL from boost.org, and some headerfiles that belong to the boost DLL. (where are those boost header files ) As you see, a lot of obfuscation MAybe I see too many bears on the road... http://boost.org/libs/python/doc/v2/scope.html - here you will find example how to expose my_int variable to Python. my_int has type int, so C++ code will not see changes to the variable that are done from Python. You will have to write set_my_int( x ) function to achieve this. If you are new to Boost.Python try to use Py++ - the code generator for the library. The Py++ GUI( http://tinyurl.com/ycwvwo ) will help you to start\learn Boost.Python. -- http://mail.python.org/mailman/listinfo/python-list
Re: a question on python dict
In message [EMAIL PROTECTED], Tim Peters wrote: [Tim Peters] You should also note that copying a dict key or value (no matter of what type) consists in its entirety of copying one machine address (a 4- or 8-byte pointer, depending on platform). [Lawrence D'Oliveiro] Actually, no. It also consists of updating reference counts as well. Not in context: dict resizing is refcount-neutral... The question wasn't about resizing, it was about copying a dict key or value. -- http://mail.python.org/mailman/listinfo/python-list
Re: Question concerning this list [WebCrawler]
Marc 'BlackJack' Rintsch schrieb: In [EMAIL PROTECTED], Thomas Ploch wrote: Alright, my prof said '... to process documents written in structural markup languages using regular expressions is a no-no.' (Because of nested Elements? Can't remember) So I think he wants us to use regexes to learn them. He is pointing to HTMLParser though. Problem is that much of the HTML in the wild is written in a structured markup language but it's in many cases broken. If you just search some words or patterns that appear somewhere in the documents then regular expressions are good enough. If you want to actually *parse* HTML from the wild better use the BeautifulSoup_ parser. .. _BeautifulSoup: http://www.crummy.com/software/BeautifulSoup/ Yes, I know about BeautifulSoup. But as I said it should be done with regexes. I want to extract tags, and their attributes as a dictionary of name/value pairs. I know that most of HTML out there is *not* validated and bollocks. This is how my regexes look like: import re class Tags: def __init__(self, sourceText): self.source = sourceText self.curPos = 0 self.namePattern = [A-Za-z_][A-Za-z0-9_.:-]* self.tagPattern = re.compile((?Pname%s)(?Pattr[^]*) % self.namePattern) self.attrPattern = re.compile( r\s+(?PattrName%s)\s*=\s*(?Pvalue\[^\]*\|'[^']*') % self.namePattern) You are probably right. For me it boils down to these problems: - Implementing a stack for large queues of documents which is faster than list.pop(index) (Is there a lib for this?) If you need a queue then use one: take a look at `collections.deque` or the `Queue` module in the standard library. Which of the two would you recommend for handling large queues with fast response times? Thomas -- http://mail.python.org/mailman/listinfo/python-list
Re: DOS, UNIX and tabs
In message [EMAIL PROTECTED], Marc 'BlackJack' Rintsch wrote: In [EMAIL PROTECTED], Paul McNett wrote: Everyone can choose their own number of spaces-per-tab and it'll look right, as long as everyone uses a monospace font. You never tried that with tabs plus additional spaces to line up e.g. arguments that are broken across lines, right? I prefer a more two-dimensional layout, keeping consistent indentation. To illustrate using the example from Paul McNett: class Apple(object): def contrived_example_function \ ( self, argument1, argument2, argument3, argument4 ) : print hello, world #end contrived_example_function #end Apple -- http://mail.python.org/mailman/listinfo/python-list
Re: Progress Box or Bar in Windows
Go for wxPython, it'll fulfill all your GUI needs. Handsdown the best GUI toolkit I ever ran into. It can't get much simpler than: wx.MessageBox('hi') And there are tons of readymade dialogs and progressbars in the library. Check out the demo.py under the wxPython installation dir to see demos (and source) of the enormous list of controls. -- http://mail.python.org/mailman/listinfo/python-list
Re: python , Boost and straight (but complex) C code
On 12/31/06, Osiris [EMAIL PROTECTED] wrote: In short: it's all rather confusing I think it must be like this: To use my C/C++ code with Python, add some stuff in the C/C++ source and compile it into a DLL, that must be combined with some boost-DLL to make it accessible to Python 2.4. Therefore I need a boost DLL from boost.org, and some headerfiles that belong to the boost DLL. (where are those boost header files ) As you see, a lot of obfuscation MAybe I see too many bears on the road... Boost project is an open source, consider to contribute your experience, knowledge and time to make it better. You can download pre-built binaries for Windows platform from here: http://www.boost-consulting.com/download.html -- Roman Yakovenko C++ Python language binding http://www.language-binding.net/ -- http://mail.python.org/mailman/listinfo/python-list
Are all classes new-style classes in 2.4+?
Hi, This is probably a very basic question, but I've been playing with new style classes, and I cannot see any difference in behavior when a declare a class as: class NewStyleClass(object): or class NewStyleClass: I declare property members in both and it seems to work the exact same way. I am using Python 2.4, and I was wondering if by default, all classes are assumed to be derived from object. If not, can someone point me to some place where I can learn more about new-style classes and their advantages? All the documentation I've found is very vague. Thanks, - Isaac. -- http://mail.python.org/mailman/listinfo/python-list
Re: PEP 3107 Function Annotations for review and comment
I have two questions: 1) I don't understand the clause ('*' [tname] (',' tname ['=' test])* in the grammar rule of typedargslist. Does it stem from another PEP? 2) Is the func_annotation information for def foo(*c: list) stored as {*c: list} preserving optional argument information or {c:list} ? Regards, Kay -- http://mail.python.org/mailman/listinfo/python-list
Re: a question on python dict
[Tim Peters] You should also note that copying a dict key or value (no matter of what type) consists in its entirety of copying one machine address (a 4- or 8-byte pointer, depending on platform). [Lawrence D'Oliveiro] Actually, no. It also consists of updating reference counts as well. [Tim Peters] Not in context: dict resizing is refcount-neutral... [Lawrence D'Oliveiro] The question wasn't about resizing, it was about copying a dict key or value. Then you misunderstood the OP. He was asking about dict resizing: ... When there are more and more items being added to the hashtable, it increase its buckets and copy the old items into the new one and re-calculate the hash value of each item. I think this will waste some time doing the increasing-copying thing. Taking my response out of context to begin with doesn't really change that I answered the question he asked ;-) -- http://mail.python.org/mailman/listinfo/python-list
Re: Are all classes new-style classes in 2.4+?
Isaac Rodriguez wrote: This is probably a very basic question, but I've been playing with new style classes, and I cannot see any difference in behavior when a declare a class as: class NewStyleClass(object): or class NewStyleClass: Try multiple inheritance (the order of superclass selection is different) or try using the keyword super. Regards, Björn -- BOFH excuse #113: Root nameservers are out of sync -- http://mail.python.org/mailman/listinfo/python-list
Re: Are all classes new-style classes in 2.4+?
Isaac Rodriguez wrote: I declare property members in both and it seems to work the exact same way. I am using Python 2.4, and I was wondering if by default, all classes are assumed to be derived from object. No, they are not. It's just that the basic functionality seems to work the same at first glance (i.e. you don't need to learn alot of new syntax in order to switch from old-style to new-style classes). Play around with things like dir() and type() on old-style and new-style classes, and you will soon see differences. If not, can someone point me to some place where I can learn more about new-style classes and their advantages? All the documentation I've found is very vague. http://www.python.org/download/releases/2.2.3/descrintro/ http://www.cafepy.com/article/python_types_and_objects/python_types_and_objects.html -- René OpenPGP key id: 0x63B1F5DB JID: [EMAIL PROTECTED] signature.asc Description: OpenPGP digital signature -- http://mail.python.org/mailman/listinfo/python-list
Re: Question concerning this list [WebCrawler]
In [EMAIL PROTECTED], Thomas Ploch wrote: This is how my regexes look like: import re class Tags: def __init__(self, sourceText): self.source = sourceText self.curPos = 0 self.namePattern = [A-Za-z_][A-Za-z0-9_.:-]* self.tagPattern = re.compile((?Pname%s)(?Pattr[^]*) % self.namePattern) self.attrPattern = re.compile( r\s+(?PattrName%s)\s*=\s*(?Pvalue\[^\]*\|'[^']*') % self.namePattern) Have you tested this with tags inside comments? You are probably right. For me it boils down to these problems: - Implementing a stack for large queues of documents which is faster than list.pop(index) (Is there a lib for this?) If you need a queue then use one: take a look at `collections.deque` or the `Queue` module in the standard library. Which of the two would you recommend for handling large queues with fast response times? `Queue.Queue` builds on `collections.deque` and is thread safe. Speedwise I don't think this makes a difference as the most time is spend with IO and parsing. So if you make your spider multi-threaded to gain some speed go with `Queue.Queue`. Ciao, Marc 'BlackJack' Rintsch -- http://mail.python.org/mailman/listinfo/python-list
Re: Are all classes new-style classes in 2.4+?
On 31 Dec 2006 03:57:04 -0800, Isaac Rodriguez [EMAIL PROTECTED] wrote: I am using Python 2.4, and I was wondering if by default, all classes are assumed to be derived from object. This won't tell you advantages or disadvantages, but will show you that the default still is the old-style: class old: ... pass ... type(old()) type 'instance' dir(old()) ['__doc__', '__module__'] class new(object): ... pass ... type(new()) class '__main__.new' dir(new()) ['__class__', '__delattr__', '__dict__', '__doc__', '__getattribute__', '__hash__', '__init__', '__module__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__str__', '__weakref__'] In general, even if you don't understand the differences, it's better to use new-style (they're new ;-). Anyway, see http://effbot.org/pyref/new-style-and-classic-classes.htm for a little more information. -- Felipe. -- http://mail.python.org/mailman/listinfo/python-list
A question about unicode() function
Hi,all I encountered a problem when using unicode() function to fetch a webpage, I don't know why this happenned. My codes and error messages are: Code: #!/usr/bin/python #Filename: test.py #Modified: 2006-12-31 import cPickle as p import urllib import htmllib import re import sys def funUrlFetch(url): lambda url:urllib.urlopen(url).read() objUrl = raw_input('Enter the Url:') content = funUrlFetch(objUrl) content = unicode(content,gbk) print content content.close() error message: C:\WINDOWS\system32\cmd.exe /c python test.py Enter the Url:http://www.msn.com Traceback (most recent call last): File test.py, line 16, in ? content = unicode(content,gbk) TypeError: coercing to Unicode: need string or buffer, NoneType found shell returned 1 Hit any key to close this window... Any suggestions would be appreciated! Thanks! -- http://mail.python.org/mailman/listinfo/python-list
Re: WebCrawler (was: 'Question concerning this list')
Marc 'BlackJack' Rintsch schrieb: In [EMAIL PROTECTED], Thomas Ploch wrote: This is how my regexes look like: import re class Tags: def __init__(self, sourceText): self.source = sourceText self.curPos = 0 self.namePattern = [A-Za-z_][A-Za-z0-9_.:-]* self.tagPattern = re.compile((?Pname%s)(?Pattr[^]*) % self.namePattern) self.attrPattern = re.compile( r\s+(?PattrName%s)\s*=\s*(?Pvalue\[^\]*\|'[^']*') % self.namePattern) Have you tested this with tags inside comments? No, but I already see your point that it will parse _all_ tags, even if they are commented out. I am thinking about how to solve this. Probably I just take the chunks between comments and feed it to the regular expressions. You are probably right. For me it boils down to these problems: - Implementing a stack for large queues of documents which is faster than list.pop(index) (Is there a lib for this?) If you need a queue then use one: take a look at `collections.deque` or the `Queue` module in the standard library. Which of the two would you recommend for handling large queues with fast response times? `Queue.Queue` builds on `collections.deque` and is thread safe. Speedwise I don't think this makes a difference as the most time is spend with IO and parsing. So if you make your spider multi-threaded to gain some speed go with `Queue.Queue`. I think I will go for collections.deque (since I have no intention of making it multi-threaded) and have several queues, one for each server in a list to actually finish one server before being directed to the next one straight away (Is this a good approach?). Thanks a lot, Thomas -- http://mail.python.org/mailman/listinfo/python-list
Re: A question about unicode() function
On 31 Dec 2006 05:20:10 -0800, JTree [EMAIL PROTECTED] wrote: def funUrlFetch(url): lambda url:urllib.urlopen(url).read() This function only creates a lambda function (that is not used or assigned anywhere), nothing more, nothing less. Thus, it returns None (sort of void) no matter what is its argument. Probably you meant something like def funUrlFetch(url): return urllib.urlopen(url).read() or funUrlFetch = lambda url:urllib.urlopen(url).read() objUrl = raw_input('Enter the Url:') content = funUrlFetch(objUrl) content gets assigned None. Try putting print content before the unicode line. content = unicode(content,gbk) This, equivalent to unicode(None, gbk), leads to TypeError: coercing to Unicode: need string or buffer, NoneType found None's are not strings nor buffers, so unicode() complains. See ya, -- Felipe. -- http://mail.python.org/mailman/listinfo/python-list
Re: Are all classes new-style classes in 2.4+?
On Sun, 31 Dec 2006 03:57:04 -0800, Isaac Rodriguez wrote: Hi, This is probably a very basic question, but I've been playing with new style classes, and I cannot see any difference in behavior when a declare a class as: class NewStyleClass(object): or class NewStyleClass: I declare property members in both and it seems to work the exact same way. Then you aren't looking very closely. Try with a calculated property. class New(object): ... def __init__(self): ... self._n = 1 ... def getter(self): ... return spam * self._n ... def setter(self, n): ... self._n = n ... spam = property(getter, setter, None, None) ... obj = New() obj.spam 'spam ' obj.spam = 3 obj.spam 'spam spam spam ' obj.spam = 7 obj.spam 'spam spam spam spam spam spam spam ' Now try with an old-style class. class Old: ... def __init__(self): ... self._n = 1 ... def getter(self): ... return spam * self._n ... def setter(self, n): ... self._n = n ... spam = property(getter, setter, None, None) ... obj = Old() obj.spam 'spam ' obj.spam = 3 obj.spam 3 Properties should not be used with old-style classes because they just don't work correctly. -- Steven. -- http://mail.python.org/mailman/listinfo/python-list
py2exe 0.6.6 released
py2exe 0.6.6 released = py2exe is a Python distutils extension which converts Python scripts into executable Windows programs, able to run without requiring a Python installation. Console and Windows (GUI) applications, Windows NT services, exe and dll COM servers are supported. Changes in 0.6.6: * Better support for Python 2.5. * Experimental support for 64-bit builds of Python on win64. * Better ISAPI support. * New samples for ISAPI and COM servers. * Support for new command-line styles when building Windows services. Changes in 0.6.5: * Fixed modulefinder / mf related bugs introduced in 0.6.4. This will be most evident when working with things like win32com.shell and xml.xpath. * Files no longer keep read-only attributes when they are copied as this was causing problems with the copying of some MS DLLs. Changes in 0.6.4: * New skip-archive option which copies the Python bytecode files directly into the dist directory and subdirectories - no archive is used. * An experimental new custom-boot-script option which allows a boot script to be specified (e.g., --custom-boot-script=cbs.py) which can do things like installing a customized stdout blackhole. See py2exe's boot_common.py for examples of what can be done. The custom boot script is executed during startup of the executable immediately after boot_common.py is executed. * Thomas Heller's performance improvements for finding needed modules. * Mark Hammond's fix for thread-state errors when a py2exe created executable tries to use a py2exe created COM DLL. Changes in 0.6.3: * First release assembled by py2exe's new maintainer, Jimmy Retzlaff. Code changes in this release are from Thomas Heller and Gordon Scott. * The dll-excludes option is now available on the command line. It was only possible to specify that in the options argument to the setup function before. The dll-excludes option can now be used to filter out dlls like msvcr71.dll or even w9xpopen.exe. * Fix from Gordon Scott: py2exe crashed copying extension modules in packages. Changes in 0.6.2: * Several important bugfixes: - bundled extensions in packages did not work correctly, this made the wxPython single-file sample fail with newer wxPython versions. - occasionally dlls/pyds were loaded twice, with very strange effects. - the source distribution was not complete. - it is now possible to build a debug version of py2exe. Changes in 0.6.1: * py2exe can now bundle binary extensions and dlls into the library-archive or the executable itself. This allows to finally build real single-file executables. The bundled dlls and pyds are loaded at runtime by some special code that emulates the Windows LoadLibrary function - they are never unpacked to the file system. This part of the code is distributed under the MPL 1.1, so this license is now pulled in by py2exe. * By default py2exe now includes the codecs module and the encodings package. * Several other fixes. Homepage: http://www.py2exe.org Download from the usual location: http://sourceforge.net/project/showfiles.php?group_id=15583 Enjoy, Jimmy -- http://mail.python.org/mailman/listinfo/python-list
request for code : Py Tic Tac Toe in action
Hi elainejackson7355_at_home.com, I read I played against your script and got a win, which, as you know, is not possible with optimal play by the opponent. A while ago I wrote a script that plays optimal tic-tac-toe. Let me know if you want to look at it. I would certainly appreciate the code. --furman === === === extra of little or no interest: I'm learning Python in order to analyze a game that I invented (the last article listed at http://www.integers-ejcnt.org/vol2.html ) called naught or cross. Neither player owns a symbol -- x or o -- but wins when achieving three of the same symbol in a tic-tac-toe line. When you place your symbol on the board you tell me which symbol I am to place. I place the assigned symbol where-ever I choose and then tell you which symbol to place. I started a hand analysis yesterday and it took hours to determine part of the game tree. I estimated, assuming other parts of the tree would take as much work, that I had about 750 times as much work left to do. So it is time to program -- which I love and I've been intending to learn Python anyway. I've taught Fortran and Pascal (and BASIC, AWK, Logo, etc) years ago and need to learn the object oriented approach. Perhaps your work will make it make sense. So far I'm thinking of a game position as a tuple where the first component shows the locations occupied by the symbol which is to be placed and the second component shows the locations of the other symbol. I'm using the following scheme for cell locations in order to simplify translating a position to a standard position (rotating by adding mod 8 to the outside cells and flipping by subtracting the outside cells from 8): 0 1 2 7 8 3 6 5 4 This is already more than you probably want to know but let me give an example. If you have just placed the piece that I've named and the board looks like o . . x o . x . . and you tell me to place an x (which is position (67,08) with x's specified in the first component, which is equivalent to standard position (12,08)) then I might place the x in the middle right and tell you to place an x on your move. Therefore the board looks like o . . x o x x . . and you are to place an x (this is equivalent to (367,08)). Since you wrote a Python program to play tic-tac-toe optimally, I bet that you will place your x in the lower right and tell me to place an o. So the position is o . . x o x x . x and I am to place an o. (a position equivalent to (08,3467)). You have me. No matter where I place the o and no matter whether I tell you to place an x or an o after that, you will be able to make three in a line. I found a neat Web page which was cached by Google, http://209.85.165.104/search?q=cache:jyTWvS7w5asJ:en.literateprograms.org/Ti c_Tac_Toe_(Python)+Py+Tic+Tac+Toehl=engl=usct=clnkcd=10 , and I'm enjoying reading it but I'd appreciate seeing your approach also. -- http://mail.python.org/mailman/listinfo/python-list
Python embedded interpreter: how to initialize the interpreter ?
Hello, I've written a C embedded application. I want to open a python gui application in my C program but when I do : PyRun_String( import gui.py, file_input, pDictionary, pDictionary ); the interpreter emits an error: tkinter module not defined What script must I load to initialize the embedded python interpreter so as I have the same modules in the python command line and in the python embedded interpreter ? /usr/lib/python2.4/*.py ?? Yann COLLETTE -- http://mail.python.org/mailman/listinfo/python-list
C app and Python
Hi, I need to create an application that the user ask for python script to run. this script will call the C application functions (in my app. the function will draw on screen). Do I need to create an extension ? Note that this is not a DLL, but a C application. or I need to embed Python in my C application. Thanks, Vertilka -- http://mail.python.org/mailman/listinfo/python-list
Re: PEP 3107 Function Annotations for review and comment
On Dec 31, 2006, at 4:26 AM, Kay Schluehr wrote: I have two questions: 1) I don't understand the clause ('*' [tname] (',' tname ['=' test])* in the grammar rule of typedargslist. Does it stem from another PEP? Yes, PEP 3102 Keyword-only Arguments. 2) Is the func_annotation information for def foo(*c: list) stored as {*c: list} preserving optional argument information or {c:list} ? {c: list} -Tony -- http://mail.python.org/mailman/listinfo/python-list
Re: PEP 3107 Function Annotations for review and comment
Tony Lownds wrote: First, it only handles functions/methods. Python FIT needs metadata on properties and assignable/readable attributes ... Third, it's half of a proposal. Type checking isn't the only use for metadata about functions/methods, classes, properties and other objects, and the notion that there are only going to be a small number of non-intersecting libraries out there is an abdication of responsibility to think this thing through. That comes from this paragraph from the PEP: There is no worry that these libraries will assign semantics at random, or that a variety of libraries will appear, each with varying semantics and interpretations of what, say, a tuple of strings means. The difficulty inherent in writing annotation interpreting libraries will keep their number low and their authorship in the hands of people who, frankly, know what they're doing. Perhaps you are right and intersecting libraries will become an issue. Designing a solution in advance of the problems being evident seems risky to me. What if the solution invented in a vacuum really is more of a hindrance? Vacuum? What vacuum? Annotating programs for various tools has a history that goes back almost to the beginning of programming languages. It goes back even farther if you want to look at scholarly use of natural language. The only vacuum I see here is the focus on a solution rather than a focus on a problem. There is a clear intersection between documentation packages and type-checking or type-coercing libraries. Documentation libraries can just use repr(annotation), possibly with a little bit of special casing to represent classes and types better. I'm not sure there will be an important use for overlap of different type-checking or type-coercing libraries within the same module. What else could intersect and why can't the intersecting pieces develop an solution when it arises? More feedback from the community on this point (whether the PEP needs to take responsibility for interoperability) would be nice. At the moment the project I'm working on has annotations from three packages: Python FIT (which is the actual package), Ned Bachelder's code coverage tool, and one of the code standards tools. None of these are either documentation or type checking / coercion. The point I'm making is that there are other uses for annotations than type checking and documentation. I specifically referenced Python FIT because it is neither of these: it is an executable requirements test tool that can be used as an acceptance test tool as well. I also mentioned Naked Objects because it's got the same issue: it needs type and other metadata information. There isn't a current Python implementation that I'm aware of, although I'm thinking of it as a next project. Thanks for the feedback from everyone so far, I stripped the comment about syntax from this response because I want to address it separately. John Roth -Tony -- http://mail.python.org/mailman/listinfo/python-list
Re: Progress Box or Bar in Windows
cyberco wrote: Go for wxPython, it'll fulfill all your GUI needs. Handsdown the best GUI toolkit I ever ran into. Thanks a lot! I had no idea wxPython was so easy to use. I added a progress bar from wx to the app. Less than 20 lines of code and it only took about 5 minutes! -- http://mail.python.org/mailman/listinfo/python-list
Re: PEP 3107 Function Annotations for review and comment
On Dec 31, 2006, at 7:54 AM, John Roth wrote: Tony Lownds wrote: Perhaps you are right and intersecting libraries will become an issue. Designing a solution in advance of the problems being evident seems risky to me. What if the solution invented in a vacuum really is more of a hindrance? Vacuum? What vacuum? No libraries use the new syntax. Hence no libraries can be currently intersecting on the usage. [...] At the moment the project I'm working on has annotations from three packages: Python FIT (which is the actual package), Ned Bachelder's code coverage tool, and one of the code standards tools. None of these are either documentation or type checking / coercion. Let me see if I can guess how those tools will use function annotations. You've decided Python FIT can't use function annotations. Code coverage tool won't even use function annotations. It's possible packages like pylint will learn to interpret function annotations to provide better static analysis. Right? The problem is, pylint may only understand annotation scheme A and the module author has written the annotations in scheme B. Is this is the kind of intersection issue you had in mind? Do you have any more specific cases to consider? Thanks -Tony -- http://mail.python.org/mailman/listinfo/python-list
Re: PEP 3107 Function Annotations for review and comment
Tony Lownds wrote: First, it only handles functions/methods. Python FIT needs metadata on properties and assignable/readable attributes of all kinds. So in no sense is it a replacement. Parenthetically, neither is the decorator facility, and for exactly the same reason. I can't argue against docstrings and maybe annotations on attributes, I'd like them myself. That should be a separate PEP because the scope of this one is Function Annotations. The syntax for function annotations has been much more thoroughly discussed than for annotations on attributes. See Guido's blog and other references in the PEP. Syntax is always an issue. Looking at the history of annotations shows that people seem to prefer using a comment mechanism. This goes along with the notion of supplying minimal mechanism until you see what the actual usage is going to be. As far as I'm concerned, an annotation mechanism has to have several properties: 1. The annotation data needs to be available at run time without having the source available. 2. It needs to be syntax checkable by a mechanism supplied by the author of the annotation schema. I'd suggest a hook at the back end of import, since this doesn't get in the way of the compiler. The converse of this, of course, is that neither the language nor the compiler needs to have any idea of the actual syntax. This provides maximal freedom to experiment. 3. It needs to have a convention that will allow authors of different schemas to stay out of each other's way. Docstrings almost manage this. While they're certainly available at run time (at least if you don't compile in a way that strips them out) you can only have one in any module, class or method. This means you can't always put them where you want them, that is, close to the item that they're annotating. Parenthetically, I'd note that adding docstring capabilities to properties was a definite step forward. John Roth Thanks for the feedback from everyone so far, -Tony -- http://mail.python.org/mailman/listinfo/python-list
trees, iterations and adding leaves
Hello I have trees like this: from nltk_lite.parse.tree import Tree tree6 = Tree('main', ['sub1', 'sub2']) tree6 ('main': 'sub1' 'sub2') I use nltk package - but it should not matter here. I could change it's lafes (add node) like this: tree6[0] = Tree('newsub',[]) tree6 ('main': ('newsub': ) 'sub2') But my tree has many levels and it's imposibble to address it like: tree6[0][1][0][1][1][1][0].. So i wanted to 'travel thru my tree' to last node which should be changed: tree6 = Tree('main', ['sub1', 'sub2']) subtree = tree6[0] subtree 'sub1' subtree = Tree('newsub',[]) subtree ('newsub': ) tree6 ('main': 'sub1' 'sub2') The problem is that subtree is some kind of a new variable (not pointer) so changing it i will not alter tree6. How to alter tree6 while 'travelling along it's nodes', without messy referencing as tree6[0][1][0][1][1][1][0].. ? Thanx -- http://mail.python.org/mailman/listinfo/python-list
Re: Question concerning this list [WebCrawler]
Thomas Ploch wrote: Marc 'BlackJack' Rintsch schrieb: In [EMAIL PROTECTED], Thomas Ploch wrote: Alright, my prof said '... to process documents written in structural markup languages using regular expressions is a no-no.' Very true. HTML is LALR(0), that is, you can parse it without looking ahead. Parsers for LALR(0) languages are easy, and work by repeatedly getting the next character and using that to drive a single state machine. The first character-level parser yields tokens, which are then processed by a grammar-level parser. Any compiler book will cover this. Using regular expressions for LALR(0) parsing is a vice inherited from Perl, in which regular expressions are easy and get next character from string is unreasonably expensive. In Python, at least you can index through a string. John Nagle -- http://mail.python.org/mailman/listinfo/python-list
Re: Question concerning this list [WebCrawler]
John Nagle schrieb: Very true. HTML is LALR(0), that is, you can parse it without looking ahead. Parsers for LALR(0) languages are easy, and work by repeatedly getting the next character and using that to drive a single state machine. The first character-level parser yields tokens, which are then processed by a grammar-level parser. Any compiler book will cover this. Using regular expressions for LALR(0) parsing is a vice inherited from Perl, in which regular expressions are easy and get next character from string is unreasonably expensive. In Python, at least you can index through a string. John Nagle I take it with LALR(0) you mean that HTML is a language created by a Chomsky-0 (regular language) Grammar? Thomas -- http://mail.python.org/mailman/listinfo/python-list
simple ftputil ssl client
Hello, I trying to make ftputil client that uses ssl security.First I was try to make that with M2Crypto,but when I use it, I get the error: Traceback (most recent call last): File pyshell#32, line 1, in -toplevel- import M2Crypto File C:\Python24\lib\site-packages\M2Crypto\__init__.py, line 15, in -toplevel- import m2 File C:\Python24\Lib\site-packages\M2Crypto\m2.py, line 28, in -toplevel- from __m2crypto import * ImportError: DLL load failed with error code 182 ...so now I trying to make it with pyOpenSSL or twistedmatrix ssl,but I don't know how.If anybody have any idea or example how to I make it,please help me!!! -- http://mail.python.org/mailman/listinfo/python-list
Missing erf()
Is there a reason why erf() is not included in the math package? According to the following URL it looks like it has been standard C since 1999. http://www.opengroup.org/onlinepubs/95399/functions/erf.html -- http://mail.python.org/mailman/listinfo/python-list
Re: looking for a better way to call a file.
This probably will meet your needs: import os os.system(csound play.orc play.sco) If you need more control try the subprocess module. [EMAIL PROTECTED] wrote: I have been auto-generating .bat files and then running os.startfile('whatever.bat'). I don't seem to be having much luck when I try other methods. All of a sudden I am stuck in a situation where I need the program that is calling to end and a new program to start (because otherwise I get several uneeded copies). csoundgrid4.csgrid(arrg1, ;sco_header, filename) with this by executing the main function os3.execvp('python', 'csoundgrid4.py', arrg1, ;sco_header, filename) and the program just ends. I would also be glad to get rid of all the bats that I generate when I run an external program like csound. The command line I run is somthing like csound play.orc play.sco I haven't had much luck using os.startfile with arguments Hopefully this is an easy question and any help would be apreaceated (befour my computer gets rabies) http://www.dexrow.com -- http://mail.python.org/mailman/listinfo/python-list
Re: Missing erf()
rrenaud Is there a reason why erf() is not included in the math rrenaud package? According to the following URL it looks like it has rrenaud been standard C since 1999. Python is implemented in the C89 dialect. Maybe Python 3.0 will be implemented using C99. Skip -- http://mail.python.org/mailman/listinfo/python-list
Re: Wow, Python much faster than MatLab
sturlamolden wrote: as well as looping over the data only once. This is one of the main reasons why Fortran is better than C++ for scientific computing. I.e. instead of for (i=0; in; i++) array1[i] = (array1[i] + array2[i]) * (array3[i] + array4[i]); one actually gets something like three intermediates and four loops: tmp1 = malloc(n*sizeof(whatever)); for (i=0; in; i++) tmp1[i] = array1[i] + array2[i]; tmp2 = malloc(n*sizeof(whatever)); for (i=0; in; i++) tmp2[i] = array3[i] + array4[i]; tmp3 = malloc(n*sizeof(whatever)); for (i=0; in; i++) tmp3[i] = tmp1[i] + tmp2[i]; free(tmp1); free(tmp2); for (i=0; in; i++) array1[i] = tmp3[i]; free(tmp3); C/C++ do not allocate extra arrays. What you posted _might_ bear a small resemblance to what numpy might produce (if using vectorized code, not explicit loop code). This is entirely unrelated to the reasons why fortran can be faster than c. -Mike -- http://mail.python.org/mailman/listinfo/python-list
Re: Help with small program
Tim Roberts wrote: [EMAIL PROTECTED] wrote: Interesting impl in Python! I am wondering what if the requirement is to find the minimum number of coins which added to the fin sum... Given the set of coins in the original problem (100, 10, 5, 1, 0.5), the solution it provides will always be optimal. Even if we change this to American coinage (50, 25, 10, 5, 1), I believe it is still optimal. It is certainly possible to construct a set of denominations for which the algorithm occasionally chooses badly. For example, if you give it the set (40,35,10) and ask it to make change for 70, it will be suboptimal. Tim, Unless I am missing the point, the minimum number of coins from the set available will be chosen. Surely this homework is past due by now. $ cat coins.py #!/usr/bin/env python import sys cointypes = (100, 10, 5, 1, 0.5) def coins(fin, cointypes): needed = {} for c in cointypes: v, r = divmod(fin, c) if v 0: needed[c] = int(v) fin = r return needed def doit(fin, cointypes = cointypes): h = coins(fin, cointypes) print '%.1f requires %d coins in hash ' % (fin, sum(h.values())), h if __name__ == '__main__': doit(51) doit(127) doit(12.5) doit(70, (40,35,10)) sys.exit(0) $ ./coins.py 51.0 requires 6 coins in hash {1: 1, 10: 5} 127.0 requires 6 coins in hash {1: 2, 10: 2, 100: 1, 5: 1} 12.5 requires 4 coins in hash {0.5: 1, 1: 2, 10: 1} 70.0 requires 4 coins in hash {40: 1, 10: 3} -- http://mail.python.org/mailman/listinfo/python-list
Re: DOS, UNIX and tabs
Marc 'BlackJack' Rintsch wrote: Did you try to open your code files with another editor, which has a different length for tabulator chars? It would look quite ugly, I guess... Actually, no. Everyone can choose their own number of spaces-per-tab and it'll look right, as long as everyone uses a monospace font. You never tried that with tabs plus additional spaces to line up e.g. arguments that are broken across lines, right? You must not understand what they're talking about, because it works fine. The example is this: \ class Foo: \tdef Function(): \t\tAnotherFunctionThatTakesManyArguments(arg1, \t\t arg2, \t\t arg3) And there are a number of environments where you can't change the length of a tab like email or terminals where code will be displayed from time to time for example as diffs from a version control system. That's the point of doing it in this way with tabs to specify indent level and spaces to specify tabular alignment. Me, I could never get emacs's python stuff to work suitably so I just use a Dead Simple Editor (SciTE) in which I use tabs exclusively; continuation indents are always exactly one additional tab over the thing that's being continued. Perhaps interestingly, for development I have my editor set to show tabs as fairly short, but my diff program shows them as eight characters. I find that makes indentation changes easier to spot in the diffs. -tom! -- -- http://mail.python.org/mailman/listinfo/python-list
Re: Managing a queue of subprocesses?
cypher543 wrote: That was a very good answer, and it sure sounds like it would work. However, I failed at implementing it. :( My updated runQueue() function is: def runQueue(self): self.buildProcess = None count = 1 # current position in the queue while True: if self.buildProcess is None: self.execute(self.cmdQueue[count][2], self.cmdQueue[count][0], self.cmdQueue[count][1]) count = count + 1 else: # I'm not really sure what to put here I pretty sure I did all of that wrong. ;) Also, how exactly would I redirect stderr to another place? You're thinking too hard. ;) class Whatever: def __init__(self): self.process = None # and other stuff, probably. def runQueue(self): # check to see if no process has been started, or if # the most-recently-started one has finished. if not (self.process or (self.process.poll() is None)): if self.process: previousReturnCode = self.process.returncode if len(self.cmdQueue) 0: command = self.cmdQueue.pop(0) # pull off the first command. self.execute(command[2], command[0], command[1]) else: self.process = None ...then, to prevent your GUI from freezing, you need to just call this function in your idle handling. If you don't want to start all of your commands at once, you need to not start all your commands at once. ;) -tom! -- -- http://mail.python.org/mailman/listinfo/python-list
Re: find login name of user?
Martin P. Hellwig wrote: Speaking of that, is there any reason why there isn't any syntactic sugar that gives the illusion of platform neutral fetching of the user name? getpass.getuser() might come the closest: http://docs.python.org/lib/module-getpass.html -- Brian Beck Adventurer of the First Order -- http://mail.python.org/mailman/listinfo/python-list
Re: Wow, Python much faster than MatLab
Klaas wrote: C/C++ do not allocate extra arrays. What you posted _might_ bear a small resemblance to what numpy might produce (if using vectorized code, not explicit loop code). This is entirely unrelated to the reasons why fortran can be faster than c. Array libraries in C++ that use operator overloading produce intermediate arrays for the same reason as NumPy. There is a C++ library that are sometimes able to avoid intermediates (Blitz++), but it can only do so for small arrays for which bounds are known at compile time. Operator overloading is sometimes portrayed as required for scientific computing (e.g. in Java vs. C# flame wars), but the cure can be worse than the disease. C does not have operator overloading and is an entirely different case. You can of course avoid intermediates in C++ if you use C++ as C. You can do that in Python as well. -- http://mail.python.org/mailman/listinfo/python-list
Q: a simple(?) raw-utf-8 conversion to internal type unicode \304\246\311\231\316\257\316\271\303\222
Hi, Apologies first as I am not a unicode expert indeed I the details probably totally elude me. Not withstanding: how can I convert a binary string containing UTF-8 binary into a python unicode string? cutdown example: $ cat ./uc.py #!/usr/bin/env python imported=\304\246\311\231\316\257\316\271\303\222 \317\216\317\203\305\224\304\271\304\220 print English/ASCII quoting:,''+imported+'',SUCCEEDS :-) # xterm encoding if UTF8 print German/ALCOR quoting:,u\N{runic cross punctuation}+test +\N{runic cross punctuation},AOK :-) print German/ALCOR quoting:,u\N{runic cross punctuation}+imported+u\N{runic cross punctuation},FAILS :-( $ ./uc.py English/ASCII quoting: ĦəίιÒ ώσŔĹĐ SUCCEEDS :-) German/ALCOR quoting: ᛭test᛭ AOK :-) German/ALCOR quoting: Traceback (most recent call last): File ./uc.py, line 5, in module print German/ALCOR quoting:,u\N{runic cross punctuation}+imported+u\N{runic cross punctuation},FAILS :-( UnicodeDecodeError: 'ascii' codec can't decode byte 0xc4 in position 0: ordinal not in range(128) The last print statement fails because the ascii imported characters are 8 bit encoded UTF-8 and dont know it! How do I tell imported that it is actually already UTF-8 unicode? Cheers NevilleDNZ -- http://mail.python.org/mailman/listinfo/python-list
Just TOO easy.... Re: Q: a simple(?) raw-utf-8 conversion to internal type unicode \304\246\311\231\316\257\316\271\303\222
It was just TOO easy... on posting my message to google groups, and when I re-read the posting on groups I found that google had pointed me to a python-unicode tutorial... www.reportlab.com/i18n/python_unicode_tutorial.html - exercise one :-) Gosh sometime a google is worth so much more then ₁₀¹⁰⁰! Happy New Year NevilleD It works now: $ ./uc.py English/ASCII quoting: ĦəίιÒ ώσŔĹĐ SUCCEEDS :-) German/ALCOR quoting: ᛭test᛭ AOK :-) German/ALCOR quoting: ᛭ĦəίιÒ ώσŔĹĐ᛭ FAILS :-( [EMAIL PROTECTED]:/root0/home/nevilled/Project/20 $ vi ./uc.py [EMAIL PROTECTED]:/root0/home/nevilled/Project/20 $ cat ./uc.py #!/usr/bin/env python imported=unicode(\304\246\311\231\316\257\316\271\303\222 \317\216\317\203\305\224\304\271\304\220,utf-8) print English/ASCII quoting:,''+imported+'',SUCCEEDS :-) # xterm encoding if UTF8 print German/ALCOR quoting:,u\N{runic cross punctuation}test\N{runic cross punctuation},AOK :-) print German/ALCOR quoting:,u\N{runic cross punctuation}+imported+u\N{runic cross punctuation},Just TOO easy :-) $ ./uc.py English/ASCII quoting: ĦəίιÒ ώσŔĹĐ SUCCEEDS :-) German/ALCOR quoting: ᛭test᛭ AOK :-) German/ALCOR quoting: ᛭ĦəίιÒ ώσŔĹĐ᛭ Just TOO easy :-) NevilleDNZ wrote: Hi, Apologies first as I am not a unicode expert indeed I the details probably totally elude me. Not withstanding: how can I convert a binary string containing UTF-8 binary into a python unicode string? cutdown example: $ cat ./uc.py #!/usr/bin/env python imported=\304\246\311\231\316\257\316\271\303\222 \317\216\317\203\305\224\304\271\304\220 print English/ASCII quoting:,''+imported+'',SUCCEEDS :-) # xterm encoding if UTF8 print German/ALCOR quoting:,u\N{runic cross punctuation}+test +\N{runic cross punctuation},AOK :-) print German/ALCOR quoting:,u\N{runic cross punctuation}+imported+u\N{runic cross punctuation},FAILS :-( $ ./uc.py English/ASCII quoting: ĦəίιÒ ώσŔĹĐ SUCCEEDS :-) German/ALCOR quoting: ᛭test᛭ AOK :-) German/ALCOR quoting: Traceback (most recent call last): File ./uc.py, line 5, in module print German/ALCOR quoting:,u\N{runic cross punctuation}+imported+u\N{runic cross punctuation},FAILS :-( UnicodeDecodeError: 'ascii' codec can't decode byte 0xc4 in position 0: ordinal not in range(128) The last print statement fails because the ascii imported characters are 8 bit encoded UTF-8 and dont know it! How do I tell imported that it is actually already UTF-8 unicode? Cheers NevilleDNZ -- http://mail.python.org/mailman/listinfo/python-list
Re: a question on python dict
In message [EMAIL PROTECTED], Tim Peters wrote: [Tim Peters] You should also note that copying a dict key or value (no matter of what type) consists in its entirety of copying one machine address (a 4- or 8-byte pointer, depending on platform). [Lawrence D'Oliveiro] Actually, no. It also consists of updating reference counts as well. [Tim Peters] Not in context: dict resizing is refcount-neutral... [Lawrence D'Oliveiro] The question wasn't about resizing, it was about copying a dict key or value. Then you misunderstood the OP. He was asking about dict resizing: Which is not what you were talking about, in the part of your posting that I was responding to (above). -- http://mail.python.org/mailman/listinfo/python-list
Re: Help with small program
Paul Watson wrote: It is certainly possible to construct a set of denominations for which the algorithm occasionally chooses badly. For example, if you give it the set (40,35,10) and ask it to make change for 70, it will be suboptimal. Unless I am missing the point, the minimum number of coins from the set available will be chosen. Surely this homework is past due by now. [...] doit(70, (40,35,10)) 70.0 requires 4 coins in hash {40: 1, 10: 3} The point was that minimum number of coins in this case is actually two, but the provided algorithm yields four. -tom! -- -- http://mail.python.org/mailman/listinfo/python-list
Re: DOS, UNIX and tabs
In message [EMAIL PROTECTED], Tom Plunket wrote: Perhaps interestingly, for development I have my editor set to show tabs as fairly short, but my diff program shows them as eight characters. I find that makes indentation changes easier to spot in the diffs. I think there should be a single environment variable, perhaps called TABS, which specifies the tab settings across all relevant tools that work with text, including less and diff. So for example setting this as export TABS=4 will cause these tools to treat tabs as equivalent to stepping to the next multiple of four columns from the start of the line. -- http://mail.python.org/mailman/listinfo/python-list
Re: Why does Python never add itself to the Windows path?
vbgunz wrote: I don't understand what all the fuss is about. Add a single page to the installer and on it, have 3 radio buttons. I don't understand what the fuss is about, and would not give that recommendation based on my not understanding it! I have never ever needed or wanted to launch the python interactive interpreter from a command-line. IPython is what I want to use when I'm going interactive, and running scripts from the command-line works just fine with Windows's file associations. Some if not most python documentation assumes Python is on the path... Really? I must live in different places in the docs, but I can't recall encountering any such documentation. Anyhow, I don't get why it doesn't apply by default in some way on Windows even if at the least it could be a simple reminder or tip to do so. Users who want it in their paths are certainly capable of putting it there. I am in the camp that detests apps that automatically install tons of crap everywhere without prompts. Certainly, though, the suggestion that one pane in the installer offer to put it in the path would leave the default as it is today (don't edit PATH), though, right? Doesn't make a whole lot of sense to add a new option and default it to something completely different from the old behavior, does it? -tom! -- -- http://mail.python.org/mailman/listinfo/python-list
OO question
I want to make an addressbook and I'm new to OO programming, so I wonder if this sounds reasonable. I think of making a class Address which contains all data about one person, that class can have UserDict as baseclass so I can access data like object['name'], etc.. Then maybe I can have a class AddressBook which has a list that contains all those Address objects. Does that sound reasonable? And then the real reason that I posted here is: If I want to save all addresses to disk, I can have a method, say, save() of AddressBook. But then what? What is a good object oriented approach? Should each Address object take care of saving itself to the file, with a method like writetofile(filename), or should the class AddressBook take care of the saving and ask each object for its data? Thanks! -- http://mail.python.org/mailman/listinfo/python-list
Re: I want to see all the variables
Steven D'Aprano wrote: What does the author of the original class know about *my* needs and requirements? The only thing that the original class author might know is that mucking with data marked private may well cause problems, and hiding it therefore prevents those problems. It may turn out that accessing his private attributes is exactly what I need to solve my problem. It may also turn out that you /think/ that's what you need to do, but actually need to do something different. E.g. it may well be possible to access the bytes on the disk that holds your database directly, and that may be easier than going through the db API, but doing so may also be highly prone to error. I'm with the Python philosophy on this one: post all the Don't Touch This warning signs you like, but if somebody really wants to access my private attributes, to do something I never even imagined, they should be allowed to. You are allowed to. Have you been following the thread? Your answer's been mentioned several times. At the same time, you should ponder very carefully the reasons why the original author deemed it important to make those attributes private in the first place. -tom! -- -- http://mail.python.org/mailman/listinfo/python-list
Re: looking for a better way to call a file.
Thanks I will give that a try.. should clean up my code quite a bit. James Thiele wrote: This probably will meet your needs: import os os.system(csound play.orc play.sco) If you need more control try the subprocess module. [EMAIL PROTECTED] wrote: I have been auto-generating .bat files and then running os.startfile('whatever.bat'). I don't seem to be having much luck when I try other methods. All of a sudden I am stuck in a situation where I need the program that is calling to end and a new program to start (because otherwise I get several uneeded copies). csoundgrid4.csgrid(arrg1, ;sco_header, filename) with this by executing the main function os3.execvp('python', 'csoundgrid4.py', arrg1, ;sco_header, filename) and the program just ends. I would also be glad to get rid of all the bats that I generate when I run an external program like csound. The command line I run is somthing like csound play.orc play.sco I haven't had much luck using os.startfile with arguments Hopefully this is an easy question and any help would be apreaceated (befour my computer gets rabies) http://www.dexrow.com -- http://mail.python.org/mailman/listinfo/python-list
Re: I want to see all the variables
On Sun, 31 Dec 2006 19:48:55 -0800, Tom Plunket wrote: Steven D'Aprano wrote: What does the author of the original class know about *my* needs and requirements? The only thing that the original class author might know is that mucking with data marked private may well cause problems, and hiding it therefore prevents those problems. Sure. That's the risk I take when I muck about with somebody else's private attributes. It may turn out that accessing his private attributes is exactly what I need to solve my problem. It may also turn out that you /think/ that's what you need to do, but actually need to do something different. And how is that different from *any* programming task? I might think I need a binary tree, when all I really need is a simple list. An error is an error, whether it is with a public API or a private one. E.g. it may well be possible to access the bytes on the disk that holds your database directly, and that may be easier than going through the db API, but doing so may also be highly prone to error. No, I doubt it is easier -- but if I'm programming a database recovery tool that fixes corrupted databases because the db vendor's supplied tool is broken or non-existent, that might be exactly what I need to do. I'm with the Python philosophy on this one: post all the Don't Touch This warning signs you like, but if somebody really wants to access my private attributes, to do something I never even imagined, they should be allowed to. You are allowed to. Have you been following the thread? Your answer's been mentioned several times. Yes, mostly by me. Do try to keep up. At the same time, you should ponder very carefully the reasons why the original author deemed it important to make those attributes private in the first place. In my experience, it is mostly because they come from bondage-and-domination languages where it is expected that everything is private except for a small, carefully chosen public API, rather than from languages like Python that encourages openness and a philosophy of we're all adults here. I wonder how many double-underscore private attributes are used in the Python standard library? That should give you an idea of best practice use of private attributes in Python. -- Steven. -- http://mail.python.org/mailman/listinfo/python-list
Re: I want to see all the variables
Steven D'Aprano [EMAIL PROTECTED] writes: At the same time, you should ponder very carefully the reasons why the original author deemed it important to make those attributes private in the first place. In my experience, it is mostly because they come from bondage-and-domination languages where it is expected that everything is private except for a small, carefully chosen public API, rather than from languages like Python that encourages openness and a philosophy of we're all adults here. Funny thing, some of those BD languages were designed by people who had plenty of experience with Lisp and were tired of being bitten by its Python-like looseness. I wonder how many double-underscore private attributes are used in the Python standard library? That should give you an idea of best practice use of private attributes in Python. If socket.py is an example of best practice use of private attributes, I shudder to imagine what kind of cruft must lurk in legacy applications. -- http://mail.python.org/mailman/listinfo/python-list
Re: OO question
On Sun, 31 Dec 2006 19:47:12 -0800, fejkadress wrote: I want to make an addressbook and I'm new to OO programming, so I wonder if this sounds reasonable. I think of making a class Address which contains all data about one person, that class can have UserDict as baseclass so I can access data like object['name'], etc.. If you are using Python 2.2 or greater, you can inherit from dict: class Address(dict): ... pass ... fred = Address({address: 123 smith street}) fred['address'] '123 smith street' But ask yourself, what benefit do you gain by subclassing dict? Why not just use a dict? If this is a learning exercise, then sure, go for it, subclass away! But if this is meant to be real code, then consider what benefits and costs using OO will give you, compared to a function-based approach. (Please don't assume that this is a thinly veiled hint that OO is the wrong approach. It isn't.) Then maybe I can have a class AddressBook which has a list that contains all those Address objects. Does that sound reasonable? Again, why create an AddressBook class? Why not just have a list of Addresses? And then the real reason that I posted here is: If I want to save all addresses to disk, I can have a method, say, save() of AddressBook. But then what? What is a good object oriented approach? Should each Address object take care of saving itself to the file, with a method like writetofile(filename), or should the class AddressBook take care of the saving and ask each object for its data? Here's one approach, assuming that AddressBook is merely a list of Addresses and that the Address class knows how to write to an open file object: def save(list_of_addresses, filename): f = file(filename, w) for address in list_of_addresses: address.save(f) f.close() Here's a more pure OO approach to do the same thing: class AddressBook(object): def __init__(self, list_of_addresses): self.addresses = list_of_addresses def save(self, filename): f = file(filename, w) for address in self.addresses: address.save(f) f.close() Here's a third approach: class AddressBook(object): def __init__(self, list_of_addresses): self.addresses = list_of_addresses self.currentfile = None def save_one_address(self, data): data = do_something_with(data) self.currentfile.write(data) def save(self, filename): self.currentfile = file(filename, w) for address in self.addresses: self.save_one_address(address.export()) self.currentfile.close() self.currentfile = None -- Steven. -- http://mail.python.org/mailman/listinfo/python-list
Re: I want to see all the variables
On Sun, 31 Dec 2006 21:23:03 -0800, Paul Rubin wrote: Steven D'Aprano [EMAIL PROTECTED] writes: At the same time, you should ponder very carefully the reasons why the original author deemed it important to make those attributes private in the first place. In my experience, it is mostly because they come from bondage-and-domination languages where it is expected that everything is private except for a small, carefully chosen public API, rather than from languages like Python that encourages openness and a philosophy of we're all adults here. Funny thing, some of those BD languages were designed by people who had plenty of experience with Lisp and were tired of being bitten by its Python-like looseness. I never said they were wrong to do so. But those languages aren't Python. Python is designed for those who are tied of the constant restraint of BD languages. I wonder how many double-underscore private attributes are used in the Python standard library? That should give you an idea of best practice use of private attributes in Python. If socket.py is an example of best practice use of private attributes, I shudder to imagine what kind of cruft must lurk in legacy applications. socket.py doesn't have any double-underscore private attributes (at least not in Python 2.4). So what's your point? -- Steven. -- http://mail.python.org/mailman/listinfo/python-list
Re: OO question
[EMAIL PROTECTED] wrote: I want to make an addressbook and I'm new to OO programming, so I wonder if this sounds reasonable. I think of making a class Address which contains all data about one person, that class can have UserDict as baseclass so I can access data In Python 2.4 or 2.5 you can subclass dict. like object['name'], etc.. Then maybe I can have a class AddressBook which has a list that contains all those Address objects. Does that sound reasonable? Yep. class AdressBook(list): def save(self, filename): import pickle ... And then the real reason that I posted here is: If I want to save all addresses to disk, I can have a method, say, save() of AddressBook. But then what? What is a good object oriented approach? Should each Address object take care of saving itself to the file, with a method like writetofile(filename), or should the class AddressBook take care of the saving and ask each object for its data? If you use the pickle module on the Addressbook then it will automatically save each Address instance. - Paddy. -- http://mail.python.org/mailman/listinfo/python-list
Re: OO question
Steven D'Aprano wrote: On Sun, 31 Dec 2006 19:47:12 -0800, fejkadress wrote: I want to make an addressbook and I'm new to OO programming, so I wonder if this sounds reasonable. I think of making a class Address which contains all data about one person, that class can have UserDict as baseclass so I can access data like object['name'], etc.. If you are using Python 2.2 or greater, you can inherit from dict: class Address(dict): ... pass ... fred = Address({address: 123 smith street}) fred['address'] '123 smith street' But ask yourself, what benefit do you gain by subclassing dict? Why not just use a dict? If this is a learning exercise, then sure, go for it, subclass away! But if this is meant to be real code, then consider what benefits and costs using OO will give you, compared to a function-based approach. (Please don't assume that this is a thinly veiled hint that OO is the wrong approach. It isn't.) Then maybe I can have a class AddressBook which has a list that contains all those Address objects. Does that sound reasonable? Again, why create an AddressBook class? Why not just have a list of Addresses? And then the real reason that I posted here is: If I want to save all addresses to disk, I can have a method, say, save() of AddressBook. But then what? What is a good object oriented approach? Should each Address object take care of saving itself to the file, with a method like writetofile(filename), or should the class AddressBook take care of the saving and ask each object for its data? Here's one approach, assuming that AddressBook is merely a list of Addresses and that the Address class knows how to write to an open file object: def save(list_of_addresses, filename): f = file(filename, w) for address in list_of_addresses: address.save(f) f.close() Here's a more pure OO approach to do the same thing: class AddressBook(object): def __init__(self, list_of_addresses): self.addresses = list_of_addresses def save(self, filename): f = file(filename, w) for address in self.addresses: address.save(f) f.close() Here's a third approach: class AddressBook(object): def __init__(self, list_of_addresses): self.addresses = list_of_addresses self.currentfile = None def save_one_address(self, data): data = do_something_with(data) self.currentfile.write(data) def save(self, filename): self.currentfile = file(filename, w) for address in self.addresses: self.save_one_address(address.export()) self.currentfile.close() self.currentfile = None -- Steven. Small addition. If a class does a save then it should also do the load of the data too. -- http://mail.python.org/mailman/listinfo/python-list
Re: Easiest way to print from XP/DOS.
jim-on-linux [EMAIL PROTECTED] wrote: Thanks, The client is in a one printer office. If the output file is opened with note and then sent to the printer everything is fine but it defeats the purpose of the utility. Also tried lpt1 but the same results. Is it a USB printer? Remember that prn and lpt1 refer to the first parallel port, not necessarily the first printer. -- Tim Roberts, [EMAIL PROTECTED] Providenza Boekelheide, Inc. -- http://mail.python.org/mailman/listinfo/python-list
Re: C app and Python
Vertilka wrote: Hi, I need to create an application that the user ask for python script to run. this script will call the C application functions (in my app. the function will draw on screen). Do I need to create an extension ? Note that this is not a DLL, but a C application. or I need to embed Python in my C application. Thanks, Vertilka A bit of both :-) http://www.python.org/doc/ext/extending-with-embedding.html Ravi Teja. -- http://mail.python.org/mailman/listinfo/python-list
Re: A question about unicode() function
Hi, I changed my codes to: #!/usr/bin/python #Filename: test.py #Modified: 2007-01-01 import cPickle as p import urllib import htmllib import re import sys funUrlFetch = lambda url:urllib.urlopen(url).read() objUrl = raw_input('Enter the Url:') content = funUrlFetch(objUrl) content = content.encode('gb2312','ignore') print content content.close() I used ignore to deal with the data lose, but it still caused a error: C:\WINDOWS\system32\cmd.exe /c python tianya.py Enter the Url:http://www.tianya.cn Traceback (most recent call last): File tianya.py, line 17, in ? content = content.encode('gb2312','ignore') UnicodeDecodeError: 'ascii' codec can't decode byte 0xbb in position 88: ordinal not in range(128) shell returned 1 Hit any key to close this window... My python version is 2.4, Does it have some problems with asian encoding support? Thanks! On Dec 31 2006, 9:30 pm, Felipe Almeida Lessa [EMAIL PROTECTED] wrote: On 31 Dec 2006 05:20:10 -0800, JTree [EMAIL PROTECTED] wrote: def funUrlFetch(url): lambda url:urllib.urlopen(url).read()This function only creates a lambda function (that is not used or assigned anywhere), nothing more, nothing less. Thus, it returns None (sort of void) no matter what is its argument. Probably you meant something like def funUrlFetch(url): return urllib.urlopen(url).read() or funUrlFetch = lambda url:urllib.urlopen(url).read() objUrl = raw_input('Enter the Url:') content = funUrlFetch(objUrl)content gets assigned None. Try putting print content before the unicode line. content = unicode(content,gbk)This, equivalent to unicode(None, gbk), leads to TypeError: coercing to Unicode: need string or buffer, NoneType foundNone's are not strings nor buffers, so unicode() complains. See ya, -- Felipe. -- http://mail.python.org/mailman/listinfo/python-list
Re: A question about unicode() function
JTree [EMAIL PROTECTED] wrote: Hi,all I encountered a problem when using unicode() function to fetch a webpage, I don't know why this happenned. My codes and error messages are: Code: #!/usr/bin/python #Filename: test.py #Modified: 2006-12-31 import cPickle as p import urllib import htmllib import re import sys def funUrlFetch(url): lambda url:urllib.urlopen(url).read() objUrl = raw_input('Enter the Url:') content = funUrlFetch(objUrl) content = unicode(content,gbk) print content content.close() Once you fix the lambda, as Felipe described, there's another issue here. You are telling the unicode function that the string you're passing it is an 8-bit string encoded as gbk. How do you know that? In your specific example, www.msn.com, I can guarantee it will produce the wrong results: www.msn.com is encoded in UTF-8. -- Tim Roberts, [EMAIL PROTECTED] Providenza Boekelheide, Inc. -- http://mail.python.org/mailman/listinfo/python-list
[ python-Feature Requests-1191964 ] asynchronous Subprocess
Feature Requests item #1191964, was opened at 2005-04-28 20:40 Message generated for change (Comment added) made by o You can respond by visiting: https://sourceforge.net/tracker/?func=detailatid=355470aid=1191964group_id=5470 Please note that this message will contain a full copy of the comment thread, including the initial issue submission, for this request, not just the latest update. Category: None Group: None Status: Open Resolution: None Priority: 5 Private: No Submitted By: Josiah Carlson (josiahcarlson) Assigned to: Peter Åstrand (astrand) Summary: asynchronous Subprocess Initial Comment: It would be terribly nice if the Popen class in the subprocess module would allow a programmer to easily say send some data right now (if I have some to send) and receive whatever information is available right now. Essentially the equivalent of asyncore.loop(count=1), only that it returns the data received, instead of placing it in a buffer. Why would this functionality be useful? Currently, when using the subprocess module with pipes, the interaction with a pipe is limited to send data if desired, close the subprocess' stdin, read all output from the subprocess' stdout, Certainly one can pull the pipes out of the Popen instance, and perform the necessary functions on posix systems (with select or poll), but the additional magic on WIndows is a little less obvious (but still possible). There is a post by Paul Du Bois with an example using win32pipe.PeekNamedPipe: http://groups-beta.google.com/group/comp.lang.python/msg/115e9332cc1ca09d?hl=en And a message from Neil Hodgeson stating that PeekNamedPipe works on anonymous pipes: http://mail.python.org/pipermail/python-dev/2000-May/004200.html With this modification, creating Expect-like modules for any platform, as well as embedded shells inside any GUI with a text input widget, becomes easy. Heck, even Idle could use it rather than a socket for its interactive interpreter. -- Comment By: Benjamin (o) Date: 2006-12-31 15:19 Message: Logged In: YES user_id=1680023 Originator: NO If there were a blocking read x bytes type call, could you not do some non-blocking stuff afterwards? If you use the read method, with a byte limit, directly on the stdout member of Popen, that could return with your bytes, and then you do some non-blocking stuff afterwards. That's the external view of course, I suspect that you're saying there's some internal lower-level reason this is currently not possible. Thanks for your interim class BTW, it is proving to be very useful. -- Comment By: Josiah Carlson (josiahcarlson) Date: 2006-12-30 23:21 Message: Logged In: YES user_id=341410 Originator: YES The way subprocess is currently written, if you were to use a blocking semantic, you would no longer be able to use an asynchronous semantic afterwards (it will read the result until there is nothing more to read). Note that this is the case whether it is mode or method based. -- Comment By: Benjamin (o) Date: 2006-12-30 21:45 Message: Logged In: YES user_id=1680023 Originator: NO I would also like to see this feature. I'm using Josiah Carlson's recipe for the time being. I'm agnostic about whether the asynchronicity is a mode or just a case of using different functions. However, if the former is chosen, then one should be able to switch modes at will, because sometimes I want blocking and sometimes I don't. -- Comment By: Josiah Carlson (josiahcarlson) Date: 2005-09-21 20:55 Message: Logged In: YES user_id=341410 I've implemented this as a subclass of subprocess.Popen in the Python cookbook, available here: http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/440554 -- Comment By: Josiah Carlson (josiahcarlson) Date: 2005-09-21 20:51 Message: Logged In: YES user_id=341410 I've implemented this as a subclass of subprocess.Popen in the Python cookbook, available here: http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/440554 Essentially this is a request for inclusion in the standard library for Python 2.5 . -- Comment By: Josiah Carlson (josiahcarlson) Date: 2005-06-26 19:47 Message: Logged In: YES user_id=341410 How about if subprocesses have 3 new methods, send(input), recv(maxlen), and recv_stderr(maxlen). send(input) would perform like socket.send(), sending as much as it currently can, returning the number of bytes sent. recv(maxlen) and recv_stderr(maxlen) would recieve up to the provided number of bytes from the stdout or stderr pipes respectively. I currently have an implementation of the above on Windows
[ python-Bugs-1625381 ] re module documentation on search/match is unclear
Bugs item #1625381, was opened at 2006-12-31 16:42 Message generated for change (Tracker Item Submitted) made by Item Submitter You can respond by visiting: https://sourceforge.net/tracker/?func=detailatid=105470aid=1625381group_id=5470 Please note that this message will contain a full copy of the comment thread, including the initial issue submission, for this request, not just the latest update. Category: Documentation Group: None Status: Open Resolution: None Priority: 5 Private: No Submitted By: Richard Boulton (richardb) Assigned to: Nobody/Anonymous (nobody) Summary: re module documentation on search/match is unclear Initial Comment: Section 4.2.2 (Matching vs Searching) of the Python Library Reference covers the match and search methods of regular expression objects. However, it doesn't begin by describing the difference between these methods. Each time I try to remember which way round match and search are, it takes several minutes of checking the documentation to work out which is which. I suggest that the first paragraph of the section is replaced with the following text (in two paragraphs), to make the distinction between the methods clearer: Python offers two different primitive operations based on regular expressions: match and search. match() checks for a match at the beginning of the search string, whereas search() checks for a match anywhere in the string. If you want something equivalent to Perl's semantics, the search operation is what you're looking for. See the search() function and corresponding method of compiled regular expression objects. -- You can respond by visiting: https://sourceforge.net/tracker/?func=detailatid=105470aid=1625381group_id=5470 ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[ python-Feature Requests-1191964 ] asynchronous Subprocess
Feature Requests item #1191964, was opened at 2005-04-28 13:40 Message generated for change (Comment added) made by josiahcarlson You can respond by visiting: https://sourceforge.net/tracker/?func=detailatid=355470aid=1191964group_id=5470 Please note that this message will contain a full copy of the comment thread, including the initial issue submission, for this request, not just the latest update. Category: None Group: None Status: Open Resolution: None Priority: 5 Private: No Submitted By: Josiah Carlson (josiahcarlson) Assigned to: Peter Åstrand (astrand) Summary: asynchronous Subprocess Initial Comment: It would be terribly nice if the Popen class in the subprocess module would allow a programmer to easily say send some data right now (if I have some to send) and receive whatever information is available right now. Essentially the equivalent of asyncore.loop(count=1), only that it returns the data received, instead of placing it in a buffer. Why would this functionality be useful? Currently, when using the subprocess module with pipes, the interaction with a pipe is limited to send data if desired, close the subprocess' stdin, read all output from the subprocess' stdout, Certainly one can pull the pipes out of the Popen instance, and perform the necessary functions on posix systems (with select or poll), but the additional magic on WIndows is a little less obvious (but still possible). There is a post by Paul Du Bois with an example using win32pipe.PeekNamedPipe: http://groups-beta.google.com/group/comp.lang.python/msg/115e9332cc1ca09d?hl=en And a message from Neil Hodgeson stating that PeekNamedPipe works on anonymous pipes: http://mail.python.org/pipermail/python-dev/2000-May/004200.html With this modification, creating Expect-like modules for any platform, as well as embedded shells inside any GUI with a text input widget, becomes easy. Heck, even Idle could use it rather than a socket for its interactive interpreter. -- Comment By: Josiah Carlson (josiahcarlson) Date: 2006-12-31 10:04 Message: Logged In: YES user_id=341410 Originator: YES Unless you use PeekNamedPipe on Windows, there is no guarantee that the pipe will return *any* data until the process ends, even if you say pipe.read(1) and there is 1k of data already sent. Note that the two async reading methods that I provide (recv() and recv_err()) take a 'maximum bytes' argument. Just like I have written a 'send_all()' utility function, I (or you) can easily write a 'recv_exact()' utility function that receives an exact number of bytes before returning. That functionality would be more or less required for one of the expected use-cases I specify in the recipe, writing a multi-platform 'expect' module. Stick with async calls (with the utility recv_exact()) until you need to use the .communicate() method. -- Comment By: Benjamin (o) Date: 2006-12-31 07:19 Message: Logged In: YES user_id=1680023 Originator: NO If there were a blocking read x bytes type call, could you not do some non-blocking stuff afterwards? If you use the read method, with a byte limit, directly on the stdout member of Popen, that could return with your bytes, and then you do some non-blocking stuff afterwards. That's the external view of course, I suspect that you're saying there's some internal lower-level reason this is currently not possible. Thanks for your interim class BTW, it is proving to be very useful. -- Comment By: Josiah Carlson (josiahcarlson) Date: 2006-12-30 15:21 Message: Logged In: YES user_id=341410 Originator: YES The way subprocess is currently written, if you were to use a blocking semantic, you would no longer be able to use an asynchronous semantic afterwards (it will read the result until there is nothing more to read). Note that this is the case whether it is mode or method based. -- Comment By: Benjamin (o) Date: 2006-12-30 13:45 Message: Logged In: YES user_id=1680023 Originator: NO I would also like to see this feature. I'm using Josiah Carlson's recipe for the time being. I'm agnostic about whether the asynchronicity is a mode or just a case of using different functions. However, if the former is chosen, then one should be able to switch modes at will, because sometimes I want blocking and sometimes I don't. -- Comment By: Josiah Carlson (josiahcarlson) Date: 2005-09-21 13:55 Message: Logged In: YES user_id=341410 I've implemented this as a subclass of subprocess.Popen in the Python cookbook, available here: http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/440554 --
[ python-Bugs-1625509 ] 'imp' documentation does not mention that lock is re-entrant
Bugs item #1625509, was opened at 2006-12-31 18:22 Message generated for change (Tracker Item Submitted) made by Item Submitter You can respond by visiting: https://sourceforge.net/tracker/?func=detailatid=105470aid=1625509group_id=5470 Please note that this message will contain a full copy of the comment thread, including the initial issue submission, for this request, not just the latest update. Category: Documentation Group: Python 2.5 Status: Open Resolution: None Priority: 5 Private: No Submitted By: Dustin J. Mitchell (djmitche) Assigned to: Nobody/Anonymous (nobody) Summary: 'imp' documentation does not mention that lock is re-entrant Initial Comment: My reading of import.c shows that imp.{acquire,release}_lock operate in the fashion of a threading.RLock, rather than a threading.Lock. Of course, this makes sense for the use to which it's put, but it would be great to have that mentioned explicitly in the documentation. Suggestion (stolen from threading documentation): acquire_lock() Acquires the interpreter's import lock for the current thread. This lock should be used by import hooks to ensure thread-safety when importing modules. Once a thread has acquired the import lock, the same thread may acquire it again without blocking; the thread must release it once for each time it has acquired it. On platforms without threads, this function does nothing. New in version 2.3. -- You can respond by visiting: https://sourceforge.net/tracker/?func=detailatid=105470aid=1625509group_id=5470 ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[ python-Bugs-1625576 ] add ability to specify name to os.fdopen
Bugs item #1625576, was opened at 2007-01-01 07:19 Message generated for change (Tracker Item Submitted) made by Item Submitter You can respond by visiting: https://sourceforge.net/tracker/?func=detailatid=105470aid=1625576group_id=5470 Please note that this message will contain a full copy of the comment thread, including the initial issue submission, for this request, not just the latest update. Category: Python Library Group: Feature Request Status: Open Resolution: None Priority: 5 Private: No Submitted By: Mark Diekhans (diekhans) Assigned to: Nobody/Anonymous (nobody) Summary: add ability to specify name to os.fdopen Initial Comment: Please add an optional argument to os.fdopen() to specify the name field in the resulting file object. This would allow for a more useful name than: open file 'fdopen'... -- You can respond by visiting: https://sourceforge.net/tracker/?func=detailatid=105470aid=1625576group_id=5470 ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com