lxml 1.3 released
Hi all, I'm proud to announce the release of lxml 1.3. http://codespeak.net/lxml/ http://cheeseshop.python.org/pypi/lxml/ ** What is lxml? In short: lxml is the most feature-rich and easy-to-use library for working with XML and HTML in the Python language. lxml is a Pythonic binding for the libxml2 and libxslt libraries. It is unique in that it combines the speed and feature completeness of these libraries with the simplicity of a native Python API. ** This is a major new release with various new features and lots of fixes compared to the 1.2 series. The complete changelog follows below. Major objectives of this release were: - API consolidation: make everything work with everything - improved namespace handling: avoid redundant namespaces wherever possible - simplicity and accessibility: improved, restructured documentation and simpler XML/HTML generation Future versions of lxml will continue this trend to make lxml the leading tool for XML and HTML in the Python world. Have fun, Stefan Behnel 1.3 (2007-06-24) Features added -- * Module ``lxml.pyclasslookup`` implemens an Element class lookup scheme that can access the entire tree to determine a suitable Element class * Parsers take a ``remove_comments`` keyword argument that skips over comments * ``parse()`` function in ``objectify``, corresponding to ``XML()`` etc. * ``Element.addnext(el)`` and ``Element.addprevious(el)`` methods to support adding processing instructions and comments around the root node * Extended type annotation in objectify: cleaner annotation namespace setup plus new ``deannotate()`` function * Support for custom Element class instantiation in lxml.sax: passing a ``makeelement()`` function to the ElementTreeContentHandler will reuse the lookup context of that function * '.' represents empty ObjectPath (identity) Bugs fixed -- * Removing Elements from a tree could make them loose their namespace declarations * ``ElementInclude`` didn't honour base URL of original document * Replacing the children slice of an Element would cut off the tails of the original children * ``Element.getiterator(tag)`` did not accept ``Comment`` and ``ProcessingInstruction`` as tags * API functions now check incoming strings for XML conformity. Zero bytes or low ASCII characters are no longer accepted. * XSLT parsing failed to pass resolver context on to imported documents * More ET compatible behaviour when writing out XML declarations or not * ``Element.attrib`` was missing ``clear()`` and ``pop()`` methods * More robust error handling in ``iterparse()`` * Documents lost their top-level PIs and comments on serialisation * lxml.sax failed on comments and PIs. Comments are now properly ignored and PIs are copied. * Raise AssertionError when passing strings containing '\0' bytes 1.3beta (2007-02-27) Features added -- * ``DTD`` validator class (like ``RelaxNG`` and ``XMLSchema``) * HTML generator helpers by Fredrik Lundh in ``lxml.htmlbuilder`` * ``ElementMaker`` XML generator by Fredrik Lundh in ``lxml.builder.E`` * Support for pickeling ``objectify.ObjectifiedElement`` objects to XML * ``update()`` method on Element.attrib * Optimised replacement for libxml2's _xmlReconsiliateNs(). This allows lxml a better handling of namespaces when moving elements between documents. Bugs fixed -- * Possible memory leaks in namespace handling when moving elements between documents Other changes - * major restructuring in the documentation -- http://mail.python.org/mailman/listinfo/python-announce-list Support the Python Software Foundation: http://www.python.org/psf/donations.html
Re: The Modernization of Emacs: terminology buffer and keybinding
On Jun 23, 8:35 pm, Robert Uhl [EMAIL PROTECTED] wrote: Twisted [EMAIL PROTECTED] writes: For an example of the latter, consider opening a file. Can't remember the exact spelling and capitalization of the file name? Sorry, bud, you're SOL. Go find it in some other app and memorize the name, then return to emacs. Once again I am forced to wonder if you have _ever_ actually used emacs. find-file has tab completion: hit tab without anything typed, and it displays _everything_ in the directory; type a few characters to narrow it down; hit tab to complete the filename and be done with it. Or of course you could use directory mode, which enables you to navigate around a directory tree, performing actions on files (including editing them). Then of course there's ido.el, which is even better: type a few characters from anywhere in the name, and it displays files matching those characters. Really? None of this happens if you just do the straightforward file- open command, which should obviously at least provide a navigable directory tree, but definitely does not. One sounds like it involves managing a separate open window on each directory you're interested in (versus having a file...open dialog that falls open to the last place you'd left it and doesn't clutter up any space when you're not opening a file); the other sounds like it involves actually installing a plugin of some kind, which is obviously well beyond what a beginner should need to do just to get a freaking directory listing. :) Tab completion is a poor cousin to a real directory tree navigator, as I'm sure most would agree. Even if it will show all matches to a partial name instead of none, it's the textual equivalent of navigating a directory tree made into menus instead of provided by a proper folder view window. Windows users unfortunately have the experience regularly: the notorious Start menu. You have to expand submenus to find stuff, and you can't leave it idling to do something somewhere else and come back to it because it's a menu. Moreover, clicking an item may display a large number of items the next level down, which runs into screen display space issues. Even a large video mode can't hide the fact that menus weren't really designed to list hundreds of sibling items or for scrolling or finding stuff in a large set of files, unlike folder windows. I can only imagine the pain of trying to navigate an equivalent way in an 80x25 box of text information. That would be like navigating the Windows start menu from outside your house by peeking through a keyhole and reaching through a window with a repurposed straightened out coathanger. Clumsy AND the neighbors'll see you and call the cops well before you find the item you're looking for. :) (Navigating the Windows start menu in safe mode, at 640x480, is about as close as most Windows users are ever likely to come to the nightmare of opening a file in emacs when you don't already know its exact path.) -- http://mail.python.org/mailman/listinfo/python-list
Re: The Modernization of Emacs: terminology buffer and keybinding
On Jun 23, 11:56 am, Bjorn Borud [EMAIL PROTECTED] wrote: [Twisted [EMAIL PROTECTED]] | | That sort of negative-sum thinking is alien to me. Software being easy | for beginners to get started using does not in and of itself detract | from its value to expert users. the fact that you imply that this is my argument tells me that either you have not paid attention, or you have a raging inferiority complex. given the sum of your postings so far I'd say that you neither are, nor consider yourself, a cerebral sort of person, so this narrows it down somewhat (although not to the exclusion of you not having paid attention). That ... makes no sense. Sorry. Previously, I said: Being beginner-friendly doesn't have to be at the expense of power or expert-user usability and you said that depended on the definition of expert. Apparently you believe there is a type of expert for whom beginner-friendly software is intrinsically less usable than beginner-hostile software. Given that beginner-friendliness does not preclude any kind of expert level functionality being available (consider something configurable enough that an advanced user can start it up and open an advanced-uses window and immediately do advanced stuff, and a real expert can make it start up with that window already open and focused by default), it follows that these experts' perceptions of decreased usability are a psychological result of simply knowing beginners can easily become proficient in using basic functions of the software in question, rather than a material result of some compromise necessarily made in the software's design, as there is no such compromise that can't in practise be avoided. An expert who feels software is less suitable for his use *purely* because the unwashed masses can actually use it to accomplish something is quite obviously some type of elitist jerk. I rest my case. -- http://mail.python.org/mailman/listinfo/python-list
Re: The Modernization of Emacs: terminology buffer and keybinding
Twisted [EMAIL PROTECTED] writes: On Jun 23, 2:04 am, Robert Uhl [EMAIL PROTECTED] wrote: Besides, ANY interface that involves fumbling around in the dark trying to find a light switch is clunky. That sounds like vi, not emacs. That sounds like any application where you need to read the help, but f1 does not bring up a separate help window, switchable with the main one using alt-tab or the mouse, and navigable using arrows, pageup, pagedn, and the mouse. Well, f1 brings up a prompt: f1 (type ? for further options)- Typing ? brings up a separate window (and instructions how to scroll it) with a variety of help options, among them the tutorial. If you want a separate window, File/New Frame will give you that. Of course, switchable with the main one using alt-tab or the mouse, and navigable using arrows, pageup, pagedn and the mouse. The result of that is invariably that when the document has the focus, the help is open to help on switching windows rather than whatever you need it to be on once the document has the focus. You can read the help on doing what you want to do with the document, but to apply it you need to transfer focus back to the document. If doing that isn't second-nature, you have to navigate the help away from where you need it to get the focus back to the document. Nonsense. Now the focus is on the document, but the help you need isn't displayed next to it anymore. Frustrating? You can't begin to imagine, I suspect. Apparently, some people are born somehow able to avoid this problem without having to memorize one or the other piece of help. You're clearly one of those. I am equally clearly NOT one of those. Of course, if emacs let you keep THREE windows open and visible at the same time, instead of being limited to one or a horizontally split two ... Which it does... and a cramped 80x10 or so each, at that ... Emacs frames can certainly be resized and repositioned at will using the mouse... You are really babbling a lot of nonsense that is, at best, somewhat relevant for prehistoric versions of Emacs without GUI support. Just shut up until you have installed and worked with a modern version of Emacs. If I haven't, it must be the case that finding this tutorial (or even discovering that it exists) was nontrivial, or it wasn't built into emacs, one or the other. My memory is somewhat fuzzy after all these years so you'll forgive me if I don't make a definite statement about which. After all these years... You really should not rely on 10-year old memories about an application. On the flip side, if I have, the tutorial can't have been all it's cracked up to be. Especially given I can program Java proficiently, Apparently, at the time you last looked at Emacs, Java did not yet exist. including some fairly sophisticated network-using tools, and clearly am not an idiot or untalented in technically demanding areas involving substantial amounts of arcana. Up to now you have not delivered any discourse that would warrant the clearly in this sentence. Not that using Emacs involved substantial amounts of arcana. The technical term for managing limited resources, such as time and effort, first where needed and never where avoidable, is efficiency, in case you were unaware. Sure, but babbling about a system you have never seen in its present state for 10 years, and consequently putting your foot in your mouth in hundreds of postings requiring hours of times spread over several months, when it would take all of 10 minutes to get your information somewhat up to scratch, is called stupidity, in case you were unaware. or you're just making things up. Also untrue, and you've just accused me of incompetence once and of lying twice, which in a formerly civil discussion constitutes behavior that I consider to be in poor taste. Well, so what is it about you accusing people of lying that report experiences about a system you have never looked at in its current state? You even accused me of lying when I posted _screenshots_ from a publicly accessible site, suspecting me of forgery. If I'm browsing the manual online, I can switch from said manual to my document buffer without making the manual scroll to the documentation for switch-to-buffer. Apparently because you find the switch second nature, despite its not being the obvious (which is ctrl-tab, to switch between documents in an MDI app). And which works fine when using Emacs frames. Look, you are making a complete spectable of yourself. Get a current version of Emacs and actually try it. Cheat sheet? Memorized with painstaking months of hard effort? Thanks for proving my point, either way. You are babbling. Not that this is new. In fact, I am not aware of any package which auto-changes the *info* or *Help* buffers to reflect the last keyboard command. I didn't say it auto-changes. It manual-changes. The exact sequence of events that causes this with a novice user
Re: The Modernization of Emacs: terminology buffer and keybinding
Twisted [EMAIL PROTECTED] writes: On Jun 23, 8:35 pm, Robert Uhl [EMAIL PROTECTED] wrote: Twisted [EMAIL PROTECTED] writes: For an example of the latter, consider opening a file. Can't remember the exact spelling and capitalization of the file name? Sorry, bud, you're SOL. Go find it in some other app and memorize the name, then return to emacs. Once again I am forced to wonder if you have _ever_ actually used emacs. find-file has tab completion: hit tab without anything typed, and it displays _everything_ in the directory; type a few characters to narrow it down; hit tab to complete the filename and be done with it. Or of course you could use directory mode, which enables you to navigate around a directory tree, performing actions on files (including editing them). Then of course there's ido.el, which is even better: type a few characters from anywhere in the name, and it displays files matching those characters. Really? None of this happens if you just do the straightforward file- open command, which should obviously at least provide a navigable directory tree, but definitely does not. It definitely _does_ when you are using the mouse to open your file dialog. Again, _try_ a current version of Emacs before showing your ignorance. [Other nonsensical speculation deleted] -- David Kastrup, Kriemhildstr. 15, 44793 Bochum -- http://mail.python.org/mailman/listinfo/python-list
RE: visual gui ides for python/jythpn
Luis M. Gonzalez wrote: PythonCard is an extremely easy to use alternative. It's like a simplified Visual Basic or Delphi IDE. Check IT out: www.pythoncard.org I second that! PythonCard is a rapid way to prototype an ugly Windows GUI. (It's not PythonCard's fault that Windows are ugly. ;) ) I use it for prototyping. But ONLY for prototyping. At least with my version in Windows, it's got bugs in the resource editor. For example, Korean characters in Korean fonts are rotated sideways. And the color of a font can't be changed; only the foreground color can, which corrupts button display. The send to back/front options don't seem to work. Transparent images (like PNG) don't seem to work ... for me, anway. Yet, still, when I'm rapidly developing the mechanics of a game and need a GUI front-end, PythonCard was a quick solution. It brilliantly stores the GUI as a recursive dictionary, which is like XML, only easy for a human to read. The widgets require very little of your coding. It's got a lot of samples, which makes some of its peculiar conventions easy to apply. And any Python app made with the PythonCard framework has a namespace viewer, shell, and GUI message integrated into the application. Flash and Python: The ultimate GUI prototyping combo? In my dreams, I would use Flash for the GUI portion of a Python app. Flash is by far my favorite environment for rapidly designing interfaces. It is an (almost) object-oriented drawing environment that can quickly produce good visual design. Because the elements are instances of prototypes (Flash calls them symbols), they can be easily replaced and updated at any time. The timeline, animation, color, layer, and drawing tools are wonderful. You can quickly make traditional or experimental interfaces. The only thing that sucked (for me), was ActionScript. It's not bad. It's quite good for interface scripting. But for back-end procedures it is prison compared to Python. Does anyone successfully use a Flash front-end and Python back-end in real-time? I've tried an example of XMLRPC servers where a Flash app (SWF) communicates with Python (http://www.cs.unc.edu/~parente/tech/tr01.shtml), but that has a round-trip time that is too slow for something like a videogame (updates at 30 frames per second). Some of the projects at OS flash look promising (http://osflash.org/ext_howto), but I haven't found the part that says that my interface made in Macromedia Flash (which is a fantastic design environment) can be used with my code in Python with a real-time frame rate. -- Ethan -- http://mail.python.org/mailman/listinfo/python-list
Re: Adding method to a class on the fly
On Jun 23, 6:24 pm, Steven D'Aprano [EMAIL PROTECTED] wrote: On Sat, 23 Jun 2007 12:31:39 -0700, John Henry wrote: it works fine but PythonCard isn't calling this function when I clicked on the button. I think you need to take this question onto a PythonCard list. I have no idea how PythonCard decides which method to call. -- Steven. I did. I am not sure I'll get an answer though. Thanks for the help. -- http://mail.python.org/mailman/listinfo/python-list
Re: The Modernization of Emacs: terminology buffer and keybinding
On Sun, 24 Jun 2007 04:57:20 -, Twisted [EMAIL PROTECTED] tried to confuse everyone with this message: On Jun 23, 2:04 am, Robert Uhl [EMAIL PROTECTED] wrote: Of course, emacs doesn't take years of mastery. It takes 30, 40 minutes. I gave it twice that, and it failed to grow on me in that amount of time. Besides, ANY interface that involves fumbling around in the dark trying to find a light switch is clunky. That sounds like vi, not emacs. That sounds like any application where you need to read the help, but f1 does not bring up a separate help window, switchable with the main one using alt-tab or the mouse, and navigable using arrows, pageup, pagedn, and the mouse. The result of that is invariably that when the document has the focus, the help is open to help on switching windows rather than whatever you need it to be on once the document has the focus. You can read the help on doing what you want to do with the document, but to apply it you need to transfer focus back to the document. If doing that isn't second-nature, you have to navigate the help away from where you need it to get the focus back to the document. Now the focus is on the document, but the help you need isn't displayed next to it anymore. Frustrating? You can't begin to imagine, I suspect. Apparently, some people are born somehow able to avoid this problem without having to memorize one or the other piece of help. You're clearly one of those. I am equally clearly NOT one of those. Of course, if emacs let you keep THREE windows open and visible at the same time, instead of being limited to one or a horizontally split two ... and a cramped 80x10 or so each, at that ... What an idiot. At least get yourt facts straight before posting such bullshit. -- |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 this a valid import sequence ?
On Jun 24, 2:51 am, [EMAIL PROTECTED] (Alex Martelli) wrote: Since that global statement is utterly useless (it's impossible to read and understand any substantial amount of Python code without realizing that accessing a variable not locally assigned means you're accessing a global, so the self-documenting character claimed for that redundancy is quite fallacious), it IS perfectly suitable to take away, and so it's at least a serious imperfection. Allow me a pun: self is pretty self-documenting. With Python 3.0 we finally get even two declarations for accessing a name for assignment from an outer scope. Maybe the Python Zen should be altered in the following way: - Namespaces are one honking great idea -- let's do more of those! + Accessor declaratives are one honking great idea -- let's do more of those! Kay -- http://mail.python.org/mailman/listinfo/python-list
Re: Portable general timestamp format, not 2038-limited
On Fri, 22 Jun 2007 13:33:04 -0700, James Harris [EMAIL PROTECTED] wrote, quoted or indirectly quoted someone who said : 1) subsecond resolution - milliseconds or, preferably, more detailed 2) not bounded by Unix timestamp 2038 limit 3) readable in Java 4) writable portably in Perl which seems to mean that 64-bit values are out 5) readable and writable in Python 6) storable in a free database - Postgresql/MySQL Unix gets in trouble in 2038 only with 32-bit timestamps. Java's 64-bit longs are fine. If you need code to create timestamps, you can modify parts of BigDate to run in Perl or Python. see http://mindprod.com/products1.html#BIGDATE To get more detailed, just use a unix long timestamp multiplied by 1000 to track in microseconds. You can use MS nanosecond timestamps. see http://mindprod.com/products1.html#FILETIMES just store them as longs in the database. The only catch is ad-hoc queries won't work with them. JDBC out the box should be fine. one of : DATEjava.sql.Date TIMEjava.sql.Time TIMESTAMP java.sql.Timestamp BIGINT long will be what you need. -- Roedy Green Canadian Mind Products The Java Glossary http://mindprod.com -- http://mail.python.org/mailman/listinfo/python-list
Re: The Modernization of Emacs: terminology buffer and keybinding
Timofei Shatrov wrote: What an idiot. At least get yourt facts straight before posting such bullshit. I think at this stage it's quite reasonable to assume he's trolling, and recycling old trolls, too. Certainly looks like someone very like him used to haunt rec.games.roguelike.development as Neo and Twisted One, in the 2005 era. Of course, by bothering to point this out, I'm giving him more attention, the recognition he presumably craves, my bad. http://groups.google.com/group/rec.games.roguelike.development/msg/6f0fac979ef1d117 Message-ID: [EMAIL PROTECTED] Date: Tue, 22 Mar 2005 19:00:06 -0500 From: Twisted One [EMAIL PROTECTED] Emacs doesn't let you do that either. It lets you have exactly two panes. http://groups.google.com/group/rec.games.roguelike.development/msg/cfd723fbdc4a93f8 From: David Damerell [EMAIL PROTECTED] Date: 23 Mar 2005 13:22:00 + (GMT) Message-ID: [EMAIL PROTECTED] Quoting Twisted One [EMAIL PROTECTED] Emacs doesn't let you do that either. It lets you have exactly two panes. No, this is completely false. ... So, probably deliberately trolling, or just maybe a learning difficulty - literally (corrected on multiple occasions, still failed to learn). -- http://mail.python.org/mailman/listinfo/python-list
Re: Collections of non-arbitrary objects ?
7stud wrote: On Jun 23, 11:45 am, walterbyrd [EMAIL PROTECTED] wrote: Suppose you are sequentially processing a list with a routine that expects every item to be of a certain type. Something in the list that doesn't conform to the type could give you unexpected results, maybe crash your application. if hasattr(elmt, some_func): elmt.some_func() Personally, I prefer try: elmt.some_func() except AttributeError: # do stuff Regards, Björn -- BOFH excuse #130: new management -- http://mail.python.org/mailman/listinfo/python-list
Re: is this a valid import sequence ?
On Sat, 23 Jun 2007 21:11:42 -0700, Alex Martelli wrote a lot, with lots of YELLING. Wow. What can I say? Given the amount of SHOUTING in your post, and the fact that you feel so strongly about the trivial question of the redundant use of the global statement that you would fail a student who did it -- even if they did everything else correctly, efficiently and elegantly -- it seems to me that you are beyond rational discussion on this subject. Perhaps you should consider writing a PEP to make the redundant use of the global statement a compile-time error? Then there would be absolutely no doubt in anyone's mind that it is _wrong_ (and not just unnecessary or redundant) to use the global statement in the circumstances discussed. Then we can move on to removing floats of the form 1.e0, unary-plus on numeric types, and string-slices like s[:]. I'm not sure where you got the idea that I'm encouraging newbies to overuse globals, when I wrote in an earlier post to this same thread: However, using global variables is almost always a bad idea. Passing parameters around is really cheap in Python, that's almost always a better solution. If you manage to calm down enough to answer without exaggerating and misrepresenting my views, I would like to hear your opinion of whether the following two functions are equally as wrong: def f1(gizmo): global spam # holds the frommet needed for the gizmo gizmo.get_frommet(spam) def f2(gizmo): # global spam holds the frommet needed for the gizmo gizmo.get_frommet(spam) I'm sure they're both wrong, but I'd like to know if there are degrees of wrongness. -- Steven. -- http://mail.python.org/mailman/listinfo/python-list
Re: is this a valid import sequence ?
In [EMAIL PROTECTED], Steven D'Aprano wrote: Perhaps you should consider writing a PEP to make the redundant use of the global statement a compile-time error? Sometimes I wished that it would be a compile time error or at least triggering a warning when ``global`` is used at module level. It seems a common error from people used to declare variables at that level in other languages. Ciao, Marc 'BlackJack' Rintsch -- http://mail.python.org/mailman/listinfo/python-list
Re: The Modernization of Emacs: terminology buffer and keybinding
Twisted wrote: On Jun 23, 10:36 am, Martin Gregorie [EMAIL PROTECTED] wrote: Actually, what I prefer in (2D and 3D) visual design apps is the ability to snap to some kind of grid/existing vertices, and to zoom in close. Then small imprecisions in mouse movement can be rendered unimportant. That might work for visual design apps, but it doesn't for CAD, where you may want to point to an arbitrary position with a (scaled) accuracy of microns. The fact remains that mechanical mice do jump when you click them, though optical mice are better in this respect. The problem of course being the complete exclusion of type 1 users. Totally untrue. They are the people that all the standard GUIs are designed for and some (e.g Mackintosh) are very fast to learn. The exclusion is down to the way that the purveyors of GUIs keep spreading bullshit about how any untrained person can use a computer and never mess it up or loose data. Thats not true and never can be: a computer is the most complex device the average person will own or use and is likely to retain that title for the foreseeable future. I grant you that type 2 users are rare, but I think flight simulators may fit this case when used for training. One with a bog-standard UI but also a console or command prompt, scripting language, and customizable bindings? Not really. What's needed is a single interface that can be used by anybody from beginner to expert and that, in the case of an error, shows precisely where it got, what caused the action to fail to complete and that allows the user to continue from that point without having to undo/redo the bits that were successful. Its not easy, but it can be done. ROM BASICs and QBasic (on any really ancient microcomputer, and old pre-Windows PCs, respectively; the former came with printed manuals and you could just run prepackaged software from disks very easily; Hang on: you don't read manuals. You object to using tutorials and to buying books, so its a bit precious to claim this example. * The word processor with the usual interface where I can define logical styles, then change them in only one place and affect every pre-existing occurrence retroactively. Thats been in Word since DOS days and is part of OpenOffice. Its called a style sheet. The only WPs I've used that didn't use them were Wordperfect, WordStar, DEC WPS+ and the Wang dedicated WP systems. All were horrid to varying degrees, with Wordperfect and Wordstar tying for worst. * The word processor with the usual interface where I can also view an underlying markup representation and hand-hack that, You're thinking of Wordperfect and its 'Reveal Codes' function. That was the worst idea I've ever seen in a WP, matched only by the illogically arranged set of 12 function keys, each with 4 shifts. and which likely has the capabilities of the first two as a direct consequence of the implied architecture. It didn't. 'Reveal codes' could only let you inspect the current document. Unfortunately it was essential to use it because some input sequences could completely mess up the formatting and the only way to recover was via 'Reveal codes'. The effect was similar to making a data entry clerk use a hex editor on a database to fix keyboarding errors. NOTE: I'm not talking about secretaries using WordPerfect. Those that used it hated it. I'm talking about the experience of IT professionals writing structured text, e.g. system specifications. * The operating system where you can do powerful stuff with a command line and a script or two, but can also get by without either. (Windows fails the former. Linux fails the latter.) Here you're talking about two different interfaces again. The nearest I've seen to good solutions at OS level were the CL interface provided by ICL's VME mainframes and IBM's AS/400 systems. The latter was particularly good, with a single unified text screen interface which provided help screens, menus and a command line. You could search for and find commands via a menu structure, and then use form filling to provide the arguments, with help available at any stage. If you were writing a script the entire menu and form filling system was available from within the text editor - but when you hit ENTER the completed command was written into your script instead of being executed. Both OS/400 and VME were very consistent in the way they assigned command names and argument keywords. In both OSen it was possible to think if there's a command to do this it will be called BLAHBLAH, type the name, hit the command completion key and have the argument entry screen pop up ready to be filled in. BTW, in both OSen this capability applied to user-written scripts and programs as well as to the standard command set. Both could claim to be object oriented: the VME command language was derived from Algol-68, arguably the granddaddy of all OO programming languages. * For that
Re: The Modernization of Emacs: terminology buffer and keybinding
Twisted wrote: At least Windows 3.1 had most apps have the same keys for the vast majority of commands, and those were the right keys. Emacs has all the applications have the vast majority of their commands use the same WRONG keys. Including whatever you'd use to rebind them. And the help you'd use to find out what the damn keys are in the first place. ;) You're mis-remembering this. Apple, first with the Lisa and then with the Mackintosh, had extremely consistent menus, menu shortcuts and other key assignments. It was possible to teach almost anybody to use them in 15 minutes flat. A major reason for the consistency was the Programmer's Toolbox, a piece of ROM that contained all the stuff an application needed to handle keyboard, mouse and menus. It was there and easy to use, so of course all applications programmers used it. Windows 3 and 3.1 were the first usable Windows versions. Windows 1 and 2 were a bad jokes. Win/286 worked but had no applications. Win 3.x worked a lot better. However, it lacked any equivalent of the Programmers Toolbox and as a result the applications were anything but consistent. MS applications were self-similar, but other apps used wildly divergent ideas about menu structures, shortcuts and key assignments. Compare 3.x versions of Word with Wordperfect, or the Borland IDEs and this is obvious. MS finally kicked applications providers into more-or-less consistency but that wasn't before Win 95 appeared and they then spoilt the record by arbitrary and capricious menu changes as each version of MS Office appeared. -- martin@ | Martin Gregorie gregorie. | Essex, UK org | -- http://mail.python.org/mailman/listinfo/python-list
Re: Collections of non-arbitrary objects ?
walterbyrd [EMAIL PROTECTED] writes: Suppose you are sequentially processing a list with a routine that expects every item to be of a certain type. Something in the list that doesn't conform to the type could give you unexpected results, maybe crash your application. A routine that demands its inputs to be of a certain *type*, rather than requiring that the implement the required *behaviour*, breaks polymorphism. Polymorphism is considered valuable in Python; search for any of polymorphism, duck typing and easier to ask forgiveness than permission. -- \Intellectual property is to the 21st century what the slave | `\ trade was to the 16th. -- David Mertz | _o__) | Ben Finney -- http://mail.python.org/mailman/listinfo/python-list
Re: how to query/test the state of a qt widget?
[EMAIL PROTECTED] schrieb: Hi, I'm writing a simple Python/Qt3 application and I am trying to write some code in which the user presses a button and the program performs action A or B depending upon the state of a pair of radio buttons. I would therefore like Python to read the state of the buttons. I was expecting this to be straightforward but I've not been able to work out how to do it and searching on Google hasn't helped. Surely there's a one-liner that will do what I want? It seems like an every-day sort of problem. I'm after something like: if self.polPlotRadioButton.enabled==1: print BLAH I've found squish from www.froglogic.com but that seems over the top. Possibly pythonqt.sourceforge.net has something that will solve my problem but that wants Qt4 and at the moment I'm making heavy use of matplotlib widgets and I've not worked out how to get them to incorporate into a Qt4 app so I'm stuck with Qt3. Anyone know the answer? RTFM. The Qt-docs are extensive. And the QRadioButton-docs are pretty straight forward: http://doc.trolltech.com/3.3/qradiobutton.html#checked-prop So your code above should be if self.polPlotRadioButton.isChecked(): print blah Diez -- http://mail.python.org/mailman/listinfo/python-list
Re: how to query/test the state of a qt widget?
RTFM. The Qt-docs are extensive. And the QRadioButton-docs are pretty straight forward: http://doc.trolltech.com/3.3/qradiobutton.html#checked-prop So your code above should be if self.polPlotRadioButton.isChecked(): print blah Thanks, that does indeed work. Also, sorry, I have been trying to RTFM but I'm new to both Python and Qt so not always sure what I'm looking for. -- http://mail.python.org/mailman/listinfo/python-list
Re: pydoc with METH_VARGS
I'm asking if there's some sort of commenting or input file or something to customize the output pydoc generates. Thanks. On Jun 23, 11:00 pm, 7stud [EMAIL PROTECTED] wrote: On Jun 23, 2:13 pm, Stuart [EMAIL PROTECTED] wrote: With my Python extension module all the function definitions are with METH_VARGS. The result being that pydoc, just puts (...) for the argument list. Can I hand edit this to put the specific variable names I want? With optional arguments in brackets or something? Thanks. Are you asking whether you can change a text file that pydoc produces? -- http://mail.python.org/mailman/listinfo/python-list
Re: is this a valid import sequence ?
Steven D'Aprano wrote: On Sat, 23 Jun 2007 21:11:42 -0700, Alex Martelli wrote a lot, with lots of YELLING. Given the amount of SHOUTING in your post, and the fact that you feel so strongly about the trivial question of the redundant use of the global statement that you would fail a student who did it -- even if they did everything else correctly, efficiently and elegantly -- it seems to me that you are beyond rational discussion on this subject. I, for one, appreciate a second voice suggesting that your (Steve's) vehement rejection of my technically correct and non-condemnatory post explaining that one use of global in the OP's code was superfluous. You said (in the previous post): That's technically true, but declaring it with global makes the code self-documenting and therefore easier to read. It's never _wrong_ to use the global statement, even if it is strictly unnecessary for the Python compiler. Your post led a newbie to presume the extra use of global was good style, while I think you'll find there is no such consensus. --Scott David Daniels [EMAIL PROTECTED] -- http://mail.python.org/mailman/listinfo/python-list
WX call a pywx program from a program, and return values
I need to call a pywx program(1) from an wxpy program(2) and return a value to program(2). Any example to do it? -- http://mail.python.org/mailman/listinfo/python-list
automatical pdf generating
Hi, all, There are 50 folders in my hard driver C: C:\01.c:\02,...,c:\50 There are 4 pictures in each folder: 1.jpg,2.jpg,3.jpg,4.jpg For each folder, I want to print the 4 pictures into a single-paged pdf file (letter sized; print horizontally). All together, I want to get 50 pdf files with names: 01.pdf,02.pdf,...,50.pdf. Is it possible to use Python to realized the above process? I know there is a module named reportlab. Is there any easy command in the module to do my job? Thanks Jackie -- http://mail.python.org/mailman/listinfo/python-list
Re: how to query/test the state of a qt widget?
On Sun Jun 24 02:20:55 CEST 2007, raacampbell wrote: I'm writing a simple Python/Qt3 application and I am trying to write some code in which the user presses a button and the program performs action A or B depending upon the state of a pair of radio buttons. You would typically connect the button's clicked() signal to a function or method and perform the actions there. Since I don't know exactly what you are doing, I can't give you an exact answer, but you probably want to write something like this: self.connect(self.pushButton, SIGNAL(clicked()), self.perform_action) This assumes that you're calling connect() from a QObject subclass. If not, you could call connect() on the button itself. I would therefore like Python to read the state of the buttons. I was expecting this to be straightforward but I've not been able to work out how to do it and searching on Google hasn't helped. Surely there's a one-liner that will do what I want? It seems like an every-day sort of problem. I'm after something like: if self.polPlotRadioButton.enabled==1: print BLAH This is more or less what you would write in the method that gets invoked when the clicked() signal is emitted, though you would need to call enabled() since it's a method and not an attribute. I've found squish from www.froglogic.com but that seems over the top. Possibly pythonqt.sourceforge.net has something that will solve my problem but that wants Qt4 and at the moment I'm making heavy use of matplotlib widgets and I've not worked out how to get them to incorporate into a Qt4 app so I'm stuck with Qt3. It's been a while since I've looked at using matplotlib with PyQt. Looking at the 0.90.1 release, it seems that there is support for PyQt4, so maybe you'll get what you need if you upgrade to that. I don't think you need Squish for this - it's a tool for automated user interface testing, and you're not doing that as far as I can tell. David -- http://mail.python.org/mailman/listinfo/python-list
Re: visual gui ides for python/jythpn
On 24 jun, 04:23, Ethan Kennerly [EMAIL PROTECTED] wrote: Luis M. Gonzalez wrote: PythonCard is an extremely easy to use alternative. It's like a simplified Visual Basic or Delphi IDE. Check IT out:www.pythoncard.org I second that! PythonCard is a rapid way to prototype an ugly Windows GUI. (It's not PythonCard's fault that Windows are ugly. ;) ) I use it for prototyping. But ONLY for prototyping. At least with my version in Windows, it's got bugs in the resource editor. For example, Korean characters in Korean fonts are rotated sideways. And the color of a font can't be changed; only the foreground color can, which corrupts button display. The send to back/front options don't seem to work. Transparent images (like PNG) don't seem to work ... for me, anway. Yet, still, when I'm rapidly developing the mechanics of a game and need a GUI front-end, PythonCard was a quick solution. It brilliantly stores the GUI as a recursive dictionary, which is like XML, only easy for a human to read. The widgets require very little of your coding. It's got a lot of samples, which makes some of its peculiar conventions easy to apply. And any Python app made with the PythonCard framework has a namespace viewer, shell, and GUI message integrated into the application. Flash and Python: The ultimate GUI prototyping combo? In my dreams, I would use Flash for the GUI portion of a Python app. Flash is by far my favorite environment for rapidly designing interfaces. It is an (almost) object-oriented drawing environment that can quickly produce good visual design. Because the elements are instances of prototypes (Flash calls them symbols), they can be easily replaced and updated at any time. The timeline, animation, color, layer, and drawing tools are wonderful. You can quickly make traditional or experimental interfaces. The only thing that sucked (for me), was ActionScript. It's not bad. It's quite good for interface scripting. But for back-end procedures it is prison compared to Python. Does anyone successfully use a Flash front-end and Python back-end in real-time? I've tried an example of XMLRPC servers where a Flash app (SWF) communicates with Python (http://www.cs.unc.edu/~parente/tech/tr01.shtml), but that has a round-trip time that is too slow for something like a videogame (updates at 30 frames per second). Some of the projects at OS flash look promising (http://osflash.org/ext_howto), but I haven't found the part that says that my interface made in Macromedia Flash (which is a fantastic design environment) can be used with my code in Python with a real-time frame rate. -- Ethan Ethan, If you are looking for something more ´advanced´ than a simple windows GUI, I suggest checking out Silverlight, wich is the new deployment technology that ties Ironpython to the browser. With it, you can use Ironpython (wich is Python for .NET) to create apps that run on the browser, the same way you would use javascript, with a lot of new features like animations (ala flash). You are not only limited to Ironpython though. You can use any .NET language, includin other dynamic ones such as Ironruby (not released yet). It is a Microsoft technology, but it works on Firefox as well as IE, on Windows and Mac. It will also run on linux through a Mono project called Moonlight. Luis -- http://mail.python.org/mailman/listinfo/python-list
Re: automatical pdf generating
Jackie wrote: Hi, all, There are 50 folders in my hard driver C: C:\01.c:\02,...,c:\50 There are 4 pictures in each folder: 1.jpg,2.jpg,3.jpg,4.jpg For each folder, I want to print the 4 pictures into a single-paged pdf file (letter sized; print horizontally). All together, I want to get 50 pdf files with names: 01.pdf,02.pdf,...,50.pdf. Is it possible to use Python to realized the above process? I know there is a module named reportlab. Is there any easy command in the module to do my job? Thanks Jackie Generate HTML for such pages, open them with OpenOffice, and have OpenOffice generate the PDF file. John Nagle -- http://mail.python.org/mailman/listinfo/python-list
Re: is this a valid import sequence ?
Scott David Daniels [EMAIL PROTECTED] wrote: Steven D'Aprano wrote: On Sat, 23 Jun 2007 21:11:42 -0700, Alex Martelli wrote a lot, with lots of YELLING. Given the amount of SHOUTING in your post, and the fact that you feel so strongly about the trivial question of the redundant use of the global statement that you would fail a student who did it -- even if they did everything else correctly, efficiently and elegantly -- it seems to me that you are beyond rational discussion on this subject. I, for one, appreciate a second voice suggesting that your (Steve's) vehement rejection of my technically correct and non-condemnatory post explaining that one use of global in the OP's code was superfluous. Glad to hear this! I think the root of the issue is in learning to read superfluous as a NEGATIVE word -- follow Occam, and learn to not multiply entities beyond need:-). You said (in the previous post): That's technically true, but declaring it with global makes the code self-documenting and therefore easier to read. It's never _wrong_ to use the global statement, even if it is strictly unnecessary for the Python compiler. Your post led a newbie to presume the extra use of global was good style, while I think you'll find there is no such consensus. I concur: having discussed style issues at many Python shops, I'm quite convinced that the general consensus is closer to the redundant is bad approach. Exhaustively listing all of the redundancies that are to be eschewed would of course take far too long; a more common approach is to try to identify those extremely few cases where redundancy IS explicitly deemed OK (and leave all other redundancies intrinsically disapproved). The cases I've seen with reasonable frequency for accepting certain redundancies basically boil down to accepting some redundant parentheses. Python has many levels of priorities in expressions, and while they do tend to work just right there are always some corner cases where even a frequent Python coder MAY feel uncertain for a moment (and these uncertainties grow for coders that also have to use, e.g., C, or Fortran, c, frequently). So, spelling things out as, e.g., (-a) ** b versus -(a ** b) is not unreasonable (vs just coding '-a**b' and relying on the reader to know exactly which of the two cases applies). An important subcase has to do with tuples -- while I personally prefer to use parentheses around tuples only where they're indispensable, I understand the opposite stance, where parentheses are always placed around tuples (it may be hard to memorize exactly all cases where they're required, e.g. when the tuple is the expression in a listcomp...). A more debatable case, IMHO, is slicing (and the related cases of range and xrange). Do you ever write x[0:N:1], xrange(0, N), etc? Or are the simpler x[:N], xrange(N), etc, always to be preferred? This is one of the few cases where I've seen group consensus fail to emerge in discussions about Python style even in close-knit teams... Alex -- http://mail.python.org/mailman/listinfo/python-list
Re: database design help
It sounds to me that you want Subversion. There is a Python binding if you have anything you'd need to do beyond what already comes with the system (there are a variety of web interfaces already out there, for instance, so I don't know that you'd need to do anything extra). Just google subversion. Jim -- http://mail.python.org/mailman/listinfo/python-list
Re: automatical pdf generating
Is it possible to use Python to realized the above process? I know there is a module named reportlab. Possible? Yes! -- http://mail.python.org/mailman/listinfo/python-list
Re: automatical pdf generating
On 2007-06-24, Jackie [EMAIL PROTECTED] wrote: For each folder, I want to print the 4 pictures into a single-paged pdf file (letter sized; print horizontally). All together, I want to get 50 pdf files with names: 01.pdf,02.pdf,...,50.pdf. Is it possible to use Python to realized the above process? Yes. I know there is a module named reportlab. Is there any easy command in the module to do my job? Yes. http://www.reportlab.org/rl_toolkit.html http://www.reportlab.com/docs/userguide.pdf -- Grant Edwards grante Yow! You mean you don't at want to watch WRESTLING visi.comfrom ATLANTA? -- http://mail.python.org/mailman/listinfo/python-list
Re: smtp server simulation using Python
Dave Borne wrote: I have a (web) development computer w/o an SMTP server and want to test form generated e-mail using a dummy SMTP server that delivers the mail message to a file, or better yet, to a text editor instead of actually sending it. Here's a quick and dirty script I use this for email testing purposes - it's windows specific, but that's easy enough to change. Actually XP is where I need it. Thanks Bill import smtpd, os, time, asyncore class mailserver(smtpd.SMTPServer): def __init__(self): smtpd.SMTPServer.__init__(self, ('',25), None) print 'Mailsink listening on port 25' def process_message(self, peer, mailfrom, rcpttos, data): basepath='c:\\.maildump' print 'mail from: %s to: %s' %(mailfrom, repr(rcpttos)) for rcpt in rcpttos: rcpt = rcpt.split('@')[0] try: os.mkdir(basepath+'\\'+rcpt) except OSError: pass f = file(basepath+'\\'+rcpt+'\\'+mailfrom+time.strftime('%Y%m%d%H%M%S'), 'w') f.write(data) f.close() def loop (): x = mailserver() try: asyncore.loop(timeout=2) except KeyboardInterrupt: print'interrupt' x.close() if __name__=='__main__': loop() -- http://mail.python.org/mailman/listinfo/python-list
Accessing variable from a function within a function
Hi, I m playing around with extended euclids algorithm from Knuth. I m trying to build a function with a function inside it. def exteuclid(m,n): a,a1,b,b1,c,d = 0,1,1,0,m,n def euclid(c,d): q = c /d r = c % d if r == 0: print a,b return d else: print a1,a,b1,b,c,d,q,r t = b1 b = t - q * b a = t - q * a c,d,a1,b1 = d,r,a,b return euclid(c,d) return euclid(c,d) Unfortunately this doesnt work since a,a1,b,b1 arent declared in the function. Is there a way to make these variables accessible to the euclid function. Or is there a better way to design this function? Many Thanks in advance, Nathan -- http://mail.python.org/mailman/listinfo/python-list
Re: The Modernization of Emacs: terminology buffer and keybinding
Thomas Bellman wrote: I seem to recall that EMACS, the old TECO version on TOPS-20 and ITS, only supported two windows (panes in Twisted's words). So it's not *completely* false, just extremely outdated. Well, that's going back a bit. I somehow doubt he was using that, but I guess it's possible (he did claim emacs is a unix text editor though)... -- http://mail.python.org/mailman/listinfo/python-list
emacs for python
I wish to set up emacs for python usage. The specific questions are: 1. Which python mode should one use? It seems there is one from python and one from emacs and both are deliberately named so as to be confusable!! I would like one that gives... 2. Good support for debugging: I hear pdbtrack is better than pdb -- but I am not able to figure how to use it. 3. Is it possible to get brief help on methods/functions using mouse-hovering/F1 rather than having to go out to pydoc etc 4. Also maybe a (minor?) mode to convert selections of interpreter text into doctests? 5. The menu contains something called IM-python but that contains nothing except *rescan* 6. Turning off semantic. semantic (is that the same as fly-make??) seems to randomly get into 99% CPU usage. How to turn it off? Thanks -- http://mail.python.org/mailman/listinfo/python-list
Re: Accessing variable from a function within a function
Nathan Harmston wrote: Hi, I m playing around with extended euclids algorithm from Knuth. I m trying to build a function with a function inside it. def exteuclid(m,n): a,a1,b,b1,c,d = 0,1,1,0,m,n def euclid(c,d): q = c /d r = c % d if r == 0: print a,b return d else: print a1,a,b1,b,c,d,q,r t = b1 b = t - q * b a = t - q * a c,d,a1,b1 = d,r,a,b return euclid(c,d) return euclid(c,d) Unfortunately this doesnt work since a,a1,b,b1 arent declared in the function. Is there a way to make these variables accessible to the euclid function. Or is there a better way to design this function? Well, it would be simpler to pass through all the variables rather than relying on variables in a wider scope. -- Michael Hoffman -- http://mail.python.org/mailman/listinfo/python-list
Re: Python's only one way to do it philosophy isn't good?
Steven D'Aprano [EMAIL PROTECTED] writes: On Sat, 23 Jun 2007 14:56:35 -0400, Douglas Alan wrote: How long did it take you to write the macros, and use them, compared to running Pylint or Pychecker or equivalent? An hour? Who cares? You write it once and then you have it for the rest of your life. You put it in a widely available library, and then *every* programmer also has it for the rest of their lives. The amortized cost: $0.00. The value: priceless. Really? Where do I download this macro? How do I find out about it? How many Lisp programmers are using it now? (1) I didn't have to write such a macro for Lisp, as Lisp works differently. For one thing, Lisp already has let and set special forms. (Lisp uses the term special form for what Python would call a statement, but Lisp doesn't call them statements since they return values.) (2) You act as if I have no heavy criticisms of Lisp or the Lisp community. I critique everything with equal vigor, and keep an eye out for the good aspects and ideas of everything with equal vigor. How does your glib response jib with your earlier claims that the weakness of Lisp/Scheme is the lack of good libraries? (1) See above. (2) My response wasn't glib. Googling for ' Douglas Allen download lisp OR scheme ' wasn't very promising. (1) You spelled my name wrong. (2) I haven't written any libraries for any mainstream dialects of Lisp since there was a web. I did write a multiple dispatch lookup cacher for a research dialect of Lisp, but it was just an exercise for a version of Lisp that few people have ever used. In fairness, the various Python lints/checkers aren't part of the standard library either, but they are well-know standards. In general I don't like such checkers, as I tend to find them more annoying than useful. Thanks, but that's just too syntactically ugly and verbose for me to use. Syntactically ugly? Verbose? Compare yours with mine: let x = 0 let y = 1 let z = 2 set x = 99 (Looks like BASIC, circa 1979.) It looks like a lot of languages. And there's a reason for that -- it was a good idea. variables.declare(x=0, y=1, z=2) variables.x = 99 (Standard Python syntax.) I don't think having two easily confused names, let and set is an advantage, Let and set are not easily confused. Lisp programmers have had absolutely no problem keeping the distinction separate for the last 47 years now. but if you don't like the word declare you could change it to let, or change the name of the module to set (although that runs the risk of confusing it with sets). Because this uses perfectly stock-standard Python syntax, you could even do this, so you type fewer characters: v = variables v.x = 99 and it would Just Work. I wouldn't program that way, and no one that I know would either. In this regard you sound exactly like all the C++ folks, who when you point out that something in C++ is inadequate for one's needs, they point you at some cumbersome and ugly solution and then tell you that since C++ can already deal with the complaint, that there's no good reason to consider changing C++. Consequently, C++ still doesn't have a finally statement, and it requires either making instance variables public or forcing the programmer to write lots of boilerplate code writing setter and getter functions. Fortunately, the Python developers finally saw the errors of their ways in this regard and fixed the situation. But, it seems to me that you would have been one of those people saying that there's no need to have a way of overriding attribute assignment and fetching, as you can always just write all that extra boilerplate code, or instead add an extra layer of indirection (proxy objects) in your instance data to have things done the way you want, at the expense of ugly code. Not only that, but my fellow Python programmers would be sure to come and shoot me if I were to code that way. *shrug* They'd shoot you if you used let x = 0 too. Clearly you are not familiar with the programmers that I work with. As I mentioned previously, at least one of them is quite upset about the auto-declaration feature of most scripting languages, and your suggestion would not make her any happier. One of the reasons that I want to use Python is because I like reading and writing code that is easy to read and looks good. I don't want to bend it to my will at the expense of ugly looking code. But the ugly looking code is stock-standard Python syntax. There many things that cannot be done in stock Python syntax elegantly (e.g. multiple predicate dispatch), which is why, when programming in Python, one often sticks to doing things the way that *can* be done elegantly. (This can often result in programs that are structured less elegantly in the large, however.) If you don't recognize this, then you must be livid over the addition to Python of decorators, list and generator comprehension, etc. After, all, Python is
Re: Accessing variable from a function within a function
On Jun 24, 11:55 am, Nathan Harmston [EMAIL PROTECTED] wrote: Hi, I m playing around with extended euclids algorithm from Knuth. I m trying to build a function with a function inside it. def exteuclid(m,n): a,a1,b,b1,c,d = 0,1,1,0,m,n def euclid(c,d): q = c /d r = c % d if r == 0: print a,b return d else: print a1,a,b1,b,c,d,q,r t = b1 b = t - q * b a = t - q * a c,d,a1,b1 = d,r,a,b return euclid(c,d) return euclid(c,d) Unfortunately this doesnt work since a,a1,b,b1 arent declared in the function. Is there a way to make these variables accessible to the euclid function. Or is there a better way to design this function? Many Thanks in advance, Nathan ef outer(): a = 10 def inner(): print a return inner f = outer() f() --output:-- 10 -- http://mail.python.org/mailman/listinfo/python-list
Re: Accessing variable from a function within a function
On Sun, 24 Jun, 7stud wrote: ef outer(): a = 10 def inner(): print a return inner f = outer() f() --output:-- 10 def outer(): ... a = 10 ... def inner(): ... a = a + 1 ... print a ... return inner ... f=outer() f() Traceback (most recent call last): File stdin, line 1, in ? File stdin, line 4, in inner UnboundLocalError: local variable 'a' referenced before assignment -- Stefan Bellon -- http://mail.python.org/mailman/listinfo/python-list
dealing with emf/wmf files
I'd like to put some emf/wmf pictures into a pdf file using 'reportlab', but the Python Imaging Library cannot recognize emf files. The wmf files are said to be 'identified only'. Therefore, the following code does not work: from reportlab.pdfgen import canvas from reportlab.lib.pagesizes import letter width, height = letter # (595.27,841.89) def hello(c): c.drawImage(r'D:\01.wmf',1,1,height,width) c = canvas.Canvas('hello.pdf', pagesize=(height,width)) hello(c) c.showPage() c.save() I do not want to convert the pictures into other formats, e.g. jpg which will lower the quality. Is there any way to get around with this problem? Thanks! Get news delivered with the All new Yahoo! Mail. Enjoy RSS feeds right on your Mail page. Start today at http://mrd.mail.yahoo.com/try_beta?.intl=ca -- http://mail.python.org/mailman/listinfo/python-list
Re: Do eval() and exec not accept a function definition? (like 'def foo: pass) ?
On Jun 24, 6:28 am, Jean-Paul Calderone [EMAIL PROTECTED] wrote: On Sun, 24 Jun 2007 11:17:40 +1000, Steven D'Aprano [EMAIL PROTECTED] wrote: On Sat, 23 Jun 2007 19:58:32 +, vasudevram wrote: Hi group, Question: Do eval() and exec not accept a function definition? (like 'def foo: pass) ? eval() is a function, and it only evaluates EXPRESSIONS, not code blocks. Actually, that's not exactly true: x = compile('def foo():\n\tprint hi\n', 'stdin', 'exec') l = {} eval(x, l) l['foo']() hi Jean-Paul Thanks, all. Will check out the replies given. - Vasudev -- http://mail.python.org/mailman/listinfo/python-list
Re: Accessing variable from a function within a function
Nathan Harmston wrote: Hi, I m playing around with extended euclids algorithm from Knuth. I m trying to build a function with a function inside it. def exteuclid(m,n): a,a1,b,b1,c,d = 0,1,1,0,m,n def euclid(c,d): q = c /d r = c % d if r == 0: print a,b return d else: print a1,a,b1,b,c,d,q,r t = b1 b = t - q * b a = t - q * a c,d,a1,b1 = d,r,a,b return euclid(c,d) return euclid(c,d) Unfortunately this doesnt work since a,a1,b,b1 arent declared in the function. Is there a way to make these variables accessible to the euclid function. Or is there a better way to design this function? Many Thanks in advance, Nathan That last return statement does not match indentation of another block. But this is probably what you mean: def exteuclid(m,n): x = 0,1,1,0,m,n def euclid(c,d,x=x): a,a1,b,b1,c,d = x q = c /d r = c % d if r == 0: print a,b return d else: print a1,a,b1,b,c,d,q,r t = b1 b = t - q * b a = t - q * a c,d,a1,b1 = d,r,a,b return euclid(c,d) return euclid(c,d) James -- http://mail.python.org/mailman/listinfo/python-list
Re: The Modernization of Emacs: terminology buffer and keybinding
On Jun 24, 8:10 am, Martin Gregorie [EMAIL PROTECTED] wrote: Actually, what I prefer in (2D and 3D) visual design apps is the ability to snap to some kind of grid/existing vertices, and to zoom in close. Then small imprecisions in mouse movement can be rendered unimportant. That might work for visual design apps, but it doesn't for CAD, where you may want to point to an arbitrary position with a (scaled) accuracy of microns. I didn't mention that you should be able to zoom and make the grid fine to whatever limit is reasonable given the application? The issue being, how accurate is accurate enough? Pinpoint precision isn't possible, unless it's an integer or a functionally derived value like pi or some arithmetic result of that. Grids are good for getting rational numbers exactly, and nothing will hit the irrational ones exactly, save if you can enter a formula for it to use to compute the point's location to any desired precision. A mouse click (sans grid) will always introduce some error; the zoom level lets you limit the magnitude of the error. So does a grid, and to zero if the desired point is a grid vertex, and to half the grid size more generally. The fact remains that mechanical mice do jump when you click them, though optical mice are better in this respect. Ultimately, the button has to be non-mechanical for this sort of thing to really work. Or else not physically part of the mouse. Being able to click from the keyboard makes sense given such requirements. So does being able to snap to a grid. The problem of course being the complete exclusion of type 1 users. Totally untrue. I'm not talking about in general. I'm talking about the specific sorts of unixy applications that are under discussion here. Those emphatically cater solely to type-3s and type-4s, aside from newer graphical apps for KDE and Gnome, which are emerging as a third group of type-1-accessible tool alongside Mac applications and Windows applications. Thats not true and never can be: a computer is the most complex device the average person will own or use and is likely to retain that title for the foreseeable future. What about the fabrication devices? Oh, but I suppose the foreseeable future has already ended by the time those trickle down to widespread consumer use. I grant you that type 2 users are rare, but I think flight simulators may fit this case when used for training. Anything you have to use to meet some important external goal, I suppose. But most usually there are options. A programmer needs a text editor but it need not be emacs. Jobs requiring the use of specific software (for training, or just on the job) maybe, of which your example is a subset. Not really. What's needed is a single interface that can be used by anybody from beginner to expert and that, in the case of an error, shows precisely where it got, what caused the action to fail to complete and that allows the user to continue from that point without having to undo/redo the bits that were successful. Its not easy, but it can be done. Why do those who have the skills, talent, knowledge, and thus capability to do this insist on making cruft like emacs then? I've never seen a classic-unix tool that didn't barf unhelpful and uninformative error messages at the drop of a hat (just like Windows!) and present a piss-poor UI, or even no UI at all (unless usage: blah blah blah qualifies as a UI, to which my response is one word. Non- interactive.) When the error messages are informative, they're still cryptic, and only someone with knowledge of the software's internals has a hope in hell of fixing the problem as a rule. Of course, the number one rule of interface design is to speak the user's language and the language of the problem domain, and remain mute (except to developers invoking debug modes) about the implementation details and the language of the solution domain. Especially given that a different version of the same software, nevermind a different app with the same usage, is probably going to use a different implementation anyway. One exception can be to expose a specific scripting language for advanced users to use to automate tasks. Emacs does this, and it's one thing I don't have a problem with. As long as knowledge of its arcana is not needed to either do straightforward stuff, or fix the errors that occur attempting to do straightforward stuff, anyway. If the beginner can safely ignore the thing's existence (e.g. the VB-based scripting language in some office and paint programs) it's fine. ROM BASICs and QBasic (on any really ancient microcomputer, and old pre-Windows PCs, respectively; the former came with printed manuals and you could just run prepackaged software from disks very easily; Hang on: you don't read manuals. You object to using tutorials and to buying books, so its a bit precious to claim this example. The manuals came with the computers, at no additional charge. It was a different
Re: Adding method to a class on the fly
On Jun 24, 1:19 am, John Henry [EMAIL PROTECTED] wrote: On Jun 23, 6:24 pm, Steven D'Aprano [EMAIL PROTECTED] wrote: On Sat, 23 Jun 2007 12:31:39 -0700, John Henry wrote: it works fine but PythonCard isn't calling this function when I clicked on the button. I think you need to take this question onto a PythonCard list. I have no idea how PythonCard decides which method to call. -- Steven. I did. I am not sure I'll get an answer though. Thanks for the help. Upon further investigation, I found the problem. Pythoncard is relying on the __name__ attribute and that's why it didn't know about the newly careated function. I can not set that attribute directly, of course, since it's a readonly attribute. Need other workaround. The author of Pythoncard has responded and so I am shifting this thread over to the Pythoncard list. Thanks again for all the help. I learned a few things about Python through this exercise. -- http://mail.python.org/mailman/listinfo/python-list
Re: dealing with emf/wmf files
Jackie Wang wrote: I'd like to put some emf/wmf pictures into a pdf file using 'reportlab', but the Python Imaging Library cannot recognize emf files. The wmf files are said to be 'identified only'. libwmf (not for Python) can convert WMF (not EMF) to SVG or EPS. http://wvware.sourceforge.net/libwmf.html -- Michael Hoffman -- http://mail.python.org/mailman/listinfo/python-list
Re: Accessing variable from a function within a function
James Stroud wrote: Nathan Harmston wrote: def exteuclid(m,n): x = 0,1,1,0,m,n def euclid(c,d,x=x): a,a1,b,b1,c,d = x q = c /d r = c % d if r == 0: print a,b return d else: print a1,a,b1,b,c,d,q,r t = b1 b = t - q * b a = t - q * a c,d,a1,b1 = d,r,a,b return euclid(c,d) return euclid(c,d) James My answer above is wrong because c and d take the wrong default values. Also, you have some ambiguity in your code. Are nested calls to euclid supposed to have the original values of a, a1, b, b1, or are they to take the original values 0, 1, 1, 0? This type of ambiguity is one reason why the interpreter does not like reference before assignment. This is my best guess at what you want because I'm not familiar with how euclid's algorithm works: def exteuclid(m,n): def euclid(a,a1,b,b1,c,d): q = c /d r = c % d if r == 0: print a,b return d else: print a1,a,b1,b,c,d,q,r t = b1 b = t - q * b a = t - q * a c,d,a1,b1 = d,r,a,b return euclid(a,a1,b,b1,c,d) return euclid(0,1,1,0,m,n) -- http://mail.python.org/mailman/listinfo/python-list
newbie tcp/ip question
Hello all, I'm having a hard time tracking down a way to open up a tcp/ip client connection and simply sending a string to the port I've opened up. For instance I want to send some hex characters as a string literal to port 7142 and to a specific ip address. How do I do that in python? thanks, zm -- http://mail.python.org/mailman/listinfo/python-list
Re: newbie tcp/ip question
Hi, Zachary Manning wrote: I'm having a hard time tracking down a way to open up a tcp/ip client connection and simply sending a string to the port I've opened up. For instance I want to send some hex characters as a string literal to port 7142 and to a specific ip address. How do I do that in python? Google for: python socket example Best regards, Jacek. -- http://mail.python.org/mailman/listinfo/python-list
Re: newbie tcp/ip question
On Sun, Jun 24, 2007 at 02:52:25PM -0500, Zachary Manning wrote: I want to send some hex characters as a string literal to port 7142 and to a specific ip address. How do I do that in python? Does this cover what you want to do? http://docs.python.org/lib/socket-example.html -- Stephen R. Laniel [EMAIL PROTECTED] Cell: +(617) 308-5571 http://laniels.org/ PGP key: http://laniels.org/slaniel.key -- http://mail.python.org/mailman/listinfo/python-list
Re: automatical pdf generating
On Jun 24, 10:03 pm, Grant Edwards [EMAIL PROTECTED] wrote: On 2007-06-24, Jackie [EMAIL PROTECTED] wrote: For each folder, I want to print the 4 pictures into a single-paged pdf file (letter sized; print horizontally). All together, I want to get 50 pdf files with names: 01.pdf,02.pdf,...,50.pdf. Is it possible to use Python to realized the above process? Yes. I know there is a module named reportlab. Is there any easy command in the module to do my job? Yes. http://www.reportlab.org/rl_toolkit.htmlhttp://www.reportlab.com/docs/userguide.pdf -- Grant Edwards grante Yow! You mean you don't at want to watch WRESTLING visi.comfrom ATLANTA? There are many different ways to do what you want, as the other replies say. 1. If you're not a programmer, the OpenOffice suggestion is good. 2.1 If you're a programmer, read up on the ReportLab docs shown in a previous reply by Grant Edwards, and try it out. Equivalently, you could use Ruby and PDF::Writer. Both ReportLab and PDF::Writer have support for creating PDFs with images, and both Python and Ruby can automate the part of iterating over the multiple files and directories. 2.2 Also you could try another approach - use some scripting language like Python (or Perl or Ruby) together with one of the free PDF creation / conversion tools that you can easily find on the Internet by a Google search (using suitable keywords like HTML to PDF, PDF conversion, etc. Make sure to try out various combinations / variations of keywords if you don't get a solution at once - this is fundamental to Web searching. And ... if you're not a programmer, consider becoming one :-) It's good fun, and will help you do a lot of things ... Vasudev Ram http://www.dancingbison.com http://jugad.livejournal.com http://sourceforge.net/projects/xtopdf -- http://mail.python.org/mailman/listinfo/python-list
Re: Collections of non-arbitrary objects ?
walterbyrd a écrit : On Jun 22, 11:43 pm, Ben Finney [EMAIL PROTECTED] wrote: Can you help us understand, by showing a use case that would in your estimation be improved by the feature you're describing? Suppose you are sequentially processing a list with a routine that expects every item to be of a certain type. it should expects every item to support a given protocol (expose a given interface, have a given set of attributes, whatever...). OOP is not about types or classes, it's about objects. And in a dynamic language like Python, where you can add/remove/replace almost each attribute (including methods and even it's class...) of an object at runtime, override the way the attribute look-up is done, etc, this is specially true. The fact that an object is an instance of a given class doesn't necessarily imply that it supports the same protocol. And the fact that an object is an instance of a given class is only true at a given time... So testing on type to allow inclusion of an object in a list for type safety reasons is mostly a waste of time. It's also counter-productive since it would reject objects that actually supports the right protocol but are not of the correct type. Something in the list that doesn't conform to the type s/conform to the type/support the protocol/ could give you unexpected results, maybe crash your application. Yes. But... you do test your application, don't you ?-) In python, as far as I know, there is nothing built into the language to keep any type of item from being included in a list No. cf above. - or any such structure. To me, that seems like a potentially vulnerability. Did you actually had some effective problem with this ? Especially since variables in python do not have to be explicitly assigned ??? I suppose you meant something else here, probably about declarative typing ? - another variable that points to the same thing, could change the data that a variable points to. Give me a reference to an object in a list, and I can change almost any attribute of the object - even it's class. FWIW, a similar - but usually much much worse wrt/ possible results - problem exists in C with pointers and memory. I came to Python from statically typed languages, and first had a similar reaction. It took me some time to believe it, but type errors are quite less frequent that you would imagine, and most of the time quite trivial to spot and fix. I've had bigger problems with memory handling and dangling pointers in C, Pascal or C++. -- http://mail.python.org/mailman/listinfo/python-list
Re: Adding method to a class on the fly
On Jun 24, 12:40 pm, John Henry [EMAIL PROTECTED] wrote: On Jun 24, 1:19 am, John Henry [EMAIL PROTECTED] wrote: On Jun 23, 6:24 pm, Steven D'Aprano [EMAIL PROTECTED] wrote: On Sat, 23 Jun 2007 12:31:39 -0700, John Henry wrote: it works fine but PythonCard isn't calling this function when I clicked on the button. I think you need to take this question onto a PythonCard list. I have no idea how PythonCard decides which method to call. -- Steven. I did. I am not sure I'll get an answer though. Thanks for the help. Upon further investigation, I found the problem. Pythoncard is relying on the __name__ attribute and that's why it didn't know about the newly careated function. I can not set that attribute directly, of course, since it's a readonly attribute. Need other workaround. The author of Pythoncard has responded and so I am shifting this thread over to the Pythoncard list. Thanks again for all the help. I learned a few things about Python through this exercise. Okay, just to complete the record - in case anybody tries to google for a solution to add control to PythonCard at run time, here's a complete code: #!/usr/bin/python __version__ = $Revision: 1.6 $ __date__ = $Date: 2004/08/17 19:46:06 $ import new from PythonCard import log from PythonCard import model from PythonCard.model import SetInitParam rsrc = {'application':{'type':'Application', 'name':'Minimal', 'backgrounds': [ {'type':'Background', 'name':'bgMin', 'title':'Minimal PythonCard Application', 'size':(200, 300), 'components': [ ] # end components } # end background ] # end backgrounds } } class Background_Dynamic(model.Background): def __init__(self, aParent, aBgRsrc, SetInitParamFct=SetInitParam): model.Background.__init__(self, aParent, aBgRsrc, SetInitParamFct) def addHandler(self, aMethod): # Add the Handler to our Handler list. if aMethod.name not in self._handlers: log.debug(addHandler: + aMethod.name) #self._handlers[aMethod.name] = event.Handler(aMethod) self._handlers[aMethod.name] = aMethod def mouseclick_factory(self, name): def function(self, background, event): self.mouseclick_factory(Button+str(int(name[-1:])+1)) function.name = on_%s_mouseClick % name method = new.instancemethod(function, self, self.__class__) setattr(self, function.name, method) self.addHandler(method) self.components[name] = {'type':'Button', 'name':name, 'label':name, 'position':(5, 5+int(name[-1:])*30), 'text':name} return function class Minimal(Background_Dynamic): def on_initialize(self, event): self.components['field1'] = {'type':'TextField','name':'field1','position':(5, 5),'size':(150, -1),'text':'Hello PythonCard'} self.mouseclick_factory(Button1) if __name__ == '__main__': app = model.Application(Minimal, None, rsrc) app.MainLoop() It goes to show how flexible and powerful PythonCard is. Too bad it doesn't draw the attention of more new comers. -- http://mail.python.org/mailman/listinfo/python-list
Re: Accessing variable from a function within a function
Nathan Harmston wrote: Unfortunately this doesnt work since a,a1,b,b1 arent declared in the function. Is there a way to make these variables accessible to the euclid function. Or is there a better way to design this function? The canonical recommendations are: use attributes of the inner function or one-element lists as writable variables visible in the outer function. Another possibility is to modify the bytecode of the functions by an appropriate decorator. See http://www-zo.iinf.polsl.gliwice.pl/~mciura/software/expose.py (you'll need the byteplay module by Noam Raphael to make it work). Marcin -- http://mail.python.org/mailman/listinfo/python-list
cx_oracle
Hi, I want to get an access to an oracle database. For that I found the module cx_oracle (http://www.python.net/crew/atuining/cx_Oracle/) and I have installed the version 'Windows Installer (Oracle 10g, Python 2.5)'. Now I tried to run the script in the readme file: --- import cx_Oracle # connect via SQL*Net string or by each segment in a separate argument #connection = cx_Oracle.connect(user/[EMAIL PROTECTED]) connection = cx_Oracle.connect(user, password, TNS) cursor = connection.cursor() cursor.arraysize = 50 cursor.execute( select Col1, Col2, Col3 from SomeTable where Col4 = :arg_1 and Col5 between :arg_2 and :arg_3, arg_1 = VALUE, arg_2 = 5, arg_3 = 15) for column_1, column_2, column_3 in cursor.fetchall(): print Values:, column_1, column_2, column_3 --- And I got an error: --- Traceback (most recent call last): File C:\Python25\cal_adjustment.py, line 1, in module import cx_Oracle ImportError: DLL load failed: Das angegebene Modul wurde nicht gefunden. --- Do someone have an idea to solve the problem? A reinstall doesn't work. Cheers lukas -- http://mail.python.org/mailman/listinfo/python-list
Re: high performance/threaded applications in Python - your experiences?
Ivan Voras wrote: Jay Loden wrote: I was hoping for some experiences that some of you on the list may have had in dealing with Python in a high performance and/or threaded environment. In essence, I'm wondering how big of a deal the GIL can be in a real-world scenario where you need to take advantage of multiple processor machines, thread pools, etc. How much does it get in the way (or not), and how difficult have you found it to architect applications for high performance? I have read a number of articles and opinions on whether or not the GIL is a good thing, and how it affects threaded performance on multiple processor machines, but what I haven't seen is experiences of people who have actually done it and reported back it was a nightmare or it's no big deal ;) The theory: If your threads mostly do IO, you can get decent CPU usage even with Python. If the threads are CPU-bound (e.g. you do a lot of computational work), you'll effectively only make use of one processor. In practice, I've noticed that Python applications don't scale very much across CPUs even if they're doing mostly IO. I blame cache trashing or similar effect caused by too many global synchronization events. I didn't measure but the speedup may even be negative with large-ish number of CPUs (=4). OTOH, if you can get by with using forking instead of threads (given enough effort) you can achieve very good scaling. Also, see the 'processing' package in the Python cheeseshop. It allows you to use processes rather than threads with most of the same abstractions. I hear it recently acquired the ability to pass file handles between processes on the same machine :) - Josiah -- http://mail.python.org/mailman/listinfo/python-list
Re: The Modernization of Emacs: terminology buffer and keybinding
Hi Twisted, Twisted == Twisted [EMAIL PROTECTED] writes: Twisted * The operating system where you can do powerful stuff with a command Twisted line and a script or two, but can also get by without either. (Windows Twisted fails the former. Linux fails the latter.) Twisted * For that matter, the operating system whose GUI takes the concept Twisted behind OLE to its logical conclusion, and lets the user separately Twisted choose and configure their text editing, this-editing, that-editing, Twisted whosit-viewing, and the like components, and those components are used Twisted in building more complex applications. All the alternatives would of Twisted course adhere to a common interface for a particular sort of Twisted component, of course. (An OO language like Java lends itself to this, Twisted what with interfaces and inheritance and dynamic Twisted class loading!) Have a look at Genera, the OS of the Lisp Machines. It offers all that and much more. Unfortunately it is almost non existent nowadays. 'Andreas -- Wherever I lay my .emacs, there's my $HOME. -- http://mail.python.org/mailman/listinfo/python-list
Re: cx_oracle
Hi Lukas, you will need a working oracle OCI client middleware before cx_oracle can talk to your database. The easiest nowadays is the so-called instant client, which must be available from the otn.oracle.com site (downloads might require a free registration). Try to get sql*plus working (the standard Oracle command-line client), and cx should then pose no problem. Cheers, Bernard. -- http://mail.python.org/mailman/listinfo/python-list
Re: Python's only one way to do it philosophy isn't good?
Steven D'Aprano [EMAIL PROTECTED] writes: Graham talks about 25% of the Viaweb code base being macros. Imagine how productive his coders would have been if the language was not quite so minimalistic, so that they could do what they wanted without the _lack_ of syntax getting in the way. Paul Graham's Viaweb code was written in Common Lisp, which is the least minimalistic dialect of Lisp that I know. Even though they were using this powerful tool, they still found it useful to create new syntactic abstractions. How much less productive would they have been had they not had this opportunity? -- http://mail.python.org/mailman/listinfo/python-list
Re: The Modernization of Emacs: terminology buffer and keybinding
Twisted [EMAIL PROTECTED] writes: On Jun 23, 8:35 pm, Robert Uhl [EMAIL PROTECTED] wrote: Twisted [EMAIL PROTECTED] writes: For an example of the latter, consider opening a file. Can't remember the exact spelling and capitalization of the file name? Sorry, bud, you're SOL. Go find it in some other app and memorize the name, then return to emacs. Once again I am forced to wonder if you have _ever_ actually used emacs. find-file has tab completion: hit tab without anything typed, and it displays _everything_ in the directory; type a few characters to narrow it down; hit tab to complete the filename and be done with it. Or of course you could use directory mode, which enables you to navigate around a directory tree, performing actions on files (including editing them). Then of course there's ido.el, which is even better: type a few characters from anywhere in the name, and it displays files matching those characters. Really? None of this happens if you just do the straightforward file- open command, which should obviously at least provide a navigable directory tree, but definitely does not. The first does. Really, it does. Fire up emacs (which you've never done before) and type C-x C-f. You will be presented with a prompt something like 'Find file: ~/'; hit tab once; you'll see the message '[Complete, but not unique]'; hit tab again and you will be presented a list of all files in that directory. Tab completion is a poor cousin to a real directory tree navigator, as I'm sure most would agree. I wouldn't. There are several directory navigators installed on this machine, but I never use anything more than bash's tab completion. If you like 'em, though, just select File:Visit New File. It gives you a platform-default (gtk+, for me) file selector. Even if it will show all matches to a partial name instead of none, it's the textual equivalent of navigating a directory tree made into menus instead of provided by a proper folder view window. Windows users unfortunately have the experience regularly: the notorious Start menu. You have to expand submenus to find stuff, and you can't leave it idling to do something somewhere else and come back to it because it's a menu. Nope, because of the way emacs works you can stop what you're doing, do something else and come back to the minibuffer. As an example, while I was typing the first paragraph, I had find-file running in the minibuffer (I was checking for the exact prompts and phrases used). I can only imagine the pain of trying to navigate an equivalent way in an 80x25 box of text information. Fortunately, folks brighter than you I have imagined a nice way for us. It pops up a new Emacs window (pane, if you prefer the terminology) showing a list of all filenames. You could continue typing, or just click on a filename in the window, or hit return while the cursor is on a filename in that window. -- Robert Uhl http://public.xdi.org/=ruhl Dilbert: Not more than ten minutes ago you beat a man senseless. Alice: He was senseless before I beat him. -- http://mail.python.org/mailman/listinfo/python-list
Re: The Modernization of Emacs: terminology buffer and keybinding
On 25 Jun., 00:52, Robert Uhl [EMAIL PROTECTED] wrote: You guys are all in the wrong newsgroups. Please stay in comp.emacs when discussing Emacs. Don't cross post. Not everyone is interested in Emacs discussions. Thanks. Follow-up set to comp.emacs. -- http://mail.python.org/mailman/listinfo/python-list
Re: WX call a pywx program from a program, and return values
On Jun 24, 10:02 am, Marcpp [EMAIL PROTECTED] wrote: I need to call a pywx program(1) from an wxpy program(2) and return a value to program(2). Any example to do it? Yup. See links below: http://mail.python.org/pipermail/tutor/2005-May/038648.html http://www-pcmdi.llnl.gov/software-portal/cdat/tips_and_tricks/python_tips/passing_arguments.html http://aspn.activestate.com/ASPN/Mail/Message/wxPython-users/3508008 Mike -- http://mail.python.org/mailman/listinfo/python-list
Re: Changing sound volume
On Jun 23, 7:47 am, simon kagwe [EMAIL PROTECTED] wrote: Hi, I am playing sounds using the winsound module. Is there a way I can change the volume? The docs don't mention anything about controlling the volume, so I doubt it's possible with winsound. However, I found this in the archives: http://mail.python.org/pipermail/edu-sig/2001-December/001899.html It's some kind of wrapper for Snack that allows you to mess with the volume. This site talks about Snack, winsound and another module: http://www.zak.co.il/gpl/misc/eng/pythonsound.html And finally a way that might work using ctypes: http://mail.python.org/pipermail/python-win32/2006-March/004436.html Mike -- http://mail.python.org/mailman/listinfo/python-list
Re: The Modernization of Emacs: terminology buffer and keybinding
Twisted [EMAIL PROTECTED] writes: Of course, if emacs let you keep THREE windows open and visible at the same time, instead of being limited to one or a horizontally split two ... and a cramped 80x10 or so each, at that ... I have two frames open right now: one 80x70, the other around 180x70 (characters, not pixels). One isn't split at all; the other is split into four windows, horizontally and vertically. I'll admit that it didn't USED TO 'eschew normal methods of navigation', but at a certain point in time there began to be 'normal methods of navigation' and emacs naturally began eschewing them promptly and has done so ever since. emacs has continued doing its own thing, mostly because that thing is better. The CUA standards (there exists an emacs package if you really want them) are broken and lame--I and most other don't wish to cripple our text editor of choice. If I haven't, it must be the case that finding this tutorial (or even discovering that it exists) was nontrivial, or it wasn't built into emacs, one or the other. When you start emacs in a text console, you see this: Welcome to GNU Emacs, one component of the GNU/Linux operating system. Type C-l to begin editing. Get help C-h (Hold down CTRL and press h) Emacs manual C-h r Emacs tutorial C-h t Undo changes C-x u Buy manualsC-h C-m Exit Emacs C-x C-c Browse manuals C-h i Activate menubar F10 or ESC ` or M-` (`C-' means use the CTRL key. `M-' means use the Meta (or Alt) key. If you have no Meta key, you may instead type ESC followed by the character.) A GUI window shows a similar message. Note the 'Emacs tutorial' entry? Or you could just go to the Help menu, then select 'Emacs Tutorial.' If I'm browsing the manual online, I can switch from said manual to my document buffer without making the manual scroll to the documentation for switch-to-buffer. Apparently because you find the switch second nature, despite its not being the obvious (which is ctrl-tab, to switch between documents in an MDI app). Clicking within the document's window isn't obvious?!? * OK, time to resort to *gulp* the help. * Oh, great, now what did it do? I hit F1 and ... * Eh. Try random stuff. Help starts with h. Alt-h? Ctrl-h? ... * Oh, right. I seem to remember the help popping up unwanted when I tried to backspace over a typo earlier, so I'll just do that. Ha! f1 and C-h do the exact same thing. You've obviously not used emacs this millennium. WHAT menu bar? We're discussing emacs. As in, a text-mode editor. As in a cramped little 80x24 grid of letters, numbers, spaces, and punctuation with no menus, no concept of a pointing device, and a bad attitude. No, we're discussing emacs, a text editor which runs in both a GUI and a text console. Which can display images. It's cool like that. At least Windows 3.1 had most apps have the same keys for the vast majority of commands, and those were the right keys. Emacs has all the applications have the vast majority of their commands use the same WRONG keys. Neither is right nor wrong; you're just used to one. The emacs keys are certainly more flexible and powerful, though. Some might consider them right for that reason. Wouldn't it be cool not to have one program implement search in one way, and another a second way, and yet another a third? Wouldn't it be cool to have access to a proper text editor when editing text on a web page? Search is usually ctrl+f, type something, hit enter in my experience. Unless you want regexp search. And if you want to find again it can be interesting. And maybe the program defaults to case-sensitive or case-insensitive search... And I can use any text editor I want to edit HTML. You could use Notepad no doubt; you could also use a Turing machine. I prefer to use a useful tool. Do you realise that emacs has a GUI these days? I'm writing this in a 70-line window, with gtk+ widgets. Which means full-resolution, full-colour. What are you talking about? Clearly not emacs, which is a console app for unix systems (with the inevitable MS-DOS ports and others). No, as I've said over and over and over again, emacs is not what you think it is. It has a GUI; it has colours; it can display images; it can use the native widget set. It can even be configured to use native keybindings, although that way lies madness. Some sort of bastardized Windows port I suppose? Hah! Dude, I don't use Windows--I've better things to do with my life. -- Robert Uhl http://public.xdi.org/=ruhl With weapons, we are citizens. Without them, we are subjects. -- http://mail.python.org/mailman/listinfo/python-list
Which XML?
I've found a lot of XML libraries for Python. Any advices on which one to use (or *not* to use)? My requirements are: support for XPath, stability (a must, segfaults are not an option), with DOM API and good performance desirable. Thanks for any advice. -- Bruno Barberi Gnecco brunobg_at_users.sourceforge.net -- http://mail.python.org/mailman/listinfo/python-list
Re: The Modernization of Emacs: terminology buffer and keybinding
On Jun 24, 6:52 pm, Robert Uhl [EMAIL PROTECTED] wrote: Really? None of [navigating a folder window analogue] happens if you just do the straightforward file-open command, which should obviously at least provide a navigable directory tree, but definitely does not. The first does. Really, it does. Fire up emacs (which you've never done before) and type C-x C-f. Whoa, Nellie. I seem to recall we were discussing the file-open command. That was something else, like C-x C-o or something. More apples-and- oranges? You will be presented with a prompt something like 'Find file: ~/'; hit tab once; you'll see the message '[Complete, but not unique]'; hit tab again and you will be presented a list of all files in that directory. Sounds clunky anyway. I don't need a bunch of keypresses to do the equivalent in an Explorer-based file-open dialog in a native Windows app. Just a double-click. Emacs, with your C-x C-f: C-x C-f tab tab (Startofnameofdirectory somethingElse otherstuff) Startofname tab tab (Subdirectory anotherSubdirectory) Subd tab tab Windows: Alt, f, o (Startofnameofdirectory somethingElse otherstuff) Click-click or Startofname-down-enter (Subdirectory anotherSubdirectory) Click-click or Subd-down-enter Worst case (all keyboard): one fewer keypress. Best case (judicious use of the mouse and smart hand placement, one by left alt and one on the mouse): five TOTAL gestures. In particular, C-x C-f tab tab is replaced by alt f o (four down to three keypresses) or click file, click open (two instead of three inputs, but you have to locate the File menu from halfway across the screen with the pointer, so count it as three as well). Being able to pick an item from a list just by touching the damn thing instead of typing in a sufficiently long prefix is definitely an advantage, and if a lot of things share the same 16-character prefix in a particular directory, the emacs way starts to look SLOW. Of course, there's an even faster Windows way, if you don't mind not seeing lists of possible items: Alt, f, o Startofname-down-/-Subd-down-/ Straight to the subdirectory without waiting for it to display the parent directory or the root. Same number of inputs. And of course there's the super-fast Alt, f, o, C-v, enter if you happen to have the exact path in the clipboard already. I'd like to see emacs do that, at least if the text to paste originated outside emacs. (If I'm doing this in Winword's file open dialog it could have originated in Notepad, Firefox, or just about anywhere else, not just Winword.) If you like 'em, though, just select File:Visit New File. It gives you a platform-default (gtk+, for me) file selector. Now we're talking about a graphical port instead of stock emacs again. :P Nope, because of the way emacs works you can stop what you're doing, do something else and come back to the minibuffer. After spending a while brushing up on my Tibetan, I may or may not agree, but until I've got some real meaning out of your use of jargon like minibuffer, I'll have to pass on this one. Nonetheless, stuff you can do but can't know you can do without learning Tibetan is unlikely to be of much help to the average user. :) Fortunately, folks brighter than you I have imagined a nice way for us. It pops up a new Emacs window (pane, if you prefer the terminology) showing a list of all filenames. You could continue typing, or just click on a filename in the window, or hit return while the cursor is on a filename in that window. Back to discussing a graphical port again. Besides the apples and oranges issue, this amounts to implementing a dodgy imitation of a file open dialog anyway. Why bother with such an imitation when you can use a natively-GUI editor written for your platform and get access to the real thing? -- http://mail.python.org/mailman/listinfo/python-list
Re: Using PSE under Win32
On Jun 24, 1:13 am, Eduardo Dobay [EMAIL PROTECTED] wrote: Hello, I've been playing around withmod_pythonthese days (using Publisher and PSP), and it has been working smoothly under Windows XP (using Apache 2.2). But when I installed PSE and went to use it withmod_python, it didn't work. The error I get whenever I try to load a PSE page is: Traceback (most recent call last): File C:\Python25\lib\site-packages\mod_python\importer.py, line 1537, in HandlerDispatch default=default_handler, arg=req, silent=hlist.silent) File C:\Python25\lib\site-packages\mod_python\importer.py, line 1229, in _process_target result = _execute_target(config, req, object, arg) File C:\Python25\lib\site-packages\mod_python\importer.py, line 1128, in _execute_target result = object(arg) TypeError: 'module' object is not callable I thought it could be some incompatibility issue between PSE andmod_python, but I tried both installing the PSE binary and building the sources, and it didn't make a difference. Has anyone out there had success using PSE under Windows? (Just for the record, I did install matching versions, at least for Apache (2.2.3), Python (2.5) andmod_python(3.3.1). PSE doesn't seem to have a strict version requirement.) What do you have PythonHandler set to and what does it identify? The error above suggests that whatever you identify as the handler is not a callable object like a function. Are you perhaps identifying some sort of PSE template object as target when you shouldn't be? Post your handler code so we can see it. Graham -- http://mail.python.org/mailman/listinfo/python-list
Re: Python's only one way to do it philosophy isn't good?
Steven D'Aprano [EMAIL PROTECTED] writes: You seem oblivious to the fact that one of the huge benefits of Python is its elegant and readable syntax. The problem with not having a flexible syntax, is that a programming language can't provide off-the-shelf an elegant syntax for all functionality that will ever be needed. It is hardly off-the-shelf if somebody has to create new syntax for it. Ummm. that's my point. No language can provide all the syntax that will ever be needed to write elegant code. If module authors can provide the syntax needed to use their module elegantly, then problem solved. Eventually programmers find themselves in need of new elegant functionality, but without a corresponding elegant syntax to go along with the new functionality, the result is code that does not look elegant and is therefore difficult to read and thus maintain. That's true, as far as it goes, but I think you over-state your case. I do not. It is so easy for you, without *any* experience with a language (i.e., Lisp) or its community to completely dismiss the knowledge and wisdom acquired by that community. Doesn't that disturb you a bit? The syntax included in Python is excellent for most things, and even at its weakest, is still good. I can't think of any part of Python's syntax that is out-and-out bad. The proposed syntax for using the proposed predicate-based multimethod library is ungainly. Until decorators were added to the language, the way to do things that decorators are good for was ugly. Decorators patch up one ugliness, but who wants Python to become an old boat with lots of patches? Nearly every addition made to Python since 1.5 could have been done in the standard library, rather than being made to the core language, if Python had a good macro system. The exceptions, I think, being objects all the way down, and generators. Though generators could have been done in the standard library too, if Python had first class continuations, like Scheme and Ruby do. Over time, an infinite number of examples will turn up like this, and I claim (1) that it is better to modify the standard library than to modify the language implementation, and that (2) it is better to allow people to experiment with language features without having to modify the implementation, and (3) that it is better to allow people to distribute new language features for experimentation or production in a loadable modular fashion, and (4) that it is better to allow application developers to develope new language features for their application frameworks than to not. The reality is, one can go a long, long, long distance with Python's syntax. And you can go a long, long way with Basic, or Fortran, or C, or C++, or Haskell, or Lisp. None of this implies that there aren't deficiencies in all of these languages. Python is no exception. Python just happens to be better than most in a number of significant regards. Most requests for new syntax I've seen fall into a few categories: * optimization, e.g. case, repeat, multi-line lambda I don't give a hoot about case or repeat, though a Lisp-like loop macro might be nice. (The loop macro is a little mini language optimized for coding complicated loops.) A multi-line lambda would be very nice. * language Foo looks like this, it is kewl Sometimes language Foo has features that are actually important to for a specific application or problem domain. It's no accident, for instance, that Lisp is still the preferred language for doing AI research. It's better for Python if Python can accommodate these applications and domains than for Python to give up these markets to Foo. * the usual braces/whitespace flamewars * trying to get static type checking into the language So let's be specific -- what do you think Python's syntax is missing? If Python did have a macro facility, what would you change? In addition to the examples given above, symbols would be nice. Lisp has 'em, Ruby has 'em, Python doesn't. They are very useful. An elegant multimethod based object system will be essential for every language someday, when the time is right for people to understand the advantages. Manifest typing will be essential. A backtracking system is important for some applications. Perhaps all applications, someday. The ability to make mini-languages for specific domains, like fields of math and science, is very useful, so the mathematicians and scientists can denote things in a notation that is closer to the notation that they actually work in. Etc., etc., etc. The future is long, and our ability to peer into it is blurry, and languages that can adapt to the unforeseen needs of that blurry future are the ones that will survive. For instance, I can state with almost 100% certainty that one hundred years from now, some dialect of Lisp will still be around and in common usage. I can't say the same thing about Python. I can't say that about Python ten years from
Re: The Modernization of Emacs: terminology buffer and keybinding
On Jun 24, 7:19 pm, Robert Uhl [EMAIL PROTECTED] wrote: Twisted [EMAIL PROTECTED] writes: Of course, if emacs let you keep THREE windows open and visible at the same time, instead of being limited to one or a horizontally split two ... and a cramped 80x10 or so each, at that ... I have two frames open right now: one 80x70, the other around 180x70 (characters, not pixels). One isn't split at all; the other is split into four windows, horizontally and vertically. Then you're obviously not using the One True Emacs I am criticizing, which is a console app. If we're not talking about the same piece of software (and the one the fanatics evangelize about) then this is pointless. emacs has continued doing its own thing, mostly because that thing is better. The CUA standards (there exists an emacs package if you really want them) are broken and lame--I and most other don't wish to cripple our text editor of choice. CUA standards? I'm sorry, I don't speak Botswanan. If you mean Windows standards like for cut, copy, and paste, broken and lame is obviously in the eye in the beholder, and something 97% of computer users are used to is the defacto standard, so it's the other 3% that are broken and lame. ;) When you start emacs in a text console, you see this: Welcome to GNU Emacs, one component of the GNU/Linux operating system. Type C-l to begin editing. Get help C-h (Hold down CTRL and press h) Emacs manual C-h r Emacs tutorial C-h t Undo changes C-x u Really? That is not what I recall seeing. Are you talking about emacs- the-text-mode-editor, or emacs-the-hybrid-somethingorother-when-you- happen-to-run-it-from-the-command-prompt-on-unix? Because I've been discussing the former. Buy manualsC-h C-m How crass. First I've seen anything open source/free software that makes sales pitches at you. Mostly I've only seen that with closed-source Windows freeware loaded with adware, and with shareware that nags you to register or otherwise spend money with its author. And with actual paid products, particularly those from Intuit which act as Intuit's front-line salesmen by trying to constantly upsell you and sell stuff to your friends and relatives. Er, thanks but no thanks. (I don't personally spend a dime on any Intuit products. I unfortunately know people who do. One version of some accounting software of theirs even spammed all of a user's email contacts, by God. Where are those Russian spammer-targeting hitmen when you need them?) Activate menubar F10 or ESC ` or M-` Definitely not the stock text-mode emacs I've had my runins with in the past, but some kind of hybrid or offshoot, then. Clicking within the document's window isn't obvious?!? Clicking within the document's window is obvious but doesn't work, unless you're using something other than vanilla emacs at least. It did of course work in MS-DOS Edit, later versions. No, we're discussing emacs, a text editor which runs in both a GUI and a text console. Which can display images. It's cool like that. No, we're discussing ... oh, nevermind. It looks like there are several utterly different pieces of software that have one thing in common - the name emacs. Anyone can dodge or seem to rebut a criticism of one of them by describing how another of them isn't like that. :P At least Windows 3.1 had most apps have the same keys for the vast majority of commands, and those were the right keys. Emacs has all the applications have the vast majority of their commands use the same WRONG keys. Neither is right nor wrong; you're just used to one. The emacs keys are certainly more flexible and powerful, though. Some might consider them right for that reason. The Windows keys are familiar to 97% of the population. Some might consider them right for that reason. This is also a change from your earlier position that they were, and I quote, broken and lame, assuming you mean the same stock Windoze keybindings you meant with the cryptic term CUA standards. Search is usually ctrl+f, type something, hit enter in my experience. Unless you want regexp search. And if you want to find again it can be interesting. I rarely want regexp search, and if I want it I can use Notetab, a notepad replacement with tabbed MDI and yes, regexp search. A few tabs and a space keypress to turn it on after ctrl+f. As for find again hitting enter additional times is the usual method, in Notetab, Notepad, and elsewhere. And I can use any text editor I want to edit HTML. You could use Notepad no doubt; you could also use a Turing machine. I prefer to use a useful tool. Painting it as a choice between Notepad and emacs is the fallacy of false dichotomy. There's Notetab (useful, but non-free) and lots of (sometimes free) other text editors (for Windows and for other platforms). Some specialize in HTML editing the way Eclipse's built-in editor specializes in Java editing (and
Re: The Modernization of Emacs: terminology buffer and keybinding
On Jun 25, 12:32 am, Twisted [EMAIL PROTECTED] wrote: It looks like there are several utterly different pieces of software that have one thing in common - the name emacs... When you start emacs in a text console, you see this: Welcome to GNUEmacs, one component of the GNU/Linux operating system. Get help C-h (Hold down CTRL and press h) Emacsmanual C-h r Emacstutorial C-h t Undo changes C-x u Really? That is not what I recall seeing. Are you talking aboutemacs- the-text-mode-editor, oremacs-the-hybrid-somethingorother-when-you- happen-to-run-it-from-the-command-prompt-on-unix? Because I've been discussing the former. Everyone now uses http://www.gnu.org/software/emacs/ or a minor derivative of it. Its official distribution FTP location is http://ftp.gnu.org/pub/gnu/emacs/ And for the Windows port, the official FTP is here http://ftp.gnu.org/pub/gnu/emacs/windows/ We don't care about the 1970 version of Emacs, because of course back then there WAS NO GUI. - JackT -- http://mail.python.org/mailman/listinfo/python-list
Re: The Modernization of Emacs: terminology buffer and keybinding
Some entity, AKA JackT [EMAIL PROTECTED], wrote this mindboggling stuff: (selectively-snipped-or-not-p) We don't care about the 1970 version of Emacs, because of course back then there WAS NO GUI. But if you are blind as bat, any 2007's GUI is useless. Cor -- (defvar MyComputer '((OS . GNU/Emacs) (IPL . GNU/Linux))) The biggest problem LISP has, is that it does not appeal to dumb people If that fails to satisfy read the HyperSpec, woman frig or Tuxoharata mailpolicy @ http://www.clsnet.nl/mail.php -- http://mail.python.org/mailman/listinfo/python-list
how to sorted by summed itemgetter(x)
for example, let from operator import itemgetter items = [('a', [5, 2]), ('c', [1]), ('b', [6]), ('d', [7])] sorted(items, key = itemgetter(1)) get this back: [('c', [1]), ('a', [5, 2]), ('b', [6]), ('d', [7])] but sorted(items, key = sum(itemgetter(1))) raise a errer: 'operator.itemgetter' object is not iterable how to sorted by summed itemgetter(1)? maybe sorted(items,key = lambda x:sum(x[1])) can't itemgetter be used here? -- http://mail.python.org/mailman/listinfo/python-list
Re: Which XML?
On Jun 24, 7:04 pm, Bruno Barberi Gnecco [EMAIL PROTECTED] wrote: I've found a lot of XML libraries for Python. Any advices on which one to use (or *not* to use)? My requirements are: support for XPath, stability (a must, segfaults are not an option), with DOM API and good performance desirable. Thanks for any advice. -- Bruno Barberi Gnecco brunobg_at_users.sourceforge.net I use the minidom module for most of my XML work, but I don't think it has much in the way of XPath. I think lxml might work better for that sort of thing and I think it's part of ElementTree: http://codespeak.net/lxml/dev/objectify.html This guy kind of reviews the major XML modules: http://www.oreillynet.com/onlamp/blog/2005/01/code_respecting_xpath_xml_pyth.html Mike -- http://mail.python.org/mailman/listinfo/python-list
Re: The Modernization of Emacs: terminology buffer and keybinding
On Jun 25, 12:56 am, Cor Gest [EMAIL PROTECTED] wrote: Some entity, AKA JackT [EMAIL PROTECTED] wrote this mindboggling stuff: (selectively-snipped-or-not-p) No need to be insulting. We don't care about the 1970 version ofEmacs, because of course back then there WAS NO GUI. But if you are blind as bat, any 2007's GUI is useless. You may have missed part of the discussion. Today's GNU emacs will still run with most of its features (even keyboard-driven text-drawn menu) when you run it on a GUI-less environment. At the same time, today's GNU emacs, when run on a GUI, will be able to pop up file-selection menus, display colors, etc. etc. - JackT -- http://mail.python.org/mailman/listinfo/python-list
Re: Portable general timestamp format, not 2038-limited
From: James Harris [EMAIL PROTECTED] I have a requirement to store timestamps in a database. ... 1) subsecond resolution - milliseconds or, preferably, more detailed How do you plan to deal with leap seconds? - Stick to astronomical time, which is absolutely consistent but which drifts from legal time? - Stick to legal time (UTC), which stalls by one second from time to time, causing time-difference calculations to be incorrect by varying numbers of seconds? Only after you make *that* crucial decision, will it be reasonable to consider milliseconds or other sub-second resolution. As for the representation to store in the DB, somebody suggested text, and I agree, with one clarification: Stick to US-ASCII, which has been incorporated into UniCode hence is pretty much guaranteed to be stable for longer than you care about. -- http://mail.python.org/mailman/listinfo/python-list
Re: how to sorted by summed itemgetter(x)
Aldarion [EMAIL PROTECTED] writes: how to sorted by summed itemgetter(1)? maybe sorted(items,key = lambda x:sum(x[1])) can't itemgetter be used here? You really want function composition, e.g. sorted(items, key=sum*itemgetter(1)) where * is a composition operator (doesn't exist in Python). You could write: def compose(f,g): return lambda *a,**k: f(g(*a,**k)) and then use sorted(items, key=compose(sum,itemgetter(1))) or spell it out inline: sorted(items, key=lambda x: sum(itemgetter(1)(x))) I'd probably do something like: snd = itemgetter(1)# I use this all the time sorted(items, key=lambda x: sum(snd(x))) -- http://mail.python.org/mailman/listinfo/python-list
Re: something similar to shutil.copytree that can overwrite?
On Jun 22, 9:07 pm, Ben Sizer [EMAIL PROTECTED] wrote: That's the easy bit to fix; what about overwriting existing files instead of copying them? Do I have to explicitly check for them and delete them? It seems like there are several different copy functions in the module and it's not clear what each of them do. What's the difference between copy, copyfile, and copy2? Why do the docs imply that they overwrite existing files when copytree skips existing files? -- Ben Sizer copytree does not skip existing files if will overwrite said files I just missed the makedirs call at the start the failed makedirs call will cause the copytree function to exit completely thus you do not get your files updated but with the if exists check, your files should get overwritten -- http://mail.python.org/mailman/listinfo/python-list
Re: The Modernization of Emacs: terminology buffer and keybinding
Twisted [EMAIL PROTECTED] writes: Really? None of [navigating a folder window analogue] happens if you just do the straightforward file-open command, which should obviously at least provide a navigable directory tree, but definitely does not. The first does. Really, it does. Fire up emacs (which you've never done before) and type C-x C-f. Whoa, Nellie. I seem to recall we were discussing the file-open command. That was something else, like C-x C-o or something. More apples-and- oranges? Fortunately, emacs has a facility to tell exactly what's bound to a key sequence. C-h k (or f1 k, if you prefer)followed by that sequence will display what's bound to it, and the documentation for that function. C-h k C-x C-o yields: C-x C-o runs the command delete-blank-lines C-h k C-x o yields: C-x o runs the command other-window C-h k C-x C-f yields: C-x C-f runs the command find-file So you can see how cool emacs is, here's the entire output for C-x C-f, demonstrating how the editor documents itself: C-x C-f runs the command find-file which is an interactive compiled Lisp function in `files.el'. It is bound to open, C-x C-f, menu-bar file new-file. (find-file filename optional wildcards) Edit file filename. Switch to a buffer visiting file filename, creating one if none already exists. Interactively, the default if you just type RET is the current directory, but the visited file name is available through the minibuffer history: type M-n to pull it into the minibuffer. Interactively, or if wildcards is non-nil in a call from Lisp, expand wildcards (if any) and visit multiple files. You can suppress wildcard expansion by setting `find-file-wildcards' to nil. To visit a file without any kind of conversion and without automatically choosing a major mode, use M-x find-file-literally. You will be presented with a prompt something like 'Find file: ~/'; hit tab once; you'll see the message '[Complete, but not unique]'; hit tab again and you will be presented a list of all files in that directory. Sounds clunky anyway. I don't need a bunch of keypresses to do the equivalent in an Explorer-based file-open dialog in a native Windows app. Just a double-click. Generally, you need to scroll, too, as the Windows file widget doesn't display a lot of files at once. Of course, there's an even faster Windows way, if you don't mind not seeing lists of possible items: Alt, f, o Startofname-down-/-Subd-down-/ How is this different from C-x C-f Startofname-tab-Subd-tab? Except emacs saves you type slashes... If you like 'em, though, just select File:Visit New File. It gives you a platform-default (gtk+, for me) file selector. Now we're talking about a graphical port instead of stock emacs again. :P That _is_ stock emacs, I assure you. Fortunately, folks brighter than you I have imagined a nice way for us. It pops up a new Emacs window (pane, if you prefer the terminology) showing a list of all filenames. You could continue typing, or just click on a filename in the window, or hit return while the cursor is on a filename in that window. Back to discussing a graphical port again. It's not a port--it's emacs. And save for the click all of the above works in both a GUI and a console. It's nice working the same way in multiple places. Besides the apples and oranges issue, this amounts to implementing a dodgy imitation of a file open dialog anyway. Why bother with such an imitation when you can use a natively-GUI editor written for your platform and get access to the real thing? Because it's nice having the same interface no matter what. Because GUIs come and GUIs go (remember CDE? OpenView?), but emacs will always be there. Because it's nice being able to fire up emacs and not care what platform one is running on. -- Robert Uhl http://public.xdi.org/=ruhl prepBut nI vrbLike adjHungarian! qWhat's artThe adjBig nProblem? -- Alec Flett -- http://mail.python.org/mailman/listinfo/python-list
Re: The Modernization of Emacs: terminology buffer and keybinding
Twisted [EMAIL PROTECTED] writes: I have two frames open right now: one 80x70, the other around 180x70 (characters, not pixels). One isn't split at all; the other is split into four windows, horizontally and vertically. Then you're obviously not using the One True Emacs I am criticizing, which is a console app. No, the One True Emacs supports GUIs. It has since 1991. Take a look at http://linux.softpedia.com/screenshots/Emacs_2.png. emacs has continued doing its own thing, mostly because that thing is better. The CUA standards (there exists an emacs package if you really want them) are broken and lame--I and most other don't wish to cripple our text editor of choice. CUA standards? I'm sorry, I don't speak Botswanan. If you mean Windows standards like for cut, copy, and paste, broken and lame is obviously in the eye in the beholder, and something 97% of computer users are used to is the defacto standard, so it's the other 3% that are broken and lame. ;) Popularity is no measure of goofness. No, we're discussing ... oh, nevermind. It looks like there are several utterly different pieces of software that have one thing in common - the name emacs. That is actually true. There's GNU emacs (the original and still the best). There's XEmacs (a fork of the same). Then there are a myriad of ancient emacsen, most particularly Gosling emacs. However, the only two which matter are GNU emacs and XEmacs. Both have supported a GUI for 16 years now. I don't have XEmacs installed, so I cannot tell you if it has the tutorial. I would be truly surprised if it didn't. Neither is right nor wrong; you're just used to one. The emacs keys are certainly more flexible and powerful, though. Some might consider them right for that reason. [snip] This is also a change from your earlier position that they were, and I quote, broken and lame, assuming you mean the same stock Windoze keybindings you meant with the cryptic term CUA standards. Not really--they're broken and lame because they are less flexible and powerful. How 'bout you actually try using a modern emacs? It'll even support your chosen operating system. -- Robert Uhl http://public.xdi.org/=ruhl Better to teach a man to fish than to give him a fish. And if he can't be bothered to learn to fish and starves to death, that's a good enough outcome for me. --Steve VanDevender, 1 May 2000 -- http://mail.python.org/mailman/listinfo/python-list
Help needed to solve this NameError
Hi, Iam new tp python programming. Iam getting compiler error when declaring frame instance as local variable. please find the code from Tkinter import * class App: def __init__(self, master): *frame = Frame(master) * frame.pack() self.button = Button(frame, text=QUIT, fg=red, command=frame.quit) self.button.pack(side=LEFT) self.hi_there = Button(frame, text=Hello, command=self.say_hi) self.hi_there.pack(side=LEFT) def say_hi(self): print hi there, everyone! root = Tk() app = App(root) root.mainloop() once compiling iam getting the error Traceback (most recent call last): File C:\chk.py, line 20, in module **frame.pack() *NameError: name 'frame' is not defined * thanks -- http://mail.python.org/mailman/listinfo/python-list
Re: Python's only one way to do it philosophy isn't good?
Steven D'Aprano wote: But if you really want declarations, you can have them. import variables variables.declare(x=1, y=2.5, z=[1, 2, 4]) variables.x = None variables.w = 0 Traceback (most recent call last): File stdin, line 1, in module File variables.py, line 15, in __setattr__ raise self.DeclarationError(Variable '%s' not declared % name) variables.DeclarationError: Variable 'w' not declared Another way is to decorate functions with their local variables: from strict import my @my(item) ... def f(x=1, y=2.5, z=[1,2,4]): ... x = float(x) ... w = float(y) ... return [item+x-y for item in z] ... Traceback (most recent call last): File stdin, line 2, in module File strict.py, line 11, in dec raise DeclarationError(No slot for %s%varname) strict.DeclarationError: No slot for w and the implementation import re class DeclarationError(TypeError): pass def my(slots=): tokens = slots.split() def dec(func): code = func.func_code for varname in code.co_varnames[code.co_argcount:]: if re.match('\w+$', varname) and varname not in tokens: raise DeclarationError(No slot for %s%varname) return func return dec The best way to catch false rebindings is to stick a comment with the word rebound after every statement where you think you're rebinding a variable. Then you can search your code for cases where there's a rebound comment but no rebinding. Assuming you're the kind of person who knows that false rebindings can lead to perplexing bugs, but doesn't check apparent rebindings in a paranoid way every time a perplexing bug comes up, anyway. (They aren't that common in modern python code, after all.) And that you remembered to add the comments (like you would have remembered the let and set). And you're also the kind of person who's troubled by perplexing bugs but doesn't run a fully fledged lint. Maybe that's the kind of person who wouldn't put up with anything short of a macro as in the original proposal. All I know is that it's the kind of person I don't want to second guess. Graham -- http://mail.python.org/mailman/listinfo/python-list
Re: Help needed to solve this NameError
En Sun, 24 Jun 2007 23:17:25 -0300, senthil arasu [EMAIL PROTECTED] escribió: Hi, Iam new tp python programming. Iam getting compiler error when declaring frame instance as local variable. please find the code In Python, indentation (number of spaces at start of lines) is important. Verify your code against the original source (book, tutorial, wherever you got it). Both def lines should be indented 1 level (let's say, 4 spaces). All lines between those two, should be indented 2 levels (8 spaces), same indentation for the hi there! line. All other lines should be at the left margin. -- Gabriel Genellina -- http://mail.python.org/mailman/listinfo/python-list
Re: Inferring initial locals()
George Sakkis wrote: On Jun 21, 4:42 pm, [EMAIL PROTECTED] [EMAIL PROTECTED] wrote: On Jun 21, 8:51 pm, George Sakkis [EMAIL PROTECTED] wrote: I wonder if there is a (preferably not too-hackish) solution to the following introspection problem: given a callable and a number of positional and/or keyword arguments, infer what would be the frame's locals() right after the function is called Turns out it wasn't that hard after all; I came up with the following: So, what should your code do about this: def someFunction(a, b, c=43, d=14, f=12): print locals() import functools a_funct = functools.partial(someFunction, d=13, c=5) b_funct = functools.partial(a_funct, 14, d=12) localsProber(b_funct) My point is simply: Introspection code is often written with a fixed idea of what other programmers write. The others don't use introspection, the others don't use higher order functions to build functions, --Scott David Daniels [EMAIL PROTECTED] -- http://mail.python.org/mailman/listinfo/python-list
Re: try/except with multiple files
[EMAIL PROTECTED] wrote: On Jun 21, 9:00 pm, Robert Hicks [EMAIL PROTECTED] wrote: Is it good practice to do something like: try: f1 = file('file1') f2 = file('file2') except: # catch the exception If what you want is to make sure that resources will be released, you can use a try/finally block or (Python 2.5) a with block. You could do something like this: files = [] try: for name in ['abc.txt', 'def.txt', 'ghi.txt']: files.append(open(name)) a, b, c = files code using the three files finally: while files: files.pop().close() --Scott David Daniels [EMAIL PROTECTED] -- http://mail.python.org/mailman/listinfo/python-list
Re: The Modernization of Emacs: terminology buffer and keybinding
Hi folks! Dont want to spoil the fun of a real flame war here but what I want to ask is directly relevant to emacs in python [And the answers may even add some light to the current heat :-) ] I will be training a bunch of kids for using python in a data-center linux-sysadmin context. I intend to use emacs [apologies twisted -- cant change my anti-rodent preferences after 20 years ] but not clear what are the best setups. My questions are 1. Which python mode should one use? It seems there is one from python and one from emacs and both are deliberately named so as to be confusable!! I would like one that gives... 2. Good support for debugging: I hear pdbtrack is better than pdb -- but I am not able to figure how to use it. 3. Is it possible to get brief help on methods/functions using mouse-hovering/F1 rather than having to go out to pydoc etc 4. Also maybe a (minor?) mode to convert selections of interpreter text into doctests? 5. The menu contains something called IM-python but that contains nothing except *rescan* 6. Turning off semantic. semantic (is that the same as fly-make??) seems to randomly get into 99% CPU usage. How to turn it off? -- http://mail.python.org/mailman/listinfo/python-list
Re: how to sorted by summed itemgetter(x)
Thanks for the reply,I got it. On 6 25 , 9 19 , Paul Rubin http://[EMAIL PROTECTED] wrote: Aldarion [EMAIL PROTECTED] writes: how to sorted by summed itemgetter(1)? maybe sorted(items,key = lambda x:sum(x[1])) can't itemgetter be used here? You really want function composition, e.g. sorted(items, key=sum*itemgetter(1)) where * is a composition operator (doesn't exist in Python). You could write: def compose(f,g): return lambda *a,**k: f(g(*a,**k)) and then use sorted(items, key=compose(sum,itemgetter(1))) or spell it out inline: sorted(items, key=lambda x: sum(itemgetter(1)(x))) I'd probably do something like: snd = itemgetter(1)# I use this all the time sorted(items, key=lambda x: sum(snd(x))) -- http://mail.python.org/mailman/listinfo/python-list
Python-based event calendar?
Greetings. One of the research groups here has been using a PHP application on one of their own computers to publish their list of seminars: http://www.k5n.us/webcalendar.php They're now asking us to support this on our department web server (the guy that set it up is leaving the group). I've looked at the product, and it seems to work well enough, but I'd prefer to have something equivalent that was based on Python. I have the impression that there is something similar available for Zope/Plone, but that seems too big a hammer for this particular problem. Is there some other Python-based event calendar that doesn't require such a heavy-weight framework? Thanks. - Mike -- Michael Hannonmailto:[EMAIL PROTECTED] Dept. of Physics 530.752.4966 University of California 530.752.4717 FAX Davis, CA 95616-8677 -- http://mail.python.org/mailman/listinfo/python-list
Identifying button pressed
Hi All, Am a newbie to GUI in python and is currently working on building a calculator with the help of python and glade. Now I want that the function which handles the pressing event of a numeric key is same for all the 10 buttons(0 to 9). But unfortunately I dont know how to recognize the button pressed so that I can get its label by get_label method and can do the work pretty easily. Even if you have a different approach idea please do tell me. Thanks in advance. -- Satyajeet Singh -- http://mail.python.org/mailman/listinfo/python-list
regular expressions eliminating filenames of type foo.thumbnail.jpg
Hi folks, I'm trying to alter a program I posted about a few days ago. It creates thumbnail images from master images. Nice and simple. To make sure I can match all variations in spelling of jpeg, and different cases, I'm using regular expressions. The code is currently: - #!/usr/bin/env python from PIL import Image import glob, os, re size = 128, 128 def thumbnailer(dir, filenameRx): for picture in [ p for p in os.listdir(dir) if os.path.isfile(os.path.join( dir,p)) and filenameRx.match(p) ]: file, ext = os.path.splitext(picture) im = Image.open (picture) im.thumbnail(size, Image.ANTIALIAS) im.save(file + .thumbnail + ext) jpg = re.compile(.*\.(jpg|jpeg), re.IGNORECASE) thumbnailer(., jpg) - The problem is this. This code outputs foo.thumbnail.jpg when ran, and when ran again it creates foo.thumbnail.thumbnail.jpg and so on, filling a directory. The obvious solution is to filter out any name that contains the term thumbnail, which I can once again do with a regular expression. My problem is the construction of this expression. The relevant page in the tutorial docs is: http://docs.python.org/lib/re-syntax.html It lists (?!...) as the proper syntax, with the example given being m = re.search('(?!abc)def', 'abcdef') I tried adding something like that to my original regex, but it added a third argument, which re.compile can't accept. jpg = re.compile((?!thumbnail).*\.(jpg|jpeg), .*\.(jpg|jpeg), re.IGNORECASE) I tried it with re.search instead and received a lot of errors. So I tried this: jpg = re.compile(.*\.(jpg|jpeg), re.IGNORECASE) jpg = re.compile((?!*thumbnail).jpg, jpg) thumbnailer(., jpg) Two assignments, but I receive more errors telling me this: [EMAIL PROTECTED] ~/pictures]$ ./thumbnail.2.py Traceback (most recent call last): File ./thumbnail.2.py, line 15, in ? jpg = re.search((?!*thumbnail).jpg, jpg) File /usr/local/lib/python2.4/sre.py, line 134, in search return _compile(pattern, flags).search(string) File /usr/local/lib/python2.4/sre.py, line 227, in _compile raise error, v # invalid expression sre_constants.error: nothing to repeat I'm stuck as to where to go forwards from here. The code which produced the above error is: - #!/usr/bin/env python from PIL import Image import glob, os, re size = 128, 128 def thumbnailer(dir, filenameRx): for picture in [ p for p in os.listdir(dir) if os.path.isfile(os.path.join( dir,p)) and filenameRx.match(p) ]: file, ext = os.path.splitext(picture) im = Image.open (picture) im.thumbnail(size, Image.ANTIALIAS) im.save(file + .thumbnail + ext) jpg = re.compile(.*\.(jpg|jpeg), re.IGNORECASE) jpg = re.search((?!*thumbnail).jpg, jpg) thumbnailer(., jpg) png = re.compile(.*\.png, re.IGNORECASE) thumbnailer(., png) gif = re.compile(.*\.gif, re.IGNORECASE) thumbnailer(., gif) - I'd like to know where I can find more information about regexs and how to think with them, as well as some idea of the solution to this problem. As it stands, I can solve it with a simple os.system call and allow my OS to do the hard work, but I'd like the code to be portable. -- http://mail.python.org/mailman/listinfo/python-list
Re: regular expressions eliminating filenames of type foo.thumbnail.jpg
Why not ditch regular expressions altogether for this problem? [ p for p in os.listdir(dir) if os.path.isfile(os.path.join(dir,p)) and p.lower().find('.thumbnail.')==-1 ] -- http://mail.python.org/mailman/listinfo/python-list
Re: Inferring initial locals()
On Jun 24, 10:52 pm, Scott David Daniels [EMAIL PROTECTED] wrote: So, what should your code do about this: def someFunction(a, b, c=43, d=14, f=12): print locals() import functools a_funct = functools.partial(someFunction, d=13, c=5) b_funct = functools.partial(a_funct, 14, d=12) localsProber(b_funct) Didn't get too far :) Traceback (most recent call last): File locprobe.py, line 54, in module localsProber(b_funct) File locprobe.py, line 9, in localsProber args, varargs, varkw, defaults = inspect.getargspec(callable) File C:\Python25\lib\inspect.py, line 728, in getargspec raise TypeError('arg is not a Python function') TypeError: arg is not a Python function My point is simply: Introspection code is often written with a fixed idea of what other programmers write. The others don't use introspection, the others don't use higher order functions to build functions, Fair enough, especially since not even the standard inspect module handles functools.partial objects. Perhaps things will improve after 2.6 with PEP 362 (Function Signature Object) in place. What you claim about introspection code though I think holds for code in general. There are quite often edge cases which the programmer doesn't anticipate or care to handle. A tool that covers X% of real- world use cases for some large X and documents the known limitations for the rest 100-X is fine with me (e.g. the current lambda). George -- http://mail.python.org/mailman/listinfo/python-list
Re: is this a valid import sequence ?
On Jun 24, 1:29 pm, Steven D'Aprano I would like to hear your opinion of whether the following two functions are equally as wrong: def f1(gizmo): global spam # holds the frommet needed for the gizmo gizmo.get_frommet(spam) def f2(gizmo): # global spam holds the frommet needed for the gizmo gizmo.get_frommet(spam) I'm sure they're both wrong, but I'd like to know if there are degrees of wrongness. I am not Alex Martelli, but I will tell you my opinion anyway. To me f2 is not wrong: at worse you can say that the comment is redundant since it is already clear from the code that spam is a global, but it is not a big deal. As a code reviewer I would not have had issues with f2. OTOH I would have had serious issues with f1. Since the global statement in correct Python code is solely used to declare that a global variable is being set in an inner scope, I would have to guess that: 1. function f1 wrong; maybe the author cut and pasted it from someplace, forgetting the line where the global variable spam was set; 2. maybe f1 is right, but then the author forgot to remove the global declaration after the cut paste; 3. the author does not know Python, and he believes that he has to use global to denote the fact that the method gizmo.get_frommet(spam) is setting a global variable. So I would have had to look at get_frommet to see that actually 'spam' is not set there, and finally I would have reached the conclusion that 4. the author was completely wrong and used global without knowing its meaning. All that analysis would have cost me some time, potentially a lot of time depending on the complexity of the code, and all that time would have been wasted time. So f1 is misleading code, and I consider misleading code actually *worse* than wrong code, since it makes you waste your time without a good reason. Michele Simionato -- http://mail.python.org/mailman/listinfo/python-list
Re: regular expressions eliminating filenames of type foo.thumbnail.jpg
On Jun 25, 1:00 pm, Justin Ezequiel [EMAIL PROTECTED] wrote: [ p for p in os.listdir(dir) if os.path.isfile(os.path.join(dir,p)) and p.lower().find('.thumbnail.')==-1 ] if you really want a regexp solution, the following seems to work (?i)(?!\.thumbnail)\.jpe?g$ download and experiment with Kodos (http://kodos.sourceforge.net/) -- http://mail.python.org/mailman/listinfo/python-list
socket on cygwin python
I've installed cygwin with latest python 2.5.1, but it seems that the socket lib file do NOT support IPv6(cygwin\lib\python2.5\lib-dynload \_socket.dll), what can I do if I want to use IPv6? Thanks -- http://mail.python.org/mailman/listinfo/python-list
Re: Python's only one way to do it philosophy isn't good?
Graham Breed [EMAIL PROTECTED] writes: Another way is to decorate functions with their local variables: from strict import my @my(item) ... def f(x=1, y=2.5, z=[1,2,4]): ... x = float(x) ... w = float(y) ... return [item+x-y for item in z] Well, I suppose that's a bit better than the previous suggestion, but (1) it breaks the style rule of not declaring variables until you need them, and (2) it doesn't catch double initialization. The best way to catch false rebindings is to stick a comment with the word rebound after every statement where you think you're rebinding a variable. No, the best way to catch false rebindings is to have the computers catch such errors for you. That's what you pay them for. Then you can search your code for cases where there's a rebound comment but no rebinding. And how do I easily do that? And how do I know if I even need to in the face of sometimes subtle bugs? Assuming you're the kind of person who knows that false rebindings can lead to perplexing bugs, but doesn't check apparent rebindings in a paranoid way every time a perplexing bug comes up, anyway. (They aren't that common in modern python code, after all.) They're not that uncommon, either. I've certainly had it happen to me on several occasions, and sometimes they've been hard to find as I might not even see the mispeling even if I read the code 20 times. (Like the time I spent all day trying to figure out why my assembly code wasn't working when I was a student and finally I decided to ask the TA for help, and while talking him through my code so that he could tell me what I was doing wrong, I finally noticed the rO where there was supposed to be an r0. It's amazing how useful a TA can be, while doing nothing at all!) And you're also the kind of person who's troubled by perplexing bugs but doesn't run a fully fledged lint. Maybe PyLint is better than Lint for C was (hated it!), but my idea of RAD does not include wading through piles of useless warning messages looking for the needle warning in the warning haystack. Or running any other programs in the midst of my code, run, code, run, ..., loop. Maybe that's the kind of person who wouldn't put up with anything short of a macro as in the original proposal. All I know is that it's the kind of person I don't want to second guess. As it is, I code in Python the way that a normal Python programmer would, and when I have a bug, I track it down through sometimes painstaking debugging as a normal Python programmer would. Just as any other normal Python programmer, I would not use the alternatives suggested so far, as I'd find them cumbersome and inelegant. I'd prefer not to have been bit by the bugs to begin with. Consequently, I'd use let and set statements, if they were provided (or if I could implement them), just as I have the equivalents to let and set in every other programming language that I commonly program in other than Python. |oug -- http://mail.python.org/mailman/listinfo/python-list
Chroot Jail Not Secure for Sandboxing Python?
This wiki page suggests using a chroot jail to sandbox Python, but wouldn't running something like this in your sandboxed Python instance still break you out of the chroot jail: os.execle ('/usr/bin/python','-c','import os; os.execlp(/bin/sh)', {}) or maybe: del os.environ['LD_PRELOAD'] os.execl ('/usr/bin/python','-c','import os; os.execlp(/bin/sh)') My ISP suggested these as counter-examples to my request for a chroot jail. (I couldn't even get Python running in chroot to test this, nor could I run these commands locally in Python on Ubuntu, though maybe they opened sh?) So is a chroot jail not adequate for sandboxing Python? -Greg -- http://mail.python.org/mailman/listinfo/python-list
Re: socket on cygwin python
[EMAIL PROTECTED] schrieb: I've installed cygwin with latest python 2.5.1, but it seems that the socket lib file do NOT support IPv6(cygwin\lib\python2.5\lib-dynload \_socket.dll), what can I do if I want to use IPv6? Use the Python binaries from python.org. If that is not acceptable, recompile Python for Cygwin to use WinSock2. Regards, Martin -- http://mail.python.org/mailman/listinfo/python-list
Re: Python's only one way to do it philosophy isn't good?
On Jun 23, 6:39 pm, Douglas Alan [EMAIL PROTECTED] wrote: One of the things that annoys me when coding in Python (and this is a flaw that even lowly Perl has a good solution for), is that if you do something like longVarableName = foo(longVariableName) You end up with a bug that can be very hard to track down. You should really be using pychecker (as well as Emacs autocompletion feature ...): ~$ cat x.py def foo(x): return x longVariableName = 1 longVarableName = foo(longVariableName) ~$ pychecker -v x.py Processing x... Warnings... x.py:4: Variable (longVarableName) not used [I know you will not be satisfied with this, but pychecker is really useful, since it catches many other errors that no amount of macroprogramming would evere remove]. Michele Simionato -- http://mail.python.org/mailman/listinfo/python-list
Re: Chroot Jail Not Secure for Sandboxing Python?
[EMAIL PROTECTED] schrieb: This wiki page suggests using a chroot jail to sandbox Python, but wouldn't running something like this in your sandboxed Python instance still break you out of the chroot jail: os.execle ('/usr/bin/python','-c','import os; os.execlp(/bin/sh)', {}) Depending on how the chroot jail is set up, this command might not work - in the jail, /bin/sh might not exist. or maybe: del os.environ['LD_PRELOAD'] os.execl ('/usr/bin/python','-c','import os; os.execlp(/bin/sh)') How could deleting LD_PRELOAD help? chroot is not a library trick. It's a mechanism implemented in the operating system. So is a chroot jail not adequate for sandboxing Python? You have to define your threat model. If the threat to prevent is a malicious user getting at your data, or spreading a virus through your files, then chroot is perfectly adequate. Regards, Martin -- http://mail.python.org/mailman/listinfo/python-list
Re: regular expressions eliminating filenames of type foo.thumbnail.jpg
On Jun 24, 10:00 pm, Justin Ezequiel [EMAIL PROTECTED] wrote: Why not ditch regular expressions altogether for this problem? [ p for p in os.listdir(dir) if os.path.isfile(os.path.join(dir,p)) and p.lower().find('.thumbnail.')==-1 ] I like `and '.thumbnail.' not in p]` as a better ending. :) ~Sean -- http://mail.python.org/mailman/listinfo/python-list
Re: Chroot Jail Not Secure for Sandboxing Python?
On Jun 25, 1:21 am, [EMAIL PROTECTED] [EMAIL PROTECTED] wrote: This wiki page suggests using a chroot jail to sandbox Python, but wouldn't running something like this in your sandboxed Python instance still break you out of the chroot jail: os.execle ('/usr/bin/python','-c','import os; os.execlp(/bin/sh)', {}) or maybe: del os.environ['LD_PRELOAD'] os.execl ('/usr/bin/python','-c','import os; os.execlp(/bin/sh)') My ISP suggested these as counter-examples to my request for a chroot jail. (I couldn't even get Python running in chroot to test this, nor could I run these commands locally in Python on Ubuntu, though maybe they opened sh?) So is a chroot jail not adequate for sandboxing Python? -Greg Edit: Google groups stripped out the URL. It's http://wiki.python.org/moin/How_can_I_run_an_untrusted_Python_script_safely_(i.e._Sandbox) (or the page titled this on the Python wiki if it strips out the url above again) How can I run an untrusted Python script safely (i.e. Sandbox) -Greg -- http://mail.python.org/mailman/listinfo/python-list
Re: Python's only one way to do it philosophy isn't good?
Michele Simionato [EMAIL PROTECTED] writes: You should really be using pychecker (as well as Emacs autocompletion feature ...): I *do* use Emacs's autocompletion, but sometimes these sorts of bugs creep in anyway. (E.g., sometimes I autocomplete in the wrong variable!) ~$ pychecker -v x.py Processing x... Warnings... x.py:4: Variable (longVarableName) not used [I know you will not be satisfied with this, but pychecker is really useful, Okay, I'll check out PyChecker and PyLint, though I'm sure they will annoy the hell out of me. They're probably less annoying than spending all day tracking down some stupid bug. since it catches many other errors that no amount of macroprogramming would evere remove]. And likewise, good macro programming can solve some problems that no amount of linting could ever solve. |oug -- http://mail.python.org/mailman/listinfo/python-list