ANN: pep8.py 0.2.0 - Python style guide checker
Announcing the first public release of pep8.py, a tool to check your Python code against some of the style conventions in `PEP 8`_. .. _PEP 8: http://www.python.org/dev/peps/pep-0008/ Features * Plugin architecture: Adding new checks is easy. * Parseable output: Jump to error location in your editor. * Small: Just one Python file, requires only stdlib. Download The file pep8.py (and a regression test suite) is available from the Browsershots subversion repository, under the Expat license: http://svn.browsershots.org/trunk/devtools/pep8/ You can look at the source code and change history online: http://trac.browsershots.org/browser/trunk/devtools/pep8/pep8.py Example usage and output :: $ pep8.py optparse.py optparse.py:69:11: E401 multiple imports on one line optparse.py:77:1: E302 expected 2 blank lines, found 1 optparse.py:88:5: E301 expected 1 blank line, found 0 optparse.py:222:34: W602 deprecated form of raising exception optparse.py:347:31: E211 whitespace before '(' optparse.py:357:17: E201 whitespace after '{' optparse.py:472:29: E221 multiple spaces before operator optparse.py:544:21: W601 .has_key() is deprecated, use 'in' You can also make pep8.py show the source code for each error, and even the relevant text from PEP 8:: $ pep8.py --show-source --show-pep8 testsuite/E111.py testsuite/E111.py:2:3: E111 indentation is not a multiple of four print x ^ Use 4 spaces per indentation level. For really old code that you don't want to mess up, you can continue to use 8-space tabs. Or you can display how often each error was found:: $ pep8.py --statistics -qq --filename=*.py Python-2.5/Lib 232 E201 whitespace after '[' 599 E202 whitespace before ')' 631 E203 whitespace before ',' 842 E211 whitespace before '(' 2531E221 multiple spaces before operator 4473E301 expected 1 blank line, found 0 4006E302 expected 2 blank lines, found 1 165 E303 too many blank lines (4) 325 E401 multiple imports on one line 3615E501 line too long (82 characters) 612 W601 .has_key() is deprecated, use 'in' 1188W602 deprecated form of raising exception Quick help is available on the command line:: $ pep8.py -h usage: pep8.py [options] input ... options: -h, --help show this help message and exit -v, --verboseprint status messages, or debug with -vv -q, --quiet report only file names, or nothing with -qq --exclude=patterns skip matches (default .svn,CVS,*.pyc,*.pyo) --filename=patterns only check matching files (e.g. *.py) --ignore=errors skip errors and warnings (e.g. E4,W) --repeat show all occurrences of the same error --show-sourceshow source code for each error --show-pep8 show text of PEP 8 for each error --statistics count errors and warnings --benchmark measure processing speed --testsuite=dir run regression tests from dir --doctestrun doctest on myself Feedback Your feedback is more than welcome. Write email to [EMAIL PROTECTED] or post bugs and feature requests here: http://trac.browsershots.org/newticket?component=devtools -- http://mail.python.org/mailman/listinfo/python-announce-list Support the Python Software Foundation: http://www.python.org/psf/donations.html
[ANN] rest2web 0.5.1
`rest2web 0.5.1 http://www.voidspace.org.uk/python/rest2web/`_ is now available. This is a minor feature enhancement release. * `Download rest2web-0.5.1.zip http://www.voidspace.org.uk/cgi-bin/voidspace/downman.py?file=rest2web-0.5.1.zip`_ * `Download rest2web-0.5.1.tar.gz http://www.voidspace.org.uk/cgi-bin/voidspace/downman.py?file=rest2web-0.5.1.tar.gz`_ What Is rest2web? = Maintaining websites or project documentation in HTML is a pain. **rest2web** takes out the pain, and brings back the joy. {sm;:wink:} **rest2web** is a simple tool that lets you build your website from a single template (or as many as you want), and keep the contents in `ReStructured Text http://docutils.sourceforge.net/`_. (You can still keep pages in HTML if needed.) It has an easy to us templating system, with embedded Python for unlimited flexibility and no new templating language to learn. It has built in functions or creating sidebars and navigation elements of a site. What's New in 0.5.1 ? Added some extra debugging info to syntax errors in the templates. Fixed odict and pathutils for Python 2.5 compatibility. Added the 'promote_headers' option to the `config file http://voidspace.org.uk/python/rest2web/config_file.html`_. Added the ``sortpages`` method to the ``sections``. This sorts the pages in a section (or all sections) alphabetically. You can also pass in a custom sort function. -- http://mail.python.org/mailman/listinfo/python-announce-list Support the Python Software Foundation: http://www.python.org/psf/donations.html
[ANN]: 'twander' 3.210 Released And Available
(Apologies for two releases in less than a week. It was, um... necessary. This should be it for quite a while barring any notable bug reports.) 'twander' Version 3.210 is now released and available for download at: http://www.tundraware.com/Software/twander The last public release was 3.204. If you are unfamiliar with this pure-Python program, see the end of this message for a brief description or see the website above. - NEW FEATURES - Implemented Association exclusions. You can now exclude the named file types from being associated with an application: ASSOC ! *.txt *.ps *.pdf This is handy if you want to use a default association for most things, but have a select group of files not be affected by the default and thereby passed down to the OS for normal processing. - Any association (normal, default, exclusion) can be removed by leaving the right-hand-side blank: ASSOC *.foo ASSOC * ASSOC ! This is useful within conditional blocks when you want to define 'twander' behavior differently based on some condition you're checking. Another use is to undefine an Association that was put in place in a global configuration you .included into your setup. CHANGES - All association checks are now case-insensitive under Windows. - Association types now support filename globbing meta- characters. This means that association statements supported in the previous release need to be changed slightly. This: ASSOC .txt ... Need to be changed to this: ASSOC *.txt This feature enables far more complete filename type specification than was previously possible with just the filename ends with .. semantic. - If a file is selected and the user double-clicks or hits Enter, and that file is not executable AND has no applicable association defined, 'twander' will present an error message. It does this only on the Unix-like systems. On Windows, the request is handed down to the underlying OS without comment because Windows itself may have an applicable association. DOCUMENTATION - The manual has been updated and corrected in several places. - Documentation for the new features has been added. Complete details of all fixes, changes, and new features can be found in the WHATSNEW.txt and documentation files included in the distribution. Users are strongly encouraged to join the twander-users mailing list as described in the documentation. A FreeBSD port has been submitted as well. What Is 'twander'? -- 'twander' is a macro-programmable Filesystem Browser that runs on both Unix-like systems as well as Win32 systems. It embraces the best ideas of both similar GUI-driven programs (Konqueror, Windows Explorer) as well as text-based interfaces (Midnight Commander, List, Sweep). Or, If You Prefer The Elevator Pitch -- 'twander' is: - A better file browser for Unix and Win32. (Tested on FreeBSD, Linux, Win32. Probably works on Mac OS/X, but not tested.) - A way to make browsing the same on all the OSs you use. - A macro-programmable tool that lets *you* define the features. - A GUI navigation front-end for your shell. - A way to can workflows for your technically-challenged colleagues. - A way to free yourself from the shackles of the mouse. - A way to significantly speed up your day-to-day workflow. - A Python/Tkinter application - about 5000 lines of code/comments - A RCT (Really Cool Tool) that will have you addicted in a day or two See the web page for more information, a screen shot, and the complete documentation. [EMAIL PROTECTED] -- http://mail.python.org/mailman/listinfo/python-announce-list Support the Python Software Foundation: http://www.python.org/psf/donations.html
Re: trouble getting google through urllib
Dr. Locke Z2A wrote: Does anyone know how I would get the bot to have permission to get the url? When I put the url in on firefox it works fine. I noticed that in the output html that google gave me it replaced some of the characters in the url with different stuff like the amp and %7C, so I'm thinking thats the problem, does anyone know how I would make it keep the url as I intended it to be? Google doesnt like Python scripts. You will need to pretend to be a browser by setting the user-agent string in the HTTP header. Will McGugan -- blog: http://www.willmcgugan.com -- http://mail.python.org/mailman/listinfo/python-list
Re: merits of Lisp vs Python
Rob Thorpe wrote: Once you can do the above then you can phrase programs entirely in terms of composition of functions, which is what functional programming is about. There are many aspects to functional programming. Some languages (like Lisp and Python) are very impure and hardly encourage functional programming. Other languages (like OCaml, SML, F# and Scheme) are impure but make functional programming easy (e.g. higher-order functions, currying, continuation passing style are all concise and statically checked). Some languages (like Haskell) are purely functional, so everything must be immutable. Getting good performance though is problematic without being able to evaluate parts at compile time. This is why almost all functional languages provide that feature in some form. Actually the languages that don't provide compile-time execution (OCaml, SML and F#) are typically much faster than those that do (Lisp, Scheme, Dylan). -- Dr Jon D Harrop, Flying Frog Consultancy Objective CAML for Scientists http://www.ffconsultancy.com/products/ocaml_for_scientists/index.html?usenet -- http://mail.python.org/mailman/listinfo/python-list
RE: Can a Tkinter GUI check for abort script:
I don't know why this happen. do you call mainloop() inside the test3.py?? you shouldn't Michael Yanowitz [EMAIL PROTECTED] wrote: Presently what happens is that the script takes over and all the buttons on the GUI disappear as the GUI is not given any cpu time to refresh or check if any activity in the dialog. __ Do You Yahoo!? Tired of spam? Yahoo! Mail has the best spam protection around http://mail.yahoo.com -- http://mail.python.org/mailman/listinfo/python-list
Re: should I distribute .pyc files?
akbar [EMAIL PROTECTED] wrote: I am creating not-so-important opensource application written in python for Linux. I have two files python source in src directory, named blabla1.py and blabla2.py. There are byte compiled files too, named blabla1.pyc and blabla2.pyc. Should I distribute these files (pyc files) to users? If I don't distribute them, and user installed my application into /usr (not writable by normal user) then run it as normal user, off course, the python cannot make byte-compiled version. Will my program runs slower in user computer then in my computer because I have byte compiled version? Short answer: use distutils or build a python egg. These will automate most of the distribution process. Longer answer: distutils (standard in Python) will build you a variety of installation packages such as zip, tar, rpm, or windows .exe (even from linux). The installation step will do all necessary compiling from .py to .pyc (and also builds extension modules although that can be problematic for a windows distribution where the correct compiler almost certainly isn't available). setuptools (http://cheeseshop.python.org/pypi/setuptools) is a collection of enhancements to distutils which let you build .egg files. Once you start using egg files you can include dependencies between package versions and if your product requires a bunch of other packages the installation step will download and install the appropriate versions. See http://peak.telecommunity.com/DevCenter/EasyInstall for instructions on installing packages built in this way, but in short, the user has to run ez_setup.py from the EasyInstall page, and then a command like: easy_install http://example.com/path/to/MyPackage-1.2.3.tgz would download and install your package and all the other products it depends on. If at a later stage they want to upgrade to a more recent version then all they need to do is to run: easy_install --upgrade MyPackage Installed eggs usually exist in a single file (importable zip) which makes uninstalling especially easy: just one file to delete. -- http://mail.python.org/mailman/listinfo/python-list
Re: trouble getting google through urllib
Will McGugan [EMAIL PROTECTED] wrote: Dr. Locke Z2A wrote: Does anyone know how I would get the bot to have permission to get the url? When I put the url in on firefox it works fine. I noticed that in the output html that google gave me it replaced some of the characters in the url with different stuff like the amp and %7C, so I'm thinking thats the problem, does anyone know how I would make it keep the url as I intended it to be? Google doesnt like Python scripts. You will need to pretend to be a browser by setting the user-agent string in the HTTP header. and possibly also run the risk of having your system blocked by Google if they figure out you are lying to them? -- http://mail.python.org/mailman/listinfo/python-list
Re: trouble getting google through urllib
Dr. Locke Z2A wrote: H1Forbidden/H1 Your client does not have permission to get URL code/translate_t?text='%20como%20estas'amp;hl=enamp;langpair=es%7Cenamp;tbb=1/code from this server. Does anyone know how I would get the bot to have permission to get the url? http://www.google.com/terms_of_service.html You may not send automated queries of any sort to Google's system without express permission in advance from Google. official API:s are available here: http://code.google.com/ /F -- http://mail.python.org/mailman/listinfo/python-list
Re: urllib.unquote and unicode
George Sakkis wrote: The following snippet results in different outcome for (at least) the last three major releases: import urllib urllib.unquote(u'%94') # Python 2.4.2 UnicodeDecodeError: 'ascii' codec can't decode byte 0x94 in position 0: ordinal not in range(128) Python 2.4.3 (#3, Aug 23 2006, 09:40:15) [GCC 3.3.3 (SuSE Linux)] on linux2 Type help, copyright, credits or license for more information. import urllib urllib.unquote(u%94) u'\x94' From the above I infer that the 2.4.2 behaviour was considered a bug. Peter -- http://mail.python.org/mailman/listinfo/python-list
Re: trouble getting google through urllib
Dr. Locke Z2A [EMAIL PROTECTED] writes: Does anyone know how I would get the bot to have permission to get the url? That's what this was for: http://code.google.com/apis/soapsearch/ -- http://mail.python.org/mailman/listinfo/python-list
Re: urllib.unquote and unicode
George Sakkis wrote: The following snippet results in different outcome for (at least) the last three major releases: import urllib urllib.unquote(u'%94') # Python 2.3.4 u'%94' # Python 2.4.2 UnicodeDecodeError: 'ascii' codec can't decode byte 0x94 in position 0: ordinal not in range(128) # Python 2.5 u'\x94' Is the current version the right one or is this function supposed to change every other week ? why are you passing non-ASCII Unicode strings to a function designed for fixing up 8-bit strings in the first place? if you do proper encoding before you quote things, it'll work the same way in all Python releases. /F -- http://mail.python.org/mailman/listinfo/python-list
Apache 2.2.3 and mod_python 3.2.10
I installed Apache 2.2.3 and mod_python 3.2.10 on WinXP plateform I configured mod_python via httpd.conf: LoadModule python_module modules/mod_python.so but my script folder configuration doesn't work correctely: Alias /myfolder D:/myfolder Directory /myfolder Order allow,deny Allow from all AddHandler mod_python .py PythonHandler mod_python.publisher PythonDebug On /Directory for test, this is a sample script d:\myfolder\test.py # test.py # from mod_python import apache # def hello(name=None): if name: return 'Hello, %s!' % name.capitalize() else: return 'Hello there!' # def handler(req): req.content_type = 'text/plain' req.write(from handler test, Hello World!) return apache.OK when I access to the url http://localhost/monrep/test.py, I obtain source test.py listing but not the rendering of handler or hello method. with url http://localhost/theriaque/test.py/hello, I obtain : =The requested URL /theriaque/test.py/hello was not found on this server. It seems like something is missing ... but what ? thanks for any help -- http://mail.python.org/mailman/listinfo/python-list
Re: urllib.unquote and unicode
Leo Kislov [EMAIL PROTECTED] wrote: George Sakkis wrote: The following snippet results in different outcome for (at least) the last three major releases: import urllib urllib.unquote(u'%94') # Python 2.3.4 u'%94' # Python 2.4.2 UnicodeDecodeError: 'ascii' codec can't decode byte 0x94 in position 0: ordinal not in range(128) # Python 2.5 u'\x94' Is the current version the right one or is this function supposed to change every other week ? IMHO, none of the results is right. Either unicode string should be rejected by raising ValueError or it should be encoded with ascii encoding and result should be the same as urllib.unquote(u'%94'.encode('ascii')) that is '\x94'. You can consider current behaviour as undefined just like if you pass a random object into some function you can get different outcome in different python versions. I agree with you that none of the results is right, but not that the behaviour should be undefined. The way that uri encoding is supposed to work is that first the input string in unicode is encoded to UTF-8 and then each byte which is not in the permitted range for characters is encoded as % followed by two hex characters. That means that the string u'\x94' should be encoded as %c2%94. The string %94 should generate a unicode decode error, but it should be the utf-8 codec raising the error not the ascii codec. Unfortunately RFC3986 isn't entirely clear-cut on this issue: When a new URI scheme defines a component that represents textual data consisting of characters from the Universal Character Set [UCS], the data should first be encoded as octets according to the UTF-8 character encoding [STD63]; then only those octets that do not correspond to characters in the unreserved set should be percent- encoded. For example, the character A would be represented as A, the character LATIN CAPITAL LETTER A WITH GRAVE would be represented as %C3%80, and the character KATAKANA LETTER A would be represented as %E3%82%A2. I think it leaves open the possibility that existing URI schemes which do not support unicode characters can use other encodings, but given that the original posting started by decoding a unicode string I think that utf-8 should definitely be assumed in this case. Also, urllib.quote() should encode into utf-8 instead of throwing KeyError for a unicode string. -- http://mail.python.org/mailman/listinfo/python-list
Re: Apache 2.2.3 and mod_python 3.2.10
sorry, I give here the right paths: I installed Apache 2.2.3 and mod_python 3.2.10 on WinXP plateform I configured mod_python via httpd.conf: LoadModule python_module modules/mod_python.so but my script folder configuration doesn't work correctely: Alias /myfolder D:/myfolder Directory /myfolder Order allow,deny Allow from all AddHandler mod_python .py PythonHandler mod_python.publisher PythonDebug On /Directory for test, this is a sample script d:\myfolder\test.py # test.py # from mod_python import apache # def hello(name=None): if name: return 'Hello, %s!' % name.capitalize() else: return 'Hello there!' # def handler(req): req.content_type = 'text/plain' req.write(from handler test, Hello World!) return apache.OK when I access to the url http://localhost/myfolder/test.py, I obtain source test.py listing but not the rendering of handler or hello method. with url http://localhost/myfolder/test.py/hello, I obtain : =The requested URL /myfolder/test.py/hello was not found on this server. It seems like something is missing ... but what ? thanks for any help -- http://mail.python.org/mailman/listinfo/python-list
Re: Script to upload Files via http/cgi
Richard Konrad wrote: Does anyone know about a python-script to upload Files via http/cgi? do you want the script to do the actual upload at the client side (i.e. behave like a browser) or to handle the uploaded data on the server side? for the latter, see this: http://docs.python.org/lib/cgi-intro.html /F -- http://mail.python.org/mailman/listinfo/python-list
wrapping problem with old-style class
I have a problem I would like some advice on. We have a Python binding to the Intersystems Cache OO database. It provides an old style class in Python as an in memory instance of a Cache class, and this is a intersystems.pythonbind.object type (= ipo). The ipo class has three basic methods, namely, get, set, and run_obj_method (which takes the Cache class method, as its first argument, and the list of its arguments as the second argument) e.g. CacheClass=ipo() CacheClass.set('Name','John') valName = CacheClass.get('Name') print valName 'John' I want to add functionality to ipo, so I have wrapped a new style class (MyWrapper class, very basic) around it. PythonCacheClass=MyWrapper(CacheClass) Now, I want to make PythonCacheClass more pythonic, so I have a dictionary of all the properties and values of each ipo. Eg dicCacheProperties = {'Name':'John', 'Address':'The Strand'} etc for key, val in dicCacheProperties.iteritems(): setattr(PythonCacheClass, key, val) So now I have: print PythonCacheClass.Name 'John' My problem is this: how do I link the set and get methods of the ipo class with the set and get methods in the wrapper class PythonCacheClass? So, I would like the following code: PythonCacheClass.Name='Alexander' to execute automatically CacheClass.set('Name','Alexander')etc My thinking is that inside the PythonCacheClass, I can reference the ipo class by self.get() - is this right? If so, how then do I set the set attribute of the PythonCacheClass to automatically run self.get().set('Name','Alexander') I hope this is sufficiently clear. Am I tackling the problem the right way? -- http://mail.python.org/mailman/listinfo/python-list
Adding an instance to a data tree
Hi, I have a data tree. A node in the tree assembles itself when called upon to do so by the level-of-detail algorithm. It creates and adds its children to itself using a base class method called add. However in the pseudo-constructor called setup, the child node needs to be already linked into the tree in order to obtain configuration information. So the add method creates the child, optionally positions it within the parents frame of reference, then invokes the child's setup method which has variable length arguments. Here is an example of code in an assemble method. self.add(Reservoir,(Reservoir, r, r + self.inner_tank_thickness)) self.add(End_tank, (End_tank, r, self.outer_tank_radius), 0.5*self.payload_length + 0.5*self.outer_tank_thickness) self.add(Inner_end_tank, (End_tank, r, self.outer_tank_radius), -0.5*self.payload_length -0.5*self.outer_tank_thickness) self.add(Zero_G_port, Zero_G_port, 0.5*self.payload_length -0.5*self.zg_length) self.add(Hangar-floor, Hangar) self.add(herc, Hercules_shuttle, (0.5*self.payload_length - 25, R3d(180.0,V3d(0,1,0 self.add(herc1,Hercules_shuttle, (V3d(0,-12.5,0.5*self.payload_length - 25), R3d(180.0,V3d(0,1,0 The add method takes the parameters name, child-information, and optional location-information. The child information is either a class, or a tuple whose first member is a class. The remaining members of the tuple are parameters to the class setup method. The problem is this: Sometimes the setup method parameters are quite numerous, leading to problems when the order is misjudged. If invoked directly, then naming parameters minimises the problems with missed parameters. However the indirect creation via the add method means the parameters are passed in a tuple, so the parameters cannot be named. How can I pre-construct the children with parent id and optional location information, and also implement the advantages of named function parameters? Looking for all suggestions. -- http://mail.python.org/mailman/listinfo/python-list
ElementTree and utf-16 encoding
Hi, ET being ElementTree in the following code, could anyone explain why it fails ? xml = ET.tostring(ET.Element(root), UTF-16) xml ?xml version='1.0' encoding='UTF-16'?\n\xff\xfer\x00o\x00o\x00t\x00 / ET.fromstring(xml) Traceback (most recent call last): ... xml.parsers.expat.ExpatError: encoding specified in XML declaration is incorrect: line 1, column 30 I s it related to the lack of BOM in the xml string ? I tried to add some \xff\xfe or \xfe\xff at the start of the xml string without much sucess with fromstring so far ... Cheers, SB -- http://mail.python.org/mailman/listinfo/python-list
Re: ElementTree and utf-16 encoding
Sébastien Boisgérault wrote: ET being ElementTree in the following code, could anyone explain why it fails ? I'm afraid the standard serializer in 1.2 only supports ASCII-compatible encodings. this will be fixed in 1.3. as a workaround, you can do: tostring(elem).decode(utf-8).encode(utf-16) /F -- http://mail.python.org/mailman/listinfo/python-list
Re: python-hosting.com projects: dead?
[EMAIL PROTECTED] wrote: I certainly hope so, but this is what I'm reacting to (from http://www.webfaction.com/freetrac): We're sorry, we're not longer accepting applications for free trac/svn accounts. People have left their Trac sites unattended and as a result our server is being flooded with spam. We need to do some serious cleanup and when that's done we'll accept new applications again (that might take weeks, if not months though). Um, that sounds to me like they're not accepting *new* projects, not that they're shutting down existing ones. Unless *my* reading comprehension skills have completely abandoned me. -- Greg -- http://mail.python.org/mailman/listinfo/python-list
Re: Apache 2.2.3 and mod_python 3.2.10
m.banaouas wrote: sorry, I give here the right paths: I installed Apache 2.2.3 and mod_python 3.2.10 on WinXP plateform I configured mod_python via httpd.conf: LoadModule python_module modules/mod_python.so but my script folder configuration doesn't work correctely: Alias /myfolder D:/myfolder Directory /myfolder Order allow,deny Allow from all AddHandler mod_python .py PythonHandler mod_python.publisher PythonDebug On /Directory for test, this is a sample script d:\myfolder\test.py # test.py # from mod_python import apache # def hello(name=None): if name: return 'Hello, %s!' % name.capitalize() else: return 'Hello there!' # def handler(req): req.content_type = 'text/plain' req.write(from handler test, Hello World!) return apache.OK when I access to the url http://localhost/myfolder/test.py, I obtain source test.py listing but not the rendering of handler or hello method. with url http://localhost/myfolder/test.py/hello, I obtain : =The requested URL /myfolder/test.py/hello was not found on this server. It seems like something is missing ... but what ? thanks for any help Get it working for a normal handler first and don't use mod_python.publisher. For a set of instructions on how to get a simple handler working, including descriptions of common problems and how to debug it, see: http://www.dscpl.com.au/wiki/ModPython/Articles/GettingModPythonWorking Once you have confirmed that your installation works, then consider looking at mod_python.publisher. I'd also suggest that you get yourself on the mod_python user mailing list and seek help there as the mod_python community there is much larger. Mailing list details are on the mod_python web site. BTW, don't you mean: Directory D:/myfolder if that is what Alias uses? Also, don't mix normal handlers and mod_python.publisher functions in the same module, and don't use files called 'test.py' as there is a standard Python module by the same name and if things aren't set up right you can be picking up the wrong module. Graham -- http://mail.python.org/mailman/listinfo/python-list
Re: ElementTree and utf-16 encoding
On Dec 19, 10:49 am, Fredrik Lundh [EMAIL PROTECTED] wrote: Sébastien Boisgérault wrote: ET being ElementTree in the following code, could anyone explain why it fails ?I'm afraid the standard serializer in 1.2 only supports ASCII-compatible encodings. this will be fixed in 1.3. as a workaround, you can do: tostring(elem).decode(utf-8).encode(utf-16) /F OK, thanks. SB -- http://mail.python.org/mailman/listinfo/python-list
Re: tuple.index()
In article [EMAIL PROTECTED], greg [EMAIL PROTECTED] writes: | Nick Maclaren wrote: | | Unfortunately, you are confusing the issue, because there are far | more extraneous aspects than relevant ones, and your view of the | similarities requires looking at the issue in a very strange way. | I think that I can see what you mean, but only just. | | Each member of a struct has a distinct, predefined | role. Even if they all have the same type, you | can't swap their values around without destroying | the meaning of the data. That's what's meant by | heterogeneous in this context -- it's not about | the values themselves, but the way they're used. | | This is the kind of thing for which Python tuples | are mainly designed -- use as a struct whose | members happen to be named by integers rather | than strings. Well, that was obvious to me on a cursory reading, because I have enough relevant experience with other languages. It wasn't what I was referring to, which was two things: C arrays are not extensible and, before C99, were fixed in size at compile time. That makes them rather more similar to tuples in those ways! I know that's not the aspect you were thinking of, but is why I made the remark that I did. It does explain why you think of lists as homogeneous, but the analogy doesn't hold water on closer inspection. There doesn't seem to be ANYTHING in the specification or implementation that assumes lists are homogeneous. Regards, Nick Maclaren. -- http://mail.python.org/mailman/listinfo/python-list
Re: regular expression
Asper Faner wrote: I seem to always have hard time understaing how this regular expression works, especially how on earth do people bring it up as part of computer programming language. Natural language processing seems not enough to explain by the way. Why no eliminate it ? I am sure you'll get an answer in one of zillion groups you posted this stupid question to... Regards, Erwin -- http://mail.python.org/mailman/listinfo/python-list
Re: tuple.index()
On 19 Dec 2006 10:01:47 GMT, Nick Maclaren [EMAIL PROTECTED] wrote: It does explain why you think of lists as homogeneous, but the analogy doesn't hold water on closer inspection. There doesn't seem to be ANYTHING in the specification or implementation that assumes lists are homogeneous. As has been said a number of times in this thread, lists are for homogeneous data isn't a technical restriction, it's purely conceptual. It's what lists were designed for, and their API reflects this. Any by objects of the same type, we are not talking about type in any technical sense. But you go ahead and put whatever you like in them if you have trouble with the idea. Similarly, the tuple API was designed for heterogeneous items where the items' position in the list has semantic meaning. Use them as you will, but don't complain if the API doesn't support what you want to do. I've had enough of this thread. You can lead a horse to water... -- Cheers, Simon B [EMAIL PROTECTED] -- http://mail.python.org/mailman/listinfo/python-list
Re: wrapping problem with old-style class
manstey wrote: The ipo class has three basic methods, namely, get, set, and run_obj_method (which takes the Cache class method, as its first argument, and the list of its arguments as the second argument) e.g. CacheClass=ipo() CacheClass.set('Name','John') valName = CacheClass.get('Name') print valName 'John' I want to add functionality to ipo, so I have wrapped a new style class (MyWrapper class, very basic) around it. PythonCacheClass=MyWrapper(CacheClass) Now, I want to make PythonCacheClass more pythonic, so I have a dictionary of all the properties and values of each ipo. Eg dicCacheProperties = {'Name':'John', 'Address':'The Strand'} etc for key, val in dicCacheProperties.iteritems(): setattr(PythonCacheClass, key, val) So now I have: print PythonCacheClass.Name 'John' My problem is this: how do I link the set and get methods of the ipo class with the set and get methods in the wrapper class PythonCacheClass? So, I would like the following code: PythonCacheClass.Name='Alexander' to execute automatically CacheClass.set('Name','Alexander')etc Maybe try: class WrapperClass(BaseClass, object): get = object.__getattribute__ set = object.__setattr_ Gerard -- http://mail.python.org/mailman/listinfo/python-list
Re: python-hosting.com projects: dead?
greg wrote: [EMAIL PROTECTED] wrote: I certainly hope so, but this is what I'm reacting to (from http://www.webfaction.com/freetrac): We're sorry, we're not longer accepting applications for free trac/svn accounts. People have left their Trac sites unattended and as a result our server is being flooded with spam. We need to do some serious cleanup and when that's done we'll accept new applications again (that might take weeks, if not months though). Um, that sounds to me like they're not accepting *new* projects, not that they're shutting down existing ones. Unless *my* reading comprehension skills have completely abandoned me. Well, nose.python-hosting.com (Jason Pellerin's project) is certainly inaccessible to me as well as most of the other free Tracs that I could scrounge up through Google. Jason's not just being paranoid. While it may be temporary and he will get hosting back in a few months(!), it's still down, and apparently without warning (I'm not a party to any of this, so I'm simply going with what Jason wrote). -- Robert Kern I have come to believe that the whole world is an enigma, a harmless enigma that is made terrible by our own mad attempt to interpret it as though it had an underlying truth. -- Umberto Eco -- http://mail.python.org/mailman/listinfo/python-list
Re: Core dump revisited
Sheldon [EMAIL PROTECTED] wrote: Sheldon skrev: Wonderful! Now I know how to used gdb with python. Good! The are results area posted below. Since I am new at this I could used some help in interpreting the problem. What I do know is this: my allocation of the array is good but when freeing the array, a problem arises. The problem is given below but since I am new as well to C Ambitious! I sure could use some help. Program received signal SIGSEGV, Segmentation fault. [Switching to Thread 1077321856 (LWP 32710)] 0x40297b83 in mallopt () from /lib/tls/libc.so.6 (gdb) bt #0 0x40297b83 in mallopt () from /lib/tls/libc.so.6 #1 0x402958ba in free () from /lib/tls/libc.so.6 #2 0x405e070a in MemoryFreeOrd () at msgppsmodule_area.c:1675 #3 0x405dae0a in msgppsarea (self=0x0, args=0x4042aa7c, kwargs=0x0) at msgppsmodule_area.c:328 #4 0x40073b16 in PyCFunction_Call () from /usr/lib/libpython2.3.so.1.0 Typing up and down to move up and down the call stack is a good thing. Type l to see a list of code at the point that things went wrong. You can type print variablename to see the values of variables. gdb understands most C syntax so you can use print this-member[1].data etc. This all assumes you compiled and linked with debugging (-g flag to compiler and linker). Turning off optimisation may make the debugger more accurate also. I can't tell exactly where your program crashed because of line wrapping it your post, but is it certainly within MemoryFreeOrd(). What I would do next is run the program under gdb, wait for it to crash then print the values of things in the MemoryFreeOrd() function. You'll find one of the pointers has been corrupted, ie doesn't point to valid memory or memory allocated with malloc() I expect. 0 or NULL is an acceptable input to most free() implementations but not all. Finding out exactly where that pointer got corrupted is harder. Maybe it was never initialised, or maybe you initialised it with a PyObject or maybe you have a memory scribble somewhere. A memory scribble is the hardest bug to find because it happened elsewhere in your program. Look at the data that was overwritten. Maybe it is a string you can identify... You'll also want to start reading the gdb manual on breakpoints and watchpoints at this moment! Find memory corruptions can be tricky and time consuming. Valgrind can help also. Good luck! -- Nick Craig-Wood [EMAIL PROTECTED] -- http://www.craig-wood.com/nick -- http://mail.python.org/mailman/listinfo/python-list
python poetry?
I'm working on a book of technology and computer programming humor. First, can anybody recommend any other such books? And second is there a repository of Python poetry, poems translated into Python, or humorous Python pseudo code limericks anywhere? I'm making my way through The Larch, but if there's more elsewhere please point me to it. I'm looking for the Python equivalent of something like this: http://www.heavyflash.com/poetry/Shakespeare_Sonnet18.html Thank you all rd http://dooling.com -- http://mail.python.org/mailman/listinfo/python-list
Class constant for extension
Hi, I have written a small prototype Python extension for a C-library. I have the methods all sorted out and it is working fine. In the C-library, they are various constants of types like string, integer, float and matrix. I'd like to expose them as READONLY values. Is the use of PyMemberDefs a suitable way to provide such access? I'd like the user of the extension to be able to do something like the follow import MyExtension MyExtension.begin() mv = MyExtension.minValue MyExtension.process(MyExtension.versionStr) MyExtension.end() Is someone able to point me to an example code of how I can write my extension so that the references to those constants can be used in the above way. Regards -- http://mail.python.org/mailman/listinfo/python-list
Re: Adding an instance to a data tree
And of course the solution occurs to me about 30 minutes after posting, to have the add method return an instance which then invokes setup. self.add(name, child_type, other_info).setup(child-setup-parameters) -- http://mail.python.org/mailman/listinfo/python-list
Re: Class property with value and class
manstey wrote: Hi, Is is possible to have two classes, ClassA and ClassB, and setattr(ClassA, 'xx',ClassB), AND to then have ClassA.xx store an integer value as well, which is not part of ClassB? e.g. If ClassB has two properties, name and address: ClassA.xx=10 ClassA.xx.name = 'John' ClassA.xx.address = 'Sydney'. etc? I've no idea if this is possible or desirable. It's neither of both options. If you must, you can subclass int, and have additional properties. But then you can't do it like above, but instead must do: ClassA.xx = MyAddressInt(10) Diez -- http://mail.python.org/mailman/listinfo/python-list
RE: Can a Tkinter GUI check for abort script:
No. test3.py (for example) is just plain Python code that sends and receives socket data from another machine. It does (or could) contain loops that last a long time, repeating the read or write operations to and from the socket. This grabs the CPU. What I am hoping for is a function call I can make, without knowing any of the GUI objects, I can call from test3.py (or while test3.py is running) which will refresh the GUI and check for activity such as button presses on the GUI itself. For example, if I just call sleep(), will it do this? Thanks in advance: Michael Yanowitz -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] Behalf Of Mohammad Tayseer Sent: Monday, December 18, 2006 11:28 AM To: python-list@python.org Subject: RE: Can a Tkinter GUI check for abort script: I don't know why this happen. do you call mainloop() inside the test3.py?? you shouldn't Michael Yanowitz [EMAIL PROTECTED] wrote: Presently what happens is that the script takes over and all the buttons on the GUI disappear as the GUI is not given any cpu time to refresh or check if any activity in the dialog. __ Do You Yahoo!? Tired of spam? Yahoo! Mail has the best spam protection around http://mail.yahoo.com -- http://mail.python.org/mailman/listinfo/python-list
Re: regular expression
Asper Faner schrieb: I seem to always have hard time understaing how this regular expression works, especially how on earth do people bring it up as part of computer programming language. Natural language processing seems not enough to explain by the way. Why no eliminate it ? Erm, I am a student of Computational Linguistics and _NO_ , they should _NOT_ be eliminated since they are an important part of language processing in python. Read this: http://www.amk.ca/python/howto/regex/ -- http://mail.python.org/mailman/listinfo/python-list
Returned mail: Data format error
The message was undeliverable due to the following reason: Your message was not delivered because the destination computer was not reachable within the allowed queue period. The amount of time a message is queued before it is returned depends on local configura- tion parameters. Most likely there is a network problem that prevented delivery, but it is also possible that the computer is turned off, or does not have a mail system running right now. Your message could not be delivered within 1 days: Host 197.66.8.215 is not responding. The following recipients did not receive this message: python-list@python.org Please reply to [EMAIL PROTECTED] if you feel this message to be in error. -- http://mail.python.org/mailman/listinfo/python-list
on PySol's popularity
Hi, On Python docs, on faq/installed.html, it's mentioned that PySol is the most common Python application. Is this a platform-specific fact? -- http://mail.python.org/mailman/listinfo/python-list
Re: regular expression
Asper Faner wrote: I seem to always have hard time understaing how this regular expression works, especially how on earth do people bring it up as part of computer programming language. Natural language processing seems not enough to explain by the way. Why no eliminate it ? I.M.H.O. anyone that is not capable to grasp the concept of regular expressions should not attempt to write computer programs at all! My suggestion to you would be to find a job that involves working with your hands... -- http://mail.python.org/mailman/listinfo/python-list
RE: Can a Tkinter GUI check for abort script:
Michael Yanowitz [EMAIL PROTECTED] wrote: What I am hoping for is a function call I can make, without knowing any of the GUI objects, I can call from test3.py (or while test3.py is running) which will refresh the GUI and check for activity such as button presses on the GUI itself. call w.update_idletasks(). see http://infohost.nmt.edu/tcc/help/pubs/tkinter/universal.html#update_idletasks For example, if I just call sleep(), will it do this? No, it won't Thanks in advance: Michael Yanowitz You're welcome __ Do You Yahoo!? Tired of spam? Yahoo! Mail has the best spam protection around http://mail.yahoo.com -- http://mail.python.org/mailman/listinfo/python-list
Re: on PySol's popularity
Tshepang Lekhonkhobe wrote: On Python docs, on faq/installed.html, it's mentioned that PySol is the most common Python application. not really; that page says that installing PySol is a common way to get a Python installation installed without noticing, not that PySol is in itself the most common Python application. and the entire python.org FAQ is horribly outdated. we're working on a replacement, which is currently hosted here: http://effbot.org/pyfaq/installed-why-is-python-installed-on-my-machine.htm /F -- http://mail.python.org/mailman/listinfo/python-list
Re: Strange error with getattr() function
Gabriel Genellina ha scritto: At Monday 18/12/2006 13:25, Hole wrote: At this point, I got the error: attribute name must be string I'm wondering if the exception is raised in a hidden function and not in the explicit call to getattr(). How can I view the traceback in a script running in zope?? (Which Zope version?) If you don't catch the exception, an error page will be displayed, pointing to the error_log object. Hi Gabriel, thanks a lot for your replies. I've resolved the problem catching the exception and printing the traceback in a file. The problem was, indeed, in a getattr() call performed in another function, to which I passed an int rather than a string. Bye! -- DN -- http://mail.python.org/mailman/listinfo/python-list
Re: python-hosting.com projects: dead?
[EMAIL PROTECTED] wrote: It looks to me like python hosting, aka webfaction, have shut down access to all projects hosted under their free hosting for open source python projects program. Including mine (nose). With no notice -- at least none that I received. Surprised doesn't quite cover it. Perhaps someone from python hosting can explain why this was done, why no notice was given (if it wasn't), and how those of us trying to restart our projects elsewhere can get access to our subversion repositories and trac data. have you tried mailing webfaction instead of ranting on the usenet? my account was temporarily disabled as well, during an attempt to clean out seemingly abandoned trac instances, but was back online in less than fifteen minutes after I'd mailed them. you'll find the contact info in the mail you got when you signed up. /F -- http://mail.python.org/mailman/listinfo/python-list
Re: urllib.unquote and unicode
Fredrik Lundh wrote: George Sakkis wrote: The following snippet results in different outcome for (at least) the last three major releases: import urllib urllib.unquote(u'%94') # Python 2.3.4 u'%94' # Python 2.4.2 UnicodeDecodeError: 'ascii' codec can't decode byte 0x94 in position 0: ordinal not in range(128) # Python 2.5 u'\x94' Is the current version the right one or is this function supposed to change every other week ? why are you passing non-ASCII Unicode strings to a function designed for fixing up 8-bit strings in the first place? if you do proper encoding before you quote things, it'll work the same way in all Python releases. I'm using BeautifulSoup, which from version 3 returns Unicode only, and I stumbled on a page with such bogus char encodings; I have the impression that whatever generated it used ord() to encode reserved characters instead of the proper hex representation in latin-1. If that's the case, unquote() won't do anyway and I'd have to go with chr() on the number part. George -- http://mail.python.org/mailman/listinfo/python-list
Re: Is htmlGen still alive?
[EMAIL PROTECTED] wrote: Does anybody know whether htmlGen, the Python-class library for generating HTML, is still being maintained? Or from where it can be downloaded? The Starship site where it used to be hosted is dead. I don't know if HTMLgen is still alive, but if you're looking for alternatives, you might give XIST a try (http://www.livinglogic.de/Python/xist) Servus, Walter -- http://mail.python.org/mailman/listinfo/python-list
Re: pyExcelerator question
Thanks!!! Looks great. Works for me. I'll try to submit the patch. Gerry -- http://mail.python.org/mailman/listinfo/python-list
Re: python-hosting.com projects: dead?
I certainly hope so, but this is what I'm reacting to (from http://www.webfaction.com/freetrac): We're sorry, we're not longer accepting applications for free trac/svn accounts. People have left their Trac sites unattended and as a result our server is being flooded with spam. We need to do some serious cleanup and when that's done we'll accept new applications again (that might take weeks, if not months though). Um, that sounds to me like they're not accepting *new* projects, not that they're shutting down existing ones. Unless *my* reading comprehension skills have completely abandoned me. Your reading comprehension skills are fine :) We're not accepting *new* projects anymore (for now), but we certainly continue to support existing ones. We would never take down the sites without at least a one month warning ... not that we have any plan to do so anyway... We had to do some serious cleanup and we disabled a lot of Trac sites that looked abandoned (people left their Trac sites open to spammers and our server was crawling under the load caused by these spammers). If your site got disabled by mistake just e-mail us and we'll re-enable it within minutes ... Remi. -- http://mail.python.org/mailman/listinfo/python-list
Re: Is htmlGen still alive?
[EMAIL PROTECTED] wrote: Does anybody know whether htmlGen, the Python-class library for generating HTML, is still being maintained? Or from where it can be downloaded? The Starship site where it used to be hosted is dead. Thanks for your help! Klaus Muller I am not certain it is, but besides some deprecation warnings, it seems to be complete/functional hg -- http://mail.python.org/mailman/listinfo/python-list
Re: trouble getting google through urllib
Duncan Booth wrote: Google doesnt like Python scripts. You will need to pretend to be a browser by setting the user-agent string in the HTTP header. and possibly also run the risk of having your system blocked by Google if they figure out you are lying to them? It is possible. I wrote a 'googlewhack' (remember them?) script a while ago, which pretty much downloaded as many google pages as my adsl could handle. And they didn't punish me for it. Although apparently they do issue short term bans on IP's that abuse their service. It is best to play nice of course. I would recommend using their official APIs if possible! Will McGugan -- http://www.willmcgugan.com -- http://mail.python.org/mailman/listinfo/python-list
Re: Using DCOP from Python
Jeffrey Barish wrote: The package python-dcop makes it possible to use DCOP from Python. Does anyone know of a tutorial for this package or an example of its use? I would like to use it to read a journal entry in Korganizer. I got as far as figuring out that DCOP offers the interface korganizer.CalendarIface.openJournalEditor(QString text, QDate date) but I'm having trouble figuring out how to call this function from Python. And will it become clear how to control whether I am reading or writing the journal? You might find an answer in the archives of the PyKDE mailing list: http://mats.imk.fraunhofer.de/mailman/listinfo/pykde There are probably people reading that list who can give you hints and tips, at the very least. You might also want to take a look at the documentation at http://www.riverbankcomputing.com/Docs/PyKDE3/dcopext.html This may be enough to get you started. David -- http://mail.python.org/mailman/listinfo/python-list
Re: Good Looking UI for a stand alone application
Ok, now here's a question for you: if crossplatform toolkits/frameworks are so great and automagically allow to produce superlickable and native-looking/feeling applications on all three major platforms, why is there so few of those applications on OS X ? Because Mac users are elitists assholes is not the good answer by the way :) You've got a ridiculous straw man here. Nobody has ever said that they do this, and nobody with any experience would. I don't actually think you're interested in what is possible and what isn't, and I don't even think that you actually evaluate the screenshots in a context where it's possible for you to have any other opinion. wx is the only popular toolkit of it's kind - it's a wrapper toolkit, that uses actual native controls, not just ones designed to look like them. For many wxPython/wxWidgets applications, there is *no difference* between an app written directly to cocoa and a wxwidgets app besides the API the author used. None, zero, zilch. Any feel issues you claim to be present are solely because the author either didn't know about or didn't care about a convention on the mac platform. The only other major cross platform toolkit with good mac support is Qt, and I don't follow it's development closely. It may also use native controls, at least in some cases, or it may still render everything via the presentation manager, but regardless it's got a lot of work and again, in most cases, it's hard if not impossible to tell the difference between a native app and a qt one. I'm not a qt expert so I won't spend too much energy defending it. The look is easiest, of course. There's more to the look than just that, of course, there's things like the stock behavior of controls. wxPython gets that mostly for free, because it's using actual native controls. There's things like the button order and layout, and wx provides APIs to address that. Not everyone uses them, which is too bad. There's some standard platform conventions like where your menu items go. wx provides support for that. There's the fairly minor issues of making sure your layout works with differently sized controls and text, the wx layout mechanism addresses that. Finally, there's some poorly defined mac style issues. wx, and no toolkit, not even the native one, can address that. Many cross platform apps are written on Windows with windows users in mind and use windows assumptions, like that it's fine for a context menu to be the only way to interact with something. This category is where almost all complaints against cross platform apps fall, and it's ridiculous because it's not something that a toolkit can address. You can, and people do, write exactly the same sort of interface into mac native applications. FinkCommander is a good example. There's a few more caveats I haven't addressed, and there are places where wx isn't perfect. In wxPython, there are quite a few commonly used controls that are custom controls hand-designed in Python, and don't wrap native controls, so that can be a problem. It's not a panacea, and anyone who sells it as such is wrong. But it doesn't suck, either. And it's a lot easier than maintaining multiple GUI codebases, especially for platforms that don't see as much use. Why are there so few applications? The real answer is probably that the mac developer community is smaller than either the windows or linux dev community, and people who develop for the mac tend not to care about any other platform. So most of the crossover comes from the other direction, and the mac community, being elitist assholes, makes scathing comments about how it assumes you have 2 mouse buttons. FYI: OS X ships with wxWidgets installed. How many applications built into OS X are built using it? Are you sure? How would you know? -- http://mail.python.org/mailman/listinfo/python-list
update attribute - (newbie)
class A: ... def __init__(self): ... self.t = 4 ... self.p = self._get_p() ... def _get_p(self): ... return self.t ... a = A() a.p 4 a.t += 7 a.p 4 I would like to have it that when I ask for p, method _get_p is always called so that attribute can be updated. How can I have this functionality here? thanks -- http://mail.python.org/mailman/listinfo/python-list
Re: Good Looking UI for a stand alone application
The Night Blogger wrote: Can someone recommend me a good API for writing a sexy looking (Rich UI like WinForms) shrink wrap application My requirement is that the application needs to look as good on Windows as on the Apple Mac I would download the wxPython demo and test it on all platforms if I were you: no coding and you see stuff right away / decide whether it is a good choice. ... I know it is mine (although I must confess I never tried it on a mac). hg -- http://mail.python.org/mailman/listinfo/python-list
permutations - fast with low memory consumption?
Hi, I'd like to hack a function which returns all possible permutations as lists (or tuples) of two from a given list. So far, I came up with this solution, but it turned out to be too slow for the given problem, because the list passed (atomlist) can be some 1e5 items long: def permute(atomlist, size = 2): returns a list of atoms grouped by two if not size or not atomlist: return [atomlist[:0]] else: result = list() for i in xrange(len(atomlist)): pick = atomlist[i:i+1] # sequence slice remainder = atomlist[:i] + atomlist[i+1:] # keep [:i] part for x in __permute(remainder, size = size - 1): result.append(pick + x) return result Does anybody know a solution which consumes less memory and is possibly faster, perhaps using generator expressions? All my attempts so far failed. Any help appreciated! TIA Christian -- http://mail.python.org/mailman/listinfo/python-list
Re: Can a Tkinter GUI check for abort script:
Michael Yanowitz wrote: Hello: I have successfully implemented a Tkinter GUI which has this (simplified here for explanation): +-+ | filename: [./test3.py] | | | | [Run Script] | +-+ But, now what I would like to do while the script is running, is replace the Run Script with Abort Script. +-+ | filename: [./test3.py] | | | | [Abort Script] | +-+ So, every tenth of a seconds or ??? better time, I would like to 'return' to the GUI and check if the Abort Script button has been pressed. How do I do this? Or is there a better way to implement this? Thanks in advance: Michael Yanowitz It depends: As you cannot kill a thread in Python, you need some mechanism to stop your script another way (is that a python script or a .sh / .bat ? ... from what you're writing, it seems you're calling some external entity which just might launch a bunch of processes) So do you or not control the inner workings of that external script ? If you don't, then killing might be the way as posted / clearly the methord will change from environment to environment. hg -- http://mail.python.org/mailman/listinfo/python-list
getting subchild of a tree through xerces
Hi I m able to parse xml file using xerces as well as JAXP but I am unable to parse the sub- child of my tree Eg : mosaic class name hello method name=call type=void...(not able to parse this) /method /class class name=demo /class /mosaic But I m unable to parse the child of classhello .but I m able to parse the .sibling of class What should I do... Regards Divya -- http://mail.python.org/mailman/listinfo/python-list
FW: [Jython-users] ERROR : parsing xml in jython
Hi But I am unable to parse all the nodes of the tree .especially the subtree of the main tree It displays only the sibling not the subtree Regards Divya -Original Message- From: Matthias Berth [mailto:[EMAIL PROTECTED] Sent: Tuesday, December 19, 2006 3:18 PM To: Divya Prakash Subject: Re: [Jython-users] ERROR : parsing xml in jython Hi, looks like you have to make an InputSource from the file, like so: from java.io import File, FileReader, StringReader textReader = FileReader(File(filename)) inputSource = InputSource(textReader) dp.parse(inputSource) Hope this helps Matthias Divya Prakash schrieb: Hi All, I m facing the problem while parsing xml file .. My code is :- import sys from org.apache.xerces.parsers import DOMParser as dp import javax.xml.parsers infilename = open(mos.xml,r) print infilename def test(infilename): Parse XML document and show attributes and names. print infilename parser = dp() print parser gh = parser.parse(infilename) print gh doc = parser.getDocument() node = doc.getFirstChild() print Attributes: show_attrs(node) print Names: show_names(node) -- http://mail.python.org/mailman/listinfo/python-list
Re: update attribute - (newbie)
Bruce wrote: class A: ... def __init__(self): ... self.t = 4 ... self.p = self._get_p() ... def _get_p(self): ... return self.t ... a = A() a.p 4 a.t += 7 a.p 4 I would like to have it that when I ask for p, method _get_p is always called so that attribute can be updated. How can I have this functionality here? thanks You need to use a property, there are several possibilities to do so, a common idiom is this: class A(object): # must be newstyle def __init__(self): self._p = 6 def get_p(self): return self._p def set_p(self, v): self._p = v p = property(get_p, set_p) Diez -- http://mail.python.org/mailman/listinfo/python-list
Using difflib to compare text ignoring whitespace differences
Hi I'm trying to compare some text to find differences other than whitespace. I seem to be misunderstanding something, since I can't even get a basic example to work: In [104]: d = difflib.Differ(charjunk=difflib.IS_CHARACTER_JUNK) In [105]: list(d.compare([' a'], ['a'])) Out[105]: ['- a', '+ a'] Surely if whitespace characters are being ignored those two strings should be marked as identical? What am I doing wrong? Thanks Neilen -- you know its kind of tragic we live in the new world but we've lost the magic -- Battery 9 (www.battery9.co.za) -- http://mail.python.org/mailman/listinfo/python-list
Re: update attribute - (newbie)
Bruce wrote: class A: ... def __init__(self): ... self.t = 4 ... self.p = self._get_p() ... def _get_p(self): ... return self.t ... a = A() a.p 4 a.t += 7 a.p 4 I would like to have it that when I ask for p, method _get_p is always called so that attribute can be updated. How can I have this functionality here? thanks Something like this? class A: def __init__(self): self.t=4 return def __getattr__(self, name): if name == 'p': return self.t else: return self.__dict__[name] if __name__ == __main__: a=A() print a.p a.t+=7 print a.p -- http://mail.python.org/mailman/listinfo/python-list
Re: Is htmlGen still alive?
If starship does not get up anymore (give it a few hours) you might want to have a look here: http://www.python.org/ftp/python/contrib-09-Dec-1999/Network/ Else, I can send you a tarfile of version 2.1, too. As hg said, apart from a few deprecation warnings it's working fine for me (but I'm only using it for one internal site, where layout doesn't matter ...). Cheers Christian [EMAIL PROTECTED] wrote: Does anybody know whether htmlGen, the Python-class library for generating HTML, is still being maintained? Or from where it can be downloaded? The Starship site where it used to be hosted is dead. Thanks for your help! Klaus Muller -- http://mail.python.org/mailman/listinfo/python-list
Re: permutations - fast with low memory consumption?
On 12/19/06, Christian Meesters [EMAIL PROTECTED] wrote: Hi, I'd like to hack a function which returns all possible permutations as lists (or tuples) of two from a given list. So far, I came up with this solution, but it turned out to be too slow for the given problem, because the list passed (atomlist) can be some 1e5 items long: Anything here? http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/190465 -- Cheers, Simon B [EMAIL PROTECTED] -- http://mail.python.org/mailman/listinfo/python-list
Re: permutations - fast with low memory consumption?
Christian Meesters wrote: Hi, I'd like to hack a function which returns all possible permutations as lists (or tuples) of two from a given list. So far, I came up with this solution, but it turned out to be too slow for the given problem, because the list passed (atomlist) can be some 1e5 items long: snip Does anybody know a solution which consumes less memory and is possibly faster, perhaps using generator expressions? All my attempts so far failed. No claims with respect to speed, but the kslice function here: http://gflanagan.net/site/python/utils/sequtils/ will give the 'k-subsets' which then need to be permuted - alternatively Google. Gerard -- http://mail.python.org/mailman/listinfo/python-list
Re: permutations - fast with low memory consumption?
Thanks Simon Gerard! I will check those exampels out. Christian PS Of course, I did google - but apparently not creative enough. -- http://mail.python.org/mailman/listinfo/python-list
Need Help on IDLE start up
Hello I have install Python 2.5 under an user directory /user/dtgtools/packages/python/2.5 after installation python works ok. but when I try idle I have the following Error message: ** IDLE can't import Tkinter. Your Python may not be configured for Tk. ** I have read the README file it mentions the setup.py script should take care of the TCl/TK setup. but I wonder because our TCL/TCL is install under /user/dtgtools/packages/TCL/8.4 how can I let ./configure know where to find Tcl/TK ? when installing Python. Thanks in advance! Tony Ha. -- http://mail.python.org/mailman/listinfo/python-list
Re: Core dump revisited
Sheldon wrote: snip Program received signal SIGSEGV, Segmentation fault. [Switching to Thread 1077321856 (LWP 32710)] 0x40297b83 in mallopt () from /lib/tls/libc.so.6 (gdb) bt #0 0x40297b83 in mallopt () from /lib/tls/libc.so.6 #1 0x402958ba in free () from /lib/tls/libc.so.6 #2 0x405e070a in MemoryFreeOrd () at msgppsmodule_area.c:1675 #3 0x405dae0a in msgppsarea (self=0x0, args=0x4042aa7c, kwargs=0x0) at msgppsmodule_area.c:328 #4 0x40073b16 in PyCFunction_Call () from /usr/lib/libpython2.3.so.1.0 From my experience, segmentation faults in malloc/free is usually the result of memory corruption. My experience comes mostly from solaris and I realize the memory allocator might work differently in Linux, but that would be my guess. The cause for memory corruption can be writing outside arrays, using deallocated memory or something like that. Under Linux, there are tools like valgrind (free), electric fence (free), purify (not for free last time I checked) and probably a few more, that may help you track down memory corruption bugs. They are often hard to find using just a debugger. HTH -- http://mail.python.org/mailman/listinfo/python-list
Re: When Closure get external variable's value?
Thanks for the clarification. But my question is: When does the closure get the value of the maxIndex in the following code snippet? def testClosure(maxIndex) : def closureTest(): return maxIndex maxIndex += 5 return closureTest() print testClosure(10) I thought it should be 10 instead of 15. That was wrong. After several tests, I found maxIndex is, though, local to testClosure() but is external to the closureTest(). closureTest() gets the value of maxIndex at run time. So that it's 15 instead of 10. The following snippet will verify that further: def testClosure1(lst): def closureTest(): lst.append(lst[-1]+1) lst.append(lst[-1]+1) return closureTest() alist = [1] testClosure1(alist) alist.append(3) testClosure1(alist) The 'lst' in function testClosure1() and the closure closureTest() are same thing as alist. So everything is dynamic. Variable's value is determined at run time. -- http://mail.python.org/mailman/listinfo/python-list
Re: tuple.index()
Roy Smith wrote: In article [EMAIL PROTECTED], greg [EMAIL PROTECTED] wrote: Roy Smith wrote: The struct does lookup by name, the tuple is inherently index based. I was trying to help people understand the distinction we're talking about by showing an example of the same distinction in another language where it's much clearer. There are a great many ways in which C structs are different from Python tuples, and C arrays are different from Python lists. But they're not the aspects I'm drawing an analogy between. -- Greg Well, yeah, but it's kind of like saying a tangerine and an orange are very different things because one of them is like an apple and the other one is like a pear :-) Actually, I found the distinction a bit more helpful than that--more like saying, a tangerine and a pear are very different things because one of them is like an orange and the other is like an apple. Still not a precise definition, but a useful analogy in many ways. Cheers, Cliff -- http://mail.python.org/mailman/listinfo/python-list
Re: tuple.index()
James Stroud wrote: Christoph Zwerschke wrote: Inhomogenous in some meaning of the word -- tuple I think that you have nailed it here. I don't think anyone on this list is capable of giving a concrete (as you have put it) operational definition of inhomogenous. They will resort to use cases and thus cloud the definition with programming philosophy. How about: A heterogenous sequence is one in which each element plays a unique role, specific to its position in the sequence. A homogenous sequence is one in which position is determinative of nothing significant other than (perhaps) order. I'm not exactly sure what you mean by programming philosophy. I suspect it does enter into the choice of which to use, (as programming philosophy determines whether a database will have a name field, or lastname, firstname, and middlename fields) but I don't see that this clouds the definitions, necessarily. So, programming philosophy, whether it will be admitted or not, is fully responsible for the exclusion of index() from the tuple interface. No. Because as pointed out in another subthread, the exclusion of index() from the tuple interface is in many ways orthogonal to the issue of homogeneity/heterogeneity. It's partly that, and partly that The Maintainers have decreed that the workarounds (list(mytuple).index()) are trivial enough to obviate the need for making all the changes to the source code, and hacking something ugly (a linear search has been suggested) into all unsuspecting hand-rolled subscriptable objects. But perhaps we could take not necessarily homogenous to be the operational definition of inhomogenous. Of course then we would have to define necessary... James I doubt the python interpreter will ever try to enforce homogeneity/heterogeneity on lists/tuples, in part because there no good ways of definining it syntactically, and in part because there are certainly good reasons for breaking the rules. As someone said: passing lists to untrustworthy functions. And as someone else said, *args passes a tuple, even though it is frequently just a homogenous list of more arguments. Forgive me for referencing throughout the threads without proper citation. I've been ill all weekend, and I just don't feel like doing it right. Cheers, Cliff -- http://mail.python.org/mailman/listinfo/python-list
Re: permutations - fast with low memory consumption?
Gerard Flanagan wrote: No claims with respect to speed, but the kslice function here: http://gflanagan.net/site/python/utils/sequtils/ will give the 'k-subsets' which then need to be permuted - alternatively Google. Maybe the function below could then do these permutations. Anton. def _sorted(seq): Return a sorted copy of seq, preserving the type. res = seq[0:0] decorated = ((x,i) for i,x in enumerate(seq)) for x,i in sorted(decorated): res += seq[i:i+1] return res def _swap_and_reverse_tail(R,i,j): Swap R[i] and R[j], reverse R[i+1:]. Returns a copy, preserving the type. a,b,c,d,e = R[:i],R[i:i+1],R[i+1:j],R[j:j+1],R[j+1:] return a+d+(c+b+e)[::-1] def permutations(seq): Generate sorted permutations of any sequence that can be indexed and sliced, preserving the type. e.g. seq can be a string, list, tuple or array. n = len(seq) if n == 1: yield seq[:] elif n = 2: R = _sorted(seq) while True: yield R i,j = n-2,n-1 while R[i] = R[i+1] : i -= 1 if i == -1: return while R[i] = R[j]: j -= 1 R = _swap_and_reverse_tail(R,i,j) def test(): seq = 'gkDr217sKGMNLPsrtqeiczxyq' P = permutations(seq) for i,x in enumerate(P): print '%s' %(x) if i == 10: break if __name__ == '__main__': test() -- http://mail.python.org/mailman/listinfo/python-list
Re: Core dump revisited
Nick Craig-Wood skrev: Sheldon [EMAIL PROTECTED] wrote: Sheldon skrev: Wonderful! Now I know how to used gdb with python. Good! The are results area posted below. Since I am new at this I could used some help in interpreting the problem. What I do know is this: my allocation of the array is good but when freeing the array, a problem arises. The problem is given below but since I am new as well to C Ambitious! I sure could use some help. Program received signal SIGSEGV, Segmentation fault. [Switching to Thread 1077321856 (LWP 32710)] 0x40297b83 in mallopt () from /lib/tls/libc.so.6 (gdb) bt #0 0x40297b83 in mallopt () from /lib/tls/libc.so.6 #1 0x402958ba in free () from /lib/tls/libc.so.6 #2 0x405e070a in MemoryFreeOrd () at msgppsmodule_area.c:1675 #3 0x405dae0a in msgppsarea (self=0x0, args=0x4042aa7c, kwargs=0x0) at msgppsmodule_area.c:328 #4 0x40073b16 in PyCFunction_Call () from /usr/lib/libpython2.3.so.1.0 Typing up and down to move up and down the call stack is a good thing. Type l to see a list of code at the point that things went wrong. You can type print variablename to see the values of variables. gdb understands most C syntax so you can use print this-member[1].data etc. This all assumes you compiled and linked with debugging (-g flag to compiler and linker). Turning off optimisation may make the debugger more accurate also. I can't tell exactly where your program crashed because of line wrapping it your post, but is it certainly within MemoryFreeOrd(). What I would do next is run the program under gdb, wait for it to crash then print the values of things in the MemoryFreeOrd() function. You'll find one of the pointers has been corrupted, ie doesn't point to valid memory or memory allocated with malloc() I expect. 0 or NULL is an acceptable input to most free() implementations but not all. Finding out exactly where that pointer got corrupted is harder. Maybe it was never initialised, or maybe you initialised it with a PyObject or maybe you have a memory scribble somewhere. A memory scribble is the hardest bug to find because it happened elsewhere in your program. Look at the data that was overwritten. Maybe it is a string you can identify... You'll also want to start reading the gdb manual on breakpoints and watchpoints at this moment! Find memory corruptions can be tricky and time consuming. Valgrind can help also. Good luck! -- Nick Craig-Wood [EMAIL PROTECTED] -- http://www.craig-wood.com/nick Man. You are good. This is most insight I have had from anyone. I did initialize the arrays with PyObjects and today, after hours of debugging and now with your insight, I think the problem lies here: /* here a python list of strings is read into a C string array */ static int readPythonObject(void) { int i; PyObject *msgop; PyObject *ppsop; PyObject *tileop; PyObject *sceneop; for (i = 0; i work.sumscenes; i++) { msgop = PyList_GetItem(work.msgobj, i); work.msg_scenes[i] = PyString_AsString(msgop); ppsop = PyList_GetItem(work.ppsobj, i); work.pps_scenes[i] = PyString_AsString(ppsop); } for (i = 0; i NumberOfTiles; i++) { tileop = PyList_GetItem(work.tileobj, i); work.tiles[i] = PyString_AsString(tileop); sceneop = PyList_GetItem(work.nscenesobj, i); work.nscenes[i] = PyInt_AsLong(sceneop); } return 1; } /*end readPythonObject*/ I am new to this and copied this code from a colleague. So, it corrupts the pointer. How do I do this properly? Your help is truly appreciated! /S -- http://mail.python.org/mailman/listinfo/python-list
FW: Crash in PyImport_Import()
Hi, And everything works fine if I link with the shared version of python. The ldap extension works fine in the interpreter, as well as with embedded python. Does anyone knows why it seems to be needed that extension modules have to be linked against the shared version of python? Regards, Geert _ From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Geert Van Muylem Sent: maandag 18 december 2006 22:51 To: python-list@python.org Subject: Crash in PyImport_Import() Hi, The following script works fine when I call it from the python interpreter but not when I call it from a c application (embedded python) It crashes in the PyImport_Import() import ldap import distutils.sysconfig def TestInit(): l = ldap.open(192.168.1.2) l.simple_bind_s(,) l.search_s(c=BE, ldap.SCOPE_SUBTREE, objectclass=*) s = distutils.sysconfig.get_config_var('LINKFORSHARED') - Python (2.5) and python-ldap (2.2.1) are recompiled for my environment (hardened linux.) Here is part of my makefile: VERSION = Python-2.5 VERSION_LDAP = python-ldap-2.2.1 compile: .python .python-ldap .python:makefile.python .glibc $(VERSION).Setup.local $(EXTRACT_PACKAGE) \ $(CP) ../$(VERSION).Setup.local Modules/Setup.local \ ./configure --prefix=/usr --enable-shared=no \ make \ make install cp $(VERSION)/libpython2.5.a /usr/lib/libpython.a (cd /usr/include; $(LN) -sf python2.5 python ) touch .python .python-ldap: makefile.python .python .sasl .glibc .openldap python-ldap.setup.cfg (rm -rf $(VERSION_LDAP) || /bin/true) \ tar xjf $(ARCHIVE_PACKAGES)/$(VERSION_LDAP).tar.bz2 \ cd $(VERSION_LDAP) \ $(CP) ../python-ldap.setup.cfg setup.cfg \ python setup.py build \ python setup.py install rm -rf $(VERSION_LDAP) touch .python-ldap And my setup.cfg # Example for setup.cfg # You have to edit this file to reflect your system configuation # $Id: setup.cfg.suse-linux,v 1.1 2003/08/20 10:04:34 stroeder Exp $ [_ldap] # Section for compiling the C extension module # for wrapping OpenLDAP 2 libs library_dirs = /usr/lib/ /usr/lib/sasl2/ include_dirs = /usr/include/sasl/ /usr/include/sasl2/ extra_compile_args = extra_objects = # Example for full-featured SuSE build: # Support for StartTLS/LDAPS, SASL bind and reentrant libldap_r. # This needs recent OpenLDAP 2.0.26+ or 2.1.3+ built with #./configure --with-cyrus-sasl --with-tls libs = python ldap_r lber sasl2 ssl crypto resolv dl db m util pthread [install] # Installation options compile = 1 optimize = 1 Everything is done in a chroot-ed environment...when building python-ldap, it uses the newly installed python includes The test application is linked against the static version libpython.a int CPyLDAP::Init() { m_iPython = 1; printf (Before Py_Initialize...\n); Py_Initialize(); printf (After Py_Initialize...\n); PyObject *pName = PyString_FromString(PyTest); if ( pName != NULL ) { // Load the Python module printf (Before Import...\n); m_pModule = PyImport_Import(pName); printf (After Import...\n); if (m_pModule != NULL) { m_iPython = 0; m_pDictionary = PyModule_GetDict(m_pModule); } } return (m_iPython); } Hope someone can give me a hint? thanks, Geert -- http://mail.python.org/mailman/listinfo/python-list-- http://mail.python.org/mailman/listinfo/python-list
Re: python-hosting.com projects: dead?
Fredrik Lundh wrote: have you tried mailing webfaction instead of ranting on the usenet? I did. I didn't get a reply within minutes (indeed not until this morning), so I posted a public message to try to find out if anyone knew what was going on -- and also to warn other people whose projects might have suddenly disappeared. As of this morning my project is back online, so my thanks to python hosting/webfaction for that. I'm very grateful to them for the great free service they have provided. I'm sorry that they are getting killed with spam, but I'm also sorry that they chose to handle the problem in the way that they did. I had no way of knowing when I'd have access to my svn repository and tickets again. I'm sure you can understand why I was dismayed by this and why, unfortunately, I'll never be comfortable trusting my data to them again. JP -- http://mail.python.org/mailman/listinfo/python-list
Re: When Closure get external variable's value?
Huayang Xia wrote: When does the closure get the value of the maxIndex in the following code snippet? def testClosure(maxIndex) : def closureTest(): return maxIndex maxIndex += 5 return closureTest() print testClosure(10) I thought it should be 10 instead of 15. That was wrong. free variables in an inner scope bind to variables in the outer scope, not objects. if you want to bind to objects, use explicit binding: def closureTest(maxIndex=maxIndex): return maxIndex /F -- http://mail.python.org/mailman/listinfo/python-list
Re: def index(self):
Gert Cuykens a écrit : FWIW, the first version raises an exception (unless of course the name 'index' is already bound in the enclosing scope). And the second won't probably work as expected with CherryPy. code class HelloWorld: def index(self): return Hello world! index.exposed = True #DOOH! And the winner is /code i skipped reading the chapter about 2.1.8 Indentation. Guess how many hours it took to realize 2 spaces isn't the same as 1 space lol Hint: - use a good code editor with auto(de)indentation (emacs + python-mode is quite nice) - use 4 spaces for indentation Any other chapters i should read horizontal instead of vertical for a php5 htm jso wane be snake user :) The whole thing, I guess. While Python is quite easy to get started with, there are a few gotchas. You're above snippet should be: class HelloWorld(object): def index(self): return Hello World index.exposed = True -- http://mail.python.org/mailman/listinfo/python-list
SQLALCHEMY - Method to have the last word, by Michael Bayer
[1] - Ο/Η metaperl: TurboEntity was quite sweet. Supposedly a complete rewrite as a new product is on its way though. Ilias Lazaridis: the first major problem of this rewrite: it happens 'silently' (non-public) Michael Bayer wrote within: http://groups.google.com/group/sqlalchemy/msg/9d7a096a61abfc6f django was not available to the public until it was fully functional (youd go to the site and just get a coming soon-style splash page)..and even then it was already in production use in earlier forms. they knew that if you release something that wasnt polished and would lead to user frustration, people would get disinterested and leave. the strategy seems to have worked for them. I understand your elaborations. Possibly sqlalchemy should do the same, until it's fully functional and do not 'frustrate users'. And Turbogears, too. And Django, as it's still not fully functional (mainly due to it's deficient ORM layer). Or all those projects remain open(!), allowing users and contributors to review the source(!), in order to be able to contribute requirements, ideas, patches, sources etc.! its not your grandfather's open source community ! Please keep relatives out of discussions. - [1] Continueing a thread from sqlalchemy group) within comp.lang.python (closest public usenet group), because Michael Bayer has closed the thread within google.groups (no reply possible to anyone) prior to enabling my answer to his message. http://groups.google.com/group/sqlalchemy/msg/841b3b14d8108ac0 . -- http://dev.lazaridis.com/base -- http://mail.python.org/mailman/listinfo/python-list
Re: python-hosting.com projects: dead?
[EMAIL PROTECTED] wrote: my svn repository and tickets again. I'm sure you can understand why I was dismayed by this and why, unfortunately, I'll never be comfortable trusting my data to them again. not really, but maybe I've just worked with computers and human beings long enough not to treat every little hiccup as if it were the end of the world as we know it. /F -- http://mail.python.org/mailman/listinfo/python-list
Re: python poetry?
BartlebyScrivener a écrit : I'm working on a book of technology and computer programming humor. First, can anybody recommend any other such books? You of course alreeady know Tao of programming and BOFH (aka the Bastard Operator From Hell') ? -- http://mail.python.org/mailman/listinfo/python-list
Reduced invective
My fat-fingered alter ego typed delete from iv where date '2006-01-01'; instead of delete from iv where date '2006-12-01'; leaving me with 50 tables to reload. :( estimated time to fix several hours estimated invective dispensed during fix = classified Python to the rescue! import os import MySQLdb files = os.listdir(d:\\hedge\\old data\\) conn = MySQLdb.connect(host = 'host', user = 'user', passwd = 'pass', db = 'db') curs = conn.cursor() for line in files: if line[-4:] == 2006: SQL = LOAD DATA SQL += INFILE 'd:/hedge/old data/ + line SQL += ' INTO TABLE iv SQL += FIELDS TERMINATED BY ',' SQL += (symbol, date, iv, pv, cv); curs.execute(SQL) time to execute = 5 mins invective dispensed while executing = 0 A hearty thank you and Happy Holidays to all in the Python community. jab -- http://mail.python.org/mailman/listinfo/python-list
Re: tuple.index()
In article [EMAIL PROTECTED], J. Clifford Dyer [EMAIL PROTECTED] writes: | | How about: A heterogenous sequence is one in which each element plays a | unique role, specific to its position in the sequence. A homogenous | sequence is one in which position is determinative of nothing | significant other than (perhaps) order. Nope. Sorry. Consider the old model where an I/O list is an ordered sequence of strings and agents (effectively procedure calls), with no constraints on how those are ordered. With your specification, that is neither heterogenous nor homogenous :-) | I doubt the python interpreter will ever try to enforce | homogeneity/heterogeneity on lists/tuples, in part because there no good | ways of definining it syntactically, and in part because there are | certainly good reasons for breaking the rules. As someone said: passing | lists to untrustworthy functions. And as someone else said, *args | passes a tuple, even though it is frequently just a homogenous list of | more arguments. It's a complete delusion, because even the claimed assumption of list homogeneity is tantmount to saying that Python doesn't encourage (or, arguably, support) ANY way of using mutable heterogenous sequences (such as the example above). To claim that they are inherently an undesirable programming practice is a clear descent into religion! I would be amused to know what Python type the lists are intended to be homogenous people use to implement mutable heterogenous sequences, or whether they claim that wanting such a feature is heresy :-) Regards, Nick Maclaren. -- http://mail.python.org/mailman/listinfo/python-list
Cpoying a PyList to a C string array
Hi, The code below is a rookie attempt to copy a python list of strings to a string array in C. It works to some extent but results in memory problems when trying to free the C string array. Does anyone know how to do this properly? *** /*Read an list of strings from a python object*/ static int readPythonObject(void) { int i; PyObject *msgop; PyObject *ppsop; PyObject *tileop; PyObject *sceneop; for (i = 0; i work.sumscenes; i++) { msgop = PyList_GetItem(work.msgobj, i); work.msg_scenes[i] = PyString_AsString(msgop); ppsop = PyList_GetItem(work.ppsobj, i); work.pps_scenes[i] = PyString_AsString(ppsop); } for (i = 0; i NumberOfTiles; i++) { tileop = PyList_GetItem(work.tileobj, i); work.tiles[i] = PyString_AsString(tileop); sceneop = PyList_GetItem(work.nscenesobj, i); work.nscenes[i] = PyInt_AsLong(sceneop); } return 1; } /*end readPythonObject*/ *** /S -- http://mail.python.org/mailman/listinfo/python-list
Re: SQLALCHEMY - Method to have the last word, by Michael Bayer
I understand your elaborations. Possibly sqlalchemy should do the same, until it's fully functional and do not 'frustrate users'. And Turbogears, too. And Django, as it's still not fully functional (mainly due to it's deficient ORM layer). Or all those projects remain open(!), allowing users and contributors to review the source(!), in order to be able to contribute requirements, ideas, patches, sources etc.! Except from outrageous demands and feeble default-parameter-alterations I've yet to encounter anything that is an actual contribution to the half dozen Python FOSS projects I've observed you evaluating. How about stop whining, and start contributing real code? Better yet, start your fabled ORM layer and see who's willing to join. its not your grandfather's open source community ! Please keep relatives out of discussions. Please keep discussions that for a good reason have been closed due to your inability to communicate with fellow human beings where they belong: in the dark abyss the news and mailing list archives of google are. And stop hurling them over to c.l.py like a small child complaining that the others won't play with it anymore, just because it smeared it's poo over their toys. You keep too much brain- and virtual-space occupied, space that otherwise could be used to produce useful stuff. So - stop it, go away, and please, pretty please with sugar on top: don't come back. Python doesn't need you, this NG doesn't need you, no FOSS project needs you. Buy a dog. That needs you. Until it runs away from being evaluated. Diez -- http://mail.python.org/mailman/listinfo/python-list
Re: python poetry?
Bruno Desthuilliers wrote: You of course already know . . . and BOFH (aka the Bastard Operator From Hell') ? Didn't know this one. It's funny! Thanks rd -- http://mail.python.org/mailman/listinfo/python-list
Re: python poetry?
BartlebyScrivener wrote: First, can anybody recommend any other such books? And second is there a repository of Python poetry, poems translated into Python, or humorous Python pseudo code limericks anywhere? I'm making my way through The Larch, but if there's more elsewhere please point me to it. Aroldo Souza-Leite did Sonnets from Pythia presentations/workshops at EuroPython in 2004 and 2005, but I don't know if he's ever published the material. google is your friend. /F -- http://mail.python.org/mailman/listinfo/python-list
Re: python-hosting.com projects: dead?
Fredrik Lundh wrote: [EMAIL PROTECTED] wrote: my svn repository and tickets again. I'm sure you can understand why I was dismayed by this and why, unfortunately, I'll never be comfortable trusting my data to them again. not really, but maybe I've just worked with computers and human beings long enough not to treat every little hiccup as if it were the end of the world as we know it. You're misreading me very badly, or I'm expressing myself very poorly. Either way, you've inferred some kind of spittle-flecked freakout where I did not mean to imply one. JP -- http://mail.python.org/mailman/listinfo/python-list
Re: permutations - fast with low memory consumption?
Christian Meesters [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] Hi, I'd like to hack a function which returns all possible permutations as lists (or tuples) of two from a given list. So far, I came up with this solution, but it turned out to be too slow for the given problem, because the list passed (atomlist) can be some 1e5 items long: def permute(atomlist, size = 2): returns a list of atoms grouped by two if not size or not atomlist: return [atomlist[:0]] else: result = list() for i in xrange(len(atomlist)): pick = atomlist[i:i+1] # sequence slice remainder = atomlist[:i] + atomlist[i+1:] # keep [:i] part for x in __permute(remainder, size = size - 1): result.append(pick + x) return result Does anybody know a solution which consumes less memory and is possibly faster, perhaps using generator expressions? All my attempts so far failed. Any help appreciated! TIA Christian Am I correct in understanding that you want to find the permutations of a list up to 1e5 elements in length, taken 2 or more at a time? FYI, P(1e5,2) evaluates to just under 10 billion, so I would suggest some implementation other than a function that returns a list of all of the permutations (think generator). Wikipedia also includes a pseudocode algorithm for computing permutations (http://en.wikipedia.org/wiki/Permutation), but beware, it appears to be 1-based. -- Paul -- http://mail.python.org/mailman/listinfo/python-list
Re: Core dump revisited
Sheldon [EMAIL PROTECTED] wrote: I am new to this and copied this code from a colleague. So, it corrupts the pointer. How do I do this properly? Here is at least part of your problem: msgop = PyList_GetItem(work.msgobj, i); work.msg_scenes[i] = PyString_AsString(msgop); ppsop = PyList_GetItem(work.ppsobj, i); work.pps_scenes[i] = PyString_AsString(ppsop); ... free(work.pps_scenes[i]); free(work.msg_scenes[i]); You initialised msg_scenes and pps_scenes with a malloc'ed block but you then just overwrote the pointer with the result of PyString_AsString. You don't own the memory for the string returned from PyString_AsString, so freeing it will cause a corruption. You should copy the string data into the malloc'ed block (with appropriate length checks). -- http://mail.python.org/mailman/listinfo/python-list
Re: SQLALCHEMY - Method to have the last word, by Michael Bayer
Ο/Η Diez B. Roggisch έγραψε: ... (several off-topics) Please control yourself. Ï/Ç metaperl: TurboEntity was quite sweet. Supposedly a complete rewrite as a new product is on its way though. Ilias Lazaridis: the first major problem of this rewrite: it happens 'silently' (non-public) 3 projects (TurboEntity, ActiveMapper, and one unpublished) join, in order to provide an better ORM layer for Python. How is the project moving on? How can one contribute? I don't know - does anyone have more information? . -- http://case.lazaridis.com/wiki/Persist -- http://mail.python.org/mailman/listinfo/python-list
Re: When Closure get external variable's value?
That is a really concise and precise answer. Thanks. So the object binding can only happen explicitly at the closure declaration argument list(non-free variable). On Dec 19, 10:37 am, Fredrik Lundh [EMAIL PROTECTED] wrote: Huayang Xia wrote: When does the closure get the value of the maxIndex in the following code snippet? def testClosure(maxIndex) : def closureTest(): return maxIndex maxIndex += 5 return closureTest() print testClosure(10) I thought it should be 10 instead of 15. That was wrong.free variables in an inner scope bind to variables in the outer scope, not objects. if you want to bind to objects, use explicit binding: def closureTest(maxIndex=maxIndex): return maxIndex /F -- http://mail.python.org/mailman/listinfo/python-list
Re: SQLALCHEMY - Method to have the last word, by Michael Bayer
Ilias Lazaridis wrote: How can one contribute? you can't. /F -- http://mail.python.org/mailman/listinfo/python-list
Portable apps
Hi Group, I want to get into writing portable apps that can run solely off a USB stick, but I have a few problems. I'm originally a java/.net developer, but I don't want it to be a requirement that the host computer has .net or a jre installed. I also am not very fond of developing with VC++ *cry*. Also done some perl, so I checked out ruby, python, python hey python seems mature enough and has been around quite long. Yea Python. So, I wonder if its possible to make distributable python apps that run off a USB stick? SQLite seems to be a nice candidate for a USB stick database. wxPython for the GUI, or maybe even make webapp guis with Django? Hmm... Soo Checked out movable python, seems pretty nice but I wouldn't be able to distribute my app with movable python since it seems to require a separate license. :( Checked out py2exe but the whole django/sqlite business seems a bit iffy with py2exe. Probably wouldn't work and the exe could end up huge. I'd like to distribute python WITH my app, in a lightweight non-bloated way, somehow. Don't need a single exe, just a small zip, and one-click to launch. Should I be looking at something else than python? TCLKit? StarKIT? Best regards Andreas -- http://mail.python.org/mailman/listinfo/python-list
Re: python script terminating
Aditya Vaish wrote: I have a python script running on Debian sarge. It loops and walk through a directory while 1: for dirn in os.listdir(buildpath): if os.path.exists(os.path.join(buildpath, dirn, 'pass')) and dirn.find(build1) != -1: # case 1 Do something elif os.path.exists(os.path.join(buildpath, dirn, 'pass')) and dirn.find(build2) != -1: # case 2 Do something The script in turn calls a perl script to do something. The problem is that the python script is getting terminated while the perl script is running and thus the program called by the perl script is hung. so how do you run the perl script ? /F -- http://mail.python.org/mailman/listinfo/python-list
Re: on PySol's popularity
Fredrik Lundh [EMAIL PROTECTED] writes: Tshepang Lekhonkhobe wrote: On Python docs, on faq/installed.html, it's mentioned that PySol is the most common Python application. not really; that page says that installing PySol is a common way to get a Python installation installed without noticing, not that PySol is in itself the most common Python application. and the entire python.org FAQ is horribly outdated. we're working on a replacement, which is currently hosted here: http://effbot.org/pyfaq/installed-why-is-python-installed-on-my-machine.htm /F A plug for PySol. My wife is totally non-techno. She doesn't get the notions of windows, or minimize/maximize, or clicking on the icon down on the toolbar. But she does get PySol. When I recently upgraded, I had to reinstall Python2.2 in order to use the old PySol binaries (couldn't get the build-from-source to work). Linux and Python got a fan due to PySol. It should be considered a cultural treasure, and if a bit of funding would help keep it rolling into the future, that might be worthwhile. -- Harry George PLM Engineering Architecture -- http://mail.python.org/mailman/listinfo/python-list
wxPython and activex problem.
Hi all! Have u tried genaxmodule.py provided by wxPython to create a wrapper module for an activex control? For me, some times it works, but some times, it doesn't. - Traceback (most recent call last): File genaxmodule.py, line 42, in ? main(sys.argv) File genaxmodule.py, line 32, in main axw = wx.activex.ActiveXWindow(f, clsid) File C:\Python23\Lib\site-packages\wx-2.6-msw-ansi\wx\activex.py, line 268, in __init__ newobj = _activex.new_ActiveXWindow(*args, **kwargs) wx._core.PyAssertionError: C++ assertion wxAssertFailure failed in contrib\activex\wxie/wxactivex.cpp(322): m_ActiveX.CreateInstance failed -- For some job, I do need to use activex and I have to choose languages other than python if genaxmodule doesn't work. It's really annoying. -- http://mail.python.org/mailman/listinfo/python-list
Re: New os.path.exists() behavior - bug or feature?
Martin v. Löwis schrieb: Neither, nor. In both cases, the operating system is asked, and gives this answer. However, in the Windows API, there is no exists function (nor is there on Unix); instead, exists is implemented by calling several underlying functions. The precise set of functions used did change between 2.4 and 2.5. It is quite difficult to investigate the precise nature of the change that leads to this change in observable behavior. If you think this is a bug, it would be best if you could also investigate a patch. I don't know if it is a bug; at least it is backwards incompatible, which I think is never a good thing. Unfortunately, I am afraid writing a patch is beyond my expertise :( Regards Michael -- http://mail.python.org/mailman/listinfo/python-list
Re: Core dump revisited
Duncan Booth skrev: Sheldon [EMAIL PROTECTED] wrote: I am new to this and copied this code from a colleague. So, it corrupts the pointer. How do I do this properly? Here is at least part of your problem: msgop = PyList_GetItem(work.msgobj, i); work.msg_scenes[i] = PyString_AsString(msgop); ppsop = PyList_GetItem(work.ppsobj, i); work.pps_scenes[i] = PyString_AsString(ppsop); ... free(work.pps_scenes[i]); free(work.msg_scenes[i]); You initialised msg_scenes and pps_scenes with a malloc'ed block but you then just overwrote the pointer with the result of PyString_AsString. You don't own the memory for the string returned from PyString_AsString, so freeing it will cause a corruption. You should copy the string data into the malloc'ed block (with appropriate length checks). Do you mean with: PyString_FromStringAndSize() and PyString_Size(PyObject *string) /S -- http://mail.python.org/mailman/listinfo/python-list
Re: Tkdnd--does anyone use it?
Kevin Walzer schrieb: Does anyone use the Tkdnd module that comes with Tkinter to allow drag-and-drop of Tkinter widgets in your application? (Not the binary extension that hooks into Xdnd and OLE-dnd on Windows.) I've looked at the various documents for Tkdnd, and it looks somewhat complicated, particulary if you want to use it outside of the canvas widget; I've also found very few examples of its actual use (as opposed to sample code snippets). I'm curious if anyone is actually using it in a production application and, if so, what your experience with it is. -- Kevin Walzer Code by Kevin http://www.codebykevin.com I use it in phonoripper (http://klappnase.zexxo.net/phonoripper.index.html) to drag files from a directory tree into a listbox. I found it to be less complicated than it looked at a first glance. If you like you can have a look at the DirTree and TrackTree modules to see how i use it. (I actually use Treectrl widgets instead of a Tkinter.Listbox and a slightly modified Tkdnd module, but the logic is the same). Regards Michael -- http://mail.python.org/mailman/listinfo/python-list
Re: on PySol's popularity
Harry A plug for PySol. Harry My wife is totally non-techno. She doesn't get the notions of Harry windows, or minimize/maximize, or clicking on the icon down on Harry the toolbar. My wife appears to be only slightly less non-techno than yours. Aside from mail and web browsing, PySol is her number one application. Harry [PySol] should be considered a cultural treasure, and if a bit of Harry funding would help keep it rolling into the future, that might be Harry worthwhile. Agreed, and +1 QOTW. Skip -- http://mail.python.org/mailman/listinfo/python-list
Re: tuple.index()
Nick Maclaren wrote: In article [EMAIL PROTECTED], J. Clifford Dyer [EMAIL PROTECTED] writes: | | How about: A heterogenous sequence is one in which each element plays a | unique role, specific to its position in the sequence. A homogenous | sequence is one in which position is determinative of nothing | significant other than (perhaps) order. Nope. Sorry. Consider the old model where an I/O list is an ordered sequence of strings and agents (effectively procedure calls), with no constraints on how those are ordered. With your specification, that is neither heterogenous nor homogenous :-) On the contrary, I think that example fits perfectly with my definition of homogenous. If there is no constraint on position, then what is the position determinative of? Order in the queue. Nothing more. By my definition, homogeneous. QED. I'll grant, it's not exactly the most intuitive definition of homogenous, but I think it is the most accurate for this situation. Perhaps homogenous and heterogenous aren't the best possible words here, but I think they work. | I doubt the python interpreter will ever try to enforce | homogeneity/heterogeneity on lists/tuples, in part because there no good | ways of definining it syntactically, and in part because there are | certainly good reasons for breaking the rules. As someone said: passing | lists to untrustworthy functions. And as someone else said, *args | passes a tuple, even though it is frequently just a homogenous list of | more arguments. It's a complete delusion, because even the claimed assumption of list homogeneity is tantmount to saying that Python doesn't encourage (or, arguably, support) ANY way of using mutable heterogenous sequences (such as the example above). To claim that they are inherently an undesirable programming practice is a clear descent into religion! I would be amused to know what Python type the lists are intended to be homogenous people use to implement mutable heterogenous sequences, or whether they claim that wanting such a feature is heresy :-) By my definition, how can it be mutable AND heterogenous? If the first element is a name, the second element is a phone number, and the third element is an email address, and you insert an element in between the first two elements, do you mean to tell me that the phone number, which has moved to the third slot, is now an email address? It doesn't make sense. Maybe the words are wrong. I'm not sure. But I think the distinction is valid. Furthermore, I think we lists are intended to be homogenous people would say that you are perfectly welcome to use lists for other purposes, if it suits you. Just as you can use a string as a list. We don't have to be rigid to appreciate the difference. :) Regards, Nick Maclaren. Blessings, Cliff -- http://mail.python.org/mailman/listinfo/python-list
[ANN] rest2web 0.5.1
`rest2web 0.5.1 http://www.voidspace.org.uk/python/rest2web/`_ is now available. This is a minor feature enhancement release. * `Download rest2web-0.5.1.zip http://www.voidspace.org.uk/cgi-bin/voidspace/downman.py?file=rest2web-0.5.1.zip`_ * `Download rest2web-0.5.1.tar.gz http://www.voidspace.org.uk/cgi-bin/voidspace/downman.py?file=rest2web-0.5.1.tar.gz`_ What Is rest2web? = Maintaining websites or project documentation in HTML is a pain. **rest2web** takes out the pain, and brings back the joy. {sm;:wink:} **rest2web** is a simple tool that lets you build your website from a single template (or as many as you want), and keep the contents in `ReStructured Text http://docutils.sourceforge.net/`_. (You can still keep pages in HTML if needed.) It has an easy to us templating system, with embedded Python for unlimited flexibility and no new templating language to learn. It has built in functions or creating sidebars and navigation elements of a site. What's New in 0.5.1 ? Added some extra debugging info to syntax errors in the templates. Fixed odict and pathutils for Python 2.5 compatibility. Added the 'promote_headers' option to the `config file http://voidspace.org.uk/python/rest2web/config_file.html`_. Added the ``sortpages`` method to the ``sections``. This sorts the pages in a section (or all sections) alphabetically. You can also pass in a custom sort function. -- http://mail.python.org/mailman/listinfo/python-list
Re: When Closure get external variable's value?
In [EMAIL PROTECTED], Huayang Xia wrote: That is a really concise and precise answer. Thanks. So the object binding can only happen explicitly at the closure declaration argument list(non-free variable). That's no declaration that's a definition and it happens at runtime! It's executed every time the outer function is called and executed and creates a function object. As far as I can see you don't create a closure BTW. You are *calling* that inner function and return the *result* of that call. Ciao, Marc 'BlackJack' Rintsch -- http://mail.python.org/mailman/listinfo/python-list