python-dev Summary for 2006-11-16 through 2006-11-30
python-dev Summary for 2006-11-16 through 2006-11-30 .. contents:: [The HTML version of this Summary is available at http://www.python.org/dev/summary/2006-11-16_2006-11-30] = Announcements = -- Python 2.5 malloc families -- Remember that if you find your extension module is crashing with Python 2.5 in malloc/free, there is a high chance that you have a mismatch in malloc families. Fredrik Lundh's FAQ has more: http://effbot.org/pyfaq/why-does-my-c-extension-suddenly-crash-under-2.5.htm Contributing thread: - `2.5 portability problems http://mail.python.org/pipermail/python-dev/2006-November/069971.html`__ - Roundup tracker schema discussion - If you'd like to be involved in the discussion of the setup for the `new tracker`_, you can now file issues on the `meta tracker`_ or post to the `tracker-discuss mailing list`_. Be sure to sign up for an account so your comments don't show up as anonymous! .. _new tracker: http://psf.upfronthosting.co.za/roundup/tracker/ .. _meta tracker: http://psf.upfronthosting.co.za/roundup/meta/ .. _tracker-discuss mailing list: http://mail.python.org/mailman/listinfo/tracker-discuss Contributing thread: - `discussion of schema for new issue tracker starting http://mail.python.org/pipermail/python-dev/2006-November/069976.html`__ = Summaries = Python and the Linux Standard Base (LSB) Ian Murdock, the chair of the Linux Standard Base (LSB), explained that they wanted to add Python to `LSB 3.2`_. Martin v. Lowis promised to go to their meeting in Berlin and report back to python-dev. The discussion then turned to the various ways in which the different Linux variants package Python. A number of people had been troubled by Debian's handling of distutils. At one point, Debian had excluded distutils completely, requiring users to install the python-dev package to get distutils functionality. While current versions of Debian had put distutils back in the stdlib, they had excluded the ``config`` directory, meaning that distutils worked only for pure Python modules, not extension modules. And because Debian had no way of knowing that a computer with both gcc and Python installed would likely benefit from having the ``config`` directory installed, the user still had to install python-dev separately. There was also some discussion about how to handle third party modules so that updating a module didn't break some application which was expecting a different version. These kinds of problems were particularly dangerous on distributions like Gentoo and Ubuntu which relied heavily on their own system Python for the OS to work properly. Guido suggested introducing a vendor-packages directory for the third party modules required by the OS and Martin v. Lowis reopened an `earlier patch`_ suggesting this. A number of folks also thought that adding a ~/.local/lib/pythonX.X/site-packages directory for user specific (not site wide) packages could be useful. Phillip J. Eby pointed out that distutils and setuptools already allow you to install packages this way by putting:: [install] prefix = ~/.local into ./setup.cfg, ~/.pydistutils.cfg, or /usr/lib/python2.x/distutils/distutils.cfg. He also explained that setuptools could address some of the application-level problems: setuptools-generated scripts adjust their sys.path to include the specific eggs they need, and can specify these eggs with an exact version if necessary. Thus OS-level scripts would likely specify exact versions and then users could feel free to install newer eggs without worrying that the OS would try to use them instead. .. _LSB 3.2: http://www.freestandards.org/en/LSB_Roadmap .. _earlier patch: http://bugs.python.org/1298835 Contributing thread: - `Python and the Linux Standard Base (LSB) http://mail.python.org/pipermail/python-dev/2006-November/070027.html`__ -- Thread-safe operations -- Fredrik Lundh has been working on `cleaning up the Python FAQ`_ and asked about what kinds of operations could be considered atomic for the purposes of thread-safety. While almost any statement in Python can invoke an arbitrary special method (e.g. ``a = b`` can invoke ``a.__del__()``), Fredrik was interested in situations where the objects involved were either builtins or objects that didn't override special methods. In situations like these, you can be guaranteed things like:: * If two threads execute ``L.append(x)``, two items will be added to the list (though the order is unspecified) * If two threads execute ``x.y = z``, the field ``y`` on the ``x`` object will exist and contain one of the values assigned by one of the threads You get
Please donate to the Python Software Foundation
Hi, I'm writing to urge members of the Python community to please keep the Python Software Foundation in mind in your year end giving. The PSF is the 501(c)3 non-profit organization that holds and protects the intellectual property rights behind Python. We deal with the licensing, contribution agreements, and legal requirements of copyright and trademark in order to keep Python open and free of legal claims. The PSF also: * Provides the financial backing that makes PyCon possible: http://us.pycon.org/ * Funds special projects such as the recent website redesign: http://python.org/ and the current Python Advocacy Coordinator experiment: http://python.org/psf/grants/advocacy/orig-proposal.pdf http://wiki.python.org/moin/PythonAdvocacyCoordinator * Funds grants: http://www.python.org/psf/grants/ * Responds to legal queries about the license, trademarks, or US export control registration, owns/renews the key Python domain names, and other such administrative chores. How to Donate - We take credit cards, checks, wire transfers, and PayPal: http://www.python.org/psf/donations/ Donations are tax deductible for US citizens and for any business where donations or sponsorship can be considered pre-tax business expenses. Businesses can also consider becoming a sponsor member of the PSF: http://www.python.org/psf/sponsorship/ Or, become a sponsor of PyCon 2007: http://us.pycon.org/TX2007/HowToSponsor If you have any questions, please email me directly. Thanks! Stephan Deibel Chairman of the Board Python Software Foundation http://python.org/psf -- http://mail.python.org/mailman/listinfo/python-announce-list Support the Python Software Foundation: http://www.python.org/psf/donations.html
Re: Sybase module 0.38pre1 released
By the way, I forgot to say that new releases can now be downloaded from this page: https://sourceforge.net/project/showfiles.php?group_id=184050 regards -- Sébastien Sablé 2006/12/12, Sébastien Sablé [EMAIL PROTECTED]: WHAT IS IT: The Sybase module provides a Python interface to the Sybase relational database system. It supports all of the Python Database API, version 2.0 with extensions. MAJOR CHANGES SINCE 0.37: * This release works with python 2.5 * It also works with sybase 15 * It works with 64bits clients * It can be configured to return native python datetime objects * The bug This routine cannot be called because another command structure has results pending. which appears in various cases has been corrected * It includes a unitary test suite based on the dbapi2.0 compliance test suite -- http://mail.python.org/mailman/listinfo/python-announce-list Support the Python Software Foundation: http://www.python.org/psf/donations.html
BayPiggies Dec. 14 Meeting Programming Productivity: What Really Matters?
Thursday Dec. 14, 2006 7:30-8:50 p.m. Technical Program Title Programming Productivity: What Really Matters? Presenter Shannon -jj Behrens (Foxmarks) About the talk Are you fascinated by programmer productivity? Do you wish you could get more done in less time without sacrificing quality? This talk will cover a broad range of topics such as work environment, development environment, and programming language features. 8:50 p.m-...Mapping and Random Access -- Mapping Moderator TBD Mapping is a rapid-fire audience announcement open to all of topic headings (one speaker at a time). Random Access session (everyone breaks up into self-organized small-group discussion) follows immediately after Mapping. More information: http://baypiggies.net -- http://mail.python.org/mailman/listinfo/python-announce-list Support the Python Software Foundation: http://www.python.org/psf/donations.html
Python training in Colorado, January 2007
Python author and trainer Mark Lutz will be teaching another 3-day Python class at a conference center in Longmont, Colorado, on January 23-25, 2007. This is a public training session open to individual enrollments, and covers the same topics as the 3-day onsite sessions that Mark teaches, with hands-on lab work. For more information on this, and our other 2007 public classes, please visit these web pages: http://home.earthlink.net/~python-training/longmont-public-classes.htm http://home.earthlink.net/~python-training/public_classes.html Thanks for your interest. --Python Training Services, Inc. -- http://mail.python.org/mailman/listinfo/python-announce-list Support the Python Software Foundation: http://www.python.org/psf/donations.html
Re: merits of Lisp vs Python
Bill Atkins [EMAIL PROTECTED] writes: the macro is just a friendlier syntax for expressing an idea. I like that phrase! -- http://mail.python.org/mailman/listinfo/python-list
Re: merits of Lisp vs Python
Neil Cerutti [EMAIL PROTECTED] writes: Is the above 'duck-typing' idiom considered very useful to a Lisper? It seems logical to me that duck-typing works best in an environment where it is ubiquitous. If users have to implement accessors specifically to use your library, it is not as good as if they had already implemented one as a matter of routine. It's a little more complicated than that, the classes involved have to have special interfaces to tell setf/getf what to do, sort of a compile time equivalent of __setattr__/__getattr__ if I remember right. -- http://mail.python.org/mailman/listinfo/python-list
Re: merits of Lisp vs Python
[EMAIL PROTECTED] [EMAIL PROTECTED] writes: Let us note that it's not FSF that gives this stuff away for free -- or if it is them proximally, it is not them ultimately -- ultimately it's the engineers who did all that work that gave it away for free. When I worked there, they paid me ;-) -- http://mail.python.org/mailman/listinfo/python-list
Re: merits of Lisp vs Python
Bill Atkins [EMAIL PROTECTED] writes: You should be pragmatic about this - I have never used a CL implementation that didn't do TCO optimization (indeed, are there any?). Although the standard doesn't require it, I treat it as a de facto requirement and don't worry too much about it. I have to confess that most of the Lisp code I've written were on simpler dialects that didn't have TCO. But I'm not sure if the CL implementations I've used (KCL back in the day, and CLISP a little bit) had it either. -- http://mail.python.org/mailman/listinfo/python-list
Re: merits of Lisp vs Python
Kay Schluehr wrote: You mean a universal language adapter? I guess this is always possible using alpha conversion but I don't believe this leads to theoretical or practical interesting solutions but is just a limit concept. Not familiarized with you terminology. I think that i would call that a universal language composer. I mean if there exists some theoretical limitation to composionality of two directly collapsing languages (G1, T1) and (G2, T2) via a unambiguous modification (e.g. 'renaming') to a third one (G2', T2'), unknown to me. I mean some theoretical limitation in the sense of known theoretical limitations to proving theorems in closed formal systems. After all proving a formal theorem is not very different from enhacement of a language. The practical problem with composing enhancements is that any two extensions L1, L2 share a lot of rules and rely on their structure. What if they don't just extend their host language L0 conservatively but also redefine rules of L0? This is not just a theoretical problem but it happens quite naturally if you want to adapt an extension developed for Python 2.4 for working with Python 2.5. Here Python 2.5 is considered as just another particular extension. Obviously Py3K will become an interesting testcase for all kinds of syntactical and semantical transformations. I would consider redefined-L0 to be L0'. I think that a concept of namespaces could be also used for versioning-like conflicts: L0v24:foo(), L0v25:foo(). The problem is that both versions may be stored and managed during initial period of time. But in the long run old libraries, extensions... would be updated to the new version. -- http://mail.python.org/mailman/listinfo/python-list
Re: merits of Lisp vs Python
On Wed, 13 Dec 2006 16:07:01 +1300, greg [EMAIL PROTECTED] tried to confuse everyone with this message: Robert Uhl wrote: o Symbols In Lisp, a symbol is essentially a hashed string; Are you aware that strings can be interned in Python? Furthermore, any string literal in the source that is a syntactically valid identifier is automatically interned, and you can intern any string explicitly if you need. This gives you exactly the same capabilities as symbols in Lisp. Are you aware that you hardly know any Lisp yet make such bold and unfounded claims? Unless interning a string somehow gives it a property list, slot value and function value it doesn't give you the same capabilities. -- |Don't believe this - you're not worthless ,gr-.ru |It's us against millions and we can't take them all... | ue il | |But we can take them on! | @ma | | (A Wilhelm Scream - The Rip)|__| -- http://mail.python.org/mailman/listinfo/python-list
Re: merits of Lisp vs Python
[Bill Atkins] (Why are people from c.l.p calling parentheses brackets?) [Kaz Kylheku] Because that's what they are often called outside of the various literate fields. For example, the English are outside of the various literate fields? FWIW, Python documentation consistently uses the jargon: () parentheses {} braces [] brackets That matches North American conventions, but occasionally confuses an international audience (for example, the English call parentheses brackets or round brackets). There's also a long tradition in both mathematics and computer science of using bracket as a generic term for any syntactic device used in pairs. For example, the Revised Report on the Algorithmic Language Algol 60 way back in 1963 even called begin and end brackets. If it's tempting to call the authors of that illiterate too, keep in mind that John McCarthy was one of them -- although I'm sure Peter Naur would be willing to take the blame for dumbing it down for Europeans ;-) -- http://mail.python.org/mailman/listinfo/python-list
Re: merits of Lisp vs Python
On 12 Dec 2006 18:03:49 -0800, Paddy [EMAIL PROTECTED] tried to confuse everyone with this message: There are a lot of people that use Wikipedia. I think some of them might want to learn to program. I think you misunderstood the goal of Wikipedia. It is not to teach people programming. I make it easier for them to find Python by helping to maintain Python within Wikipedia. If someone wants to find Python, he types Python in the search bar and works from there. He certainly wouldn't end up in doctest article. Some people dislike Wikipedia which is fine. Some people dislike Wikipedia and deliberately sabotage it, which is vandalism. Writing vanity articles about non-notable things is not much better. -- |Don't believe this - you're not worthless ,gr-.ru |It's us against millions and we can't take them all... | ue il | |But we can take them on! | @ma | | (A Wilhelm Scream - The Rip)|__| -- http://mail.python.org/mailman/listinfo/python-list
Re: Is anyone using Python for embedded applications?
Not sure what your target embedded platform is, but there is a Python version for the Nokia S60 mobile phone platform (Symbian). http://s60.com/ Python for S60http://www.forum.nokia.com/info/sw.nokia.com/id/ee447e84-2851-471a-8387-3434345f2eb0/Python_for_S60.html Python for S60 allows developers to execute Python commands and run Python scripts and applications in devices based on S60 Platform. In addition, developers can execute Python commands and scripts in the emulators of S60 Developer Platform SDKs. Development starts with an interactive console in a S60 compatible device where Python commands can be executed. hth Andre On 12/12/06, Carl J. Van Arsdall [EMAIL PROTECTED] wrote: I'm aware of a couple python projects for embedded systems. I am currently considering using Python on an embedded platform to develop a simple application as a personal project, mostly to see if it will work. I was wondering if anyone here was using python for anything of that nature? For those that are involved in these types of projects, how does development in python differ for embedded projects versus a non-embedded project? Is there a community standard technique or style for this type of development (i.e. heavy in OO design? commonly used patterns?) Are there any good tools to assist for this type of development environment? Oh, and if anyone has opinions/facts on why python should not be used in an embedded platform, I'd like to know that too. I'm somewhat familiar with pythons needs on a system, but there are a number of things I am not aware of. Thanks to everyone for their input! -carl -- Carl J. Van Arsdall [EMAIL PROTECTED] Build and Release -- http://mail.python.org/mailman/listinfo/python-list -- Dr. Andre P. Meyerhttp://python.openspace.nl/meyer TNO Defence, Security and Safety http://www.tno.nl/ Delft Cooperation on Intelligent Systems http://www.decis.nl/ Ah, this is obviously some strange usage of the word 'safe' that I wasn't previously aware of. - Douglas Adams -- http://mail.python.org/mailman/listinfo/python-list
Re: how can i write a hello world in chinese with python
kernel1983 wrote: and I tried unicode and utf-8 How did you try unicode? Like this? : EasyDialogs.Message(u'\u4e2d') I tried to both use unicodeutf-8 head just like \xEF\xBB\xBF and not to use Anyone knows about the setting in the python code file? Maybe python doesn't know I'm to use chinese?! It depends on how EasyDialogs works. And by the way, when you say utf-8 encoded text is not displayed correctly, what do you actually see on the screen? -- Leo -- http://mail.python.org/mailman/listinfo/python-list
Re: One module per class, bad idea?
Isaac Rodriguez wrote: Yes, it would be a bad idea. =) Saying it is a bad idea and not explaining why will not help anyone. I would like you to elaborate on why it is a bad idea to have one file per class. Thanks, - Isaac. Because it's just a useless limitation. Python lets you the freedom to decide if using one class per file or a lot of classes per file and this, imho, is a great advantage of Python other Java. Personally I like to have the possibility to include multiple classes in one module if I need them. Obviously I'll hardly mix classes having different tasks in the same .py file. If you come from Java feel free to use the Java approach. -- http://mail.python.org/mailman/listinfo/python-list
Re: merits of Lisp vs Python
greg ha escrito: Juan R. wrote: I see no dinamism on your example, just static overloading. There's nothing static about it: q = raw_input() if q == A: a = 1 b = 2 else: a = x b = y c = a + b There is no way that the compiler can statically determine what the + operator needs to do here. Before or after the input? :] No, it is not that i did mean. Of course, the operation for c is dinamic, but just statically overloading the +. The definition for c could be adapted to the cases and introduced on the if. I would call dinamic code, for instance, if the if, the different cases and the def for c could be modified on the fly _á la_ LISP macro style. -- http://mail.python.org/mailman/listinfo/python-list
Re: merits of Lisp vs Python
Robert Uhl a écrit : [EMAIL PROTECTED] (Aahz) writes: Consider this: Lisp has had years of development, it has had millions of dollars thrown at it by VC firms -- and yet Python is winning over Lisp programmers. Think about it. The argument from popularity is invalid. French units have overtaken standard units, Never heard of that French unit thing. Unless you talk about that archaic unit system that was in use before the metric system was created. -- http://mail.python.org/mailman/listinfo/python-list
Re: About alternatives to Matlab
Filip Wasilewski wrote: Jon, both Python and Matlab implementations discussed here use the lifting scheme, while yours is a classic convolution based approach. I've done both in OCaml. The results are basically the same. These are two *different* algorithms for computing wavelet transforms. Although they have similar names and give similar results, it does not mean you can use them interchangeably in one benchmark! It just does not make sense. It makes sense because they solve the same problem. When you're comparing non-trivial problems between disparate languages you are not likely to use the same algorithms. Using built-in hash functions is an obvious example. What's more, taking only very big input 'n' gives only very limited information about true performance. I've presented times for 2 different n. I agree that it would be better to present infinite different n but I only had finite time. If you want to draw objective conclusions about algorithm implementation you should measure timing and memory usage characteristic for different input lengths. I did. The results are unsurprising: multi-pass (Matlab/Python) gets comparatively slower for bigger n. Memory usage is roughly the same for different languages. This will also give you some idea about call overhead and possible memory bandwidth influence. For example, the 4-tap db2 lifting transform should be about 50% faster than the one using subband filtering. That's theory. In practice, due to specific memory usage, the speedup gained with reduction of number of arithmetic operations is easily wasted by huge cache miss overhead (C implementation, measured on x86 architecture) for arrays which don't fit entirely in the CPU cache. See my point? No. The effects you are talking about are swamped by the interpreted vs compiled effect. 1.88s C++ (816 non-whitespace bytes) 2.00s OCaml (741 b) 2.33s F# (741 b) 9.83s Your Python (1,002 b) The original python was 789 bytes. Is the byte count a standard measure you apply to describe code quality? You can use bytes, lines, words, tokens or just look at the code. Whatever you do, Python loses on this benchmark in terms of brevity, clarity and performance. I don't think you would be much happier to see totally obfuscated golf one-liners. That doesn't even make sense. Squeezing code onto one line doesn't improve byte count. It is probably just as easy. Instead of dynamic typing you have parametric polymorphism. If you want to make your function generic over arithmetic type then you can pass in the arithmetic operators. Probably? Using the interactive interpreter, how can I easily create two n-dimensional arrays of arbitrary data type, add them and multiply by 17? In F#: open Math.Matrix.Generic let a = init n m (fun i j - ...) let b = init n m (fun i j - ...) 17. $* (a + b) In OCaml you'd either use an array of arrays and define your own functions over them, or you'd use the built-in Bigarray.Array2 and define some functions over that. Either way, you have to use different operator names for different types. You'd end up with something like: open Array2 let a = init n m (fun i j - ...) let b = init n m (fun i j - ...) 17. $* (a +: b) I just prefer fair comparisons and clean use cases instead of marketing like that and I don't believe anyone will buy your story about OCaml superior brevity after seeing one fairly irrelevant loop with few arithmetic operations as a killer argument. Sure. There are lots of other examples of OCaml's brevity out there: http://www.ffconsultancy.com/free/ocaml http://www.ffconsultancy.com/free/sudoku http://www.ffconsultancy.com/free/maze http://www.ffconsultancy.com/free/ray_tracer and now F#: http://www.ffconsultancy.com/dotnet/fsharp/ Here's my complete OCaml: ... and C++: #include vector ... You didn't mention your platform and compiler settings. 2.2GHz Athlon64 x2 with 2Gb RAM running Debian Linux. g++ -O2 ocamlopt Using vector at() method instead of plain C/C++ array indexing increases the timings by factor of ~1.5 to 10 or more (GCC, MSVC), depending on the optimizations set, so it doesn't seem to be the best possible solution. Bounds checking is 1% slower with GCC and only 14% slower with MSVC. I was also unable to run your OCaml example for n = 2^21 (win32, out of the box OCaml installation). Is there some 16MB memory limit imposed on Array? # let q = Array.make (1 lsl 21) 0.0;; Exception: Invalid_argument Array.make. On 32-bit, yes. You'd either have to use a different data structure (Bigarrays), upgrade or switch to F#. -- 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: merits of Lisp vs Python
Christophe wrote: Robert Uhl a écrit : [EMAIL PROTECTED] (Aahz) writes: Consider this: Lisp has had years of development, it has had millions of dollars thrown at it by VC firms -- and yet Python is winning over Lisp programmers. Think about it. The argument from popularity is invalid. French units have overtaken standard units, Never heard of that French unit thing. Unless you talk about that archaic unit system that was in use before the metric system was created. And who do you think created the metric system? Regards, Jan -- http://mail.python.org/mailman/listinfo/python-list
Re: merits of Lisp vs Python
Raffael Cavallaro [EMAIL PROTECTED]'espam-s'il-vous-plait-mac.com: +--- | George Sakkis [EMAIL PROTECTED] said: | If you mistakenly select an extra parenthesis or omit one, it's | the same thing. | | Because you can't mistakenly select an extra paren or omit one in a | lisp-aware editor. Whether its a commercial lisp IDE or emacs, you | don't manually select s-expressions. You put your cursor/point at one | paren and you tell the editor - with a keystroke or a mouse click - to | find the matching paren and select everything contained between the two. +--- And for any of you who are rejecting this because you don't want to learn or use Emacs, Raffael's point is even true in the Vi family of editors (nvi vim, at least). The y% command yanks (copies) everything through the matching paren into the anonymous buffer; d% deletes likewise [and saves in the anonymous buffer]; p (or P) pastes after (or before) the current location. All can be prefixed with a buffer (Q-register) name for more flexibility. Lisp's parens really *do* make editing ever so much easier! -Rob - Rob Warnock [EMAIL PROTECTED] 627 26th Avenue URL:http://rpw3.org/ San Mateo, CA 94403 (650)572-2607 -- http://mail.python.org/mailman/listinfo/python-list
Re: merits of Lisp vs Python
On Dec 13, 8:39 am, [EMAIL PROTECTED] (Timofei Shatrov) wrote: On 12 Dec 2006 18:03:49 -0800, Paddy [EMAIL PROTECTED] tried to confuse everyone with this message: There are a lot of people that use Wikipedia. I think some of them might want to learn to program. I think you misunderstood the goal of Wikipedia. It is not to teach people programming. You think wrong. Wikipedia articles get searched and links get followed. Its good for some of those to link to articles on Python. I make it easier for them to find Python by helping to maintain Python within Wikipedia. If someone wants to find Python, he types Python in the search bar and works from there. He certainly wouldn't end up in doctest article. If someone is looking up comments or testing, then they might well end up reading the doctest article. And why not! Does Lisp have similar? Is the Lisp community as welcoming? Do you have to think yourself a genius to join the club? Is Lisp approachable? Some people dislike Wikipedia which is fine. Some people dislike Wikipedia and deliberately sabotage it, which is vandalism. Writing vanity articles about non-notable things is not much better. Should I have asked you first ;-) - Paddy. -- http://mail.python.org/mailman/listinfo/python-list
Re: merits of Lisp vs Python
On Wed, 13 Dec 2006 02:41:29 -0500 Raffael Cavallaro [EMAIL PROTECTED]'espam-s'il-vous-plait-mac.com wrote: # On 2006-12-12 19:18:10 -0500, George Sakkis [EMAIL PROTECTED] said: # # If you mistakenly select an extra parenthesis or omit one, it's # the same thing. # # Because you can't mistakenly select an extra paren or omit one in a # lisp-aware editor. Sure I can! I think you misunderstood what George said. (unless (eq 1 2) (if (eql 2 3) (x)) (y)) How is the editor supposed to know whether I want to cut/paste the s-expression starting with if or the one with eql? # Whether its a commercial lisp IDE or emacs, you don't manually select # s-expressions. You put your cursor/point at one paren and you tell # the editor - with a keystroke or a mouse click - to find the matching # paren and select everything contained between the two. Oh, you mean you have never seen a Python environment which could mark the current block of code? -- Best wishes, Slawomir Nowaczyk ( [EMAIL PROTECTED] ) Truth is stranger than fiction, because fiction has to make sense. -- http://mail.python.org/mailman/listinfo/python-list
call of __del__ non-deterministic in python 2.4 (cpython)?
Hi all, I've recently run into a problem that I haven't seen with python 1.5.2 and python 2.3. It seems that under certain conditions __del__ does not get immediately called when a local variable goes out of scope. I ended up with deadlocks in a threaded application because a locked section was supposed to be entered from within __del__ but apparently the same thread (the main thread, in that case) was already holding that lock. The result looked really strange with the main thread entering the locked section and then suddenly the delayed call of __del__ taking control, also wanting to acquire the lock but never being able to. Unfortunately I fail to put together a minimal example. Anyway: Is relying on __del__ getting called immediately when the refcount drops to 0 a no-no? If so should that maybe be prominently stated in the docs? Cheers, Holger Der Inhalt dieser E-Mail ist vertraulich. Falls Sie nicht der angegebene Empfänger sind oder falls diese E-Mail irrtümlich an Sie adressiert wurde, verständigen Sie bitte den Absender sofort und löschen Sie die E-Mail sodann. Das unerlaubte Kopieren sowie die unbefugte Übermittlung sind nicht gestattet. Die Sicherheit von Übermittlungen per E-Mail kann nicht garantiert werden. Falls Sie eine Bestätigung wünschen, fordern Sie bitte den Inhalt der E-Mail als Hardcopy an. The contents of this e-mail are confidential. If you are not the named addressee or if this transmission has been addressed to you in error, please notify the sender immediately and then delete this e-mail. Any unauthorized copying and transmission is forbidden. E-Mail transmission cannot be guaranteed to be secure. If verification is required, please request a hard copy version. -- http://mail.python.org/mailman/listinfo/python-list
[unicode] inconvenient unicode conversion of non-string arguments
Hi there, I consider the behaviour of unicode() inconvenient wrt to conversion of non-string arguments. While you can do: unicode(17.3) u'17.3' you cannot do: unicode(17.3, 'ISO-8859-1', 'replace') Traceback (most recent call last): File stdin, line 1, in ? TypeError: coercing to Unicode: need string or buffer, float found This is somehow annoying when you want to convert a mixed-type argument list to unicode strings, e.g. for a logging system (that's where it bit me) and want to make sure that possible raw string arguments are also converted to unicode without errors (although by force). Especially as this is a performance-critical part in my application so I really do not like to wrap unicode() into some custom tounicode() function that handles such cases by distinction of argument types. Any reason why unicode() with a non-string argument should not allow the encoding and errors arguments? Or some good solution to work around my problem? (Currently running on python 2.4.3) Regards, Holger Der Inhalt dieser E-Mail ist vertraulich. Falls Sie nicht der angegebene Empfänger sind oder falls diese E-Mail irrtümlich an Sie adressiert wurde, verständigen Sie bitte den Absender sofort und löschen Sie die E-Mail sodann. Das unerlaubte Kopieren sowie die unbefugte Übermittlung sind nicht gestattet. Die Sicherheit von Übermittlungen per E-Mail kann nicht garantiert werden. Falls Sie eine Bestätigung wünschen, fordern Sie bitte den Inhalt der E-Mail als Hardcopy an. The contents of this e-mail are confidential. If you are not the named addressee or if this transmission has been addressed to you in error, please notify the sender immediately and then delete this e-mail. Any unauthorized copying and transmission is forbidden. E-Mail transmission cannot be guaranteed to be secure. If verification is required, please request a hard copy version. -- http://mail.python.org/mailman/listinfo/python-list
Re: merits of Lisp vs Python
[EMAIL PROTECTED] ha escrito: FWIW, Python documentation consistently uses the jargon: () parentheses {} braces [] brackets That matches North American conventions, but occasionally confuses an international audience (for example, the English call parentheses brackets or round brackets). There's also a long tradition in both mathematics and computer science of using bracket as a generic term for any syntactic device used in pairs. Brackets are unequal paired syntatic delimiters used for packaging. Quotations marks string or exclamation marks ¡Esto es español! are used in pairs but not are brackets. A natural convention is brackets = ( ), [ ], { }, ( ) parentheses or round brackets { } braces or curly brackets [ ] box or square brackets chevrons or angle brackets A English calling brackets or round brackets to the parentheses is doing nothing wrong, but brackets are not parentheses. In mathematics the braces are also often called brackets and again that is not wrong. -- http://mail.python.org/mailman/listinfo/python-list
Re: About alternatives to Matlab
[EMAIL PROTECTED] wrote: A concrete example of interest to me: can I get an OCaml-to-native compiler for an IBM BlueGene? The processor is in the PowerPC family, but it has some modifications, and the binary format is different from standard Linux as well. No idea. OCaml has quite a good PPC backend for the Mac already so you might be able to persuade a student to do the conversion as a project. If Mono runs on that platform then you might also consider F#... -- 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: One module per class, bad idea?
Matias Jansson wrote: I come from a background of Java and C# where it is common practise to have one class per file in the file/project structure. As I have understood it, it is more common practice to have many classes in a Python module/file. What is the motivation behind it, would it be a bad idea to have a guideline in your project that promotes a one class per file structure (assuming most of the programmers a background similar to mine)? It's a good idea. And I encourage it in my project. It makes sense for us because we document classes and methods copiously. However, use whatever works for your project. -- http://mail.python.org/mailman/listinfo/python-list
Re: inconvenient unicode conversion of non-string arguments
Holger Joukl wrote: Hi there, I consider the behaviour of unicode() inconvenient wrt to conversion of non-string arguments. While you can do: unicode(17.3) u'17.3' you cannot do: unicode(17.3, 'ISO-8859-1', 'replace') Traceback (most recent call last): File stdin, line 1, in ? TypeError: coercing to Unicode: need string or buffer, float found This is somehow annoying when you want to convert a mixed-type argument list to unicode strings, e.g. for a logging system (that's where it bit me) and want to make sure that possible raw string arguments are also converted to unicode without errors (although by force). Especially as this is a performance-critical part in my application so I really do not like to wrap unicode() into some custom tounicode() function that handles such cases by distinction of argument types. Any reason why unicode() with a non-string argument should not allow the encoding and errors arguments? There is reason: encoding is a property of bytes, it is not applicable to other objects. Or some good solution to work around my problem? Do not put undecoded bytes in a mixed-type argument list. A rule of thumb working with unicode: decode as soon as possible, encode as late as possible. -- Leo -- http://mail.python.org/mailman/listinfo/python-list
Re: call of __del__ non-deterministic in python 2.4 (cpython)?
Holger Joukl wrote: Anyway: Is relying on __del__ getting called immediately when the refcount drops to 0 a no-no? yes, but more importantly, relying on the refcount dropping to 0 when something goes out of scope is a major no-no. If so should that maybe be prominently stated in the docs? is it perhaps the color that made you miss the big bold boxes in the documentation? http://docs.python.org/ref/customization.html#l2h-177 /F -- http://mail.python.org/mailman/listinfo/python-list
Re: Re: inconvenient unicode conversion of non-string arguments
[EMAIL PROTECTED] schrieb am 13.12.2006 11:02:30: Holger Joukl wrote: Hi there, I consider the behaviour of unicode() inconvenient wrt to conversion of non-string arguments. While you can do: unicode(17.3) u'17.3' you cannot do: unicode(17.3, 'ISO-8859-1', 'replace') Traceback (most recent call last): File stdin, line 1, in ? TypeError: coercing to Unicode: need string or buffer, float found [...] Any reason why unicode() with a non-string argument should not allow the encoding and errors arguments? There is reason: encoding is a property of bytes, it is not applicable to other objects. Ok, but I still don't see why these arguments shouldn't simply be silently ignored for non-string arguments. Or some good solution to work around my problem? Do not put undecoded bytes in a mixed-type argument list. A rule of thumb working with unicode: decode as soon as possible, encode as late as possible. It's not always that easy when you deal with a tree data structure with the tree elements containing different data types and your user may decide to output root.element.subelement.whateverData. I have the problems in a logging mechanism, and it would vanish if unicode(non-string, encoding, errors) would work and just ignore the obsolete arguments. Best regards, Holger Der Inhalt dieser E-Mail ist vertraulich. Falls Sie nicht der angegebene Empfänger sind oder falls diese E-Mail irrtümlich an Sie adressiert wurde, verständigen Sie bitte den Absender sofort und löschen Sie die E-Mail sodann. Das unerlaubte Kopieren sowie die unbefugte Übermittlung sind nicht gestattet. Die Sicherheit von Übermittlungen per E-Mail kann nicht garantiert werden. Falls Sie eine Bestätigung wünschen, fordern Sie bitte den Inhalt der E-Mail als Hardcopy an. The contents of this e-mail are confidential. If you are not the named addressee or if this transmission has been addressed to you in error, please notify the sender immediately and then delete this e-mail. Any unauthorized copying and transmission is forbidden. E-Mail transmission cannot be guaranteed to be secure. If verification is required, please request a hard copy version. -- http://mail.python.org/mailman/listinfo/python-list
Re: Sybase module 0.38pre1 released
By the way, I forgot to say that new releases can now be downloaded from this page: https://sourceforge.net/project/showfiles.php?group_id=184050 regards -- Sébastien Sablé 2006/12/12, Sébastien Sablé [EMAIL PROTECTED]: WHAT IS IT: The Sybase module provides a Python interface to the Sybase relational database system. It supports all of the Python Database API, version 2.0 with extensions. MAJOR CHANGES SINCE 0.37: * This release works with python 2.5 * It also works with sybase 15 * It works with 64bits clients * It can be configured to return native python datetime objects * The bug This routine cannot be called because another command structure has results pending. which appears in various cases has been corrected * It includes a unitary test suite based on the dbapi2.0 compliance test suite -- http://mail.python.org/mailman/listinfo/python-list
Re: merits of Lisp vs Python
Juan R. schrieb: Kay Schluehr wrote: You mean a universal language adapter? I guess this is always possible using alpha conversion but I don't believe this leads to theoretical or practical interesting solutions but is just a limit concept. Not familiarized with you terminology. I think that i would call that a universal language composer. I mean if there exists some theoretical limitation to composionality of two directly collapsing languages (G1, T1) and (G2, T2) via a unambiguous modification (e.g. 'renaming') to a third one (G2', T2'), unknown to me. I mean some theoretical limitation in the sense of known theoretical limitations to proving theorems in closed formal systems. After all proving a formal theorem is not very different from enhacement of a language. But proving the theorem might be trivial and the implementation useless. It's like saying you want universal composition of two geometric objects e.g. two manifolds M1, M2 and I write down M3 = M1 x M2. This is always feasible but this is just not the right kind of thing in many occasions. I want to give a practical example. The Python grammar defines a compound_stmt rule by: compound_stmt: for_stmt | while_stmt | if_stmt | ... Now you might add a switch_stmt to G1 and a repeat_stmt to G2 G1: compound_stmt: for_stmt | while_stmt | if_stmt | switch_stmt |... G2: compound_stmt: for_stmt | while_stmt | if_stmt | repeat_stmt |... What you actually want in G3 is G3: compound_stmt: for_stmt | while_stmt | if_stmt | switch_stmt | repeat_stmt |... You don't want to rename each statement and mangle each terminal of G2 although this might always be possible. Renaming also negatively affects the transformer of G2 which precedes composition and is encoded as Python source. It has to be refactored too when you rename a rule. So one requirement on a system of composition rules is to drop alpha conversion which is just a last resort. I guess in any *reasonable* system of composition rules the question whether G1 and G2 are composable is decidable and this can also be proofed at least for certain classes of grammars that are not Turing complete languages by themselves. The practical problem with composing enhancements is that any two extensions L1, L2 share a lot of rules and rely on their structure. What if they don't just extend their host language L0 conservatively but also redefine rules of L0? This is not just a theoretical problem but it happens quite naturally if you want to adapt an extension developed for Python 2.4 for working with Python 2.5. Here Python 2.5 is considered as just another particular extension. Obviously Py3K will become an interesting testcase for all kinds of syntactical and semantical transformations. I would consider redefined-L0 to be L0'. I think that a concept of namespaces could be also used for versioning-like conflicts: L0v24:foo(), L0v25:foo(). The problem is that both versions may be stored and managed during initial period of time. But in the long run old libraries, extensions... would be updated to the new version. Sure, but it's preferable to see how far one gets without name mangling and other crutches. -- http://mail.python.org/mailman/listinfo/python-list
Re: merits of Lisp vs Python
Paul Rubin http://[EMAIL PROTECTED] wrote: +--- | CLTL2 is a model of precision and thoroughness compared | with any document that's ever been written about Python. +--- It's a great book, but one needs to be clear that CLtL2 is *not* the same as the ANSI Common Lisp standard, but was the author's best guess at the time as to where the standardization effort was going after CLtL1. You may find the following useful in marking up your copy of CLtL2 to be closer to the final standard: http://cbbrowne.com/info/commonlisp.html#AEN10499 http://bc.tech.coop/cltl2-ansi.htm But note the caveat therein: A doctored CLTL2 is NOT the ANSI standard. In fact, this FAQ has many known but minor omissions that are too awkward to add with pencil to CLTL2. The Common Lisp HyperSpec (CLHS), while also not the official ANSI standard per se, was created from the same TeX input as the ANSI standard (with permission from ANSI X3), and is the reference most CL programmers use: http://www.lisp.org/HyperSpec/FrontMatter/index.html http://www.lispworks.com/documentation/HyperSpec/Front/index.htm For a downloadable tarball of the whole thing, there's a link near the bottom of this page: http://www.lispworks.com/documentation/HyperSpec/index.html -Rob - Rob Warnock [EMAIL PROTECTED] 627 26th Avenue URL:http://rpw3.org/ San Mateo, CA 94403 (650)572-2607 -- http://mail.python.org/mailman/listinfo/python-list
Re: merits of Lisp vs Python
Christophe [EMAIL PROTECTED] writes: Robert Uhl a écrit : [EMAIL PROTECTED] (Aahz) writes: Consider this: Lisp has had years of development, it has had millions of dollars thrown at it by VC firms -- and yet Python is winning over Lisp programmers. Think about it. The argument from popularity is invalid. French units have overtaken standard units, Never heard of that French unit thing. Unless you talk about that archaic unit system that was in use before the metric system was created. Who invented the metric system? -- __Pascal Bourguignon__ http://www.informatimago.com/ Wanna go outside. Oh, no! Help! I got outside! Let me back inside! -- http://mail.python.org/mailman/listinfo/python-list
Re: merits of Lisp vs Python
[EMAIL PROTECTED] a écrit : Bjoern Schliessmann wrote: Robert Uhl wrote: Because it's the language for which indentation is automatically determinable. That is, one can copy/paste a chunk of code, hit a key and suddenly everything is nicely indented. Cool, so in other languages I need to set block marks like () and {} and also indent the code for readability, and in Python I indent only. From my POV that's less work. Try reading again. In Lisp, you use () and *your editor* automatically indents according to the universal standard, or you leave it sloppy until other folks reading your code convince you to get a proper programming editor. Indentation does not get out of sync with semantics because the editor virtually never misses parentheses that the Lisp compiler sees. Expressions keep the same meaning even if you have to start breaking them across lines, etc. In Python, you group in your mind, and press indentation keys to make it happen in your editor. The editor cannot help that much, because it cannot read your mind. White space screwups in copy-paste cannot be fixed by the editor automatically, because it cannot read the original programmer's mind, and you have to fix it manually, and risk screwing it up. Call us when you have an editor that reads your mind and writes the () for you. -- http://mail.python.org/mailman/listinfo/python-list
Re: inconvenient unicode conversion of non-string arguments
Holger Joukl wrote: Ok, but I still don't see why these arguments shouldn't simply be silently ignored import this /F -- http://mail.python.org/mailman/listinfo/python-list
Re: merits of Lisp vs Python
Paul Rubin schrieb: Neil Cerutti [EMAIL PROTECTED] writes: Is the above 'duck-typing' idiom considered very useful to a Lisper? It seems logical to me that duck-typing works best in an environment where it is ubiquitous. If users have to implement accessors specifically to use your library, it is not as good as if they had already implemented one as a matter of routine. No, it's not as ubiquitious as in Python. I guess that has many different reasons, probably many historical. IIRC Peter Seibel writes in Practical Common Lisp that CLOS (and thus defgeneric) was introduced late in the CL standardization process. That my be one reason why it is not used extensively by the rest of the standardized language. It's a little more complicated than that, the classes involved have to have special interfaces to tell setf/getf what to do, sort of a compile time equivalent of __setattr__/__getattr__ if I remember right. The code I've posted is all you need. You can specialize it for any class (including numbers, functions, symbols etc.) you like. In case of the lookup ($ a 0) there is nothing done at compile time, it's just a call of the generic function $. (setf ($ a 0) 1) is translated at compile time (setf is a macro) to something like (funcall #'(setf $) 1 a 0). -- http://mail.python.org/mailman/listinfo/python-list
Re: YouTube written in Python
On 12/13/06, Terry Reedy [EMAIL PROTECTED] wrote: [EMAIL PROTECTED] wrote: Really? It's awful! Awesome? Well, it's got some pretty awful clips on it, but I don't think you can blame that on the technology. ;-) -- Cheers, Simon B [EMAIL PROTECTED] http://www.brunningonline.net/simon/blog/ -- http://mail.python.org/mailman/listinfo/python-list
Re: merits of Lisp vs Python
On Wed, 13 Dec 2006 03:13:26 +0100, Paddy [EMAIL PROTECTED] wrote: Not even close. In my example above: for a in y: dosomethingwith(a) y could be a lot of built-in types such as an array, list, tuple, dict, file, or set. - Paddy. I was refering to the recursive Lisp example. Did you even read the post? -- Using Opera's revolutionary e-mail client: http://www.opera.com/mail/ -- http://mail.python.org/mailman/listinfo/python-list
Re: Re: call of __del__ non-deterministic in python 2.4 (cpython)?
[EMAIL PROTECTED] schrieb am 13.12.2006 11:09:13: Holger Joukl wrote: Anyway: Is relying on __del__ getting called immediately when the refcount drops to 0 a no-no? yes, but more importantly, relying on the refcount dropping to 0 when something goes out of scope is a major no-no. In my particular use case I think can rule out the problematic situations, except for the object being referenced in the stack trace, but that won't put me into problems (and there were no exceptions at all when I ran into the deadlocks) If so should that maybe be prominently stated in the docs? is it perhaps the color that made you miss the big bold boxes in the documentation? http://docs.python.org/ref/customization.html#l2h-177 /F I did read this but didn't think it applied to my situation. I'm quite sure that the refcount of the local variable is 1 before the local scope is left. So let me rephrase the question: Even if I can make sure that non of the problematic situtions apply, might it _still_ happen that __del__ gets called after some other code has already been entered? Thanks, Holger Der Inhalt dieser E-Mail ist vertraulich. Falls Sie nicht der angegebene Empfänger sind oder falls diese E-Mail irrtümlich an Sie adressiert wurde, verständigen Sie bitte den Absender sofort und löschen Sie die E-Mail sodann. Das unerlaubte Kopieren sowie die unbefugte Übermittlung sind nicht gestattet. Die Sicherheit von Übermittlungen per E-Mail kann nicht garantiert werden. Falls Sie eine Bestätigung wünschen, fordern Sie bitte den Inhalt der E-Mail als Hardcopy an. The contents of this e-mail are confidential. If you are not the named addressee or if this transmission has been addressed to you in error, please notify the sender immediately and then delete this e-mail. Any unauthorized copying and transmission is forbidden. E-Mail transmission cannot be guaranteed to be secure. If verification is required, please request a hard copy version. -- http://mail.python.org/mailman/listinfo/python-list
Re: merits of Lisp vs Python
On Wed, 13 Dec 2006 09:39:44 +0100, Timofei Shatrov [EMAIL PROTECTED] wrote: On 12 Dec 2006 18:03:49 -0800, Paddy [EMAIL PROTECTED] tried to confuse everyone with this message: There are a lot of people that use Wikipedia. I think some of them might want to learn to program. I think you misunderstood the goal of Wikipedia. It is not to teach people programming. I make it easier for them to find Python by helping to maintain Python within Wikipedia. If someone wants to find Python, he types Python in the search bar and works from there. He certainly wouldn't end up in doctest article. Some people dislike Wikipedia which is fine. Some people dislike Wikipedia and deliberately sabotage it, which is vandalism. Writing vanity articles about non-notable things is not much better. You are being silly. Wikipedia has for instance the best coverage of math of any encyclopedia (if you can call it that). This is how I came in touch with it. If you want trivia you get trivia. If you want Phd. level math it has that as well. It is as diverse as the people that use it. -- Using Opera's revolutionary e-mail client: http://www.opera.com/mail/ -- http://mail.python.org/mailman/listinfo/python-list
Re: merits of Lisp vs Python
Pascal Bourguignon a écrit : Christophe [EMAIL PROTECTED] writes: Robert Uhl a écrit : [EMAIL PROTECTED] (Aahz) writes: Consider this: Lisp has had years of development, it has had millions of dollars thrown at it by VC firms -- and yet Python is winning over Lisp programmers. Think about it. The argument from popularity is invalid. French units have overtaken standard units, Never heard of that French unit thing. Unless you talk about that archaic unit system that was in use before the metric system was created. Who invented the metric system? That system is called the metric system, not French units. French units refer to the archaic system used before the metric system was invented ( at least according to google ) So, let's admit that French Units refer to the metric system. I suppose then that the so called standard units refer to the imperial system. Saying that the French units are technically worse than standard units is a troll of very poor quality and a very weak argument. -- http://mail.python.org/mailman/listinfo/python-list
Re: merits of Lisp vs Python
Robert Uhl [EMAIL PROTECTED] wrote: +--- | [EMAIL PROTECTED] [EMAIL PROTECTED] writes: | I have the code here (probably not the latest bcs I left the company | when it was acquired), let's do a little experiment, for what it's | worth: 89727 lines of Lisp code in 131 modules (lisp code files), 3306 | (defun (by grep|wc), and 261 (defmacro. [We did NOT use macros as | functions!] [Note that lines of code doesn't really matter in Lisp.] | | Wow--my emacs install has 1,152,598 lines of code in 1,570 files, | 29,244 defuns and 1,393 defmacros. +--- Wow, indeed! The entire CMUCL-19c distribution is only 592081 lines of source code in 1192 files, with 10699 DEFUNs and 1839 DEFMACROs. I didn't realize CMUCL was so small compared to Emacs. ;-} [Of course, that doesn't include the number of DEFUNs DEFMACROs which are defined *by* macros, or the total of 2809 DEFINE-VOPs in the various flavors of the compiler...] -Rob - Rob Warnock [EMAIL PROTECTED] 627 26th Avenue URL:http://rpw3.org/ San Mateo, CA 94403 (650)572-2607 -- http://mail.python.org/mailman/listinfo/python-list
Re: Re: inconvenient unicode conversion of non-string arguments
[EMAIL PROTECTED] schrieb am 13.12.2006 11:37:03: Holger Joukl wrote: Ok, but I still don't see why these arguments shouldn't simply be silently ignored import this /F You probably refer to Explicit is better than implicit.. In that particular case I still think it wouldn't hurt to allow the encoding/errors arguments to keep the unicode() signature consistent for all types of the first argument. I'd go with Although practicality beats purity. ;-) Holger (But maybe I'm not aware of tricky-implementation issues...) Der Inhalt dieser E-Mail ist vertraulich. Falls Sie nicht der angegebene Empfänger sind oder falls diese E-Mail irrtümlich an Sie adressiert wurde, verständigen Sie bitte den Absender sofort und löschen Sie die E-Mail sodann. Das unerlaubte Kopieren sowie die unbefugte Übermittlung sind nicht gestattet. Die Sicherheit von Übermittlungen per E-Mail kann nicht garantiert werden. Falls Sie eine Bestätigung wünschen, fordern Sie bitte den Inhalt der E-Mail als Hardcopy an. The contents of this e-mail are confidential. If you are not the named addressee or if this transmission has been addressed to you in error, please notify the sender immediately and then delete this e-mail. Any unauthorized copying and transmission is forbidden. E-Mail transmission cannot be guaranteed to be secure. If verification is required, please request a hard copy version. -- http://mail.python.org/mailman/listinfo/python-list
Re: inconvenient unicode conversion of non-string arguments
Holger Joukl wrote: [EMAIL PROTECTED] schrieb am 13.12.2006 11:02:30: Holger Joukl wrote: Hi there, I consider the behaviour of unicode() inconvenient wrt to conversion of non-string arguments. While you can do: unicode(17.3) u'17.3' you cannot do: unicode(17.3, 'ISO-8859-1', 'replace') Traceback (most recent call last): File stdin, line 1, in ? TypeError: coercing to Unicode: need string or buffer, float found [...] Any reason why unicode() with a non-string argument should not allow the encoding and errors arguments? There is reason: encoding is a property of bytes, it is not applicable to other objects. Ok, but I still don't see why these arguments shouldn't simply be silently ignored for non-string arguments. That's rather bizzare and sloppy approach. Should unicode(17.3, 'just-having-fun', 'I-do-not-like-errors') unicode(17.3, 'sdlfkj', 'ewrlkj', 'eoirj', 'sdflkj') work? Or some good solution to work around my problem? Do not put undecoded bytes in a mixed-type argument list. A rule of thumb working with unicode: decode as soon as possible, encode as late as possible. It's not always that easy when you deal with a tree data structure with the tree elements containing different data types and your user may decide to output root.element.subelement.whateverData. I have the problems in a logging mechanism, and it would vanish if unicode(non-string, encoding, errors) would work and just ignore the obsolete arguments. I don't really see from your example what stops you from putting unicode instead of bytes into your tree, but I can believe some libraries can cause some extra work. That's the problem with libraries, not with builtin function unicode(). Would you be happy if floating point value 17.3 would be stored as 8 bytes in your tree? After all, that is how 17.3 is actually represented in computer memory. Same story with unicode, if some library gives you raw bytes *you* have to do extra work later. -- Leo -- http://mail.python.org/mailman/listinfo/python-list
Re: merits of Lisp vs Python
Timofei Shatrov wrote: Are you aware that you hardly know any Lisp yet make such bold and unfounded claims? Unless interning a string somehow gives it a property list, slot value and function value it doesn't give you the same capabilities. I'm talking about the capability of comparing symbols efficiently by address, which Robert seemed to think that Python couldn't do. I was pointing out that it can, despite not having a distinct symbol type. I know about property lists. The Pythonic way to do the equivalent thing is using a dictionary. I also know about the dual function/other value of a symbol, which has alway seemed like an idiotic feature to me. All it seems to do is make it more awkward than necessary to deal with functions as first class objects, which is supposedly meant to be one of Lisp's strengths. So I regard it as a feature that Python *doesn't* have this. :-) -- Greg -- http://mail.python.org/mailman/listinfo/python-list
slices - handy summary
If, like me, you're always forgetting which way around your list/seq slices need to go then worry no more. Just put my handy slice lookupper (TM) ) on a (large!) PostIt beside your screen and, Hey Presto! no more tediously typing a 1-9 seq into your interpreter and then getting a slice just to check what you get.. (Yes you. You know you do that !) ...Cheers Steve x = '0123456789' x[-10: ] 0123456789 x[ 0: ] x[ -9: ] 123456789 x[ 1: ] x[ -8: ] 23456789 x[ 2: ] x[ -7: ] 3456789x[ 3: ] x[ -6: ] 456789 x[ 4: ] x[ -5: ] 56789 x[ 5: ] x[ -4: ] 6789 x[ 6: ] x[ -3: ] 789x[ 7: ] x[ -2: ] 89 x[ 8: ] x[ -1: ] 9 x[ 9: ] x[ :-9 ] 0 x[ :1 ] x[ :-8 ] 01 x[ :2 ] x[ :-7 ] 012x[ :3 ] x[ :-6 ] 0123 x[ :4 ] x[ :-5 ] 01234 x[ :5 ] x[ :-4 ] 012345 x[ :6 ] x[ :-3 ] 0123456x[ :7 ] x[ :-2 ] 01234567 x[ :8 ] x[ :-1 ] 012345678 x[ :9 ] 0123456789 x[ :10 ] -- http://mail.python.org/mailman/listinfo/python-list
Re: YouTube written in Python
Leif K-Brooks wrote: Terry Reedy wrote: In a thread on the PyDev list, Guido van Rossum today wrote: And I just found out (after everyone else probably :-) that YouTube is almost entirely written in Python. (And now I can rub shoulders with the developers since they're all Googlers now... :-) Interesting. I wonder what they're using for a Web framework? Of course, sites that size generally use lots of custom stuff, but it would presumably be based on something. awesome.Could you give the link where guido told this -Chandru -- http://mail.python.org/mailman/listinfo/python-list
Re: inconvenient unicode conversion of non-string arguments
Holger Joukl wrote: Ok, but I still don't see why these arguments shouldn't simply be silently ignored import this You probably refer to Explicit is better than implicit.. Errors should never pass silently. is a better match, I think. you're trying to do an invalid operation. python tells you to fix your code. /F -- http://mail.python.org/mailman/listinfo/python-list
Re: Tarfile .bz2
Martin v. Löwis [EMAIL PROTECTED] (MvL) wrote: MvL Jordan schrieb: Not really on topic anymore but what's the method for tar.gz? MvL It works like .tar.bz2, except that it uses gzip (www.gzip.org) MvL as the compression library. The underlying compression algorithm MvL is LZW. No, it uses a compression algorithm based on LZ77 (called DEFLATE). Therefore gzip was not encumbered by the the LZW patent. -- Piet van Oostrum [EMAIL PROTECTED] URL: http://www.cs.uu.nl/~piet [PGP 8DAE142BE17999C4] Private email: [EMAIL PROTECTED] -- http://mail.python.org/mailman/listinfo/python-list
Re: YouTube written in Python
Leif K-Brooks wrote: Terry Reedy wrote: In a thread on the PyDev list, Guido van Rossum today wrote: And I just found out (after everyone else probably :-) that YouTube is almost entirely written in Python. (And now I can rub shoulders with the developers since they're all Googlers now... :-) Interesting. I wonder what they're using for a Web framework? Of course, sites that size generally use lots of custom stuff, but it would presumably be based on something. awesome.Could you give the link where guido told this -Chandru -- http://mail.python.org/mailman/listinfo/python-list
Re: Is anyone using Python for embedded applications?
Hendrik van Rooyen wrote: It depends a *lot* on what is meant by embedded : Indeed. This definition seems to cover everything from: - a cut down PC in a non standard box, through - a processor in a Washing Machine, to - a bare PIC processor in a Burglar Alarm... CPython doesn't span all these situations, but there are a few different strategies involving Python: * A cut-down build of CPython, or perhaps just a recompiled or cross-compiled build; this is good enough for some of the more luxurious embedded devices. The Gumstix hardware is a reasonable example: http://www.gumstix.org/ * A re-engineered version of CPython with things taken out or optimised for simpler hardware. An example of this approach is PyMite: http://wiki.python.org/moin/PyMite * Software which isn't actually running in Python on the device but which has been designed using Python. Projects like MyHDL and WhatOS at least allow you to prototype things in Python: http://myhdl.jandecaluwe.com/doku.php http://www.sticlete.com/whatos/ [...] as I in fact discovered Python because it is embedded in a GPS module we were evaluating for building into a device - so I will follow your progress with interest... Interesting! Any links, or is it related to the Telit hardware already discussed? Paul -- http://mail.python.org/mailman/listinfo/python-list
Re: slices - handy summary
meridian wrote: If, like me, you're always forgetting which way around your list/seq slices need to go then worry no more. Just put my handy slice lookupper (TM) ) on a (large!) PostIt beside your screen and, Hey Presto! no more tediously typing a 1-9 seq into your interpreter and then getting a slice just to check what you get.. (Yes you. You know you do that !) ...Cheers Steve Actually, I don't. I just remember that, for a natural (positive nonzero) number y: x[:y] is the first y elements x[-y:] is the last y elements As shown here: x = range(5) x [0, 1, 2, 3, 4] x[:2] [0, 1] x[-2:] [3, 4] And I just work it out from there. Just my method for remembering slices, that happens to work pretty well for me. x = '0123456789' x[-10: ] 0123456789 x[ 0: ] x[ -9: ] 123456789 x[ 1: ] x[ -8: ] 23456789 x[ 2: ] x[ -7: ] 3456789x[ 3: ] x[ -6: ] 456789 x[ 4: ] x[ -5: ] 56789 x[ 5: ] x[ -4: ] 6789 x[ 6: ] x[ -3: ] 789x[ 7: ] x[ -2: ] 89 x[ 8: ] x[ -1: ] 9 x[ 9: ] x[ :-9 ] 0 x[ :1 ] x[ :-8 ] 01 x[ :2 ] x[ :-7 ] 012x[ :3 ] x[ :-6 ] 0123 x[ :4 ] x[ :-5 ] 01234 x[ :5 ] x[ :-4 ] 012345 x[ :6 ] x[ :-3 ] 0123456x[ :7 ] x[ :-2 ] 01234567 x[ :8 ] x[ :-1 ] 012345678 x[ :9 ] 0123456789 x[ :10 ] -- http://mail.python.org/mailman/listinfo/python-list
Re: namespace question
[EMAIL PROTECTED] [EMAIL PROTECTED] (jssgc) wrote: jssgc This one works. But I suppose there must be a way to artificially jssgc create a new block of code, some thing like this, jssgc class Test: jssgcc = None jssgchowToCreateANewNameSpace: jssgc# Objects created here are local to this scope jssgca = 1 jssgcb = 2 jssgcglobal c jssgcc = a + b As you want c to be an *instance* variable, the normal idiom would be: class Test: def __init__(self): a = 1 b = 2 self.c = a+b x = Test() print x.c -- Piet van Oostrum [EMAIL PROTECTED] URL: http://www.cs.uu.nl/~piet [PGP 8DAE142BE17999C4] Private email: [EMAIL PROTECTED] -- http://mail.python.org/mailman/listinfo/python-list
Re: merits of Lisp vs Python
Markus Triska schrieb: Ken Tilton [EMAIL PROTECTED] writes: I think all-rules-all-the-time Prolog is the poster boy for paradigm slavery. (I did try for a famous two months to use Prolog as a general-purpose programming language.) Don't expect to learn Prolog properly in so little time. To your previous question whether the ~180 lines of Lisp code in some online book constitute an industrial strength Prolog: only if the following ~180 lines of Prolog code implement an industrial strength Lisp. Hallo, you are of course right. There are some prolog implementations for Lisp that implement some parts of Prolog. To get the full thing one would of course need a big lot more of work. The idea is to get the basic constructs of Prolog available for Lisp. And with 2k LOC there are already some nice things that one can do. Those who know the paradigm of logical programming can recognize that a problem falls into this domain and then use inside of Lisp some tools that allow to express the problem in this domain specific language. If one really wants/needs Prolog then one should use it ;) The Prolog implementations are much more efficient and very stable. But often even 60% of Prolog are so expressive, that it can be a real productivity booster. André -- -- http://mail.python.org/mailman/listinfo/python-list
Re: namespace question
[EMAIL PROTECTED] wrote: Yes. I want to have only one class variable called c and a and b are required as temporary variables to calculate the value for c. I just found one way: class Test: a = 1 b = 2 c = a + b del a,b Or even... a = 1 b = 2 class Test: c = a + b Or even the apparently nonsensical... a = 1 b = 2 c = a + b class Test: c = c Insert del statements to remove module globals where appropriate. Paul -- http://mail.python.org/mailman/listinfo/python-list
Re: paramiko public key
hg wrote: [EMAIL PROTECTED] wrote: paramiko http://www.lag.net/paramiko/docs/ __str__ ? hi thanks for the tip i done up a function to generate priv/pub key pairs like this def keygen(bits,fil,password=None): k = paramiko.RSAKey.generate(bits) k.write_private_key_file(fil, password) pk = paramiko.RSAKey(filename=fil) o = open(pubk ,w).write(pk.__str__()) Is this the correct way to do it ? thanks -- http://mail.python.org/mailman/listinfo/python-list
Re: Re: inconvenient unicode conversion of non-string arguments
[EMAIL PROTECTED] schrieb am 13.12.2006 12:05:33: Holger Joukl wrote: Ok, but I still don't see why these arguments shouldn't simply be silently ignored import this You probably refer to Explicit is better than implicit.. Errors should never pass silently. is a better match, I think. you're trying to do an invalid operation. python tells you to fix your code. /F I'm not doing an invalid operation with unicode(17.3) What's invalid about unicode(17.3, latin-1, replace)? IMHO the encoding/errors args can only ever apply for string arguments so this could well fall back to unicode(17.3). Might be I'm overlooking something grave, but I'm still not convinced. But thanks for your advice, Holger Der Inhalt dieser E-Mail ist vertraulich. Falls Sie nicht der angegebene Empfänger sind oder falls diese E-Mail irrtümlich an Sie adressiert wurde, verständigen Sie bitte den Absender sofort und löschen Sie die E-Mail sodann. Das unerlaubte Kopieren sowie die unbefugte Übermittlung sind nicht gestattet. Die Sicherheit von Übermittlungen per E-Mail kann nicht garantiert werden. Falls Sie eine Bestätigung wünschen, fordern Sie bitte den Inhalt der E-Mail als Hardcopy an. The contents of this e-mail are confidential. If you are not the named addressee or if this transmission has been addressed to you in error, please notify the sender immediately and then delete this e-mail. Any unauthorized copying and transmission is forbidden. E-Mail transmission cannot be guaranteed to be secure. If verification is required, please request a hard copy version. -- http://mail.python.org/mailman/listinfo/python-list
Re: newb: Creating Exception
johnny wrote: Thank you Dennis, So when line 2, gets executed, its exception goes to do_some1_error. And when line 3, gets executed, its exception goes to do_some2_error and so on. line 1: try line 2:do_some1 line 3:do_some2 line 4:do_some3 line 5: except do_some1_error: line 6:whatever1 line 7: except do_some2_error: line 8:whatever2 line 9: except do_some3_error: line 10:whatever3 Documentation is not written for newbs, it's written by guys with 6yrs of experience FOR guys with 6yrs of experience. You might want to get a book on python, rather than depend on the documentation, which is, as you say, written for more experienced programmers. http://wiki.python.org/moin/IntroductoryBooks I started with a book, and reading the tutorial now, am quite glad I did. One thing that did bug me, at least briefly, is sometimes beginner books don't explain what a line of code is actually doing - not necessarily how it works, but as much information as is necessary to actually be able to use the code shown. Dennis Lee Bieber wrote: On 11 Dec 2006 16:02:02 -0800, johnny [EMAIL PROTECTED] declaimed the following in gmane.comp.python.general: I want to print individual exception for database connection, sql execution, database closing, closing the cursor. Can I do it with one try..catch or I need a nested try...catch? Python does not have a catch instruction. You could do: try: make connection #though that should, in my mind, be done #as part of the initialization of the thread #and not as part of any processing loop make cursor execute sql fetch results if any close cursor commit transaction close connection#which I'd make part of the termination #of the thread except Exception1, msg: do something except Exception2, msg: do something2 ... IF each step raises a different exception type -- if all the database returns is DatabaseError, then there is nothing to separate them by. Also note that if an exception happens in the execute sql stage, your handler may need to do a rollback, and the closes. -- WulfraedDennis Lee Bieber KD6MOG [EMAIL PROTECTED] [EMAIL PROTECTED] HTTP://wlfraed.home.netcom.com/ (Bestiaria Support Staff: [EMAIL PROTECTED]) HTTP://www.bestiaria.com/ -- http://mail.python.org/mailman/listinfo/python-list
Re: newb: Creating Exception
Dustan wrote: johnny wrote: Documentation is not written for newbs, it's written by guys with 6yrs of experience FOR guys with 6yrs of experience. You might want to get a book on python, rather than depend on the documentation, which is, as you say, written for more experienced programmers. http://wiki.python.org/moin/IntroductoryBooks I started with a book, and reading the tutorial now, am quite glad I did. One thing that did bug me, at least briefly, is sometimes beginner books don't explain what a line of code is actually doing - not necessarily how it works, but as much information as is necessary to actually be able to use the code shown. I didn't complete my thought. If you run into a situation like this, then you might want to look to the python documentation on the web for help; think of the web documentation as a reference manual rather than a tutorial, even though it does provide a tutorial. -- http://mail.python.org/mailman/listinfo/python-list
Re: how can i write a hello world in chinese with python
Leo Kislov wrote: kernel1983 wrote: and I tried unicode and utf-8 How did you try unicode? Like this? : EasyDialogs.Message(u'\u4e2d') I tried to both use unicodeutf-8 head just like \xEF\xBB\xBF and not to use Anyone knows about the setting in the python code file? Maybe python doesn't know I'm to use chinese?! It depends on how EasyDialogs works. And by the way, when you say utf-8 encoded text is not displayed correctly, what do you actually see on the screen? There is a Windows version of EasyDialogs -- unfortunately it appears not to support Unicode, even for the most simple case. This works: | EasyDialogs.Message('fubar') but this doesn't: | EasyDialogs.Message(u'fubar') The title of the window is empty, the text consists of only 'f, and there is no OK button. Not very robust. -- http://mail.python.org/mailman/listinfo/python-list
Re: oo problem
Hi, First, let me thanks you for all your clear comments. This is, in my mind, both a usage and a design flaw. You are creating (and throwing away) instances of drawable objects to the draw method of a paper instance. But what does paper.draw() actually do with the drawable object? Call a draw method within it? No, actually the paper instance is a subclass of a canvas from an external module. And this one have a stroke() method. In reading your comments, I think it's now clear that I must get back and let any primitive have an inner draw() method ( a subclass of Drawable object in our case). If so, that is when you should pass the paper instance (or just the part needed -- clipping rectangle perhaps?). In fact, my approach was a bad one : in initialising the paper instance, I was already clipping it. If I wrote : p = Paper(-5,-5,5,5), all drawings made on that paper will be clipped inside a rectangle with lower-left corner (-5,-5) and upper-right corner (5,5). Now, I think it's better to clip after all primitives have been added to the paper. The actual implementation of draw() for each primitive will have to handle clipping to the boundaries of the Canvas object that is passed to it. You'll notice that the only place the primitive needs to know about the canvas is in its specific draw method. And only at that time is the canvas (paper) passed to it. Instead of the concept; Paper, draw a line from x to y (and having to pass the paper to the initializer of the line primitive), you have to think in terms of: Line, draw yourself on this paper Or, if you consider the last example above… Compare that to your example: -=-=-=-=- paper.draw( Line( paper, x1, y1, x2, y2) ) -=-=-=-=-=- Here, you are telling the paper to do the drawing, and passing it a Line instance (and passing it the paper it is supposed to be drawn on). Why? The paper isn't drawing the line on itself… While -=-=-=-=- Line(Point(x1, y1), Point(x2, y2)).draw(paper) -=-=-=-=- initializes a Line instance, then asks it to draw itself using paper as the surface to be drawn upon. Yes I was wrong, that's all clear now. Thanks again, this was very helpfull. 6TooL9 -- http://mail.python.org/mailman/listinfo/python-list
Re: Re: call of __del__ non-deterministic in python 2.4 (cpython)?
On 12/13/06, Holger Joukl [EMAIL PROTECTED] wrote: I did read this but didn't think it applied to my situation. I'm quite sure that the refcount of the local variable is 1 before the local scope is left. So let me rephrase the question: Even if I can make sure that non of the problematic situtions apply, might it _still_ happen that __del__ gets called after some other code has already been entered? You shouldn't rely on __del__ being called exactly when you expect it, particularly in a threaded application. Make explicit cleanup calls, instead. -- http://mail.python.org/mailman/listinfo/python-list
Re: YouTube written in Python
Speaking of YouTube, does anyone know how they uploads big files( 100MB) I need to solve that problem ( in Python of course) and YouTube is a good sample of that. Lad. -- http://mail.python.org/mailman/listinfo/python-list
Re: Large files uploading
to use any communications protocol (including HTTP), both ends must have programs that can talk that protocol... Sure, but browsers have FTP support. But how to call the FTP API from Python? Lad. -- http://mail.python.org/mailman/listinfo/python-list
Re: YouTube written in Python
[EMAIL PROTECTED] wrote: awesome.Could you give the link where guido told this you need to work on your google skills: http://mail.python.org/pipermail/python-dev/2006-December/070323.html /F -- http://mail.python.org/mailman/listinfo/python-list
Re: How do I edit a PythonWin path to import custom built modules???
Fredrik Lundh wrote: Python does *not* use the Path when searching for modules; sys.path is initialized based on the contents of PYTHONPATH, the location of the Python executable (or PYTHONHOME), some heuristics, and certain registry entries. Now I'm stumped. Unless it's heuristics. The registry entry for PythonPath does NOT reference the location of my Python scripts (d:/Python). And Python is installed in the usual place on C:\Python24. The only place that I can see where I've told it the location of my scripts is in the Path variable. I have no doubt that you're correct. Just confused as usual. rd -- http://mail.python.org/mailman/listinfo/python-list
Re: About alternatives to Matlab
In [EMAIL PROTECTED], Jon Harrop wrote: I don't think you would be much happier to see totally obfuscated golf one-liners. That doesn't even make sense. Squeezing code onto one line doesn't improve byte count. So you don't count line endings when counting bytes. ;-) Ciao, Marc 'BlackJack' Rintsch -- http://mail.python.org/mailman/listinfo/python-list
Re: Validate XML against a set of XSD files, with Python
Fast google query, uncheked, leads to: - XSV: http://www.ltg.ed.ac.uk/~ht/xsv-status.html I tried this before. Unfortunately, xsv is not officially supported on my system (FreeBSD 6.1) :-( - libxml : http://codespeak.net/lxml/ Probably this is what I need to use. (However, I see in the mailing lists that there are problems with this part of libxml2.) Thank you, Laszlo -- http://mail.python.org/mailman/listinfo/python-list
Re: [unicode] inconvenient unicode conversion of non-string arguments
In [EMAIL PROTECTED], Holger Joukl wrote: Der Inhalt dieser E-Mail ist vertraulich. Falls Sie nicht der angegebene Empfänger sind oder falls diese E-Mail irrtümlich an Sie adressiert wurde, verständigen Sie bitte den Absender sofort und löschen Sie die E-Mail sodann. Das unerlaubte Kopieren sowie die unbefugte Übermittlung sind nicht gestattet. Die Sicherheit von Übermittlungen per E-Mail kann nicht garantiert werden. Falls Sie eine Bestätigung wünschen, fordern Sie bitte den Inhalt der E-Mail als Hardcopy an. The contents of this e-mail are confidential. If you are not the named addressee or if this transmission has been addressed to you in error, please notify the sender immediately and then delete this e-mail. Any unauthorized copying and transmission is forbidden. E-Mail transmission cannot be guaranteed to be secure. If verification is required, please request a hard copy version. Maybe you should rethink if it really makes sense to add this huge block of nonsense to a post to a newsgroup or public mailing list. If it's confidential, just keep it secret. ;-) Ciao, Marc 'BlackJack' Rintsch -- http://mail.python.org/mailman/listinfo/python-list
Iterating over several lists at once
Hi, I am writing a code that needs to iterate over 3 lists at the same time, i.e something like this: for x1 in l1: for x2 in l2: for x3 in l3: print do something with, x1, x2, x3 What I need to do is go over all n-tuples where the first argument is from the first list, the second from the second list, and so on... I was wondering if one could write this more easily in some manner using only 1 for loop. What I mean is something like this: for (x1,x2,x3) in (l1,l2,l3): print do something with, x1, x2, x3 Or maybe like this: for x1 in l1, x2 in l2, x3 in l3: print do something with, x1, x2, x3 However, this code obviously doesn't work... I'd be very happy to receive ideas about how to do this in one loop and with minimal initialization (if at all required). Thanks in advance, Gal -- http://mail.python.org/mailman/listinfo/python-list
Re: Iterating over several lists at once
Gal Diskin wrote: I am writing a code that needs to iterate over 3 lists at the same time, i.e something like this: for x1 in l1: for x2 in l2: for x3 in l3: print do something with, x1, x2, x3 What I need to do is go over all n-tuples where the first argument is from the first list, the second from the second list, and so on... I was wondering if one could write this more easily in some manner using only 1 for loop. What I mean is something like this: for (x1,x2,x3) in (l1,l2,l3): print do something with, x1, x2, x3 how about for x1, x2, x3 in func(l1, l2, l3): print x1, x2, x3 where func is defined as, say, def func(l1, l2, l3): return ((x1, x2, x3) for x1 in l1 for x2 in l2 for x3 in l3) or if you prefer def helper(l1, l2, l3): for x1 in l1: for x2 in l2: for x3 in l3: yield x1, x2, x3 /F -- http://mail.python.org/mailman/listinfo/python-list
Re: binary input and memory address passing
Thanks Dennis and Scott for both responses. Since Dennis has slam dunked my notion of sharing memory addresses (my ignorance in computing is pretty much unbounded), I guess I will need to continue on with sharing through files. Opening up and loading the binary info into a string variable is very fast. The process bogs when changing the representation to float. So it appears that Scott's Block module might do what I need. My original: nc = #something given nr = #something given f_o=open('junk.bin','rb') x=reshape(array('d',f_o.read()),(nr,nc)) gives me any array with nr rows and nc columns. Using Block I think I would use: f_o=open('junk.bin','rb') x = View('d', Block(f_o.read())) Okay, so now how can I use this? Is this like an array type so that x = reshape(x,(nr,nc)) makes sense? Regards, Eric -- http://mail.python.org/mailman/listinfo/python-list
Re: Iterating over several lists at once
Gal Diskin wrote: Hi, I am writing a code that needs to iterate over 3 lists at the same time, i.e something like this: for x1 in l1: for x2 in l2: for x3 in l3: print do something with, x1, x2, x3 What's wrong with this? [...] I'd be very happy to receive ideas about how to do this in one loop and with minimal initialization (if at all required). def cartesian_product(l1, l2, l3): for i in l1: for j in l2: for k in l3: yield (i, j, k) for (i, j, k) in cartesian_product(l1, l2, l3): print do something with, i, j, k -- Roberto Bonvallet -- http://mail.python.org/mailman/listinfo/python-list
newbie - HTML character codes
Hi sorry if I'm asking something very obvious but I'm stumped. I have a text that looks like this: Sentence 401 4.00pm mdash; We set off again; this time via Tony's home to collect a variety of possessions, finally arriving at hospital no.3. Sentence 402 4.55pm mdash; Tony is ushered into a side ward with three doctors and I stay outside with Mum. And I want the HTML char codes to turn into their equivalent plain text. I've looked at the newsgroup archives, the cookbook, the web in general and can't manage to sort it out. I thought doing something like this - file = open('filename', 'r') ofile = open('otherfile', 'w') done = 0 while not done: line = file.readline() if 'THE END' in line: done = 1 elif 'mdash;' in line: line.replace('mdash;', '--') ofile.write(line) else: ofile.write(line) would do it but it isn'twhere am I going wrong? many thanks rachele -- http://mail.python.org/mailman/listinfo/python-list
Re: About alternatives to Matlab
Marc 'BlackJack' Rintsch wrote: So you don't count line endings when counting bytes. ;-) You'd probably replace \n - so it wouldn't affect the byte count. Anyway, I think I was using non-whitespace bytes, so neither \n nor is counted. -- 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
How to manage two (different) sockets without using threads?
Hi all. I'm (re)writing an FTP server application by using asyncore/asynchat modules. FTP tipically got two different channels: command and data. I'm succesfully managing command channel through asynchat framework, but I'm not sure about how to manage data channel without using a thread/subprocess. Is there an optimal to do that? Can anyone point me in the right direction? -- http://mail.python.org/mailman/listinfo/python-list
Re: newbie - HTML character codes
ardief wrote: [...] And I want the HTML char codes to turn into their equivalent plain text. I've looked at the newsgroup archives, the cookbook, the web in general and can't manage to sort it out. I thought doing something like this - file = open('filename', 'r') It's not a good idea to use 'file' as a variable name, since you are shadowing the builtin type of the same name. ofile = open('otherfile', 'w') done = 0 while not done: line = file.readline() if 'THE END' in line: done = 1 elif 'mdash;' in line: line.replace('mdash;', '--') The replace method doesn't modify the 'line' string, it returns a new string. ofile.write(line) else: ofile.write(line) This should work (untested): infile = open('filename', 'r') outfile = open('otherfile', 'w') for line in infile: outfile.write(line.replace('mdash;', '--')) But I think the best approach is to use a existing aplication or library that solves the problem. recode(1) can easily convert to and from HTML entities: recode html..utf-8 filename Best regards. -- Roberto Bonvallet -- http://mail.python.org/mailman/listinfo/python-list
Re: newbie - HTML character codes
ardief wrote: sorry if I'm asking something very obvious but I'm stumped. I have a text that looks like this: Sentence 401 4.00pm mdash; We set off again; this time via Tony's home to collect a variety of possessions, finally arriving at hospital no.3. Sentence 402 4.55pm mdash; Tony is ushered into a side ward with three doctors and I stay outside with Mum. And I want the HTML char codes to turn into their equivalent plain text. I've looked at the newsgroup archives, the cookbook, the web in general and can't manage to sort it out. file = open('filename', 'r') ofile = open('otherfile', 'w') done = 0 while not done: line = file.readline() if 'THE END' in line: done = 1 elif 'mdash;' in line: line.replace('mdash;', '--') this returns a new line; it doesn't update the line in place. ofile.write(line) else: ofile.write(line) for a more general solution to the actual replace problem, see: http://effbot.org/zone/re-sub.htm#unescape-html you may also want to lookup the fileinput module in the library reference manual. /F -- http://mail.python.org/mailman/listinfo/python-list
Re: Large files uploading
Lad kirjoitti: to use any communications protocol (including HTTP), both ends must have programs that can talk that protocol... Sure, but browsers have FTP support. But how to call the FTP API from Python? Lad. See Python Library Reference for documentation on 'ftplib -- FTP protocol client'. It has an example to get you started. HTH, Jussi Salmela -- http://mail.python.org/mailman/listinfo/python-list
Re: Iterating over several lists at once
Gal Diskin [EMAIL PROTECTED] writes: I am writing a code that needs to iterate over 3 lists at the same time, i.e something like this: for x1 in l1: for x2 in l2: for x3 in l3: print do something with, x1, x2, x3 This does look a little kludgy (untested): for x1,x2,x3 in ((x1,x2,x3) for x1 in l1 for x2 in l2 for x3 in l3): print do something with, x1, x2, x3 -- http://mail.python.org/mailman/listinfo/python-list
Re: Iterating over several lists at once
Gal Diskin wrote: I am writing a code that needs to iterate over 3 lists at the same time, i.e something like this: for x1 in l1: for x2 in l2: for x3 in l3: print do something with, x1, x2, x3 I was wondering if one could write this more easily in some manner using only 1 for loop. def nested_loops(*args): assert args if len(args) == 1: for item in args[0]: yield (item,) else: gap = len(args) // 2 for left in nested_loops(*args[:gap]): for right in nested_loops(*args[gap:]): yield left + right if __name__ == __main__: for i, k in nested_loops(abc, 12): print i, k for i, j, k in nested_loops(ab, 123, xyz): print i, j, k Be prepared for a significant performance hit. Peter PS: Did anybody say macro? No? I must be hallucinating... -- http://mail.python.org/mailman/listinfo/python-list
Re: Iterating over several lists at once
Nothing seriously wrong, but it's not too elegent. Especially when the number of lists you want to iterate over gets bigger (especially because of the indentation in python). As you noticed (an phrased better than me), what I was wondering is if there is a way to iterate over the cartesian product, but without actually doing all n for loops but using a single for loop. Thanks for replying me. On Dec 13, 3:58 pm, Roberto Bonvallet [EMAIL PROTECTED] wrote: Gal Diskin wrote: Hi, I am writing a code that needs to iterate over 3 lists at the same time, i.e something like this: for x1 in l1: for x2 in l2: for x3 in l3: print do something with, x1, x2, x3What's wrong with this? [...] I'd be very happy to receive ideas about how to do this in one loop and with minimal initialization (if at all required).def cartesian_product(l1, l2, l3): for i in l1: for j in l2: for k in l3: yield (i, j, k) for (i, j, k) in cartesian_product(l1, l2, l3): print do something with, i, j, k -- Roberto Bonvallet -- http://mail.python.org/mailman/listinfo/python-list
Re: Iterating over several lists at once
Gal Diskin schrieb: Hi, I am writing a code that needs to iterate over 3 lists at the same time, i.e something like this: for x1 in l1: for x2 in l2: for x3 in l3: print do something with, x1, x2, x3 What I need to do is go over all n-tuples where the first argument is from the first list, the second from the second list, and so on... Heard about recursion? def collect(L,*lists): if not lists: return [(x,) for x in L] collection = [] for x in L: for y in collect(lists[0],*lists[1:]): collection.append((x,)+y) return collection for item in collect( l1, l2, l3): func(*item) Here is the same in generator form def collect(L,*lists): if not lists: for x in L: yield (x,) else: for x in L: for y in collect(lists[0],*lists[1:]): yield (x,)+y ( o.k - it required two nested for-loops in each implementation :) -- http://mail.python.org/mailman/listinfo/python-list
Conditional iteration
I would like to spark the discussion about the following syntax problem I encounter. THE PROBLEM I have a lot times the following code: for x in [-2, -1, 0, 1, 2, 3, 4]: if x 0: ... more code... It is not the addional line containing 'if x 0:' that bothers me, but the additional indentation. THE SOLUTION More pythonic in view would be: for x in [-2, -1, 0, 1, 2, 3, 4] if x 0: ... more code ... This blends basically [x for x in [-2, -1, 0, 1, 2, 3, 4] if x 0] and x = y if x 0 else 10 EXTENDING And maybe a few usefull variants, like: for x in [-2, -1, 0, 1, 2, 3, 4] if x 0 else -x: ... more code ... In this case x will be 2, 1, 0, 1, 2, 3, 4. -- http://mail.python.org/mailman/listinfo/python-list
Re: Iterating over several lists at once
Thanks, that's an improvment (your first way). But I still wish I could find an even shorter (or more elegent) way of doing it. (Well, I guess if I expect every wish I have to come true I should at least wish for something more valuable.) Thanks again, Gal On Dec 13, 3:58 pm, Fredrik Lundh [EMAIL PROTECTED] wrote: Gal Diskin wrote: I am writing a code that needs to iterate over 3 lists at the same time, i.e something like this: for x1 in l1: for x2 in l2: for x3 in l3: print do something with, x1, x2, x3 What I need to do is go over all n-tuples where the first argument is from the first list, the second from the second list, and so on... I was wondering if one could write this more easily in some manner using only 1 for loop. What I mean is something like this: for (x1,x2,x3) in (l1,l2,l3): print do something with, x1, x2, x3how about for x1, x2, x3 in func(l1, l2, l3): print x1, x2, x3 where func is defined as, say, def func(l1, l2, l3): return ((x1, x2, x3) for x1 in l1 for x2 in l2 for x3 in l3) or if you prefer def helper(l1, l2, l3): for x1 in l1: for x2 in l2: for x3 in l3: yield x1, x2, x3 /F -- http://mail.python.org/mailman/listinfo/python-list
Re: Conditional iteration
at wrote: THE PROBLEM I have a lot times the following code: for x in [-2, -1, 0, 1, 2, 3, 4]: if x 0: ... more code... It is not the addional line containing 'if x 0:' that bothers me, but the additional indentation. for x in ...: if not x 0: continue ... more code ... -- Giovanni Bajo -- http://mail.python.org/mailman/listinfo/python-list
Re: Frame hacking
George Sakkis wrote: Gabriel Genellina wrote: On 12 dic, 17:46, George Sakkis [EMAIL PROTECTED] wrote: I wonder if the following is possible: def inject_n_call(func, **kwds): '''Call func by first updating its locals with kwds.''' def f(): return x*y eval(f.func_code, dict(x=3,y=4)) 12 Sweet! I think I just reinvented what eval does in this case by fiddling with sys.settrace and frame.f_globals. Glad to trash my 20-line function for an one-liner :) Actually I thought about this and it would be more convenient in my case if I could change the signature of f to def f(x,y) so that I can pass positional arguments instead of a keywords (don't ask why). I've tried creating a new code object by tweaking co_varnames, co_argcount, co_nlocals and making a new function out of it but it doesn't work.. does co_code have to be changed as well, and if so, how? George -- http://mail.python.org/mailman/listinfo/python-list
Re: Validate XML against a set of XSD files, with Python
On Dec 13, 2:28 pm, Laszlo Nagy [EMAIL PROTECTED] wrote: Fast google query, uncheked, leads to: - XSV:http://www.ltg.ed.ac.uk/~ht/xsv-status.htmlI tried this before. Unfortunately, xsv is not officially supported on my system (FreeBSD 6.1) :-( - libxml :http://codespeak.net/lxml/Probably this is what I need to use. (However, I see in the mailing lists that there are problems with this part of libxml2.) Yep, maybe. I suspect some issues with the validation of Relax NG documents, at least with the libxml2 that was used in my lxml build ... Thank you, Laszlo -- http://mail.python.org/mailman/listinfo/python-list
Re: newbie - HTML character codes
thank you both - in the end I used recode, which I wasn't aware of. Fredrik, I had come across your script while googling for solutions, but failed to make it work On Dec 13, 2:21 pm, Fredrik Lundh [EMAIL PROTECTED] wrote: ardief wrote: sorry if I'm asking something very obvious but I'm stumped. I have a text that looks like this: Sentence 401 4.00pm mdash; We set off again; this time via Tony's home to collect a variety of possessions, finally arriving at hospital no.3. Sentence 402 4.55pm mdash; Tony is ushered into a side ward with three doctors and I stay outside with Mum. And I want the HTML char codes to turn into their equivalent plain text. I've looked at the newsgroup archives, the cookbook, the web in general and can't manage to sort it out. file = open('filename', 'r') ofile = open('otherfile', 'w') done = 0 while not done: line = file.readline() if 'THE END' in line: done = 1 elif 'mdash;' in line: line.replace('mdash;', '--')this returns a new line; it doesn't update the line in place. ofile.write(line) else: ofile.write(line)for a more general solution to the actual replace problem, see: http://effbot.org/zone/re-sub.htm#unescape-html you may also want to lookup the fileinput module in the library reference manual. /F -- http://mail.python.org/mailman/listinfo/python-list
Re: Conditional iteration
at wrote: More pythonic in view would be: for x in [-2, -1, 0, 1, 2, 3, 4] if x 0: ... more code ... Pythonic? Do you realize that Python hasn't even adopted well-known statements like 'switch' and 'do while' because they would be redundant? This could be more convenient to you, but certainly not pythonic. Cheers, -- Roberto Bonvallet -- http://mail.python.org/mailman/listinfo/python-list
Re: not a big deal or anything, but, curiously:
Tim Peters kirjoitti: [Simon Schuster] following this tutorial, Which tutorial? He's reading this tutorial which he was already advised not to do: === === === Simon Schuster wrote: I'm new to python, and almost new to programming in general. I'm at http://www.pasteur.fr/formation/infobio/python/ch04.html in that tutorial, and my 'count' function (if it's called a function?) isn't working suddenly. x = fljshfjh x 'fljshfjh' count(x, 'h') Traceback (most recent call last): File stdin, line 1, in ? NameError: name 'count' is not defined I'm not sure what changed, because it used to work. anyhow thanks a lot! Probably because you omiitted the line from string import * However IMHO your use of a tutorial which: (1) introduces from some_module import * as though it is the normal way of doing things From chapter 1: Some magical stuff, that will be explained later: from string import * That's *bad* magic (2) is still using (outdated) functions in the string module instead of teaching string methods should be discontinued immediately. You may wish to have a look at some of the /other/ tutorials mentioned on this page: http://wiki.python.org/moin/BeginnersGuide/NonProgrammers HTH, John === === === I copied and pasted: from string import * cds = atgagtgaacgtctgagcattagctccgtatatcggcgcacaaa tttcgggtgccgacctgacgcgcccgttaagcgataatcagtttgaacagctttaccatgcggtg ctgcgccatcaggtggtgtttctacgcgatcaagctattacgccgcagcagcaacgcgcgctggc ccagcgggcgaattgcatattcaccctgtttacccgcatgccgaattgacgagatca tcgtgctggatacccataacgataatccgccagataacgacaactggcataccgatgtgacattt attgaaacgccacccgcacgattctggcagctaaagagttaccttcgaccggcggtgatac gctctggaccagcggtattgcggcctatgaggcgctctctgttcccttccgccagctgctgagtg ggctgcgtgcggagcatgatttccgtaaatcgttcccggaatacaaataccgcccgaggag gaacatcaacgctggcgcgaggcggtcgcgacccgccgttgctacatccggtggtgcgaac gcatccggtgagcggtaaacaggcgctgtttgtgaatgaaggctttactacgcgaattgttgatg tgagcgagaaagagagcgaagccttgttaagttgtttgcccatatcaccaaaccggagttt caggtgcgctggcgctggcaaccaaatgatattgcgatttgggataaccgcgtgacccagcacta tgccaatgccgattacctgccacagcgacggataatgcatcgggcgacgatccttataaac cgatcgggctaa.replace(\n,) gc = float(count(cds, 'g') + count(cds, 'c'))/ len(cds) print gc -fin- which should yield: 0.54460093896713613.. but when I ran it I got: 0.544600938967 looking now I see it's truncating after a certain number of decimal places. any ideas why? Read the Python Tutorial appendix on floating-point issues: http://docs.python.org/tut/node16.html As it says, str(a_float) rounds to 12 significant digits, and repr(a_float) to 17. The `print` statement implicitly applies str() to each item it prints. Cheers, Jussi Salmela -- http://mail.python.org/mailman/listinfo/python-list
Re: Large files uploading
Lad wrote: to use any communications protocol (including HTTP), both ends must have programs that can talk that protocol... Sure, but browsers have FTP support. ftp upload support ? But how to call the FTP API from Python? if you want the users to upload things using FTP, why do *you* need to call the FTP API (whatever that is) from Python ? why not just set up a server? /F -- http://mail.python.org/mailman/listinfo/python-list
Re: Conditional iteration
On 2006-12-13, Roberto Bonvallet [EMAIL PROTECTED] wrote: at wrote: More pythonic in view would be: for x in [-2, -1, 0, 1, 2, 3, 4] if x 0: ... more code ... Pythonic? Do you realize that Python hasn't even adopted well-known statements like 'switch' and 'do while' because they would be redundant? This could be more convenient to you, but certainly not pythonic. Cheers, I tried it once myself. It seemed like a feasible thing that might work in Python. It didn't annoy me that it didn't work, but it did seem natural to me given the syntax of comprehensions. -- Neil Cerutti -- http://mail.python.org/mailman/listinfo/python-list
Re: Conditional iteration
at [EMAIL PROTECTED] writes: I have a lot times the following code: for x in [-2, -1, 0, 1, 2, 3, 4]: if x 0: ... more code... Use: for x in (x in [-2, -1, 0, 1, 2, 3, 4] if x 0): ... more code ... -- http://mail.python.org/mailman/listinfo/python-list
Re: Sybase module 0.38pre1 released
Sébastien Sablé wrote: By the way, I forgot to say that new releases can now be downloaded from this page: https://sourceforge.net/project/showfiles.php?group_id=184050 regards -- Sébastien Sablé Thanks. Vasudev -- http://mail.python.org/mailman/listinfo/python-list
Re: Conditional iteration
On 13 Dec 2006 07:47:23 -0800, Paul Rubin http://phr.cx@nospam.invalid wrote: at [EMAIL PROTECTED] writes: I have a lot times the following code: for x in [-2, -1, 0, 1, 2, 3, 4]: if x 0: ... more code... Use: for x in (x in [-2, -1, 0, 1, 2, 3, 4] if x 0): ... more code ... -- or filter: from itertools import ifilter for x in ifilter(lambda x: x 0, [-2, -1, 0, 1, 2, 3, 4]): ...more code... http://mail.python.org/mailman/listinfo/python-list -- http://mail.python.org/mailman/listinfo/python-list
Re: Large files uploading
Lad wrote: Or is there another way( besides FTP) how to upload large files to server? You can upload via http. The primary problem is that the browser don't work well with large uploads (give little feedback on the process, IE may hang etc). You can workaround some limitations by using applets such as JUpload http://www.jupload.biz/ i. -- http://mail.python.org/mailman/listinfo/python-list
Re: merits of Lisp vs Python
George Sakkis [EMAIL PROTECTED] writes: Why is selecting a valid s-expression easier than selecting a python block ? If you mistakenly select an extra parenthesis or omit one, it's the same thing. Having said that, I find this problem is mostly academic in both languages with modern editors... Or even nearly 30 year old editors; emacs provides support for error-free selection of s-expressions, although to be frank I still don't use them as often as I should. -- Robert Uhl http://public.xdi.org/=ruhl Thanks to the joint efforts of OpenOffice, Mozilla, and a few others, Emacs officially entered the category of lightweight utilities.--kalifa on /. -- http://mail.python.org/mailman/listinfo/python-list