ANN: PyEnchant 1.3.1
Hi All, I'm pleased to announce the release of PyEnchant version 1.3.1. This release brings several minor enhancements over the previous version, and includes upgrades to the bundled components (glib, hunspell, dictionary files) in the Windows version. Cheers, Ryan About: -- Enchant (http://www.abisource.com/enchant/) is the spellchecking package behind the AbiWord word processor, is being considered for inclusion in the KDE office suite, and is proposed as a FreeDesktop.org standard. It's completely cross-platform because it wraps the native spellchecking engine to provide a uniform interface. PyEnchant brings this simple, powerful and flexible spellchecking engine to Python: http://pyenchant.sourceforge.net/ It also provides extended functionality including classes for tokenizing text and iterating over the spelling errors in it, as well as a ready-to-use text interface and wxPython dialog. Current Version: 1.3.1 Licence: LGPL with exemptions, as per Enchant itself ChangeLog for 1.3.1: * treat combining unicode marks as letters during tokenization * cleanup of wxSpellCheckerDialog, thanks to Phil Mayes * upgrades of bundled components in Windows version * upgraded glib DLLs * latest dictionaries from OpenOffice.org * latest version of Hunspell -- Ryan Kelly http://www.rfk.id.au | This message is digitally signed. Please visit [EMAIL PROTECTED]| http://www.rfk.id.au/ramblings/gpg/ for details signature.asc Description: This is a digitally signed message part -- http://mail.python.org/mailman/listinfo/python-announce-list Support the Python Software Foundation: http://www.python.org/psf/donations.html
Leo 4.4.4 beta 2 released
Leo 4.4.4 beta 2 is available at: http://sourceforge.net/project/showfiles.php?group_id=3458package_id=29106 Leo is a text editor, data organizer, project manager and much more. See: http://webpages.charter.net/edreamleo/intro.html The highlights of Leo 4.4.4: - A threading_colorizer plugin replaces the __jEdit_colorizer__ plugin. This plugin features much better performance. - Support for @auto nodes. Such nodes allow people to collaborate using Leo without inserting Leo sentinels in the files Leo generates. - New commands for resolving cvs conflicts. Links: -- Leo: http://webpages.charter.net/edreamleo/front.html Home: http://sourceforge.net/projects/leo/ Download: http://sourceforge.net/project/showfiles.php?group_id=3458 CVS: http://leo.tigris.org/source/browse/leo/ Quotes: http://webpages.charter.net/edreamleo/testimonials.html Edward K. Ream email: [EMAIL PROTECTED] Leo: http://webpages.charter.net/edreamleo/front.html -- http://mail.python.org/mailman/listinfo/python-announce-list Support the Python Software Foundation: http://www.python.org/psf/donations.html
[ANN] Underscode 0.1.0 released
Hi people, I'm really happy to announce the first public version of Underscode, a Python identifier-like encoding. I took it mainly as a hobby so its development in time has been very irregular, but I think it's already time to release and enjoy it! Now the announcement text: == Underscode == - A Python identifier-like encoding - :Author: `Ivan Vilata i Balaguer [EMAIL PROTECTED]`__ :URL: http://underscode.selidor.net/ About Underscode Underscode_ is an encoding which is capable of representing *any* Unicode string as a valid (and quite similar) Python identifier. The way Unicode strings are encoded minimises the chances of clashing with other existing names, while not obscuring the resulting string too much. Some method decorators are provided which allow arbitrary objects to be accessed as normal instance attributes, with optional tab-completion support for interactive usage. The standard Python codec API is also supported. Underscode-encoded (or *underscoded*) strings can be quickly spotted because they end with an *odd* number of underscores, and they contain escape sequences beginning with an underscore where characters not allowed in identifiers would be found. Some examples of underscoded strings are: * ``_`` encodes the empty string. * ``foo_`` encodes ``foo``. * ``class_`` encodes ``class``. * ``foo__bar_`` encodes ``foo_bar``. * ``foo_x20bar_`` encodes ``foo bar``. * ``_2006_09_18_``, like ``_20060918_``, encodes ``20060918``. * ``_x2fbin_x2fls_``, encodes ``/bin/ls``. * ``The_x20Knights_x20Who_x20Say_x20_u201cNi_x21_u201d_`` encodes the properly quoted ``The Knights Who Say “Ni!”``. * And the very flat ``init_`` which happens to be ``__init__``. As you see, underscoded strings are quite similar to their decoded counterparts when these are more or less identifier-like, but complex strings can still be handled. Underscode is a very basic tool which may have several uses: * Avoiding clashes between method names and table field names in ORMs. * Enabling interactive attribute-like completion for children in hierarchically arranged structures (DOM trees, filesystems...), with full Unicode support. * As an aid in the generation of RPC stubs for identifiers which are not allowed by Python. * Computing unique IDs for sections in automatically generated XML or HTML documents. * Naming page handlers for web server frameworks like CherryPy. * ... just use your imagination! The Underscode package is released under the GNU Lesser General Public License (LGPL) version 3 or later (see http://www.gnu.org/licenses/). Underscoded strings as attributes - Underscode provides a module with decorators that allow you to use plain attribute access as a flexible way of accessing all kinds of child objects without polluting the normal attribute namespace, and with optional interactive completion if you wish so. For instance, you can make the (string) keys of a dictionary accessible as attributes:: from underscode.decorators import proxy_method class AttributedDict(dict): @proxy_method(dict.__getitem__) def __getattr__(self, name): return super(AttributedDict, self).__getattr__(name) @proxy_method(dict.__setitem__) def __setattr__(self, name, value): super(AttributedDict, self).__setattr__(name, value) @proxy_method(dict.__delitem__) def __delattr__(self, name): super(AttributedDict, self).__delattr__(name) Then, access to an attribute which looks like an underscoded string gets the name decoded and used as an argument to ``__getitem__()``: d = AttributedDict() d {} d.foo = 1 d.foo_ = 42 d.foo_, d['foo'], d.foo (42, 42, 1) d {u'foo': 42} del d.foo_ d {} Adding tab-completion on underscoded attributes to this simple example is as easy as applying some ready-to-use decorators on the methods used as arguments to ``proxy_method``. See the documentation of the ``underscode.decorators`` module for more information and examples. Python codec API support Since the Underscode package is compliant with the standard Python codec API, you can use Underscode to encode and decode strings with the usual ``unicode.encode()`` and ``str.decode()`` calls at any time just by importing the ``underscode.codec`` subpackage (it is not automatically imported by the main ``underscode`` package): import underscode.codec print u'this is \u201ca test\u201d' this is “a test” u'this is \u201ca test\u201d'.encode('underscode') 'this_x20is_x20_u201ca_x20test_u201d_' 'this_x20is_x20_u201ca_x20test_u201d_'.decode('underscode') u'this is \u201ca test\u201d' Getting Underscode == You can point your browser at http://underscode.selidor.net/ if you want to download the source code distribution of Underscode. It uses
Drag image
i want show image from button? and the image can be drag and rezise ? any body help me!!! i try to make it but is not sucsseful yet -- http://mail.python.org/mailman/listinfo/python-list
Re: Processing drag drop on the desktop
On 17 sep, 17:08, Larry Bates [EMAIL PROTECTED] wrote: Pierre Quentel wrote: Hi all, I would like to create an application on a Windows machine, such that when a document is dragged and dropped on the application icon on the desktop, the document is processed by the application For instance, if I drag drop an Outlook message or a PPT presentation, the application would propose to tag the document with keywords taken from a database Is it possible to do this with a Python script, and how ? Regards, Pierre If you write a python application and put a shortcut on the desktop, when you drop any file on it in Windows it is passed into the program via the sys.argv list as the second (e.g. sys.argv[1]) argument. If you drop multiple files, they are passed in sys.argv[1] sys.argv[n]. All you need to do is to pick up the filename and do your processing. -Larry- Masquer le texte des messages précédents - - Afficher le texte des messages précédents - Thanks for the answers, but it still doesn't work I tried to do this : create a Python script with import sys out = open(dummy,wb) out.write(str(sys.argv)) out.close() === then put a shortcut to this script on the desktop When I drop a file on the shortcut, nothing happens (when I double- click on the shorcut, a console window opens and sys.argv is actually stored in the file) Am I missing something ? Regards, Pierre -- http://mail.python.org/mailman/listinfo/python-list
Puzzled in the coding of Chinese
Dear list members, I am a newcomer in the world of Python. But I am attracted by Python's power in handling text! Now I apply it to handle Chinese but the Chinese character cann't be displayed on the screen. What displayed on the screen is the 16bits codes. I am so puzzled! I believe this is an easy question to most of python users and an important question to me. Thanks a lot to your help! -- http://mail.python.org/mailman/listinfo/python-list
Re: Web Programming thru python
python_lover [EMAIL PROTECTED] wrote: Please help how to execute a py file with xitami. I installed xitami , downloaded lrwp file. accessing the first web application program ... through browser like http://localhost/first.py it is dispaying the source code of the first.py. Please help me how to execute the file. If you want this called as a CGI script, then you probably want this in the cgi-bin directory. You can use [Cgi-Alias] to make other directories into CGI directories as well. If you want ALL .py files to be executed, you should be able to create a filter using Xitami's configuration stuff at http://localhost/admin. -- Tim Roberts, [EMAIL PROTECTED] Providenza Boekelheide, Inc. -- http://mail.python.org/mailman/listinfo/python-list
Re: Deserializing specific objects from a file
On Tue, 18 Sep 2007 16:02:38 -0700, Aaron J. M. wrote: There are many objects that I want be able to move in and out of memory at runtime; namely the game levels. I only want one level in memory at a time, so I want to be able to unpickle specific Level objects as the player moves between levels. I would prefer my serialized objects to reside in one file. I haven't come across references that say how to do something like what I'm describing. Does anyone here know what techniques I have to employ here? Take a look at the `shelve`-Module. Another option might be pickling to individual files and store them in a ZIP archive. Ciao, Marc 'BlackJack' Rintsch -- http://mail.python.org/mailman/listinfo/python-list
Re: [ANN] Metatest 0.1.0
Ben Finney wrote: [Jonathan, please don't send me copies of messages sent to the discussion thread. I follow comp.lang.python via a non-mail interface, and it's irritating to get unwanted copies of messages via email.] [Thank you for letting me know your preference. For myself, I often appreciate it when people send me a copy directly.] The line plus(2, '', _ex=TypeError) causes something to be recorded, snip That's confusing, then, for two reasons: It looks like '_ex' is an argument to the 'plus' function, which otherwise (probably by design) looks exactly like a call to the 'plus' function the programmer is testing. Actually, 'plus' above is an instance of a class (which for now we will call PyUnknown) that has a __call__ method. We know this because we imported it from metaclass.py.mymod. It is, if you like, a /test surrogate/ or /instrumented wrapper/ for the function 'plus' in mymod. And as such it has different properties. For example, the '_ex' parameter has a special significance. Since this is, instead, an assertion *about* that function, it is misleading to see it as an argument *to* the function. Although, by design, it looks like an argument to 'plus' in mymod, it is as I said an argument to 'plus' in metatest.py.mymod, which is something completely different, namely a PyUnknown object. We can think of test-first programming as 1. Stating the problem to be solved. 2. Solving that problem. In mathematics, we often use unknowns when stating problems. We can think of a PyUnknown as being analogous, in programming, to the unknowns we use in mathematics. However, if the difference confuses one (and it can in some situations), then instead do from metatest.py.mymod import plus as mt_plus and then the confusing line becomes mt_plus(2, '', _ex=TypeError) which I think you will find much clearer. It uses the leading-underscore convention which means this is not part of the public interface, and you'd better know what you're doing if you use this externally. This convention is exactly that, a convention. Conventions allow us to communicate efficiently, without spelling everything out. Implicit in metatest are some other conventions or the like. Oh, and this use of metatest does confirm to the convention, and extra knowledge is required to use leading underscore parameters. Finally, if you can think of a better way of saying, in Python, The function call plus(2, '') raises a TypeError, please let me know, and I'll consider using it in the next version of Metatest. I would think an explicit function call that says what it's doing would be better. The unittest module implements this as: self.failUnlessRaises(TypeError, plus, 2, '') snip which has the benefit of being explicit about what it's doing. Well, you did not tell me what self is (althout I guessed it is an instance of a subclass of unittest.TestCase). Nor did you tell me that this statement is part of a class method. To my eye, your example puts the focus on failUnlessRaises and on TypeError. I think the metatest way puts an equal focus on calling plus(2, '') and the result of this call. I give a comparison of three ways of writing tests in my slides: http://metatest.sourceforge.net/doc/pyconuk2007/metatest.html#slide13 To summarise: both metatest and unittest require the user to know something. Once that something is known, the choices for the crucial test line are plus(2, '', _ex=TypeError) self.failUnlessRaises(TypeError, plus, 2, '') I hope you know find the first option less confusing. (It certainly is shorter.) -- Jonathan -- http://mail.python.org/mailman/listinfo/python-list
Re: super() doesn't get superclass
Ben Finney [EMAIL PROTECTED] writes: Possibly the name 'next_in_mro', while ugly, would at least match the actual behaviour of this function. In common lisp there's (call-next-method ...) -- http://mail.python.org/mailman/listinfo/python-list
Re: Using python to create windows apps that everyone can use?
On Sep 18, 9:22 pm, Matt McCredie [EMAIL PROTECTED] wrote: On 9/18/07, Thomas Harding [EMAIL PROTECTED] wrote: Hi guys, sorry to post another topic on this, as I am aware that it has already been posted a few times, but not with specifically what I am looking for. I want an app that makes a gui interface for python (similar to Microsoft visual studio or qt designer, not a code based one) and/or an app that can make this into a .exe that can be opened by any person on any computer without python installed. check out py2exe:http://py2exe.org matt I am currently building an application with Python using Qt4.3 as widget-toolkit. So I can use designer too ;) Links that might be of interest to you: - http://www.riverbankcomputing.co.uk/pyqt/ - http://www.py2exe.org/index.cgi/Py2exeAndPyQt This works quite well. -- http://mail.python.org/mailman/listinfo/python-list
Re: Sets in Python
On Sep 19, 1:59 am, Raymond Hettinger [EMAIL PROTECTED] wrote: On Sep 18, 5:39 pm, sapsi [EMAIL PROTECTED] wrote: I recently tried using the set function in Python and was surprised to find that a=[ 1, 2,3, [1,2] ] doesn't work with 'set', throwing TyperError (unhashable exception). I found out that this is because lists can't be hashed. So,this implies 'a' cannot be a set in python which i think is quite unfortunate, after all 'a' does look like a mathematical set. This is written as: a = set([1, 2, 3, frozenset([1, 2])]) This is not related, but is there i neat way (without pop and list comprehension) to convert a set into a list? list(a) Raymond frozenset over turning the embedded list into a tuple? The tuple would preserve order in the item (1,2) a = set([1,2,3, (1,2)]) - Paddy. -- http://mail.python.org/mailman/listinfo/python-list
Re: Tutorial or Example (or Tutorial) of Using Canvas to Produce a Plot
On Sep 18, 11:58 pm, Richard Townsend [EMAIL PROTECTED] wrote: On Tue, 18 Sep 2007 13:18:36 -0700, W. Watson [EMAIL PROTECTED] wrote: Tk is it. I'm really not interested in the others at this point. John Grayson's book 'Python and Tkinter Programming' has a chapter on plotting Graphs and Charts. You can even download that chapter as a PDF file: http://www.manning-source.com/books/grayson/grayson_ch11.pdf Seehttp://www.manning.com/grayson/for more info about the book. Also, if the graph is really all you need, matplotlib might be a very interesting choice: http://matplotlib.sourceforge.net/ It's got some user-interface facilities as well. But I never used those so far. -- http://mail.python.org/mailman/listinfo/python-list
Re: Troubleshooting installing new package
On Sep 13, 8:10 pm, Gheorghe Postelnicu [EMAIL PROTECTED] wrote: Hi, I have Python 2.5 installed on WinXP and I am trying to install a new package. I ran thesetup.pybuild and I get the following message: C:\packages\reedsolomon-0.1setup.pybuild running build running build_ext error: Python was built with Visual Studio 2003; extensions must be built with a compiler than can generate compatible binaries. Visual Studio 2003 was not found on this system. If you have Cygwin installed, you can try compiling with MingW32, by passing -c mingw32 tosetup.py. I have Visual Studio 2005 Express (the free one) installed. Is there a way to specify an option to compile using that version of the compiler? Sorry for the silly question and thanks in advance for any helpful suggestions! -- Gheorghe Postelnicu, PhD MGH, Harvard Medical School Hello, newbee here. I was looking for other solutions to other problems. However, in my research for building wxPython I read from the docs/build.html concerning the WIN crowd ... -- [quote] If you woudl rather use a different version of VisualStudio keep in mind that you'll also have to build Python and any other extension modules that you use with that compiler because a different version of the C runtime library is used. The stock Python 2.4 and 2.5 executables are built with MSVC 7.1, and the same rules apply to it.[/ quote] So... did you build your Python2.5?? or did you install the binaries?? It makes a big difference. -- http://mail.python.org/mailman/listinfo/python-list
Re: Using python to create windows apps that everyone can use?
On Sep 18, 9:22 pm, Matt McCredie [EMAIL PROTECTED] wrote: On 9/18/07, Thomas Harding [EMAIL PROTECTED] wrote: Hi guys, sorry to post another topic on this, as I am aware that it has already been posted a few times, but not with specifically what I am looking for. I want an app that makes a gui interface for python (similar to Microsoft visual studio or qt designer, not a code based one) and/or an app that can make this into a .exe that can be opened by any person on any computer without python installed. check out py2exe:http://py2exe.org matt Oh... I forgot. With newer versions of Qt, you have to adapt the setup script a bit. Here's an example (even with an icon-resource ) ;) setup(windows=['ide.py'], options={py2exe:{ includes:[sip, PyQt4._qt], icon_resources:[(1,gnucash.ico)]}}) The trick here, is to also add PyQt4._qt to the includes. -- http://mail.python.org/mailman/listinfo/python-list
Re: super() doesn't get superclass
Ben Finney [EMAIL PROTECTED] writes: Hrvoje Niksic [EMAIL PROTECTED] writes: class X(Y): def foo(self): super(X, self).foo() ...there is in fact no guarantee that super() calls a superclass of X. However, it is certainly guaranteed that it will call a superclass of type(self). Not even that. It could call *any class in the inheritance hierarchy*, The inheritance hierarchiy is populated by the various (direct and indirect) superclasses of type(self). depending on how the MRO has resolved next class. Even one that is neither an ancestor nor a descendant of X. My point exactly. superclass of X is not the same as superclass of type(self). Super iterates over the latter, where you expect the former. -- http://mail.python.org/mailman/listinfo/python-list
Re: Sets in Python
On 9/19/07, Paddy [EMAIL PROTECTED] wrote: frozenset over turning the embedded list into a tuple? The tuple would preserve order in the item (1,2) a = set([1,2,3, (1,2)]) The OP was probably thinking in mathematical terms as in the set of all the possible subsets of the set composed by 1, 2 and 3 and thus order would not be important. francesco -- http://mail.python.org/mailman/listinfo/python-list
Re: super() doesn't get superclass
Ben Finney [EMAIL PROTECTED] writes: Evan is claiming that the next class in the MRO _is_ a superclass, apparently by his definition or some other that I've not seen. The definition of superclass is not the issue, the issue is superclass *of which class*? You expect super(A, self) to iterate only over superclasses of A, even when self is an instance of a subtype of A. What really happens is that super(A, self) yields the next method in type(self)'s MRO, which can and does cause include classes that are not by any definition superclasses of A. All of those classes are, however, superclasses of the instance's type. I think it is not possible to have super(A, self) only call superclasses of A and at the same time having multiple inheritance work without calling some methods in the hierarchy twice or not at all. Guido's paper at http://tinyurl.com/qkjgp explains the reasoning behind super in some detail. I agree that the documentation for super is somewhat misleading (and obviously wrong), Well, that's the first time someone has acknowledged that in this thread, so I guess this is something. For the record, I also agree with that. The documentation should document in some detail that super(type, obj) yields superclasses of type(obj), not of type, and that the type argument is only used for super to be able to locate the next type in the list. I wouldn't use such an extreme word as 'madness', but I totally agree that this should be corrected. Care to submit a doc patch ? I don't understand what practical uses 'super' is intended for It's intended for cooperative multiple inheritance, a la CLOS's call-next-method. -- http://mail.python.org/mailman/listinfo/python-list
Re: Extracting xml from html
George Sakkis wrote: Given that you can do in 2 lines what took you around 15 with lxml, I wouldn't think it twice. Don't judge a tool by beginner's code. Stefan -- http://mail.python.org/mailman/listinfo/python-list
Re: Help, I'm going mad with this
azrael wrote: Help, I'm going mad with this Is Otsu threshold algorithm to boring as a subject? Meanwhile I tried about 5 different implementations of the otsu threshold algorithm. I'll go mad. Please help me. I don't know what to do. I even tried to implement it from c and java, but no way. nothing. I've been reading about 5 ppt presentations and 4 pdf's and I failed. Can someone look at this code. If needed I can paste 3 other codes. Hmm, you just learned that quality is more important than quantity then. Choose the text that seems most accessible while still complete and try to understand it. if __name__==__main__: otsu(histogram) You are using a parameter before defining it. It seems you have not yet groked the basics of cut and past then. histogram= [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 2, 0, 0, 2, 1, 2, 0, 1, 3, 3, 3, 3, 1, 3, 1, 3, 5, 2, 3, 3, 3, 6, 3, 4, 5, 4, 9, 6, 11, 6, 10, 3, 11, 9, 9, 12, 22, 18, 34, 22, 28, 32, 25, 34, 38, 34, 54, 65, 106, 160, 167, 203, 282, 364, 446, 637, 816, 1022, 1264, 1456, 1646, 1753, 1845, 1922, 2203, 2231, 1973, 2245, 2369, 2349, 2258, 2130, 2066, 1835, 1640, 1554, 1414, 1179, 1024, 974, 938, 838, 785, 756, 803, 921, 952, 865, 722, 625, 608, 547, 498, 412, 438, 408, 413, 415, 339, 366, 330, 320, 293, 315, 368, 411, 434, 500, 531, 538, 552, 665, 811, 869, 998, 1021, 1075, 1080, 1030, 934, 926, 1074, 942, 941, 1014, 1440, 2966, 5301, 2729, 3400, 5563, 13096, 9068, 6045, 2813, 686, 180] Well, this list is a example list that i have exported. for this list the result the threshold should be at 218. If you need the result and don't want to bother with understanding the algorithm -- I found an implementation in C via Google Codesearch http://www.google.com/codesearch?hl=deq=+otsu+threshold+show:3rXPo8eEzw0:z-1MzowD-bQ:cDGSVzqKA7Msa=Ncd=1ct=rccs_p=http://www.studio-to-go.co.uk/source-packages/2.x/gocr-0.41.tar.bz2cs_f=gocr-0.41/src/otsu.c#a0 It gives the desired result if you use the line that is commented out // orig: sb ... instead of its current replacement. Translation to Python should be straightforward, but you can ask on c.l.py if you run into problems. Peter -- http://mail.python.org/mailman/listinfo/python-list
help, I'll go crazy
Some time ago I started a thread about the Otsu Threshold. Well I didn' manage to make any progress to acomplish this task. I tried to implement it from other Languages including Java and C. Well, this is the example list. histogram=[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 2, 0, 0, 2, 1, 2, 0, 1, 3, 3, 3, 3, 1, 3, 1, 3, 5, 2, 3, 3, 3, 6, 3, 4, 5, 4, 9, 6, 11, 6, 10, 3, 11, 9, 9, 12, 22, 18, 34, 22, 28, 32, 25, 34, 38, 34, 54, 65, 106, 160, 167, 203, 282, 364, 446, 637, 816, 1022, 1264, 1456, 1646, 1753, 1845, 1922, 2203, 2231, 1973, 2245, 2369, 2349, 2258, 2130, 2066, 1835, 1640, 1554, 1414, 1179, 1024, 974, 938, 838, 785, 756, 803, 921, 952, 865, 722, 625, 608, 547, 498, 412, 438, 408, 413, 415, 339, 366, 330, 320, 293, 315, 368, 411, 434, 500, 531, 538, 552, 665, 811, 869, 998, 1021, 1075, 1080, 1030, 934, 926, 1074, 942, 941, 1014, 1440, 2966, 5301, 2729, 3400, 5563, 13096, 9068, 6045, 2813, 686, 180] # var() is from the numpy module My Example is This def otsu(hi): s=sum(hi) border=len(hi) for i in range(border): if hi[i]!=0:break for j in range(border-1,0-1,-1): if hi[j] != 0:break li=[] for l in range(len(hi)): hi[l]=float(hi[l])/s for k in range(i+1,j+1): q1=sum(hi[i:k]) q2=sum(hi[k:j+1]) v1=var(hi[i:k]) v2=var(hi[k:j+1]) a=q1*v1 + q2*v2 li.append(a) print min(li) m,n=li[0],i for k in range(len(li)): if li[k]m: m=li[k] n=k return n This is a Threshold Method that accepts a list like a histogram and return the optimal threshold value. As I have been surfing the internet, I found several formulas. Please, dear comunity, help me.I am desperate, I'll go mad. I can't bealive it that I can't implement something so simple looking. For this example list the thresh value should be 218. I know it because I i tested it on an image in ImageJ, and then I exported the histogram. If any other examples needed I cant'get you as much as needed If needed, I can Paste 3 other algorithms I tried. Thaks in advance -- http://mail.python.org/mailman/listinfo/python-list
Re: Pseudo-Private Class Attributes
Ricardo Aráoz a écrit : That is self.__attributes Been reading about the reasons to introduce them and am a little concerned. As far as I understand it if you have a class that inherits from two other classes which have both the same name for an attribute then you will have a name clash because all instance attributes wind up in the single instance object at the bottom of the class tree. Now I guess this means that in any real OOP project you'd better use __attr for all your attributes, because classes are usually meant to be subclassed and you can never know when you'll be subclassing from two classes with attributes with the same name, and I guess you can't take the risk of this happening because when it happens it will be hell to find out what's going on. Is this right? Wild guess : you're coming from Java or C++ ?-) I don't know for sure what you mean by real OOP project, but any non-trivial Python project surely qualifies IMHO, and it seems that so far no one had too much problem with this, so you're perhaps needlessly worrying. Note that given Python's type system, inheritence is mostly about implementation - you don't need it for polymorphic dispatch. This results in class hierarchies being way much flatter in Python than in languages with declarative static typing - IOW, Python's classes are not necessarily meant to be subclassed. Also, while Python does support multiple inheritance, it's rarely used in practice (except perhaps in Zope 2, which is that pythonic). Python has great support for delegation, so composition/delegation is often used where MI would have been used in C++. FWIW, __private names are of very rare use in Python. As far as I'm concerned, I must have use this feature a couple of times at most, in base classes or metaclasses of a small framework, because these couple attributes where really vital to the sytem and should by no mean be overloaded. My 2 cents. -- http://mail.python.org/mailman/listinfo/python-list
Re: Creating OpenOffice doc's
Go to http://ooolib.sourceforge.net/ and download the Python version and unzip the file. There are a few examples illustrating various features. I have used this to create simple OO spreadsheets. Regards, Hemanth Sethuram -- http://mail.python.org/mailman/listinfo/python-list
Re: Extracting xml from html
[EMAIL PROTECTED] a écrit : On Sep 18, 1:56 am, Stefan Behnel [EMAIL PROTECTED] wrote: [EMAIL PROTECTED] wrote: I am attempting to extract some XML from an HTML document that I get returned from a form based web page. For some reason, I cannot figure out how to do this. Here's a sample of the html: html body lots of screwy text including divs and spans Row status=o RecordNum1126264/RecordNum MakeMitsubishi/Make ModelMirage DE/Model /Row /body /html What's the best way to get at the XML? Do I need to somehow parse it using the HTMLParser and then parse that with minidom or what? lxml makes this pretty easy: parser = etree.HTMLParser() tree = etree.parse(the_file_or_url, parser) This is actually a tree that can be treated as XML, e.g. with XPath, XSLT, tree iteration, ... You will also get plain XML when you serialise it to XML: xml_string = etree.tostring(tree) Note that this doesn't add any namespaces, so you will not magically get valid XHTML or something. You could rewrite the tags by hand, though. Stefan I got it to work with lxml. See below: def Parser(filename): parser = etree.HTMLParser() tree = etree.parse(r'path/to/nextpage.htm', parser) xml_string = etree.tostring(tree) events = (recordnum, primaryowner, customeraddress) context = etree.iterparse(StringIO(xml_string), tag='') for action, elem in context: tag = elem.tag if tag == 'primaryowner': owner = elem.text elif tag == 'customeraddress': address = elem.text else: pass print 'Primary Owner: %s' % owner print 'Address: %s' % address Does this make sense? It works pretty well, but I don't really understand everything that I'm doing. Mike Q? Once you get your document into an XML tree in memory, while do you go to event-based handling to extract your data ? Try to directly manipulate the tree. parser = etree.HTMLParser() tree = etree.parse(r'path/to/nextpage.htm', parser) myrows = tree.findall(.//Row) # Then work with the sub-elements. for r in myrows : rnumelem = r.find(RecordNum) makeeleme = r.find(Make) modelelem = r.find(Model) co. -- http://mail.python.org/mailman/listinfo/python-list
lxml codespeak pages empty ?
I can no longer get codespeak's lxml page at http://codespeak.net/lxml/ (get an empty HTML document !DOCTYPE html PUBLIC -//W3C//DTD HTML 4.01 Transitional//ENhtmlheadtitle/title/headbody/body/html)... Am-I alone in this case ? Any codespeaker reading ? A+ Laurent. -- http://mail.python.org/mailman/listinfo/python-list
Re: Extracting xml from html
[EMAIL PROTECTED] wrote: Does this make sense? It works pretty well, but I don't really understand everything that I'm doing. def Parser(filename): It's uncommon to give a function a capitalised name, unless it's a factory function (which this isn't). parser = etree.HTMLParser() tree = etree.parse(r'path/to/nextpage.htm', parser) xml_string = etree.tostring(tree) What you do here is parse the HTML page and serialise it back into an XML string. No need to do that - once it's a tree, you can work with it. lxml is a highly integrated set of tools, no matter if you use it for XML or HTML. events = (recordnum, primaryowner, customeraddress) You're not using this anywhere below, so I assume this is left-over code. context = etree.iterparse(StringIO(xml_string), tag='') for action, elem in context: tag = elem.tag if tag == 'primaryowner': owner = elem.text elif tag == 'customeraddress': address = elem.text else: pass print 'Primary Owner: %s' % owner print 'Address: %s' % address Admittedly, iterparse() doesn't currently support HTML (although this might become possible in lxml 2.0). You could do this more easily in a couple of ways. One is to use XPath: print [el.text for el in tree.xpath(//primaryowner|//customeraddress)] Note that this works directly on the tree that you retrieved right in the third line of your code. Another (and likely simpler) solution is to first find the Row element and then start from that: row = tree.find(//Row) print row.findtext(primaryowner) print row.findtext(customeraddress) See the lxml tutorial on this, as well as the documentation on XPath support and tree iteration: http://codespeak.net/lxml/xpathxslt.html#xpath http://codespeak.net/lxml/api.html#iteration Hope this helps, Stefan -- http://mail.python.org/mailman/listinfo/python-list
Re: lxml codespeak pages empty ?
Laurent Pointal wrote: I can no longer get codespeak's lxml page at http://codespeak.net/lxml/ (get an empty HTML document !DOCTYPE html PUBLIC -//W3C//DTD HTML 4.01 Transitional//ENhtmlheadtitle/title/headbody/body/html)... Am-I alone in this case ? Any codespeaker reading ? Hmm, it's working for me... Stefan -- http://mail.python.org/mailman/listinfo/python-list
Re: lxml codespeak pages empty ? Come back.
Laurent Pointal a écrit : I can no longer get codespeak's lxml page at http://codespeak.net/lxml/ (get an empty HTML document !DOCTYPE html PUBLIC -//W3C//DTD HTML 4.01 Transitional//ENhtmlheadtitle/title/headbody/body/html)... Am-I alone in this case ? Any codespeaker reading ? It magically come-back -- http://mail.python.org/mailman/listinfo/python-list
Re: The meaning of a = b in object oriented languages
Lew schreef: Roel Schroeven wrote: Laurent Pointal schreef: Summercool a écrit : The meaning of a = b in object oriented languages. zip Oups, reading the subject I thought it was a Xah Lee post. me too ... Nah, this dude's all right, so far. As if my opinion mattered. Stay with it, Summercool. It's what discussion groups are for. Here's why the reaction: cross-posting of computer-science-type essays, something Xah Lee does. But he recycles all his decades-old crap and really doesn't participate in the discussion. This isn't that at all. I fully agree and I didn't in any way mean to compare Summercool to Xah Lee. My apologies to Summercool if anyone interpreted it that way. It's just that somehow the subject seems to follow the same template as what I've become used to from Xah Lee. I almost skipped reading the post because of that. Once I started reading it though, it became immediately clear that it was not comparable to Xah Lee's postings in any way, shape or form. -- The saddest aspect of life right now is that science gathers knowledge faster than society gathers wisdom. -- Isaac Asimov Roel Schroeven -- http://mail.python.org/mailman/listinfo/python-list
Re: Using pseudonyms
On Sep 19, 5:07 am, [EMAIL PROTECTED] (Alex Martelli) wrote: Aahz [EMAIL PROTECTED] wrote: For that matter, there are plenty of people who are better known by some nickname that is not their legal name. Yep. For example, some people whose legal name is Alessandro (which no American is ever going to be able to spell right -- ONE L, TWO S's, NOT an X or a J instead, DRO ending rather than DER, etc), might choose to avoid the hassle and go by Alex (just to make up a case...). Alex ... and someone whose nickname is Paddy which is very common, and who finds it hard to remember birthdates decides to add the days in the month that his first two children were born on to his used name and now only gets worried near his partners birthday :-) - Paddy. -- http://mail.python.org/mailman/listinfo/python-list
How to know the starting point
Hi, I need help regarding the starting point in python project, As we can find main() function in java class to know the starting class in java, what is the starting point in python project? How to find the starting point. Thank you - Get the freedom to save as many mails as you wish. Click here to know how.-- http://mail.python.org/mailman/listinfo/python-list
Re: How to know the starting point
On 9/19/07, Raj kumar [EMAIL PROTECTED] wrote: Hi, I need help regarding the starting point in python project, As we can find main() function in java class to know the starting class in java, what is the starting point in python project? How to find the starting point. Thank you There is no such thing, you can start where you like: try to write a simple .py file defining some functions and classes and then using them. Then launch the app by python your_file.py, and it will just work. You will often find a test like if __name__ == '__main__': do_something() __name__ is the variable which contains the name of the module. If the module is being run as python your_module.py, the __name__ becomes '__main__' and the condition of the if statement is satisfied. This is a common method to define a starting point for a python application. Keep in mind that many python modules are intended to be imported by other modules and not to be used as standalone applications, but rather as libraries. As such, they don't have a starting point, and the if __name__ == '__main__': test could be used for instance to start a test suite. francesco -- http://mail.python.org/mailman/listinfo/python-list
AttributeError: How to list existing attributes?
Hi, how can you list the attributes of an object if you catch an AttributeError? I couldn't find a reference in the exception object, which points to the object. I want to call dir() on the object to list the user the known attributes. Is there a way to find the object by inspecting the stacktrace? Thomas -- Thomas Güttler, http://www.thomas-guettler.de/ http://www.tbz-pariv.de/ E-Mail: guettli (*) thomas-guettler + de Spam Catcher: [EMAIL PROTECTED] -- http://mail.python.org/mailman/listinfo/python-list
Re: How can I know how much to read from a subprocess
In message [EMAIL PROTECTED], [EMAIL PROTECTED] wrote: ... how can I know if the process wrote something to its output, and how much it wrote? Others have mentioned using one-byte reads. To tell if something is available for reading, use select http://docs.python.org/lib/module-select.html. -- http://mail.python.org/mailman/listinfo/python-list
Quick shallow-copy idiom
y = type(x)(x) -- http://mail.python.org/mailman/listinfo/python-list
Re: AttributeError: How to list existing attributes?
Thomas Guettler wrote: Hi, how can you list the attributes of an object if you catch an AttributeError? I couldn't find a reference in the exception object, which points to the object. I want to call dir() on the object to list the user the known attributes. Is there a way to find the object by inspecting the stacktrace? By looking at the code at the line the stacktrace lists? And at least for me, there is a type-information as well: Python 2.5.1 (r251:54863, May 2 2007, 16:56:35) [GCC 4.1.2 (Ubuntu 4.1.2-0ubuntu4)] on linux2 Type help, copyright, credits or license for more information. clWelcome to rlcompleter2 0.96 for nice experiences hit tab multiple times class Foo(object): pass ... f = Foo() f.foo Traceback (most recent call last): File stdin, line 1, in module AttributeError: 'Foo' object has no attribute 'foo' You can't possibly know which attributes the object has, though. Because it might be an attribute dynamically added. So the best thing is to put a print-statement before the exception-throwing line or put a import pdb; pdb.set_trace() there, and fiddle around with the object. Diez -- http://mail.python.org/mailman/listinfo/python-list
Re: Help, I'm going mad with this
I didn't found this one. Looks interesting and complex because I ran away from C to Python because of the developing speed and pointers. Thanks mate, I'll try it. Other C implementations I found were much shorter, at least this is going to be a little challenge. :D -- http://mail.python.org/mailman/listinfo/python-list
still get a defunct using a python script in the crontab
H! I have made a program that is checking if a program is running or not. If the program is not running then it must start the program again. in the /etc/crontab: * * * * * root/usr/sbin/ program_prgchk in the /usr/sbin/program_prgchk: /usr/local/bin/python /home/reseller/domeinaanvraag/program_prgchk.py in the program_prgchk.py: import string import os import commands def checkifrunning(): line = string.strip(commands.getoutput(ps x -o pid,command | grep program_reseller.py | grep -v 'grep')) pid = string.split(line,' ')[0] if pid'':pid = int(pid) return pid if checkifrunning()=='': os.system('/usr/sbin/program_reseller') #os.wait() #os.waitpid(checkifrunning(),0) os._exit(0) If I run the command /usr/sbin/program_prgchk everything works (no defunct process) But when I use it in the crontab I get a defunct process Thanks for helping, GC-Martijn -- http://mail.python.org/mailman/listinfo/python-list
Re: Metatest 0.1.0
On 19 Sep., 01:30, Jonathan Fine [EMAIL PROTECTED] wrote: there is no fundamental reason why it can't be separated from eeconsole.py. OK. That might be a good idea. Ironically, I liked the idea of having more expressive assert statements - a discussion you brought up. But this requires either syntcatical analysis in the general case ( EE and assert magic ) some particular API ( Ben Finney ) or a somewhat restricted, but fully embedded, domain specific language ( Metatest ). Here is what I got after an hour of hacking and filtering assert. Additional remarks are in line comments: ___ ZERO On Python 2.5 (r25:51908, Sep 19 2006, 09:52:17) [MSC v.1310 32 bit (Intel)] Reuses session report ZERO_20.eerp ___ # define a test function add and check it out def add(y,x): ... return x+y ... assert add(1,2) == 0 Traceback (most recent call last): File input, line 1, in module AssertionError: 3 == 0 # An tested assertion is splitted into lhs, op, rhs. If this is not possible assert # won't be changed by magics. # Here we see a simple formatting of the result in the form: # %s %s %s % (eval(lhs), op, eval(rhs)) # More elaborated formatting schemes are user defined: class MyFormatter(AssertionFormatter): ... def format(self, lhs, op, rhs): ... if op == ==: ... return Expected: %s. Received: %s%(lhs, rhs) ... else: ... return super(MyFormatter, self).format(lhs, op, rhs) ... # The class AssertionFormatter is defined in EasyExtend.fibers.zero.fiber. # It provides a single method # #format(lhs: str, op: str, rhs: str) - str # # The default behaviour is the one # demonstrated above. One can overwrite format in subclasses and pass the subclass # instance to assert. # The arguments will be supplied by the framework. # Here we see the new formatter in action: assert add(1,2) == 0, MyFormatter Traceback (most recent call last): File input, line 1, in module AssertionError: Expected: 3. Received: 0 # Now it falls back to the default formatting: ? ! assert add(1,2) =0, MyFormatter Traceback (most recent call last): File input, line 1, in module AssertionError: 3 = 0 quit . Recorded assertions | -- Status |eerp ln|repl ln| Assertion ---+---+--- +-- ERROR | 14| 14| assert add(1,2) == 0 ERROR | 26| 26| assert add(1,2) == 0, MyFormatter ERROR | 31| 31| assert add(1,2) =0, MyFormatter ---+---+--- +-- Regards, Kay -- http://mail.python.org/mailman/listinfo/python-list
Re: Metatest 0.1.0
On 19 Sep., 01:30, Jonathan Fine [EMAIL PROTECTED] wrote: there is no fundamental reason why it can't be separated from eeconsole.py. OK. That might be a good idea. Ironically, I liked the idea of having more expressive assert statements - a discussion you brought up. But this requires either syntcatical analysis in the general case ( EE and assert magic ) some particular API ( Ben Finney ) or a somewhat restricted, but fully embedded, domain specific language ( Metatest ). Here is what I got after an hour of hacking and filtering assert. Additional remarks are in line comments: ___ ZERO On Python 2.5 (r25:51908, Sep 19 2006, 09:52:17) [MSC v.1310 32 bit (Intel)] Reuses session report ZERO_20.eerp ___ # define a test function add and check it out def add(y,x): ... return x+y ... assert add(1,2) == 0 Traceback (most recent call last): File input, line 1, in module AssertionError: 3 == 0 # An tested assertion is splitted into lhs, op, rhs. If this is not possible assert # won't be changed by magics. # Here we see a simple formatting of the result in the form: # %s %s %s % (eval(lhs), op, eval(rhs)) # More elaborated formatting schemes are user defined: class MyFormatter(AssertionFormatter): ... def format(self, lhs, op, rhs): ... if op == ==: ... return Expected: %s. Received: %s%(lhs, rhs) ... else: ... return super(MyFormatter, self).format(lhs, op, rhs) ... # The class AssertionFormatter is defined in EasyExtend.fibers.zero.fiber. # It provides a single method # #format(lhs: str, op: str, rhs: str) - str # # The default behaviour is the one # demonstrated above. One can overwrite format in subclasses and pass the subclass # instance to assert. # The arguments will be supplied by the framework. # Here we see the new formatter in action: assert add(1,2) == 0, MyFormatter Traceback (most recent call last): File input, line 1, in module AssertionError: Expected: 3. Received: 0 # Now it falls back to the default formatting: ? ! assert add(1,2) =0, MyFormatter Traceback (most recent call last): File input, line 1, in module AssertionError: 3 = 0 quit . Recorded assertions | -- Status |eerp ln|repl ln| Assertion ---+---+--- +-- ERROR | 14| 14| assert add(1,2) == 0 ERROR | 26| 26| assert add(1,2) == 0, MyFormatter ERROR | 31| 31| assert add(1,2) =0, MyFormatter ---+---+--- +-- Regards, Kay -- http://mail.python.org/mailman/listinfo/python-list
HTTP Protocol Client
Hi, I am writing http protocol to get some data from servers. If i was using my localhost, getting replay from local and if want access other remote sites, i am getting error. Please reply it My localhost client script::: Code: ( python ) import httplib h = httplib.HTTP('localhost',80) h.putrequest('GET','') h.putheader('User-Agent','Lame Tutorial Code') h.putheader('Accept','text/html') h.endheaders() errcode,errmsg, headers = h.getreply() print errcode,errmsg, headers f = h.getfile() # Get file object for reading data data = f.read() print data f.close() the Reply getting from this 403 Forbidden Date: Tue, 18 Sep 2007 05:20:36 GMT Server: Apache/2.0.52 (Red Hat) Accept-Ranges: bytes Content-Length: 3985 Connection: close Content-Type: text/html; charset=UTF-8 And some Html script If I want to access other sites::: import httplib h = httplib.HTTP('http://Google.com',80) h.putrequest('GET','') h.putheader('User-Agent','Lame Tutorial Code') h.putheader('Accept','text/html') h.endheaders() errcode,errmsg, headers = h.getreply() print errcode,errmsg, headers f = h.getfile() # Get file object for reading data data = f.read() print data f.close() I got the error like::: Traceback (most recent call last): File c.py, line 6, in ? h.endheaders() File /usr/lib/python2.3/httplib.py, line 712, in endheaders self._send_output() File /usr/lib/python2.3/httplib.py, line 597, in _send_output self.send(msg) File /usr/lib/python2.3/httplib.py, line 564, in send self.connect() File /usr/lib/python2.3/httplib.py, line 532, in connect socket.SOCK_STREAM): socket.gaierror: (-2, 'Name or service not known') How can I access Remote sites using http protocol . I did'nt write server script. Thanks And Regards Allavarapu -- http://mail.python.org/mailman/listinfo/python-list
HTTP Protocol Client
Hi, I am writing http protocol to get some data from servers. If i was using my localhost, getting replay from local and if want access other remote sites, i am getting error. Please reply it My localhost client script::: Code: ( python ) import httplib h = httplib.HTTP('localhost',80) h.putrequest('GET','') h.putheader('User-Agent','Lame Tutorial Code') h.putheader('Accept','text/html') h.endheaders() errcode,errmsg, headers = h.getreply() print errcode,errmsg, headers f = h.getfile() # Get file object for reading data data = f.read() print data f.close() the Reply getting from this 403 Forbidden Date: Tue, 18 Sep 2007 05:20:36 GMT Server: Apache/2.0.52 (Red Hat) Accept-Ranges: bytes Content-Length: 3985 Connection: close Content-Type: text/html; charset=UTF-8 And some Html script If I want to access other sites::: import httplib h = httplib.HTTP('http://Google.com',80) h.putrequest('GET','') h.putheader('User-Agent','Lame Tutorial Code') h.putheader('Accept','text/html') h.endheaders() errcode,errmsg, headers = h.getreply() print errcode,errmsg, headers f = h.getfile() # Get file object for reading data data = f.read() print data f.close() I got the error like::: Traceback (most recent call last): File c.py, line 6, in ? h.endheaders() File /usr/lib/python2.3/httplib.py, line 712, in endheaders self._send_output() File /usr/lib/python2.3/httplib.py, line 597, in _send_output self.send(msg) File /usr/lib/python2.3/httplib.py, line 564, in send self.connect() File /usr/lib/python2.3/httplib.py, line 532, in connect socket.SOCK_STREAM): socket.gaierror: (-2, 'Name or service not known') How can I access Remote sites using http protocol . I did'nt write server script. Thanks And Regards Allavarapu -- http://mail.python.org/mailman/listinfo/python-list
Re: super() doesn't get superclass
Ben Finney a écrit : Bruno Desthuilliers [EMAIL PROTECTED] writes: Ben Finney a écrit : Evan Klitzke [EMAIL PROTECTED] writes: On Tue, 2007-09-18 at 14:15 +1000, Ben Finney wrote: [the 'super' function] doesn't return the superclass, it returns the next class in the MRO, whether that's a superclass or not. The next class in the MRO _is_ a superclass. [demonstration that the next class in the MRO is not necessarily a superclass] You seem to be saying that now suddenly D *is* a superclass of A. I don't see such an assertion in Evan's answer. Chapter and verse ??? I've trimmed the quoting to make it clearer. Evan is claiming that the next class in the MRO _is_ a superclass, apparently by his definition or some other that I've not seen. The next class in the MRO *is* a superclass of the *instance*. Else it wouldn't be in the MRO !-) I've shown a fairly simple multiple-inheritance hierarchy where the next class in the MRO is not an ancestor of the subject class, It's an ancestor of the class of the instance on which the method is called. Either superclass of A is equivalent to ancestor class of A, or it's not. I maintain that many programmers will expect that it is, but Evan's assertion says otherwise. It can't be both. That's certainly not what users will think of when they think superclass though. If a class X is in the MRO of call Y, then X is a superclass of Y. s/call/class/, of course. That goes completely against what Alex Martelli told me, which was that superclass can be thought of as synonymous with ancestor. Pardon ??? I repeat: if class X is in the MRO of class Y, then X is a superclass of class Y. Which indeed makes X an ancestor of Y. I agree that the documentation for super is somewhat misleading (and obviously wrong), Well, that's the first time someone has acknowledged that in this thread, so I guess this is something. OTHO, I don't think anyone here stated that the doc was right !-) but it still *give access to* (at least one of) the superclass(es). Only if you allow some class somewhere in the inheritance tree, even one this class never inherited from directly or indirectly to be in the definition of superclass. By definition, if the class is in the inheritence tree, then this class is inherited from directly or indirectly. FWIW, I've never caught super() calling a class that was not in the inheritence tree of the instance passed to it... If you noticed such a thing, then by all mean fill a bug report. I'm arguing that what people mean by superclass is a direct or indirect ancestor class, and it's highly misleading to imply that by the function name what that's not what the function does. Please remember that super() is usually called with *2* arguments : the class in which the method is defined (let's call this class C), *and* an instance. This instance may be an instance of a *subclass* of C. So the MRO to consider is the MRO *of the instance*. Else, super would be totally useless. After reading the rest of the article, I'm amazed that 'super' as currently implemented is in Python at all. If you have a better solution for handling multiple inheritence, please share with us. My concern is to at least not *directly mislead* the programmer through a badly-named Or badly documented function class. super is not a function, it's a class. If 'super' can invoke a non-superclass super won't never invoke anything that's not in the MRO of the *instance* passed to it. — if instead it gets the next class in the MRO — then this is at the least badly-named. Possibly, but this is another point. FWIW, after all the articles I've read explaining why Python is badly designed, badly implemented, and totally flawed, I do wonder why this language exists at all !-) In most of those arguments I'm firmly on the side of the Python designers. Not on this one. Well, I understand that you disagree with both the documention and the name of super. As far as I'm concerned, the mere fact that this discussion happens is probably a sign that there's something to be fixed here - at least wrt documentation, possibly wrt/ naming. But the *feature* by itself is certainly something we do want to keep, whatever some may argue. I don't want to break the inheritance chain. I want the superclass, A soon as you have either multiple inheritence and/or an inheritence tree with depth 1, there's no such thing as the superclass. wrt/ your exemple, object, A, B, C and D are *all* superclasses of E. Yes, they are. But my example was not get the superclass of E, but get the superclass of A. You wrote: If I define a class hierarchy as follows:: class A(object): pass class B(object): pass class C(A): pass class D(B): pass is it true to say that D is a superclass of A? No, because they're entirely unrelated except that they inherit from 'object'. The superclass of 'A' is 'object'. How about this:
Re: super() doesn't get superclass
On Sep 19, 12:36 pm, Bruno Desthuilliers bruno. [EMAIL PROTECTED] wrote: The next class in the MRO *is* a superclass of the *instance*. Else it wouldn't be in the MRO !-) Bruno, there is no such a thing as a superclass in a multiple inheritance world, and it is a very bad idea to continue to use that terminology. I was convinced of that by Bjorn Pettersen in a thread on comp.lang.python in May 2003 and you may Google for it. You may find there convincing arguments against the superclass concept, some of which I report in http://www.phyast.pitt.edu/~micheles/python/super.html Well, I understand that you disagree with both the documention and the name of super. As far as I'm concerned, the mere fact that this discussion happens is probably a sign that there's something to be fixed here - at least wrt documentation, possibly wrt/ naming. But the *feature* by itself is certainly something we do want to keep, whatever some may argue. Well, I am personally *against* multiple inheritance (i.e. IMO it gives more troubles than advantages) The goal is to call the correct next method according to MRO. Indeed, it could have been name call_next_method. Right. Michele Simionato -- http://mail.python.org/mailman/listinfo/python-list
Help for Otsu implementation from C
Can somone look at this def otsu(hi): fmax=-1.0 border=len(hi) for i in range(border): if hi[i]!=0:break for j in range(border-1,0-1,-1): if hi[j] != 0:break s = sum([k*hi[k] for k in range(border)]) n = sum(hi) # product(im.size) n1=n2=csum=0.0 for k in range(i,j): n1 += hi[k] n2 = n - n1 csum+= k * hi[k] m1 = csum/ n1 m2 = (s - csum)/n2 sb = n1 * n2 * (m2 - m1) if sb fmax: fmax = sb V=k+1 print V I try to implement it from C from this location. http://www.google.com/codesearch?hl=deq=+otsu+threshold+show:3rXPo8eEzw0:z-1MzowD-bQ:cDGSVzqKA7Msa=Ncd=1ct=rccs_p=http://www.studio-to-go.co.uk/source-packages/2.x/gocr-0.41.tar.bz2cs_f=gocr-0.41/src/otsu.c#a0 It gives me till now the closest threshold value but still not the exact Testing Histogram given to the function as an atribute is: hi = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 2, 0, 0, 2, 1, 2, 0, 1, 3, 3, 3, 3, 1, 3, 1, 3, 5, 2, 3, 3, 3, 6, 3, 4, 5, 4, 9, 6, 11, 6, 10, 3, 11, 9, 9, 12, 22, 18, 34, 22, 28, 32, 25, 34, 38, 34, 54, 65, 106, 160, 167, 203, 282, 364, 446, 637, 816, 1022, 1264, 1456, 1646, 1753, 1845, 1922, 2203, 2231, 1973, 2245, 2369, 2349, 2258, 2130, 2066, 1835, 1640, 1554, 1414, 1179, 1024, 974, 938, 838, 785, 756, 803, 921, 952, 865, 722, 625, 608, 547, 498, 412, 438, 408, 413, 415, 339, 366, 330, 320, 293, 315, 368, 411, 434, 500, 531, 538, 552, 665, 811, 869, 998, 1021, 1075, 1080, 1030, 934, 926, 1074, 942, 941, 1014, 1440, 2966, 5301, 2729, 3400, 5563, 13096, 9068, 6045, 2813, 686, 180] it gives me 221 value but it should give me 218 Thanks in advance -- http://mail.python.org/mailman/listinfo/python-list
Re: super() doesn't get superclass
Michele Simionato [EMAIL PROTECTED] writes: On Sep 19, 12:36 pm, Bruno Desthuilliers bruno. [EMAIL PROTECTED] wrote: The next class in the MRO *is* a superclass of the *instance*. Else it wouldn't be in the MRO !-) Bruno, there is no such a thing as a superclass in a multiple inheritance world, and it is a very bad idea to continue to use that terminology. Your arguments against the superclass term seem to assume that there is only a single superclass to a particular class. In the example you give in your essay, I would say that all of A, B, and T are superclasses of C, and Python's super correctly iterates over all of them. Wikipedia defines superclass as a class from which other classes are derived, which seems perfectly valid for MI. -- http://mail.python.org/mailman/listinfo/python-list
Re: uninstall python2.5 on debian
In message [EMAIL PROTECTED], dimitri pater wrote: I would like to uninstall Python2.5 which was installed from source (make install) and keep 2.3. How about doing the make install again, and making a note of which files were installed, and removing those? -- http://mail.python.org/mailman/listinfo/python-list
Re: super() doesn't get superclass
On Sep 19, 1:16 pm, Hrvoje Niksic [EMAIL PROTECTED] wrote: Your arguments against the superclass term seem to assume that there is only a single superclass to a particular class. If you say the superclass, then you also assume it is unique. But the big issue is that the order of the methods depends on the second argument to super, the instance, so there is no useful concept of the superclass of the first argument of super. I rest my case. Michele Simionato -- http://mail.python.org/mailman/listinfo/python-list
lambda-funcs problem
hi all, I need to create a Python list of lambda-funcs that are dependent on the number of the ones, for example F = [] for i in xrange(N): F.append(lambda x: x + i) however, the example don't work - since i in end is N-1 it yields x+ (N-1) for any func. So what's the best way to make it valid? Evaluation speed is also very important to me. Thank you in advance, D. -- http://mail.python.org/mailman/listinfo/python-list
UTF-8 characters in doctest
Hello, I have problems with running doctests if I use czech national characters in UTF-8 encoding. I have Python script, which begin with encoding definition: # -*- coding: utf-8 -*- I have this function with doctest: def get_inventary_number(block): t = u'''28. České královské insignie ... mědirytina, grafika je zcela vyřezána z papíru - max. rozměr ... 420×582 neznačeno ... text: opis v levém medailonu: CAROL VI IMP.ELIS.CHR. AVG. P.P.''' get_inventary_number(t) (u'nezna\xc4\x8deno', u'28. \xc4\x8cesk\xc3\xa9 kr\xc3\xa1lovsk \xc3\xa9 insignie\nm\xc4\x9bdirytina, grafika je zcela vy\xc5\x99ez \xc3\xa1na z pap\xc3\xadru \xe2\x80\x93 max. rozm\xc4\x9br \n420\xc3\x97582 \ntext: opis v lev\xc3\xa9m medailonu: CAROL VI IMP.ELIS.CHR. AVG. P.P.') m = RE_INVENTARNI_CISLO.search(block) if m: return m.group(1), block.replace(m.group(0), '') else: return None, block After running doctest.testmod() I get this error message: File vizovice_03.py, line 417, in ? doctest.testmod() File /usr/local/lib/python2.4/doctest.py, line 1841, in testmod for test in finder.find(m, name, globs=globs, extraglobs=extraglobs): File /usr/local/lib/python2.4/doctest.py, line 851, in find self._find(tests, obj, name, module, source_lines, globs, {}) File /usr/local/lib/python2.4/doctest.py, line 910, in _find globs, seen) File /usr/local/lib/python2.4/doctest.py, line 895, in _find test = self._get_test(obj, name, module, globs, source_lines) File /usr/local/lib/python2.4/doctest.py, line 985, in _get_test filename, lineno) File /usr/local/lib/python2.4/doctest.py, line 602, in get_doctest return DocTest(self.get_examples(string, name), globs, File /usr/local/lib/python2.4/doctest.py, line 616, in get_examples return [x for x in self.parse(string, name) File /usr/local/lib/python2.4/doctest.py, line 577, in parse (source, options, want, exc_msg) = \ File /usr/local/lib/python2.4/doctest.py, line 648, in _parse_example lineno + len(source_lines)) File /usr/local/lib/python2.4/doctest.py, line 732, in _check_prefix raise ValueError('line %r of the docstring for %s has ' ValueError: line 17 of the docstring for __main__.get_inventary_number has inconsistent leading whitespace: 'm\xc4\x9bdirytina, grafika je zcela vy\xc5\x99ez\xc3\xa1na z pap\xc3\xadru \xe2\x80\x93 max. rozm \xc4\x9br' I try to fill expected output in docstring according to output from Python shell, from doctest (if I bypass it in docstring, doctest says me what he expect and what it get), I try to set variable t as t='some text' together t=u'some unicode text'. But everything fails. So my question is: Is it possible to run doctests with UTF-8 characters? And if your answer will be YES, tell me please how... Thank you for any advice. Regards Michal -- http://mail.python.org/mailman/listinfo/python-list
Re: super() doesn't get superclass
Michele Simionato a écrit : On Sep 19, 12:36 pm, Bruno Desthuilliers bruno. [EMAIL PROTECTED] wrote: The next class in the MRO *is* a superclass of the *instance*. Else it wouldn't be in the MRO !-) Bruno, there is no such a thing as a superclass in a multiple inheritance May I disagree ? Of course, with MI, there's no such thing as the superclass, but there are still superclasses - the classes listed in the MRO. At least according to a commonly agreed definition of superclass... (snip) Well, I understand that you disagree with both the documention and the name of super. As far as I'm concerned, the mere fact that this discussion happens is probably a sign that there's something to be fixed here - at least wrt documentation, possibly wrt/ naming. But the *feature* by itself is certainly something we do want to keep, whatever some may argue. Well, I am personally *against* multiple inheritance (i.e. IMO it gives more troubles than advantages) Given Python's type system and support for delegation, it's a fact that MI is not that necessary - FWIW, I don't remember having ever used it except in Zope2 (where it's commonly a PITA). Now I don't think there's any reason to remove from MI, since it's already there, and about as usable as it can be. -- http://mail.python.org/mailman/listinfo/python-list
Re: lambda-funcs problem
On Wed, 19 Sep 2007 04:39:44 -0700, dmitrey.kroshko wrote: I need to create a Python list of lambda-funcs that are dependent on the number of the ones, for example F = [] for i in xrange(N): F.append(lambda x: x + i) however, the example don't work - since i in end is N-1 it yields x+ (N-1) for any func. So what's the best way to make it valid? The variable is bound to the name `i` when the lambda function is created not to the value that `i` had at that time. The idiomatic way is to use a default value for an argument because those are evaluated at definition time of functions:: F.append(lambda x, i=i: x + i) Ciao, Marc 'BlackJack' Rintsch -- http://mail.python.org/mailman/listinfo/python-list
Re: Help for Otsu implementation from C
azrael wrote: Can somone look at this def otsu(hi): fmax=-1.0 border=len(hi) for i in range(border): if hi[i]!=0:break for j in range(border-1,0-1,-1): if hi[j] != 0:break s = sum([k*hi[k] for k in range(border)]) n = sum(hi) # product(im.size) n1=n2=csum=0.0 for k in range(i,j): n1 += hi[k] n2 = n - n1 csum+= k * hi[k] m1 = csum/ n1 m2 = (s - csum)/n2 As I said in my previous post, try replacing this line sb = n1 * n2 * (m2 - m1) with the original sb = n1 * n2 * (m1 - m2) * (m1 - m2) that has been commented out. if sb fmax: fmax = sb V=k+1 print V I try to implement it from C from this location. Personally, I would start with a literal translation and not try to improve it until it works. Peter -- http://mail.python.org/mailman/listinfo/python-list
RE: lambda-funcs problem
On Behalf Of [EMAIL PROTECTED] F = [] for i in xrange(N): F.append(lambda x: x + i) however, the example don't work - since i in end is N-1 it yields x+ (N-1) for any func. How about: def make_adder(i): def adder(x): return x+i return adder funcs = [make_adder(i) for i in xrange(10)] print [func(10) for func in funcs] [10, 11, 12, 13, 14, 15, 16, 17, 18, 19] Regards, Ryan Ginstrom -- http://mail.python.org/mailman/listinfo/python-list
Re: super() doesn't get superclass
Michele Simionato [EMAIL PROTECTED] writes: On Sep 19, 1:16 pm, Hrvoje Niksic [EMAIL PROTECTED] wrote: Your arguments against the superclass term seem to assume that there is only a single superclass to a particular class. If you say the superclass, then you also assume it is unique. FWIW, Bruno said a, at least in the section you quoted. But the big issue is that the order of the methods depends on the second argument to super, the instance, so there is no useful concept of the superclass of the first argument of super. No argument here. -- http://mail.python.org/mailman/listinfo/python-list
Re: lambda-funcs problem
[EMAIL PROTECTED] a écrit : hi all, I need to create a Python list of lambda-funcs that are dependent on the number of the ones, for example F = [] for i in xrange(N): F.append(lambda x: x + i) however, the example don't work - since i in end is N-1 it yields x+ (N-1) for any func. So what's the best way to make it valid? It's a FAQ. The answer is (using list-comp instead of a for loop): funcs = [lambda x, i=i : x + i for i in xrange(n)] -- http://mail.python.org/mailman/listinfo/python-list
Re: UTF-8 characters in doctest
Bzyczek wrote: So my question is: Is it possible to run doctests with UTF-8 characters? And if your answer will be YES, tell me please how... Use raw strings in combination with explicit decoding and a little try-and-error. E. g. this little gem passes ;) # -*- coding: utf8 -*- r f(äöü.decode(utf8)) (u'\xe4\xf6\xfc',) def f(s): return (s,) if __name__ == __main__: import doctest doctest.testmod() Peter -- http://mail.python.org/mailman/listinfo/python-list
stdout and embedding into Windows apps
Hi, I'm extending a windows application (C++) by embedding Python calls. It seems to be a known problem that windows applications detach immediately from the calling console, so that all output to stdout (from both C++ and Python) doesn't get shown anywhere. A workaround seems to be the allocation of a windows console and redirecting stdout to it: AllocConsole(); freopen(conin$, r, stdin); freopen(conout$, w, stdout); freopen(conout$, w, stderr); Still, this console only shows the output of my C++ application, not the output of the embedded python calls. The following code Py_Initialize(); std::cout start printing... std::endl; PyRun_SimpleString(print('PRINT')\n); std::cout done printing. std::endl; only prints start printing... done printing. Does anybody know how to fix this issue? Basically I want to get an ipython console running in the background of my Windows app, so that I can process its data. Cheers, Thomas -- http://mail.python.org/mailman/listinfo/python-list
cannot create my own dict
Hello all, This morning I tried to create my own read-only dictionary, and failed miserably. I don't understand why, can somebody enlighten me? Below is a brute-force experiment that cannot deal with x in obj, plz read the explanation below the code: class myowndict(object): def __init__(self, mydict): self.mydict = mydict # Below is produced with # print '\n'.join(['self.%s = self.mydict.%s' % (v,v) # for v in dir(dict)]) # commented-out functions done by hand # #self.__class__ = self.mydict.__class__ self.__cmp__ = self.mydict.__cmp__ self.__contains__ = self.mydict.__contains__ self.__delattr__ = self.mydict.__delattr__ self.__delitem__ = self.mydict.__delitem__ #self.__doc__ = self.mydict.__doc__ self.__eq__ = self.mydict.__eq__ self.__ge__ = self.mydict.__ge__ self.__getattribute__ = self.mydict.__getattribute__ self.__getitem__ = self.mydict.__getitem__ self.__gt__ = self.mydict.__gt__ self.__hash__ = self.mydict.__hash__ #self.__init__ = self.mydict.__init__ self.__iter__ = self.mydict.__iter__ self.__le__ = self.mydict.__le__ self.__len__ = self.mydict.__len__ self.__lt__ = self.mydict.__lt__ self.__ne__ = self.mydict.__ne__ #self.__new__ = self.mydict.__new__ self.__reduce__ = self.mydict.__reduce__ self.__reduce_ex__ = self.mydict.__reduce_ex__ self.__repr__ = self.mydict.__repr__ self.__setattr__ = self.mydict.__setattr__ self.__setitem__ = self.mydict.__setitem__ self.__str__ = self.mydict.__str__ self.clear = self.mydict.clear self.copy = self.mydict.copy self.fromkeys = self.mydict.fromkeys self.get = self.mydict.get self.has_key = self.mydict.has_key self.items = self.mydict.items self.iteritems = self.mydict.iteritems self.iterkeys = self.mydict.iterkeys self.itervalues = self.mydict.itervalues self.keys = self.mydict.keys self.pop = self.mydict.pop self.popitem = self.mydict.popitem self.setdefault = self.mydict.setdefault self.update = self.mydict.update self.values = self.mydict.values # end of __init__ if __name__ == '__main__': fd = myowndict({1:10}) print 1 in fd # FAILS! (with TypeError: iterable argument required) I wanted to make my own dictionary. However, a simple element test failed (after implementing various __*__ functions), and I cannot figure out why. The above code is a brute force attempt, where I forward all methods (except __class__, __doc__, __init__, and __new__) to my local 'mydict' object. IT STILL FAILS. So if copying all methods of a native dictionary is not enough, what should I do to make my class work as a dictionary WITHOUT deriving from dict (which will obviously work). Sincerely, Albert -- http://mail.python.org/mailman/listinfo/python-list
Re: How can I know how much to read from a subprocess
On 2007-09-18, [EMAIL PROTECTED] [EMAIL PROTECTED] wrote: On Sep 18, 1:48 pm, A.T.Hofkamp [EMAIL PROTECTED] wrote: On 2007-09-17, [EMAIL PROTECTED] [EMAIL PROTECTED] wrote: It seems that another solution is gobject.io_add_watch, but I don't see how it tells me how much I can read from the file - if I don't know that, I won't know the argument to give to the read() method in order to get all the data: http://www.pygtk.org/docs/pygobject/gobject-functions.html#function-g... Usually, gobject only tells you that data is there (that is all it knows). Therefore a read(1) should be safe. But even if it's fast enough, how do you know how many times you should call read(1)? If you do it too much, you'll be blocked until more output is available. after reading 1 byte, wait for gobject again. In other words, when gobject sends a notice, read 1 byte. When there is more, gobject will tell you (probably very often :-) ). If that is too slow, consider os.read() which reads all data available (afaik, never tried it myself). I tried it now, and it blocks just like the normal file.read(). So os.read(handle.fileno(), 100) blocks after gobject tells you there is data? That is different than I heard, but you are probably correct, I cannot easily test this. Albert -- http://mail.python.org/mailman/listinfo/python-list
re question
I'm trying to construct a regular expression to match valid IP address, without leading zeroes (i.e 1.2.3.4, 254.10.0.0, but not 324.1.1.1, nor 010.10.10.1) This is what I come up with, and it does not work. r'(^[12]?\d{0,2}\.){3,3}[12]?\d{0,2}' What am I doing wrong? Any common knowledge IP matching RE? Thanks, Dan -- http://mail.python.org/mailman/listinfo/python-list
Odd files; just left behind?
I see a folder .python-eggs in my home directory on one of our servers with various .so files ~/.python-eggs/MySQL_python-1.2.2-py2.3-freebsd-6.1-SECURITY-i386.egg-tmp/_mysql.so are these just left behind from some install process? -- Robin Becker -- http://mail.python.org/mailman/listinfo/python-list
Re: How to know the starting point
Raj kumar wrote: Hi, I need help regarding the starting point in python project, As we can find main() function in java class to know the starting class in java, what is the starting point in python project? How to find the starting point. Thank you The starting point is the top of the file. Class and def statements are executable, and bind their names to the definitions. The bodies are this compiled, but the compiled code is only executed when a call is made (which avoids forward referencing problems, by and large: names are late-bound). So the interpreter just starts at the top and runs through the code in sequence. regards Steve -- Steve Holden+1 571 484 6266 +1 800 494 3119 Holden Web LLC/Ltd http://www.holdenweb.com Skype: holdenweb http://del.icio.us/steve.holden Sorry, the dog ate my .sigline -- http://mail.python.org/mailman/listinfo/python-list
Re: super() doesn't get superclass
On 2007-09-19, Hrvoje Niksic [EMAIL PROTECTED] wrote: Ben Finney [EMAIL PROTECTED] writes: Hrvoje Niksic [EMAIL PROTECTED] writes: class X(Y): def foo(self): super(X, self).foo() ...there is in fact no guarantee that super() calls a superclass of X. However, it is certainly guaranteed that it will call a superclass of type(self). Not even that. It could call *any class in the inheritance hierarchy*, The inheritance hierarchiy is populated by the various (direct and indirect) superclasses of type(self). depending on how the MRO has resolved next class. Even one that is neither an ancestor nor a descendant of X. My point exactly. superclass of X is not the same as superclass of type(self). Super iterates over the latter, where you expect the former. I can't blame a person for thinking that the call super(A, self) is taking the superclass of A. A is perhaps too prominently placed. -- Neil Cerutti -- http://mail.python.org/mailman/listinfo/python-list
Re: HTTP Protocol Client
[EMAIL PROTECTED] wrote: Hi, I am writing http protocol to get some data from servers. If i was using my localhost, getting replay from local and if want access other remote sites, i am getting error. Please reply it My localhost client script::: Code: ( python ) import httplib h = httplib.HTTP('localhost',80) h.putrequest('GET','') h.putheader('User-Agent','Lame Tutorial Code') h.putheader('Accept','text/html') h.endheaders() errcode,errmsg, headers = h.getreply() print errcode,errmsg, headers f = h.getfile() # Get file object for reading data data = f.read() print data f.close() the Reply getting from this 403 Forbidden Date: Tue, 18 Sep 2007 05:20:36 GMT Server: Apache/2.0.52 (Red Hat) Accept-Ranges: bytes Content-Length: 3985 Connection: close Content-Type: text/html; charset=UTF-8 And some Html script If I want to access other sites::: import httplib h = httplib.HTTP('http://Google.com',80) h.putrequest('GET','') h.putheader('User-Agent','Lame Tutorial Code') h.putheader('Accept','text/html') h.endheaders() errcode,errmsg, headers = h.getreply() print errcode,errmsg, headers f = h.getfile() # Get file object for reading data data = f.read() print data f.close() I got the error like::: Traceback (most recent call last): File c.py, line 6, in ? h.endheaders() File /usr/lib/python2.3/httplib.py, line 712, in endheaders self._send_output() File /usr/lib/python2.3/httplib.py, line 597, in _send_output self.send(msg) File /usr/lib/python2.3/httplib.py, line 564, in send self.connect() File /usr/lib/python2.3/httplib.py, line 532, in connect socket.SOCK_STREAM): socket.gaierror: (-2, 'Name or service not known') How can I access Remote sites using http protocol . I did'nt write server script. I would recommend taking a look at urllib or urllib2 if you just want to write an HTTP client that accesses the server output, there is no need to re-implement low-level HTTP calls. regards Steve -- Steve Holden+1 571 484 6266 +1 800 494 3119 Holden Web LLC/Ltd http://www.holdenweb.com Skype: holdenweb http://del.icio.us/steve.holden Sorry, the dog ate my .sigline -- http://mail.python.org/mailman/listinfo/python-list
Re: HTTP Protocol Client
On Sep 19, 6:10 am, [EMAIL PROTECTED] wrote: Hi, I am writing http protocol to get some data from servers. If i was using my localhost, getting replay from local and if want access other remote sites, i am getting error. Please reply it My localhost client script::: Code: ( python ) import httplib h = httplib.HTTP('localhost',80) h.putrequest('GET','') h.putheader('User-Agent','Lame Tutorial Code') h.putheader('Accept','text/html') h.endheaders() errcode,errmsg, headers = h.getreply() print errcode,errmsg, headers f = h.getfile() # Get file object for reading data data = f.read() print data f.close() the Reply getting from this 403 Forbidden Date: Tue, 18 Sep 2007 05:20:36 GMT Server: Apache/2.0.52 (Red Hat) Accept-Ranges: bytes Content-Length: 3985 Connection: close Content-Type: text/html; charset=UTF-8 And some Html script If I want to access other sites::: import httplib h = httplib.HTTP('http://Google.com',80) h.putrequest('GET','') h.putheader('User-Agent','Lame Tutorial Code') h.putheader('Accept','text/html') h.endheaders() errcode,errmsg, headers = h.getreply() print errcode,errmsg, headers f = h.getfile() # Get file object for reading data data = f.read() print data f.close() I got the error like::: Traceback (most recent call last): File c.py, line 6, in ? h.endheaders() File /usr/lib/python2.3/httplib.py, line 712, in endheaders self._send_output() File /usr/lib/python2.3/httplib.py, line 597, in _send_output self.send(msg) File /usr/lib/python2.3/httplib.py, line 564, in send self.connect() File /usr/lib/python2.3/httplib.py, line 532, in connect socket.SOCK_STREAM): socket.gaierror: (-2, 'Name or service not known') How can I access Remote sites using http protocol . I did'nt write server script. Thanks And Regards Allavarapu 1. First try setting the debug level with h.set_debuglevel(9) 2. nslookup or dig google.com 3. are you behind a firewall ? 4. why not just use urllib.urlopen ? Its a lot easier and sets up all the headers, and yes it can do POSTs. -- http://mail.python.org/mailman/listinfo/python-list
Re: cannot create my own dict
A.T.Hofkamp wrote: Hello all, This morning I tried to create my own read-only dictionary, and failed miserably. I don't understand why, can somebody enlighten me? Below is a brute-force experiment that cannot deal with x in obj, plz read the explanation below the code: class myowndict(object): def __init__(self, mydict): self.mydict = mydict # Below is produced with # print '\n'.join(['self.%s = self.mydict.%s' % (v,v) # for v in dir(dict)]) # commented-out functions done by hand # #self.__class__ = self.mydict.__class__ self.__cmp__ = self.mydict.__cmp__ self.__contains__ = self.mydict.__contains__ self.__delattr__ = self.mydict.__delattr__ self.__delitem__ = self.mydict.__delitem__ #self.__doc__ = self.mydict.__doc__ self.__eq__ = self.mydict.__eq__ self.__ge__ = self.mydict.__ge__ self.__getattribute__ = self.mydict.__getattribute__ self.__getitem__ = self.mydict.__getitem__ self.__gt__ = self.mydict.__gt__ self.__hash__ = self.mydict.__hash__ #self.__init__ = self.mydict.__init__ self.__iter__ = self.mydict.__iter__ self.__le__ = self.mydict.__le__ self.__len__ = self.mydict.__len__ self.__lt__ = self.mydict.__lt__ self.__ne__ = self.mydict.__ne__ #self.__new__ = self.mydict.__new__ self.__reduce__ = self.mydict.__reduce__ self.__reduce_ex__ = self.mydict.__reduce_ex__ self.__repr__ = self.mydict.__repr__ self.__setattr__ = self.mydict.__setattr__ self.__setitem__ = self.mydict.__setitem__ self.__str__ = self.mydict.__str__ self.clear = self.mydict.clear self.copy = self.mydict.copy self.fromkeys = self.mydict.fromkeys self.get = self.mydict.get self.has_key = self.mydict.has_key self.items = self.mydict.items self.iteritems = self.mydict.iteritems self.iterkeys = self.mydict.iterkeys self.itervalues = self.mydict.itervalues self.keys = self.mydict.keys self.pop = self.mydict.pop self.popitem = self.mydict.popitem self.setdefault = self.mydict.setdefault self.update = self.mydict.update self.values = self.mydict.values # end of __init__ if __name__ == '__main__': fd = myowndict({1:10}) print 1 in fd # FAILS! (with TypeError: iterable argument required) I wanted to make my own dictionary. However, a simple element test failed (after implementing various __*__ functions), and I cannot figure out why. The above code is a brute force attempt, where I forward all methods (except __class__, __doc__, __init__, and __new__) to my local 'mydict' object. IT STILL FAILS. So if copying all methods of a native dictionary is not enough, what should I do to make my class work as a dictionary WITHOUT deriving from dict (which will obviously work). You have to overwrite the __new__ method to return an object of your new type. regards Steve -- Steve Holden+1 571 484 6266 +1 800 494 3119 Holden Web LLC/Ltd http://www.holdenweb.com Skype: holdenweb http://del.icio.us/steve.holden Sorry, the dog ate my .sigline -- http://mail.python.org/mailman/listinfo/python-list
Re: cannot create my own dict
A.T.Hofkamp wrote: This morning I tried to create my own read-only dictionary, and failed miserably. I don't understand why, can somebody enlighten me? Below is a brute-force experiment that cannot deal with x in obj, plz read the explanation below the code: class myowndict(object): def __init__(self, mydict): self.mydict = mydict # Below is produced with # print '\n'.join(['self.%s = self.mydict.%s' % (v,v) # for v in dir(dict)]) # commented-out functions done by hand # #self.__class__ = self.mydict.__class__ self.__cmp__ = self.mydict.__cmp__ self.__contains__ = self.mydict.__contains__ self.__delattr__ = self.mydict.__delattr__ self.__delitem__ = self.mydict.__delitem__ #self.__doc__ = self.mydict.__doc__ self.__eq__ = self.mydict.__eq__ self.__ge__ = self.mydict.__ge__ self.__getattribute__ = self.mydict.__getattribute__ self.__getitem__ = self.mydict.__getitem__ self.__gt__ = self.mydict.__gt__ self.__hash__ = self.mydict.__hash__ #self.__init__ = self.mydict.__init__ self.__iter__ = self.mydict.__iter__ self.__le__ = self.mydict.__le__ self.__len__ = self.mydict.__len__ self.__lt__ = self.mydict.__lt__ self.__ne__ = self.mydict.__ne__ #self.__new__ = self.mydict.__new__ self.__reduce__ = self.mydict.__reduce__ self.__reduce_ex__ = self.mydict.__reduce_ex__ self.__repr__ = self.mydict.__repr__ self.__setattr__ = self.mydict.__setattr__ self.__setitem__ = self.mydict.__setitem__ self.__str__ = self.mydict.__str__ self.clear = self.mydict.clear self.copy = self.mydict.copy self.fromkeys = self.mydict.fromkeys self.get = self.mydict.get self.has_key = self.mydict.has_key self.items = self.mydict.items self.iteritems = self.mydict.iteritems self.iterkeys = self.mydict.iterkeys self.itervalues = self.mydict.itervalues self.keys = self.mydict.keys self.pop = self.mydict.pop self.popitem = self.mydict.popitem self.setdefault = self.mydict.setdefault self.update = self.mydict.update self.values = self.mydict.values # end of __init__ if __name__ == '__main__': fd = myowndict({1:10}) print 1 in fd # FAILS! (with TypeError: iterable argument required) I wanted to make my own dictionary. However, a simple element test failed (after implementing various __*__ functions), and I cannot figure out why. The above code is a brute force attempt, where I forward all methods (except __class__, __doc__, __init__, and __new__) to my local 'mydict' object. IT STILL FAILS. __special__ methods are looked up in the class, never in the instance for newstyle classes: def class_method(self, *v): print class ... def inst_method(*v): print instance ... class B(object): ... __contains__ = class_method ... copy = class_method ... def __init__(self): ... self.__contains__ = inst_method ... self.copy = inst_method ... 42 in B() class False B().copy() instance So if copying all methods of a native dictionary is not enough, what should I do to make my class work as a dictionary WITHOUT deriving from dict (which will obviously work). Write wrappers like def __contains__(self, value): return value in self.mydict Peter -- http://mail.python.org/mailman/listinfo/python-list
Re: super() doesn't get superclass
Michele Simionato wrote: ... interesting stuff ommitted super seems to return an object of type super, but I cannot seem to find any documention on this type except for 3.4.2.3 Super Binding If a is an instance of super, then the binding super(B, obj).m() searches obj.__class__.__mro__ for the base class A immediately preceding B and then invokes the descriptor with the call: A.__dict__['m'].__get__(obj, A). -- Robin Becker -- http://mail.python.org/mailman/listinfo/python-list
Re: Tutorial or Example (or Tutorial) of Using Canvas to Produce a Plot
I'm just trying to get some feel for how canvas works. I'm about to modify a program I use for meteor work. It uses canvas to display images, and I plan to draw on the image. For example, I plan to draw compass headings on a circle every 30 degrees. Just warming up to the task. exhuma.twn wrote: On Sep 18, 11:58 pm, Richard Townsend [EMAIL PROTECTED] wrote: On Tue, 18 Sep 2007 13:18:36 -0700, W. Watson [EMAIL PROTECTED] wrote: Tk is it. I'm really not interested in the others at this point. John Grayson's book 'Python and Tkinter Programming' has a chapter on plotting Graphs and Charts. You can even download that chapter as a PDF file: http://www.manning-source.com/books/grayson/grayson_ch11.pdf Seehttp://www.manning.com/grayson/for more info about the book. Also, if the graph is really all you need, matplotlib might be a very interesting choice: http://matplotlib.sourceforge.net/ It's got some user-interface facilities as well. But I never used those so far. -- Wayne Watson (Nevada City, CA) Web Page: speckledwithStars.net -- http://mail.python.org/mailman/listinfo/python-list
Re: Tutorial or Example (or Tutorial) of Using Canvas to Produce a Plot
Here seems to be another good source. http://effbot.org/tkinterbook/canvas.htm W. Watson wrote: Ah, I missed your link to Chap 11. That looks very helpful. W. Watson wrote: Thanks. I've arranged for an inter-library loan(ILL), and probably will not get his book for several days yet. I've had the book before, but was really unable to get the time to pursue it (the ILL). I have his web site bookmarked. I do not yet plan to buy his book, web or hardbound yet. Maybe I can re-examine his site for examples, and find one that is appropriate. Richard Townsend wrote: On Tue, 18 Sep 2007 13:18:36 -0700, W. Watson [EMAIL PROTECTED] wrote: Tk is it. I'm really not interested in the others at this point. John Grayson's book 'Python and Tkinter Programming' has a chapter on plotting Graphs and Charts. You can even download that chapter as a PDF file: http://www.manning-source.com/books/grayson/grayson_ch11.pdf See http://www.manning.com/grayson/ for more info about the book. -- Wayne Watson (Nevada City, CA) Web Page: speckledwithStars.net -- http://mail.python.org/mailman/listinfo/python-list
Re: Sets in Python
sapsi [EMAIL PROTECTED] wrote: Why can't lists be hashed? Several people have answered because they're mutable without explaining why mutability precludes hashing. So: Consider a dict (dicts have been in Python a *lot* longer than sets, and have the same restriction) which allowed lists as keys: d = {} k = [1, 2] d[k] = None Now, if I were to do: k.append(3) what would you expect: d.keys() to return? Did d magically rehash k when it was modified? Did d[k] take a copy of k, and if so, how deep was the copy (consider d[[1, k]] = None followed by a modification to k)? Leaving the hash unchanged and relying on collision detection to resolve won't work, since you may go directly for d[[1, 2, 3]] and not spot that there's already an entry for it since it's been hashed under [1, 2]. Practicality beats purity and the design decision was to simply sidestep these issues by disallowing mutable dict keys. And as the set implementation is based on the dict implementation, it applies to sets to. -- \S -- [EMAIL PROTECTED] -- http://www.chaos.org.uk/~sion/ Frankly I have no feelings towards penguins one way or the other -- Arthur C. Clarke her nu becomeþ se bera eadward ofdun hlæddre heafdes bæce bump bump bump -- http://mail.python.org/mailman/listinfo/python-list
Re: super() doesn't get superclass
Ben Finney [EMAIL PROTECTED] wrote: If a function is named 'super' and operates on classes, it's a pretty strong implication that it's about superclasses. But it doesn't (under normal circumstances) operate on classes. It operates on an *instance*. And what you get back is a (proxy to) a superclass/ancestor of the *instance*. (And in the super(A, B) case, you get a superclass/ancestor of *B*. As has just been said somewhere very near here, what is misleading is the prominence of A, which isn't really the most important class involved.) -- \S -- [EMAIL PROTECTED] -- http://www.chaos.org.uk/~sion/ Frankly I have no feelings towards penguins one way or the other -- Arthur C. Clarke her nu becomeþ se bera eadward ofdun hlæddre heafdes bæce bump bump bump -- http://mail.python.org/mailman/listinfo/python-list
Re: Puzzled in the coding of Chinese
On Wed, 2007-09-19 at 13:57 +0800, Xing wrote: Dear list members, I am a newcomer in the world of Python. But I am attracted by Python's power in handling text! Now I apply it to handle Chinese but the Chinese character cann't be displayed on the screen. What displayed on the screen is the 16bits codes. I am so puzzled! I believe this is an easy question to most of python users and an important question to me. Thanks a lot to your help! You are not giving us any background information for troubleshooting this. Your problem could be caused by a million different things, and there is not point in us guessing. Please start by answering the following questions: 1) What operating system are you using? 2) Can any programs on your computer display Chinese characters? 3) Where are you trying to display Chinese characters? Python command line, in IDLE, in some GUI window? 4) Where are the Chinese characters you're trying to display coming from? Are they hard-coded in your script, are they read from the keyboard, from a file, from a database, from a web page? -- Carsten Haese http://informixdb.sourceforge.net -- http://mail.python.org/mailman/listinfo/python-list
Keeping a database connection with a Singleton?
I remember reading about the Singleton pattern in python and how it's an unpythonic pattern and all. At the time I did not need the Singleton anyways, so I just glanced over the document. But, setting this aside: I have an application where I have a connection to a database. At some point in the application I open up a new window. The new windows resides in a different module. So I have a directory structure like this: - mainapp.py - newwindow.py So I import newwindow in mainapp so I can instantiate and display it. Meanwhile, the main-app has an open connection to the database. What's the cleanest way to hand this connection to the new window? I can see several possibilities: 1) Simply pass the connection as paramtere to the constructor of new- window. 2) Use the Singleton deisign pattern to keep a reference to the connection 3) Open up a completely new connection to the database in the new window. Now, option 1) is clearly the easiest to implement, however, I somehow tend to use option 2 (the singleton) as it's more flexible. Option 3 looks ugly to me. This is a stuation I run into many times. And I am always faced with the same choice. And I never know which one to chose. And now that I am getting more and more comfortable with the basics of python, I would like to know if I am missing something more pythonic. So, what would you recommend? -- http://mail.python.org/mailman/listinfo/python-list
Re: lambda-funcs problem
Ryan Ginstrom software at ginstrom.com writes: How about: def make_adder(i): def adder(x): return x+i return adder funcs = [make_adder(i) for i in xrange(10)] print [func(10) for func in funcs] [10, 11, 12, 13, 14, 15, 16, 17, 18, 19] Or if you want a one liner: funcs = [(lambda i: lambda x: x+i)(i) for i in xrange(10)] Stéphane -- http://mail.python.org/mailman/listinfo/python-list
Re: Keeping a database connection with a Singleton?
On Sep 19, 7:26 am, exhuma.twn [EMAIL PROTECTED] wrote: I remember reading about the Singleton pattern in python and how it's an unpythonic pattern and all. At the time I did not need the Singleton anyways, so I just glanced over the document. But, setting this aside: I have an application where I have a connection to a database. At some point in the application I open up a new window. The new windows resides in a different module. So I have a directory structure like this: - mainapp.py - newwindow.py So I import newwindow in mainapp so I can instantiate and display it. Meanwhile, the main-app has an open connection to the database. What's the cleanest way to hand this connection to the new window? I can see several possibilities: 1) Simply pass the connection as paramtere to the constructor of new- window. 2) Use the Singleton deisign pattern to keep a reference to the connection 3) Open up a completely new connection to the database in the new window. Now, option 1) is clearly the easiest to implement, however, I somehow tend to use option 2 (the singleton) as it's more flexible. Option 3 looks ugly to me. This is a stuation I run into many times. And I am always faced with the same choice. And I never know which one to chose. And now that I am getting more and more comfortable with the basics of python, I would like to know if I am missing something more pythonic. So, what would you recommend? You don't need a way to make every instance the same. You need a way where every instance shares the same state. Aka, the Borg pattern, courtesy of Alex Martelli. It's in the Python Cookbook at http:// aspn.activestate.com/ASPN/Cookbook/Python/Recipe/66531. Good luck! --Jason -- http://mail.python.org/mailman/listinfo/python-list
Find the ID, but how to select/copy the whole string by ID?
Hi everybody, I am a beginer for Python, hope can get help from you guys. What I want to do is : Input an ID - find the ID in the file - copy the whole string str id='xxx'y/str stringID = str(raw_input('Enter the string ID : ')) file = open('strings.txt') sourcefile = file.read() file.close() sourcefile.find (stringID) but how can I select and copy the specific string from str to /str with id I input? Thanks!!! -- http://mail.python.org/mailman/listinfo/python-list
Re: super() doesn't get superclass
On Sep 19, 3:22 pm, Sion Arrowsmith [EMAIL PROTECTED] wrote: Ben Finney [EMAIL PROTECTED] wrote: If a function is named 'super' and operates on classes, it's a pretty strong implication that it's about superclasses. But it doesn't (under normal circumstances) operate on classes. It operates on an *instance*. And what you get back is a (proxy to) a superclass/ancestor of the *instance*. (And in the super(A, B) case, you get a superclass/ancestor of *B*. As has just been said somewhere very near here, what is misleading is the prominence of A, which isn't really the most important class involved.) Happily A (and B too) will become invisible in Python 3000. Michele Simionato -- http://mail.python.org/mailman/listinfo/python-list
Re: Keeping a database connection with a Singleton?
exhuma.twn wrote: I remember reading about the Singleton pattern in python and how it's an unpythonic pattern and all. At the time I did not need the Singleton anyways, so I just glanced over the document. But, setting this aside: I have an application where I have a connection to a database. At some point in the application I open up a new window. The new windows resides in a different module. So I have a directory structure like this: - mainapp.py - newwindow.py So I import newwindow in mainapp so I can instantiate and display it. Meanwhile, the main-app has an open connection to the database. What's the cleanest way to hand this connection to the new window? I can see several possibilities: 1) Simply pass the connection as paramtere to the constructor of new- window. 2) Use the Singleton deisign pattern to keep a reference to the connection 3) Open up a completely new connection to the database in the new window. Now, option 1) is clearly the easiest to implement, however, I somehow tend to use option 2 (the singleton) as it's more flexible. Option 3 looks ugly to me. This is a stuation I run into many times. And I am always faced with the same choice. And I never know which one to chose. And now that I am getting more and more comfortable with the basics of python, I would like to know if I am missing something more pythonic. So, what would you recommend? Passing the connection as a parameter is the best approach because it keeps the dependencies explicit. Also, it allows you to switch between singleton and one connection per window without ever touching the newwindow module. By the way, there is a pythonic (near) singleton: the module. So if you go with option 2, just move the connection setup into a separate module that you can import into client code. Peter -- http://mail.python.org/mailman/listinfo/python-list
Re: Keeping a database connection with a Singleton?
On Sep 19, 3:45 pm, Peter Otten [EMAIL PROTECTED] wrote: exhuma.twn wrote: [...] By the way, there is a pythonic (near) singleton: the module. So if you go with option 2, just move the connection setup into a separate module that you can import into client code. Peter You say (near) singleton. What's the difference then? -- http://mail.python.org/mailman/listinfo/python-list
Re: Keeping a database connection with a Singleton?
exhuma.twn wrote: On Sep 19, 3:45 pm, Peter Otten [EMAIL PROTECTED] wrote: exhuma.twn wrote: [...] By the way, there is a pythonic (near) singleton: the module. So if you go with option 2, just move the connection setup into a separate module that you can import into client code. Peter You say (near) singleton. What's the difference then? I was thinking of the main script of an application. If you import that by its name import main # assuming the file is main.py you end up with two instances sys.modules[main] and sys.modules[__main__]. Peter -- http://mail.python.org/mailman/listinfo/python-list
Re: Extracting xml from html
On Sep 19, 3:13 am, Stefan Behnel [EMAIL PROTECTED] wrote: [EMAIL PROTECTED] wrote: Does this make sense? It works pretty well, but I don't really understand everything that I'm doing. def Parser(filename): It's uncommon to give a function a capitalised name, unless it's a factory function (which this isn't). Yeah. I was going to use a class (and I still might), so that's how it got capitalized. events = (recordnum, primaryowner, customeraddress) You're not using this anywhere below, so I assume this is left-over code. I realized I didn't need that line soon after I posted. Sorry about that! You could do this more easily in a couple of ways. One is to use XPath: print [el.text for el in tree.xpath(//primaryowner|//customeraddress)] This works quite well. Wish I'd thought of it. Note that this works directly on the tree that you retrieved right in the third line of your code. Another (and likely simpler) solution is to first find the Row element and then start from that: row = tree.find(//Row) print row.findtext(primaryowner) print row.findtext(customeraddress) I tried this your way and Laurent's way and both give me this error: AttributeError: 'NoneType' object has no attribute 'findtext' See the lxml tutorial on this, as well as the documentation on XPath support and tree iteration: http://codespeak.net/lxml/xpathxslt.html#xpathhttp://codespeak.net/lxml/api.html#iteration Hope this helps, Stefan I'm not sure what George's deal is. I'm not a beginner with Python, just with lxml. I don't have all the hundreds of modules of Python memorized and I have yet to meet any one who does. Even if I had used Beautiful Soup, my code would probably still suck and I was told explicitly by my boss to avoid adding new dependencies to my programs whenever possible. Thanks for the help. I'll add the list comprehension to my code. Mike -- http://mail.python.org/mailman/listinfo/python-list
Re: Keeping a database connection with a Singleton?
On Sep 19, 4:03 pm, Peter Otten [EMAIL PROTECTED] wrote: exhuma.twn wrote: On Sep 19, 3:45 pm, Peter Otten [EMAIL PROTECTED] wrote: exhuma.twn wrote: [...] By the way, there is a pythonic (near) singleton: the module. So if you go with option 2, just move the connection setup into a separate module that you can import into client code. Peter You say (near) singleton. What's the difference then? I was thinking of the main script of an application. If you import that by its name import main # assuming the file is main.py you end up with two instances sys.modules[main] and sys.modules[__main__]. Peter I see. Thanks. I will give it a go. -- http://mail.python.org/mailman/listinfo/python-list
Re: Drag image
On Sep 19, 1:06 am, ndoe [EMAIL PROTECTED] wrote: i want show image from button? and the image can be drag and rezise ? any body help me!!! i try to make it but is not sucsseful yet Please post some code so we can see what you're up to. Mike -- http://mail.python.org/mailman/listinfo/python-list
Re: super() doesn't get superclass
On 2007-09-19, Michele Simionato [EMAIL PROTECTED] wrote: On Sep 19, 3:22 pm, Sion Arrowsmith [EMAIL PROTECTED] wrote: Ben Finney [EMAIL PROTECTED] wrote: If a function is named 'super' and operates on classes, it's a pretty strong implication that it's about superclasses. But it doesn't (under normal circumstances) operate on classes. It operates on an *instance*. And what you get back is a (proxy to) a superclass/ancestor of the *instance*. (And in the super(A, B) case, you get a superclass/ancestor of *B*. As has just been said somewhere very near here, what is misleading is the prominence of A, which isn't really the most important class involved.) Happily A (and B too) will become invisible in Python 3000. Nobody will miss A, but doesn't making B invisible recreate the current mystery in a new form? We want to get rid of A because it isn't possible to avoid repeating ourselves. But self is usually easily available and helps define what's happening. super.foo() to me, is even more confusing. self.super.foo() or super(self).foo() seem like improvements. Unfortunately, neither is one of the current alternate proposals. The closest competing proposal in PEP3135 is: self.__super__.foo() That syntax seems justified given the specialized application and involved pitfalls of super that you disclosed in your article. -- Neil Cerutti These people haven't seen the last of my face. If I go down, I'm going down standing up. --Chuck Person -- http://mail.python.org/mailman/listinfo/python-list
ONYX
Hi everybody! Is there anything out there that can validate and parse some onyx-style xml? I searched the web, but coulnd't find nothing really interesting about it... thank you! korovev -- http://mail.python.org/mailman/listinfo/python-list
Re: Using python to create windows apps that everyone can use?
Matt McCredie wrote: On 9/18/07, Thomas Harding [EMAIL PROTECTED] wrote: Hi guys, sorry to post another topic on this, as I am aware that it has already been posted a few times, but not with specifically what I am looking for. I want an app that makes a gui interface for python (similar to Microsoft visual studio or qt designer, not a code based one) and/or an app that can make this into a .exe that can be opened by any person on any computer without python installed. check out py2exe: http://py2exe.org matt Might want to take a look at wxGlade (http://wxglade.sourceforge.net), you will need wxWindows and py2exe to complete the toolkit. -Larry -- http://mail.python.org/mailman/listinfo/python-list
Re: Find the ID, but how to select/copy the whole string by ID?
On 9/19/07, Leon [EMAIL PROTECTED] wrote: stringID = str(raw_input('Enter the string ID : ')) file = open('strings.txt') sourcefile = file.read() file.close() sourcefile.find (stringID) but how can I select and copy the specific string from str to /str with id I input? If the file you are parsing is in xml, there are many parser out there which can help you (this is discussed very often on this list, even today) . If the format is very simple and you really want to do it by hand, you could do something like: stringID = raw_input('Enter the string ID:') for line in open('strings.txt'): if line.find(stringID) -1: print 'Found!' Note that find returns the index where the substring you look for is found, and it returns -1 if the substring is not found. The problem is that -1 is a valid index to refer to a character in a string (actually it refers to the last character of the string), so be careful with interpreting the results of the find method. francesco -- http://mail.python.org/mailman/listinfo/python-list
Re: Find the ID, but how to select/copy the whole string by ID?
sourcefile.find(stringID) returns the start location. You can use print to see this. You can then slice from start+len(stringID) and print it out. That should give you enough info to figure out how to find and extract to the end of the string tag as well. There are other ways to do this, but string.find is the easiest to understand. -- http://mail.python.org/mailman/listinfo/python-list
Re: still get a defunct using a python script in the crontab
If I run the command /usr/sbin/program_prgchk everything works (no defunct process) But when I use it in the crontab I get a defunct process The crontabs file on my system is stored in /var/spool/cron/ crontabs/. It appears you are checking the wrong file. Try a crontab -e from the command line and compare it to the contents in the /etc/crontab file. -- http://mail.python.org/mailman/listinfo/python-list
Re: Find the ID, but how to select/copy the whole string by ID?
On Wed, 2007-09-19 at 16:41 +0200, Francesco Guerrieri wrote: On 9/19/07, Leon [EMAIL PROTECTED] wrote: stringID = str(raw_input('Enter the string ID : ')) file = open('strings.txt') sourcefile = file.read() file.close() sourcefile.find (stringID) but how can I select and copy the specific string from str to /str with id I input? If the file you are parsing is in xml, there are many parser out there which can help you (this is discussed very often on this list, even today) . If the format is very simple and you really want to do it by hand, you could do something like: stringID = raw_input('Enter the string ID:') for line in open('strings.txt'): if line.find(stringID) -1: print 'Found!' Using find() for XML parsing is like using a machine gun to pound a nail into a wall. It is absolutely the wrong tool for the job. If the input file looks something like this: str id=123blah/str str id=12spam/str , then looking for id 12 is going to match on the wrong ID. Besides, that code only tells you where something that looks like the ID you're looking for is in the file. There is no guarantee that the match actually occurs inside an ID attribute. It also doesn't help in retrieving the text contents of the str tag that has this ID. If your input is an XML file, using an actual XML parser is the only correct solution. -- Carsten Haese http://informixdb.sourceforge.net -- http://mail.python.org/mailman/listinfo/python-list
Re: Metatest 0.1.0
Kay Schluehr wrote: On 19 Sep., 01:30, Jonathan Fine [EMAIL PROTECTED] wrote: there is no fundamental reason why it can't be separated from eeconsole.py. OK. That might be a good idea. Ironically, I liked the idea of having more expressive assert statements - a discussion you brought up. But this requires either syntcatical analysis in the general case ( EE and assert magic ) some particular API ( Ben Finney ) or a somewhat restricted, but fully embedded, domain specific language ( Metatest ). Here is what I got after an hour of hacking and filtering assert. Additional remarks are in line comments: snip Thank you for doing this coding, and providing an example of its use. It seems to me that /writing the tests/ and /running the tests/ are two distinct, although linked, matters. When programming, we are interested in running the tests. When designing, we are interested in writing the tests. And when looking at someone else's modules, we are interested in /reading the tests/. Both Metatest and EasyExtend show that we have some freedom in how we choose to write our tests. What I am interested in doing is developing and promoting a /language for writing tests/. This has both a formal side and also conventions and examples of its use. We would, of course, like that language to be Pythonic (if not exactly Python, although that would be a distinct advantage). I think we can do this without having to think too much about implementation (although it would be useful to have experience of using the language). I also think that some sort of 'filter' between the user and the Python commmand line would be useful. GNU readline is a simple, and effective, example of the sort of thing I have in mind. Thank you for discussing this with me, Kay and Ben. -- Jonathan -- http://mail.python.org/mailman/listinfo/python-list
Re: still get a defunct using a python script in the crontab
On 19 sep, 16:50, Zentrader [EMAIL PROTECTED] wrote: If I run the command /usr/sbin/program_prgchk everything works (no defunct process) But when I use it in the crontab I get a defunct process The crontabs file on my system is stored in /var/spool/cron/ crontabs/. It appears you are checking the wrong file. Try a crontab -e from the command line and compare it to the contents in the /etc/crontab file. The crontab is working because I can see that he started the os.system('/usr/sbin/program_reseller') AND a defunct process (what I can only kill by killing the '/usr/sbin/program_reseller' -- http://mail.python.org/mailman/listinfo/python-list
psycopg2 or pygresql?
Plain and simple. What would you use? So far I have written everything with psycopg2. One thing that annoys me is that I cannot easily access the column names from a query. I know that this is not part of the DBAPI2 so I cannot expect the model to suport it. I quite like the mogrify method of psycopg2 very much. It's very useful for debugging. And before someone says: Use the DictCursor-factory to access column names. Yes I can do that. But a dict does not guarantee the same order of keys as the columns were specified in the query. The reason: I wrote a very simple Qt-Widget (inherited from QTableWidget) that takes a SQL query and displays the results. And I would like to have the columns ordered the same way as I specified in the query *with* a header-label. For now I hava a method on the widget which takes a query, *and* a list of labels. I can live with that though. Although it itches me. Would pygresql solve my dilemma? Or would you rather say: Don't use pygresql! ;) -- http://mail.python.org/mailman/listinfo/python-list
Re: AttributeError: How to list existing attributes?
Diez B. Roggisch wrote: Thomas Guettler wrote: Hi, how can you list the attributes of an object if you catch an AttributeError? I couldn't find a reference in the exception object, which points to the object. I want to call dir() on the object to list the user the known attributes. Is there a way to find the object by inspecting the stacktrace? By looking at the code at the line the stacktrace lists? And at least for me, there is a type-information as well: Hello, I want to customize the debug tracebacks displayed in django. It is not to find one particular error. That's why changing the source is not a solution. Thomas -- Thomas Güttler, http://www.thomas-guettler.de/ http://www.tbz-pariv.de/ E-Mail: guettli (*) thomas-guettler + de Spam Catcher: [EMAIL PROTECTED] -- http://mail.python.org/mailman/listinfo/python-list
Re: Find the ID, but how to select/copy the whole string by ID?
On 9/19/07, Carsten Haese [EMAIL PROTECTED] wrote: , then looking for id 12 is going to match on the wrong ID. Besides, that code only tells you where something that looks like the ID you're looking for is in the file. There is no guarantee that the match actually occurs inside an ID attribute. It also doesn't help in retrieving the text contents of the str tag that has this ID. If your input is an XML file, using an actual XML parser is the only correct solution. You're perfectly right. The code example was purposedly incomplete for this very reason. It could be made less sensitive to false matches by constructing a correct substring, something like pattern = 'str id = ' + stringID + '' and then in the loop: line.find(pattern) but I agree that it would be wrong to proceed this way. The motivation of my reply was more to suggest a better way to iterate over a file than else... but since I've been confusing it probably would have been better to avoid. francesco -- http://mail.python.org/mailman/listinfo/python-list
Re: Using pseudonyms (was Re: Python 3K or Python 2.9?)
In article [EMAIL PROTECTED], Bruno Desthuilliers [EMAIL PROTECTED] wrote: Aahz a écrit : In article [EMAIL PROTECTED], Steve Holden [EMAIL PROTECTED] wrote: Aahz wrote: In article [EMAIL PROTECTED], Bruno Desthuilliers [EMAIL PROTECTED] wrote: Aahz a écrit : In article [EMAIL PROTECTED], Bruno Desthuilliers [EMAIL PROTECTED] wrote: But what, given that I'm an AOL user still thinking it's kewl to hide behind a pseudo, what else would you expect ? What exactly is a pseudo, pray tell? Sorry : a pseudonym (a nickname). You apparently missed the thrust of my sarcasm. You can't tell what is or is not a pseudonym online. For all I know, Bruno Desthulliers is a pseudonym. While I recognize that there is some social advantage to linking consistent identifiers with people, I have I think understandable irritation with people who insist that names follow certain patterns. (For those joining only recently, my full legal name is Aahz, which I changed from my former name precisely because of attitudes like Bruno's.) For the record, I usually don't give a damn about what name/nickname/whatever peoples use. Then why mention pseudonyms at all? -- Aahz ([EMAIL PROTECTED]) * http://www.pythoncraft.com/ The best way to get information on Usenet is not to ask a question, but to post the wrong information. -- http://mail.python.org/mailman/listinfo/python-list
Re: The meaning of a = b in object oriented languages
On Tue, 18 Sep 2007 18:02:59 -0400, Lew wrote: Summercool wrote: when a writing or a book reads a is a Hash object; a is an Array object; or a is an Animal object it is just a short form to say that a is a reference to that object. b = a means whatever a is referencing to, now b is referencing it too. so that's why a[1] = foobar will change what b will display, but a = foobar will not change what b will display. You can't do both in Java. Is a an array or a String? If a is a String and b is an array, then neither `a = b' nor `b = a' will compile in Java. Java is a strongly-typed, compiled language which means it does more static type checking and thus would reject treating a as both an array and a String. In that environment the programmer must choose one or the other. In this Java example, a and b are statically typed to be of type Object. Both Strings and Arrays descend from Object. (And primatives like integers and the like will be autoboxed into descendants of Object). -- Ken Bloom. PhD candidate. Linguistic Cognition Laboratory. Department of Computer Science. Illinois Institute of Technology. http://www.iit.edu/~kbloom1/ -- http://mail.python.org/mailman/listinfo/python-list
Re: psycopg2 or pygresql?
On Sep 19, 10:06 am, exhuma.twn [EMAIL PROTECTED] wrote: And before someone says: Use the DictCursor-factory to access column names. Yes I can do that. But a dict does not guarantee the same order of keys as the columns were specified in the query. But you can iterate over the cursor.description sequence and then look up the column value (by name or index). I haven't specifically tried this with your setup but I have used it with various DBAPI2 compliant modules. (SQLite, pyodbc, win32 odbc, etc) There are lots of goodies in the cursor.description but each implementation varies on what it provides. Check out the PEP for more info. http://www.python.org/dev/peps/pep-0249/ HTH. Jay -- http://mail.python.org/mailman/listinfo/python-list