Re: csv module and NULL data byte
>Any idea why it might throw an exception on encountering a NULL in the >input stream? It accepts all other 255 byte values. Was this behaviour >intended? Perhaps a comment should be added to the docs. >Thanks for your work on the module anyway. The original module was like this - it comes about through the C convention of null-terminated strings (the module is coded in C). It would have been fairly involved to removed the restriction, and I would have run the risk of introducing subtle breakage for a feature nobody had asked for in the years we were maintaining the module outside the Python core... 8-) -- Andrew McNamara, Senior Developer, Object Craft http://www.object-craft.com.au/ -- https://mail.python.org/mailman/listinfo/python-list
Re: csv module and NULL data byte
>> Last time I read the documentation, it was recommended that >> the file be opened in BINARY mode ("rb"). > >It recommends binary mode, but seems to largely work fine with >text/ascii mode or even arbitrary iterables. I've not seen the >rationale behind the binary recommendation, but in 10+ years of using >the csv module, I've not found any issues in using text/ascii mode >that were solved by switching to using binary mode. The CSV module was originally written by Dave Cole. I subsequently made changes necessary to get it included a standard part of Python. I also implemented the "dialect" logic, and I put a lot of time into making the parser and generator produce the same results as Excel. That particular recommendation is necessary because Excel has some particular behaviours around CR and LF and quoting. For the parser to produce the same result as Excel, it must see the raw bytes with no re-ordering or suppression of CRs. Unfortunately, I haven't had time to be involved in the module for a few years. I wasn't involved with the Unicode changes necessary in Python 3, and I have not verified that it is still compatible with recent versions of Excel. -- Andrew McNamara, Senior Developer, Object Craft http://www.object-craft.com.au/ -- https://mail.python.org/mailman/listinfo/python-list
Re: import sqlite3
On 04/06/2009, at 9:45 PM, willgun wrote: By the way ,what does 'best regards' means at the end of a mail? The correspondent is wishing you well. You'll also see things like "kind regards", "best wishes" and so on. "Regard" essentially means respect. -- http://mail.python.org/mailman/listinfo/python-list
Re: import sqlite3
On 04/06/2009, at 4:14 PM, willgun wrote: What did you call the .py file? sqlite3.py? If so, you've just imported your own module again. 8-) After the import, try "print sqlite3.__file__", which will tell you where the module came from. Thank you all the same. I'm a student from China.It's painful for us to read python documentation entirely due to poor english.So I often make these mistakes. Don't worry - even experienced Python coders get caught by this one. Just remember the "print module.__file__" trick for next time something odd happens. When you import a module in python, it is only imported the first time you request it (which is why your import did not become recursive and raise an error). -- http://mail.python.org/mailman/listinfo/python-list
Re: import sqlite3
On 04/06/2009, at 3:15 PM, willgun wrote: When i run the following in IDLE: IDLE 2.6.1 import sqlite3 con =sqlite3.connect (r'g:\db1') everything goes well,but when i save these to a .py file and run it: Traceback (most recent call last): File "C:\Users\hp\Desktop\SQLite3\sqlite3.py", line 2, in import sqlite3 File "C:\Users\hp\Desktop\SQLite3\sqlite3.py", line 3, in con=sqlite3.connect(r'g:\db1') AttributeError: 'module' object has no attribute 'connect' Anyone can tell me why? What did you call the .py file? sqlite3.py? If so, you've just imported your own module again. 8-) After the import, try "print sqlite3.__file__", which will tell you where the module came from. -- http://mail.python.org/mailman/listinfo/python-list
Re: How to make "rainbow" RGB values?
>>Consider using an HSV->RGB conversion function. Saturation (S) and value >>(V) should remain constant, while Hue (H) varies to get your rainbow >>effect. > >Hey thank you very much, that worked like a charm! :] > >There's even a library function in the colorsys module (http:// >docs.python.org/lib/module-colorsys.html) Well, now you've helped me - I had no idea there was an HSV->RGB conversion function in the standard library. 8-) -- Andrew McNamara, Senior Developer, Object Craft http://www.object-craft.com.au/ -- http://mail.python.org/mailman/listinfo/python-list
Re: How to make "rainbow" RGB values?
>I want to map an int to a color on a rainbow spectrum, i.e. for an int >n in the range 0..N, low values (near 0) should map to the red end, >and high values (near N) to the blue/violet end. [...] >I've tried a simple scheme of overlapping sines, but this resulted in >too much red and blue, and no indigo/violet. Consider using an HSV->RGB conversion function. Saturation (S) and value (V) should remain constant, while Hue (H) varies to get your rainbow effect. -- Andrew McNamara, Senior Developer, Object Craft http://www.object-craft.com.au/ -- http://mail.python.org/mailman/listinfo/python-list
Re: CSV module: incorrectly parsed file.
>Here is a file "test.csv" >number,name,description,value >1,"wer","tape 2"",5 >1,vvv,"hoohaa",2 > >I want to convert it to tab-separated without those silly quotes. Note >in the second line that a field is 'tape 2"' , ie two inches: there is >a double quote in the string. The input format is ambiguous - how is the parser to distinguish between a double-quote in the field, and the double-quote that delimits the field? Excel would have written that field as "tape 2""" (it doubles double-quotes that appear within a field). You can turn off the double-double-quote handling by passing "doublequote=False" to the parser, but the results still might not be what you want (because the format is ambiguous). -- Andrew McNamara, Senior Developer, Object Craft http://www.object-craft.com.au/ -- http://mail.python.org/mailman/listinfo/python-list
Re: BDFL in wikipedia
>Hi I just hit this page in wikipedia BDFL[1] > >and it redirected me to Guido's wikipedia[2] entry >now without causing any troubles (read flamewar) shouldn't > >a) that page have an explanation of what BDFL is >b) shouldn't it mention Linus, Larry Wall, others?[3] >c) for the ones that have been around longer then me who was the first >being call like that? > >[1] http://en.wikipedia.org/wiki/BDFL >[2] http://en.wikipedia.org/wiki/Guido_van_Rossum >[3] http://www.answers.com/topic/list-of-benevolent-dictators-for-life I'm sure you'll get 101 people telling you this, but this really isn't a question for the python list, rather, it's a question for the Wikipedia editors (and that's anyone). I suspect, in this case, the redirect is implicit. It's happening because the Wikipedia search engine finds no page called BDFL, and the Guido_van_Rossum is the next closest match. If you care and you have enough to say on the subject, maybe you could start a BDFL page. -- Andrew McNamara, Senior Developer, Object Craft http://www.object-craft.com.au/ -- http://mail.python.org/mailman/listinfo/python-list
Re: 'r' vs 'rb' in csv (was Re: Python SHA-1 as a method for unique file identification ? [help!])
>> On a semi-related note, I have a database on Linux that imports from a >> Macintosh CSV file. The 'csv' module says to always open files in >> binary mode, but this didn't work in my case: I had to open it as 'rU' >> (text with universal newlines) or 'csv' misparsed it. I'd like the >> program to be portable to Windows and Mac. Is there a way around this? >> Will I really burn in hell for using 'rU'? > >Yes, you will burn in hell for using any old kludge that gets results >(by accident) instead of reading the manual to find a principled solution: > >""" >lineterminator >The string used to terminate lines in the CSV file. It defaults to '\r\n'. >""" > >In the case of a Mac CSV file, '\r' is probably required. Unfortunately, the documentation is misleading in this case: "lineterminator" is only used for output. The documentation specifies that the file should be opened in binary mode, because the CSV parser has it's own idea of "universal newlines". The complicating factor is that newlines can appear quoted inside a field: using universal newlines, these "quoted newlines" would be damaged (because it's unaware of the quoting conventions). If your data file contains no quoted newlines (they're rare, but if you need them, you need them), then opening the file in "universal newline" mode should be harmless (and in this case, is the right thing to do). -- Andrew McNamara, Senior Developer, Object Craft http://www.object-craft.com.au/ -- http://mail.python.org/mailman/listinfo/python-list
Albatross 1.35 released
OVERVIEW Albatross is a small toolkit for developing highly stateful web applications. The toolkit has been designed to take a lot of the pain out of constructing intranet applications although you can also use Albatross for deploying publicly accessed web applications. In slightly more than 4500 lines of Python (according to pycount) you get the following: * An extensible HTML templating system similar to DTML including tags for: - Conditional processing. - Macro definition and expansion. - Sequence iteration and pagination. - Tree browsing. - Lookup tables to translate Python values to arbitrary template text. * Application classes which offer the following features: - Optional server side or browser side sessions. - The ability to place Python code for each page in a dynamically loaded module, or to place all page processing code in a single mainline. * The ability to deploy applications as CGI, FastCGI, mod_python or a pure python HTTP server by changing less than 10 lines of code. The toolkit application functionality is defined by a collection of fine grained mixin classes. Nine different application types and six different execution contexts are prepackaged, you are able to define your own drop in replacements for any of the mixins to alter any aspect of the toolkit semantics. Application deployment is controlled by your choice of either cgi, FastCGI, mod_python, or BaseHTTPServer Request class. It should be possible to develop a Request class for Medusa or Twisted to allow applications to be deployed on those platforms with minimal changes. Albatross comes with over 180 pages of documentation. HTML and PDF formatted documentation is available from the toolkit homepage. The toolkit homepage: http://www.object-craft.com.au/projects/albatross/ The Albatross mailing list subscription and archives: http://object-craft.com.au/cgi-bin/mailman/listinfo/albatross-users CHANGES SINCE 1.33: ==- Note that release 1.34 was an internal release. New Features * A drop-in replacement for the fcgiapp module, called fcgiappnew has been added. This version implements the FastCGI protocol itself, rather than relying on an external module to implement the protocol. This new module addresses several minor problems with fcgi.py, and should be faster, although it should not be used in critical applications until it has received wider testing. Functional Changes -- * When extension tags (alx-*) are registered, their name is now checked against the template parsing regexp to ensure they can subsequently be matched. Bug Fixes - * The AnyTag functionality was given knowledge of HTML tags for which the close tag is forbidden, so it can avoid generating XHTML empty tag (which could cause the page to fail HTML validation). * When the disabledbool attribute was used on input tags, the disabled state was not being passed through to the input registry within the NameRecorderMixin. * If a client closed it's connection to the session server while the server had data pending for the client, a subsequent del_write_file would generate an exception, killing the session server. -- Andrew McNamara, Senior Developer, Object Craft http://www.object-craft.com.au/ -- http://mail.python.org/mailman/listinfo/python-list
Re: CSV module and Mac excel format problem
>Hi. I have had good success with CSV module but recently came across >problem with reading excel from Mac Office. The trouble is with line >endings. Instead of \r\n you have just \r and the file as a whole >appears as a single line. CSV coughs and provides this exception: > >_csv.Error: newline inside string > >Saving as Windows (text) in Mac Office solves this but I don't >necessarily want to force users to save this way just to avoid >modifying my code. There is a lineterminator in the package. Adding >parameter lineterminator='\r' did not correct the problem. Open the file in universal-newline mode - for example: sample = open(filename, 'rU') "lineterminator" is only used for output - we use the supplied iterator (and whatever conventions it imposes) for input. -- Andrew McNamara, Senior Developer, Object Craft http://www.object-craft.com.au/ -- http://mail.python.org/mailman/listinfo/python-list
Re: Last mod date
>This is my first post--I'm a Java developer trying to expand my >horizons. I'm trying to figure out how to find out the last >modification date/time for a file. I've found a reference to >*PyOS_GetLastModificationTime *as an Operating System Utility, but I >can't figure out which module I need to import to access it. Look at the "os" module. -- Andrew McNamara, Senior Developer, Object Craft http://www.object-craft.com.au/ -- http://mail.python.org/mailman/listinfo/python-list
Albatross 1.32 released
OVERVIEW Albatross is a small toolkit for developing highly stateful web applications. The toolkit has been designed to take a lot of the pain out of constructing intranet applications although you can also use Albatross for deploying publicly accessed web applications. In slightly more than 4500 lines of Python (according to pycount) you get the following: * An extensible HTML templating system similar to DTML including tags for: - Conditional processing. - Macro definition and expansion. - Sequence iteration and pagination. - Tree browsing. - Lookup tables to translate Python values to arbitrary template text. * Application classes which offer the following features: - Optional server side or browser side sessions. - The ability to place Python code for each page in a dynamically loaded module, or to place all page processing code in a single mainline. * The ability to deploy applications as CGI, FastCGI, mod_python or a pure python HTTP server by changing less than 10 lines of code. The toolkit application functionality is defined by a collection of fine grained mixin classes. Nine different application types and six different execution contexts are prepackaged, you are able to define your own drop in replacements for any of the mixins to alter any aspect of the toolkit semantics. Application deployment is controlled by your choice of either cgi, FastCGI, mod_python, or BaseHTTPServer Request class. It should be possible to develop a Request class for Medusa or Twisted to allow applications to be deployed on those platforms with minimal changes. Albatross comes with over 170 pages of documentation. HTML, PDF and PostScript formatted documentation is available from the toolkit homepage. The toolkit homepage: http://www.object-craft.com.au/projects/albatross/ The Albatross mailing list subscription and archives: http://object-craft.com.au/cgi-bin/mailman/listinfo/albatross-users BUGFIXES SINCE 1.30: * To obtain a reference to the current frame, _caller_globals was raising and catching an exception, then extracting the tb_frame member of sys.exc_traceback. sys.exc_traceback was deprecated in python 1.5 as it is not thread-safe. It now appears to be unreliable in 2.4, so _caller_globals has been changed to use sys._getframe(). * If ctx.set_page() was called from within the start page, then the wrong page methods (page_enter, page_display, etc) would be called (those of the initial page, rather than the page requested via set_page). * Fixes to handling of missing RandomPage page modules. -- http://mail.python.org/mailman/listinfo/python-list
Albatross 1.30 released
OVERVIEW Albatross is a small toolkit for developing highly stateful web applications. The toolkit has been designed to take a lot of the pain out of constructing intranet applications although you can also use Albatross for deploying publicly accessed web applications. In slightly more than 4500 lines of Python (according to pycount) you get the following: * An extensible HTML templating system similar to DTML including tags for: - Conditional processing. - Macro definition and expansion. - Sequence iteration and pagination. - Tree browsing. - Lookup tables to translate Python values to arbitrary template text. * Application classes which offer the following features: - Optional server side or browser side sessions. - The ability to place Python code for each page in a dynamically loaded module, or to place all page processing code in a single mainline. * The ability to deploy applications as CGI, FastCGI, mod_python or a pure python HTTP server by changing less than 10 lines of code. The toolkit application functionality is defined by a collection of fine grained mixin classes. Nine different application types and six different execution contexts are prepackaged, you are able to define your own drop in replacements for any of the mixins to alter any aspect of the toolkit semantics. Application deployment is controlled by your choice of either cgi, FastCGI, mod_python, or BaseHTTPServer Request class. It should be possible to develop a Request class for Medusa or Twisted to allow applications to be deployed on those platforms with minimal changes. Albatross comes with over 170 pages of documentation. HTML, PDF and PostScript formatted documentation is available from the toolkit homepage. The toolkit homepage: http://www.object-craft.com.au/projects/albatross/ The Albatross mailing list subscription and archives: http://object-craft.com.au/cgi-bin/mailman/listinfo/albatross-users CHANGES SINCE 1.20 * Any HTML tag can now be prefixed with "al-" allowing any attribute to be the result of python evaluation. For example: could produce and: could produce * Since macros and lookups are an application global resource, they can only be defined once per application, however this was not previously checked. Redefinition of macros or lookups will now result in an ApplicationError exception. * an in-line version of the tag has been introduced, which is expanded in place if the tag has an expr= attribute. * a new tag has been added to allow templates to assert that specific Albatross features are available, or templating scheme version number is high enough. * "Cache-Control: no-cache" is now set in addition to "Pragma: no-cache" - the former is defined for HTTP/1.1, the later for HTTP/1.0. * Simplified session cookie handling. BUGFIXES SINCE 1.20: * FastCGI apps were not being explicitly finalised, relying instead on their object destructor, with the result that writing application output (or errors) would be indefinitely deferred if object cycles existed. We now call "fcgi.Finish()" from the fcgiapp Request.return_code() method. * When handling exceptions, the traceback is now explicitly deleted from the local namespace to prevent cycles (otherwise the garbage collection of other objects in the local namespace will be delayed). * Two fixes to the tag: the albatross-specific "list" attribute was leaking into resulting markup, and the use of the "expr" attribute would result in invalid markup being emitted. * Thanks to Robert Fendt for picking this up: the Albatross-generated hidden field input element must not appear naked inside a form element for strict HTML conformance. The solution is to wrap the input elements in div. * BranchingSession sessions could not be "deleted" - the solution is to add a dummy "session" shared by all branches, which is deleted when one branch "logs out". -- Andrew McNamara, Senior Developer, Object Craft http://www.object-craft.com.au/ -- http://mail.python.org/mailman/listinfo/python-list