Re: PEP 288 ponderings
[Steven Bethard] (1) What's the benefit of the generator versions of these functions over the class-based versions? Generators are easier to write, are clearer, and run faster. They automatically * create a distinct generator-iterator object upon each invocation * create the next() and idempotent __iter__() methods. * raise StopIteration upon termination * remain stopped if next() is called too many times * save their own local variable state, avoiding the need for self.var references * resume execution at the point of the last yield (2) Since in all the examples there's a one-to-one correlation between setting a generator attribute and calling the generator's next function, aren't these generator attribute assignments basically just trying to define the 'next' parameter list? They are not the same. The generator needs some way to receive the values. The function arguments cannot be used because they are needed to create the generator-iterator. The yield statements likewise won't work because the first yield is not encountered until well after the first next() call. The given examples are minimal and are intended only to demonstrate the idea. I definitely don't like the idea of a magical __self__ variable that isn't declared anywhere. It is no more magical than f.__name__ or f.__doc__ for functions. The concept is almost identical to that for threading.local(). Also, the __self__ argument is a non-issue because there are other alternate approaches such as providing a function that retrieves the currently running generator. Which approach is ultimately taken is a matter of aesthetics -- the PEP itself concentrates on the core idea instead of debating syntax. The real issue with PEP 288's idea for generator attributes is that the current C implementation doesn't readily accommodate this change. Major surgery would be required :-( The more important part of the PEP is the idea for generator exceptions. The need arises in the context of flushing/closing resources upon generator termination. Raymond Hettinger -- http://mail.python.org/mailman/listinfo/python-list
Re: Frameworks for Non-Content Oriented Web Apps
You need Twisted - http://twistedmatrix.com --- : http://en.wikipedia.org/wiki/User:Sridharinfinity -- http://mail.python.org/mailman/listinfo/python-list
Re: What can I do with Python ??
Aren't games using full screen mode to address only 320 by 240 resolution for faster screen painting? If one used only 320 by 240 in a window, then that would be 1/4 of the screen or less! -- Regards, Casey -- http://mail.python.org/mailman/listinfo/python-list
Re: screen clear question
On Sun, 02 Jan 2005 14:23:07 +0800, Craig Ringer [EMAIL PROTECTED] wrote: On Sun, 2005-01-02 at 11:31, jcollins wrote: Is there a command in Python to clear the screen? That is without writing multiple blank lines. Without knowing what 'screen' you're talking about, it's hard to say. If you mean clearing a terminal, you can call 'tput clear' or '/usr/bin/clear' on many UNIX systems; no idea about Windows. On Windows the DOS CLS command will clear a command prompt, it also works for CP/M and VAX terminals too. Finally I think the curses module allows you to clear a window, including the main window - ie the terminal screen. In each case run CLS (or clear) via os.system() But the bottom line is that there is no builtin command because the mechanism is different on each platform. Alan G. Author of the Learn to Program website http://www.freenetpages.co.uk/hp/alan.gauld -- http://mail.python.org/mailman/listinfo/python-list
Re: Frameworks for Non-Content Oriented Web Apps
On 1 Jan 2005 20:51:06 -0800, [EMAIL PROTECTED] wrote: Is there something that can ease the development of application that are not content oriented(I call them NON CONTENT-ORIENTED WEB APPLICATIONS because I don't know what else to call them). I mean the applications like, accounting, high volume data entry apps, where normally GUI clients have ruled. I know very high quality ERP I don;t know of any such frameworks. The Siebel CRM system may be the kind of thing you mean I think, but it uses standard technology. IT just puts up a form then uses client side Javascript to detect changes and send the data requests to/from the data server... No special frameworks as such... HTH, Alan G. Author of the Learn to Program website http://www.freenetpages.co.uk/hp/alan.gauld -- http://mail.python.org/mailman/listinfo/python-list
Python! Is! Truly! Amazing!
Hello Everyone, I have to say: Python! Is! Truly! Amazing! So I started with python about a month ago and put in 24 hours across three weekends. My first project was to recreate a simple maze-let thingie that I remember as my first program way back on the Vic-20. That was a quick snap and a pleasure. Since then I have settled down into working on a Mahjong game. I have uploaded a current version at my personal website: www.erikbethke.com/Python/mahjong.zip also note screenshots: www.erikbethke.com/Python/screenshot01.jpg www.erikbethke.com/Python/screenshot02.pg www.erikbethke.com/Python/screenshot03.pg www.erikbethke.com/Python/screenshot04.pg www.erikbethke.com/Python/screenshot05.pg So I have been using Python 2.3.4 as that is what was compatible with the excellent PyGame last month. After reading the posts here I am using wing IDE, and over all I like it... some minor issues and I am sure if I RTFM I would have these handled. I will be buying a bunch of licenses for us. I also used this project to learn a little about XML, so I used XML to fully describe the UI, the tilesets and the tile layouts and have it able to go back and forth between 3 different tilesets, and backgounds. The XML is crappy as you can see I am experimenting with putting some data in attributes and elsewhere in elements. So now I have it laying out the tiles, tile picking correctly, and I was even able to write many new little feature-ettes in wickedly fast single edit-run passes such as this to highlight the currently available matches: def findMatchingTiles(self): matchList = [] visibleTiles = [] for i, c in enumerate ( self.tiles ): if c.state != 'clear': visibleTiles.append( c ) for i, c in enumerate ( visibleTiles ): if self.testForClear( c ): for j, d in enumerate ( visibleTiles ): if d != c and d.tileNum == c.tileNum and self.testForClear( d ): matchList.append( [c, d] ) return matchList def showHint(self): matchList = self.findMatchingTiles() for i, c in enumerate( matchList ): c[0].state='clicked' c[1].state='clicked' self.draw() I have NEVER experienced this kind of programming joy. I am a 33 year-old professional game developer (www.gopetslive.com) and have been in the industry for 11 years, and have been programming since 4th grade like all the rest of you guys. And I am not saying all this to brag, no seriously I am delirious in joy right now. I have a bad cold and went to sleep at 1am last night and woke at 5am just to get back to playing with Python! I have been looking into Python to see if it is a good answer for getting a lot of new fresh mini-game and UI work done for our project GoPets, and clearly it is. I haven't yet explored the server-side but I will. The Mahjong game in the future will take its tile art dynamically from the portraits of the users that are your friends and the people your GoPet has visited recently. Anyways, I am now a super gushing fan-boy. I have worked my way up from a scripter working in crappy proprietary languages to a c++ programmer, to now biz guy. But when I walked away from programming I gave it a grim farewell, c++ work is good, but so much mind goes into it to make progree compared to other creative uses of the mind. But Python rocks, it makes programming very fun again and now I finding myself coming home earlier so I can get to work on Python and I have an entire heap of new projects I wanted to get done. Anyways, the Mahjong game code is quite crappy. No effort has been made to optimize it, nor have I handled any sorts of errors whatsoever. I know it sucks. But I posted the code there anyways in case any one else is just coming along and wants some more example code. I also have no real UI going on. Hit R to randomize the tiles, M to try to setup a solvable game (but my algorithm for this is not very effective yet), and H for hints on tiles that can be matched. Other than the tile art anyone can do what the feel with it. Thank you all for posting here, you have already solved dozens and dozens of questions for me with a little help of google groups. Truly thank you. -Erik -- http://mail.python.org/mailman/listinfo/python-list
Re: PEP 288 ponderings
Raymond Hettinger wrote: [Steven Bethard] (2) Since in all the examples there's a one-to-one correlation between setting a generator attribute and calling the generator's next function, aren't these generator attribute assignments basically just trying to define the 'next' parameter list? They are not the same. The generator needs some way to receive the values. The function arguments cannot be used because they are needed to create the generator-iterator. The yield statements likewise won't work because the first yield is not encountered until well after the first next() call. Yeah, I wasn't trying to claim that passing the arguments to .next() is equivalent to generator attributes, only that the point at which new values for the generator state variables are provided correspond with calls to .next(). So if there was a means within a generator of getting access to the arguments passed to .next(), generator attributes would be unnecessary for the examples provided. The given examples are minimal and are intended only to demonstrate the idea. Do you have an example where the generator state isn't updated in lock-step with .next() calls? I'd be interested to look at an example of this... I definitely don't like the idea of a magical __self__ variable that isn't declared anywhere. It is no more magical than f.__name__ or f.__doc__ for functions. I'm not sure this is quite a fair parallel. The difference here is that f.__name__ and f.__doc__ are accessed as attributes of the f object, and the __name__ and __doc__ attributes are created as a result of function creation. The proposed __self__ is (1) not an attribute that becomes available, rather, a new binding local to the function, and (2) not created as a result of generator object creation but created as a result of calling .next() on the generator object. Also, the __self__ argument is a non-issue because there are other alternate approaches such as providing a function that retrieves the currently running generator. Is there a discussion of some of these alternate suggested approaches somewhere you could point me to? The more important part of the PEP is the idea for generator exceptions. The need arises in the context of flushing/closing resources upon generator termination. I wonder if maybe it would be worth moving this part to a separate PEP. It seems like it could probably stand on its own merit, and having it in with the generator attributes PEP means it isn't likely to be accepted separately. Of course, I would probably declare a class and provide a .close() method. =) Steve -- http://mail.python.org/mailman/listinfo/python-list
Re: Python! Is! Truly! Amazing!
Oh yeah, and farmer, no I didn't yet get back to making an exe by fixing the problem with pygame2exe i just got disctracted getting other things done so fast! -Erik www.gopetslive.com -- http://mail.python.org/mailman/listinfo/python-list
Re: The Industry choice
Cameron Laird wrote: Let me add a cautionary note, though: Big Companies, including Oracle, Software AG, IBM, Cisco, and so on, have adopted Tcl over and over. All of them still rely on Tcl for crucial products. All of them also have employees who sincerely wonder, Tcl? Isn't that dead? I offer this as a counter-example to the belief that Adop- tion by a heavyweight necessarily results in widespread acceptance. -- I think the adoption of computer languages is quite complex, but one useful metaphorical model may be gravity, e.g. the clumpy universe of stars, with gravity working on different scales to shape the overall distribution of matter. Adoption by a heavyweight may have some effect if that force is allowed to operate on other bodies, but the overall distribution of mass is complex. In the practice of business, companies generally find a need to consciously limit methodological diversity as they grow in size. Control is usually made more centralized, but becomes more distant from the atom (programmer writing code) as the firm grows large, and entropy becomes the enemy, lower level entropy a source of uncertainty and risk. If so, there is some legitimate reason for trying to standardize on tools (i.e. programming languages). Less sophisticated business minds may latch onto the notion of gains from economies of scale, which is usually an easy sell (and good route for a fast career rise) but an overly simple optimization. Not to say that such restrictive mindsets and policies are inevitable, but they seem the prevailing wind. Preserving intellectual diversity and innovation may be critical to a big company in the long run, and allowing the use of (for example) Python would seem very in tune with those goals. It might be nice if it was widely understood (in IT) that Python was a language any competent programmer could pick up in an afternoon, such that Java, C, and Perl shops would not be concerned about the need for their staff to learn a new language. Eric Pederson Linear? What is linear? Digital M4 (music) http://www.songzilla.blogspot.com ::: domainNot=@something.com domainIs=domainNot.replace(s,z) ePrefix=.join([chr(ord(x)+1) for x in do]) mailMeAt=ePrefix+domainIs ::: -- http://mail.python.org/mailman/listinfo/python-list
Continuations Based Web Framework - Seaside.
'Seaside' is a Smalltalk framework for what might be called Modal Web Development or Synchronous Web Programming, or even Continuation Based Web Apps. http://www.beta4.com/seaside2/ Very sexy it looks too. And it seems to be generating a lot of interest - Ruby and Java variants have already sprung up: http://rubyforge.org/projects/borges/ http://lakeshore.sourceforge.net/ I googled for the python spin-off but didn't find one. Closest I found was Imposter (http://csoki.ki.iif.hu/~vitezg/impostor/) which looks like an earlier, partially failed attempt to do what Seaside now seems to be delivering. Anyway, I guess all I'm doing is drawing this to the community's attention. Sophisticated web applications seems to be one of Python's key domains and this looks a significant new development in the area. -- Mike -- http://mail.python.org/mailman/listinfo/python-list
Re: The Industry choice
Paul Rubin http://[EMAIL PROTECTED] writes: [...] I don't understand that. If I see str x = str(3), then I know that x is a string. def foo(x): return str(x) str = foo(x) And now, let's say that foo()'s definition is in another module. It is hard for a programmer to quickly determine the type for str, that's the problem with programming in languages that don't have type declarations. -- http://mail.python.org/mailman/listinfo/python-list
Re: The Industry choice
Paul Rubin wrote: I do believe that it's a horrible deficiency in Python that it has no declarations at all, even optional ones, like perl -w or use strict. Python's scoping hacks that result from the lack of declarations just seem to me like pure insanity. Yes, ignoring most of the debate about static vs. dynamic typing, I've also longed for 'use strict'. Sure Python isn't as bad as (say) Awk in this respect; you have to at least assign a variable to make it spring into existence, but I've been bitten by typos there as well. Same when it comes to object methods (I can often never remember my method names). Pychecker helps to some extent, but I wouldn't mind a compiler that only accepted identifiers that had been declared. I don't think that anyone could argue that typing 'use apa' before the first actual use (or words to that effect) would 'slow them down', or be very onerous. Stefan, -- Stefan Axelsson (email at http://www.cs.chalmers.se/~sax) -- http://mail.python.org/mailman/listinfo/python-list
Re: The Industry choice
Donn Cave [EMAIL PROTECTED] writes: [...] For me, the effect is striking. I pound out a little program, couple hundred lines maybe, and think hm, guess that's it and save it to disk. Run the compiler, it says no, that's not it - look at line 49, where this expression has type string but context requires list string. OK, fix that, iterate. I believe program-specific unit tests are more effective than compiler typechecking :) -- http://mail.python.org/mailman/listinfo/python-list
Problems programming with Tkinter
Hi ! I'm trying to create a graphical program using Tkinter. The program is supposed to save a string the user defines as a filename. I've made it work with the the first button in the program that's named Spara ett värde i en sträng till ett filnamn, that's swedish for Save a value in a string as a file name. The button Skriv ett värde till filen (swedish for Write a value to the file) But, i want the program to open a new dialogue when i press the button Visa ruta and in that dialogue will be a field where you can enter a value directly in the program, but a can't get it to work because is don't know how i shall do to open a new dialogue window in the program? Is there someone who can help me with my problem? Here's the sourcecode for my program: from Tkinter import * class App: def __init__(self, master): frame = Frame(master) frame.pack() self.hi_there = Button(frame, text=Spara ett värde i en sträng till ett filnamn, command=self.say_hi) self.hi_there.pack(side=LEFT) self.skriv_varde = Button(frame, text=Skriv ett värde till filen, command=self.skriv_varde) self.skriv_varde.pack(side=LEFT) self.visa_ruta = Button(frame, text=Visa ruta, command=self.visa_ruta) self.visa_ruta.pack(side=LEFT) def say_hi(self): print Sparar fil S = filen.fil output = open(S, 'w') print Filen sparad def skriv_varde(self): print Skriver värde till filen myfile = open('filen.fil', 'w') myfile.write('Ny mening') myfile.close() print Värdet till filen skrivet def visa_ruta(self, parent): top = self.top = Toplevel(parent) Label(top, text=Value).pack() self.e = Entry(top) self.e.pack(padx=5) b = Button(top, text=OK, command=self.ok) b.pack(pady=5) def ok(self): print value is, self.e.get() self.top.destroy() root = Tk() app = App(root) root.mainloop() -- http://mail.python.org/mailman/listinfo/python-list
Re: The Industry choice
It might be nice if it was widely understood (in IT) that Python was a language any competent programmer could pick up in an afternoon I am a programmer who works for a firm of engineers, where they program in VBA, badly. I've often mentioned Python, whereupon I'm usually dismissed as a crank. One of them expressed concern that if they used Python and I left, then nobody would understand what to do. I could have countered that Python is actually quite an easy language to pick up, but what's the point. We might be doing a project which involves web-type stuff. I pointed out that if they did, they wouldn't be able to use VB/VBA, and may need to use something like Python. I didn't get a reaction from that at the time, but no doubt they'll be telling me that I'll have to make Excel work through the internet, or something. -- http://mail.python.org/mailman/listinfo/python-list
[OT] Re: The Industry choice
Paul Rubin http://[EMAIL PROTECTED] writes: Peter Dembinski [EMAIL PROTECTED] writes: If it has to be both reliable and secure, I suggest you used more redundant language such as Ada 95. That's something to think about and it's come up in discussions, but probably complicates stuff since it's not currently available on the target platform. Also, the people on the project have significant Java and Python experience but haven't used Ada. Do you think it has real advantages over Java? As I wrote before, it is more redundant language[1], plus (AFAIR) it has the strongest type checking of all the programming languages I know about. Plus, most of Ada compilers (such as gnat) generate machine/operating system - specific code[2], not bytecode, which could be advantage if performance is one of priorities. I may have a little skewed viewpoint because Ada 95 is the language I have recently studied on my RTS labs : [1] for example, one has to define interface and implementation parts of each module in separate files [2] AFAIR gnat generates C code, which is then compiled with gcc. -- http://mail.python.org/mailman/listinfo/python-list
Re: The Industry choice
Mark Carter [EMAIL PROTECTED] writes: We might be doing a project which involves web-type stuff. I pointed out that if they did, they wouldn't be able to use VB/VBA, and may need to use something like Python. They'll probably use vb.net. -- http://mail.python.org/mailman/listinfo/python-list
Re: Python! Is! Truly! Amazing!
somehow lost my j's: www.erikbethke.com/Python/screenshot02.jpg www.erikbethke.com/Python/screenshot03.jpg www.erikbethke.com/Python/screenshot04.jpg www.erikbethke.com/Python/screenshot05.jpg -- http://mail.python.org/mailman/listinfo/python-list
Re: Continuations Based Web Framework - Seaside.
Mike Thompson wrote: 'Seaside' is a Smalltalk framework for what might be called Modal Web Development or Synchronous Web Programming, or even Continuation Based Web Apps. Continuation Based Frameworks seem to be getting quite some attention lately. For example in the Lisp world. Check out Bill Clementson's blog for some excellent posts. http://home.comcast.net/~bc19191/blog/041229.html And Seaside looks indeed very nice. Would be good to see it generate some new interests in Smalltalk/Squeak. I googled for the python spin-off but didn't find one. Does Python really need yet another framework? Apart from the intellectual excersise, wouldn't it be nice if Python would get a framework for the rest of us (meaning: mere mortals) which would focus upon getting work done in a simple manner instead of creating yet another, new, hip, exciting, way of creating dynamic websites? If Python cannot deliver a PHP clone, at least you would expect a Rails lookalike. And though part of the Rails stack may be surpassed easily by Python equivalents, no Python alternative offers (imho of course) the same level of simplicity, elegance and pragmatism (!!) as Rails does. Regards, Iwan -- http://mail.python.org/mailman/listinfo/python-list
Re: Frameworks for Non-Content Oriented Web Apps
I have started a topic that is really vauge. I knew that this topic is very general and abstract but I think it turned out to be more general that I had expected. Let me make an attemp at defining Non-Content Oriented Web Applications. A Non-Content Oriented Web Application: (1) will be accessed from web browser(obviously). (2) will be developed using 'W3C' and other open standards(STRICTLY, to ensure compatibility and portablity). (3) will expose some kind of functionality to the user, not just some document to read. (4) functionality can be very simple to very complex. I sat down to define what I actually mean by Non-Content Oriented Web Applications with a fairly clear idea, But suddenly every thing vanished from my mind, OH MY GOD, I AM OUT OF WORDS. I think all of you have been i such situation at least once. So please help me in defining these Non-Content Oriented Web Applications. To give a example, I think GMAIL comes quite close to what I am talking aout. -- http://mail.python.org/mailman/listinfo/python-list
Re: Continuations Based Web Framework - Seaside.
Mike Thompson ha scritto: 'Seaside' is a Smalltalk framework for what might be called Modal Web Development or Synchronous Web Programming, or even Continuation Based Web Apps. http://www.beta4.com/seaside2/ Very sexy it looks too. And it seems to be generating a lot of interest - Ruby and Java variants have already sprung up: http://rubyforge.org/projects/borges/ http://lakeshore.sourceforge.net/ actually, there are also implementations in Scheme, Common Lisp (UnCommonWeb) and Cocoon-FLOW has similar concepts. And somewhere (I think on the portland pattern repository) I recall reading that Viaweb (aka the first web app) was written in CPS. Also notice that the Wee project in ruby is more advanced that Borges. I googled for the python spin-off but didn't find one. Closest I found was Imposter (http://csoki.ki.iif.hu/~vitezg/impostor/) which looks like an earlier, partially failed attempt to do what Seaside now seems to be delivering. I think independent more than earlier, it seem many people are reinventing this from time to time. Anyway, I just wanted to point out that IIRC something on this lines appeared recently in the nevow svn tree, maybe you can take a look. -- http://mail.python.org/mailman/listinfo/python-list
Re: The Industry choice
Stefan Axelsson [EMAIL PROTECTED] wrote: Yes, ignoring most of the debate about static vs. dynamic typing, I've also longed for 'use strict'. You can use __slots__ to get the effect you're after. Well, sort of; it only works for instance variables, not locals. And the gurus will argue that __slots__ wasn't intended for that, so you shouldn't do it. Sure Python isn't as bad as (say) Awk in this respect; you have to at least assign a variable to make it spring into existence I think you've hit the nail on the head. In awk (and perl, and most shells, and IIRC, FORTRAN), using an undefined variable silently gets you a default value (empty string or zero). This tends to propagate errors and make them very difficult to track down. In Python, you raise NameError or AttributeError, so you find out about your mistake quickly, and you know exactly where it is. The only time you can really go wrong is when you've got multiple assignment statements with the same lhs and you make a typo in one of them. And even then, as you say, things like Pychecker will probably catch the mistake. In perl, I always use use strict, but in Python, I just don't feel the need. Between the exception mechanism and unit tests, the odds of a typo going unnoticed for very long are pretty slim. I'll admit I don't use Pychecker, but if I was doing production code, I would probably use it as part of my QA process. I don't think that anyone could argue that typing 'use apa' before the first actual use (or words to that effect) would 'slow them down', or be very onerous. Well, I'll have to (respectfully) disagree with you on that. It's not that there's no value in explicit declarations, it's just that (IMHO) the cost exceeds the value, given the other tools we have in Python to catch the mistake. -- http://mail.python.org/mailman/listinfo/python-list
RE: Problems programming with Tkinter
Svenglenn writes: But, i want the program to open a new dialogue when i press the button Visa ruta and in that dialogue will be a field where you can enter a value directly in the program, but a can't get it to work because is don't know how i shall do to open a new dialogue window in the program? For simple data entry (and file choosing, too!), use the built-in Tk dialogs. For example: .import tkSimpleDialog . .answer = tkSimpleDialog.askString( .Dialog title, .Prompt, .parent=root, .initialvalue=Howdy!) .if answer is not None: ....do something... -- Walt -- http://mail.python.org/mailman/listinfo/python-list
Re: The Industry choice
Paul Rubin wrote: Steve Holden [EMAIL PROTECTED] writes: It seems to me that IDLE and a lot of the rest of Python are examples of someone having a cool idea and writing a demo, then releasing it with a lot of missing components and rough edges, without realizing that it can't reasonably be called complete without a lot more work. ^Python^open source^ I wouldn't say so. I'd say the Linux kernel, GCC, Emacs, Apache, Mozilla, etc. are all developed with a much more serious attitude than Python is. Of course there are lots of other FOSS programs that someone wrote for their own use and released, that are less polished than Python, but that are also the subject of less advocacy than Python. Well clearly there's a spectrum. However, I have previously written that the number of open source projects that appear to get stuck somewhere between release 0.1 and release 0.9 is amazingly large, and does imply some dissipation of effort. Give that there's no overall coordination this is of course inevitable, but some open source projects are doomed from the start to be incomplete because the original authors have never been involved in producing software with a reasonably large user base, and so their production goals and quite often their original specifications (where there are any) are unrealistic. These projects meander towards a half-assed initial implementation and then become moribund. This is not to tar respectable projects like Linux, many (but not all) of the Gnu projects, and Python with that same brush, and personally I think the Python *core* is pretty solid and quite well-documented, but I don;t regard IDLE as part of the core myself. Since I'm not an active developer, this may not be in line with python-dev's opinions on the matter. regards Steve -- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/ Holden Web LLC +1 703 861 4237 +1 800 494 3119 -- http://mail.python.org/mailman/listinfo/python-list
Re: The Industry choice
Aahz wrote: In article [EMAIL PROTECTED], Paul Rubin http://[EMAIL PROTECTED] wrote: I was pretty skeptical of Java's checked exceptions when I first used them but have been coming around about them. There's just been too many times when I wrote something in Python that crashed because some lower-level function raised an exception that the upper level hadn't been expecting, after the program had been in use for a while. I'd sure rather find out about that at compile time. That's funny -- Bruce Eckel talks about how he used to love checked exceptions but has come to regard them as the horror that they are. I've learned to just write throws Exception at the declaration of every method. Pretty sloppy, though, no? And surely the important thing is to have a broad handler, not a broad specification of raisable exceptions? regards Steve -- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/ Holden Web LLC +1 703 861 4237 +1 800 494 3119 -- http://mail.python.org/mailman/listinfo/python-list
Re: The Industry choice
Mark Carter wrote: It might be nice if it was widely understood (in IT) that Python was a language any competent programmer could pick up in an afternoon I am a programmer who works for a firm of engineers, where they program in VBA, badly. I've often mentioned Python, whereupon I'm usually dismissed as a crank. One of them expressed concern that if they used Python and I left, then nobody would understand what to do. I could have countered that Python is actually quite an easy language to pick up, but what's the point. We might be doing a project which involves web-type stuff. I pointed out that if they did, they wouldn't be able to use VB/VBA, and may need to use something like Python. I didn't get a reaction from that at the time, but no doubt they'll be telling me that I'll have to make Excel work through the internet, or something. They'll probably just move to .NET, which allows them to write .aspx pages using VB. regards Steve -- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/ Holden Web LLC +1 703 861 4237 +1 800 494 3119 -- http://mail.python.org/mailman/listinfo/python-list
Re: The Industry choice
Roy Smith wrote: In perl, I always use use strict, but in Python, I just don't feel the need. Between the exception mechanism and unit tests, the odds of a typo going unnoticed for very long are pretty slim. I'll admit I don't use Pychecker, but if I was doing production code, I would probably use it as part of my QA process. Well, I don't have any experience with Python in the industrial setting (all my Python has been solo so far). I do have quite a bit of experience with Erlang (http://www.erlang.org) though, and while I agree that it's not quite as bad in practice as the most vocal static typing people would have it, it's not all roses either. The problem with unit tests is that they can be skipped (and frequently are) and you also have to be certain you exercise all code paths, even to detect a simple typo. It's not that these survive for 'very long' or (God forbid) to the final product, but many of them survive for long enough that they cost more than they should/would have. So *if* (substantial 'if' I realise that) my Erlang experiences generalises to this case, I'd say the benefits would outweigh the cost. Then again I'm seriously considering going back to Haskell, so I guess I'm at least a little biased. :-) :-) Stefan, -- Stefan Axelsson (email at http://www.cs.chalmers.se/~sax) -- http://mail.python.org/mailman/listinfo/python-list
Re: Gate Oxide thickness of CMOS
it's depend on the various product, 200 Angstrom or 30 Angstrom is possible. the number of mask:15 or 30 ^^ -- http://mail.python.org/mailman/listinfo/python-list
Re: Continuations Based Web Framework - Seaside.
gabriele renzi wrote: Mike Thompson ha scritto: 'Seaside' is a Smalltalk framework for what might be called Modal Web Development or Synchronous Web Programming, or even Continuation Based Web Apps. http://www.beta4.com/seaside2/ Very sexy it looks too. And it seems to be generating a lot of interest - Ruby and Java variants have already sprung up: http://rubyforge.org/projects/borges/ http://lakeshore.sourceforge.net/ actually, there are also implementations in Scheme, Common Lisp (UnCommonWeb) and Cocoon-FLOW has similar concepts. And somewhere (I think on the portland pattern repository) I recall reading that Viaweb (aka the first web app) was written in CPS. Also notice that the Wee project in ruby is more advanced that Borges. I googled for the python spin-off but didn't find one. Closest I found was Imposter (http://csoki.ki.iif.hu/~vitezg/impostor/) which looks like an earlier, partially failed attempt to do what Seaside now seems to be delivering. I think independent more than earlier, it seem many people are reinventing this from time to time. Anyway, I just wanted to point out that IIRC something on this lines appeared recently in the nevow svn tree, maybe you can take a look. I did actually do some sort-of-related work in this area, which I presented at PyCon DC 2004 - you can access the paper at http://www.python.org/pycon/dc2004/papers/18/Setting_A_Context.pdf An audience member mentioned the Smalltalk and Scheme-based work on web continuation frameworks, and I was sorry my answer at the time seemed unduly dismissive. There are some interesting similarities, and though my own implementation is decidedly clunky I like to think the paper explains some of the advantages of maintaining state and why the back button is an obnoxious anachronism :-) regards Steve -- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/ Holden Web LLC +1 703 861 4237 +1 800 494 3119 -- http://mail.python.org/mailman/listinfo/python-list
Re: What can I do with Python ??
Casey Hawthorne wrote: Aren't games using full screen mode to address only 320 by 240 resolution for faster screen painting? If one used only 320 by 240 in a window, then that would be 1/4 of the screen or less! And, on many of our screens, only a few inches across and too small to see without a magnifying glass... Providing the user with the *option* of running in a window, preferably resizable, or full-screen, would be best. -Peter -- http://mail.python.org/mailman/listinfo/python-list
Re: What can I do with Python ??
On 2005-01-02, Brian Beck [EMAIL PROTECTED] wrote: Alex Martelli wrote: You _gotta_ be kidding, right...? The Beginner's Guide link takes you right to the BeginnersGuide page which starts with the reassurance that Python is easy to learn even if you're new to programming and continues with a zillion useful links. The Python Books link takes you to a huge While I agree that there is much useful content on the official Python site, I particularly hate the BeginnersGuide and much of the resulting introduction pages. Often when I happily refer Python to someone who wants to learn a simple language, I go to the Python site and imagine where I would start if I were them. Once I get to the BeginnersGuide I don't see anything immediately useful, and when I look for it I get frustrated. I think it looks pretty good. The only problem I see is section 5 where it says: 5. Did we miss your concern? Please add a comment to this page. but the page is immutable. -- http://mail.python.org/mailman/listinfo/python-list
Re: Python! Is! Truly! Amazing!
Erik Bethke [EMAIL PROTECTED] wrote: Hello Everyone, I have to say: Python! Is! Truly! Amazing! So I started with python about a month ago and put in 24 hours across three weekends. ... Truly thank you. -Erik I enjoyed to read about your enthusiasm about Python you have recently discovered. :) After checking out your personal and business site, I'm sure you'll be even more pleased when Python will be an essential component in your business and, say, GoPets take on a bit of snake-like inner working. :-) Best, Miklós --- Jegenye 2001 Bt. Egyedi szoftverkészítés, tanácsadás | Custom software development, consulting Magyarul: http://jegenye2001.parkhosting.com In English: http://jegenye2001.parkhosting.com/en -- http://mail.python.org/mailman/listinfo/python-list
Re: Python! Is! Truly! Amazing!
Erik Bethke [EMAIL PROTECTED] writes: I have NEVER experienced this kind of programming joy. Yep, I feel the same way since learning Python. It's really a productive and pleasant language. Congratulations on all your game successes! -- http://mail.python.org/mailman/listinfo/python-list
Re: The Industry choice
On Fri, 31 Dec 2004 21:08:02 GMT, [EMAIL PROTECTED] (Cameron Laird) wrote: Let me add a cautionary note, though: Big Companies, including Oracle, Software AG, IBM, Cisco, and so on, have adopted Tcl over and over. All of them still rely on Tcl for crucial products. All of them also have employees who sincerely wonder, Tcl? Isn't that dead? I offer this as a counter-example to the belief that Adop- tion by a heavyweight necessarily results in widespread acceptance. It's a quiet adoption. It's not a firework show a la Java combined with blowing all those truckloads of money on it (I've read this good comment in one of the IT periodicals that in future Java will be cited as an example of work of genius - not a genius of computing, though, but of marketing). There is a rational element in this craziness: people around watch and see that $$$ has been sunk in this, so they know that this who sank all those $$$ has very, very much of motivation not to let this thing wither away. No guarantee, of course, but a much better chance they just won't drop it. The problem of Python is not that it's not used, but because some company like IBM didn't decide to blow $1 bln on it or smth. Using it alone and even announcing it is not enough. put your money where your mouth is, or so the thinking goes. -- It's a man's life in a Python Programming Association. -- http://mail.python.org/mailman/listinfo/python-list
Re: The Industry choice
In article [EMAIL PROTECTED], [EMAIL PROTECTED] (Aahz) wrote: In article [EMAIL PROTECTED], Steve Holden [EMAIL PROTECTED] wrote: Aahz wrote: In article [EMAIL PROTECTED], Paul Rubin http://[EMAIL PROTECTED] wrote: I was pretty skeptical of Java's checked exceptions when I first used them but have been coming around about them. There's just been too many times when I wrote something in Python that crashed because some lower-level function raised an exception that the upper level hadn't been expecting, after the program had been in use for a while. I'd sure rather find out about that at compile time. That's funny -- Bruce Eckel talks about how he used to love checked exceptions but has come to regard them as the horror that they are. I've learned to just write throws Exception at the declaration of every method. Pretty sloppy, though, no? And surely the important thing is to have a broad handler, not a broad specification of raisable exceptions? Yes, it's sloppy, but I Don't Care. I'm trying to write usable code while learning a damnably under-documented Java library -- and I'm *not* a Java programmer in the first place, so I'm also fighting with the Java environment. Eventually I'll add in some better code. The whole point of exceptions is that they get propagated automatically. If I'm not going to catch it, why do I have to even know it exists? I don't consider throws Exception to be sloppy, I consider it to be programmers voting with their feet. -- http://mail.python.org/mailman/listinfo/python-list
Re: Python! Is! Truly! Amazing!
you did this with pygame!!?? Erik Bethke [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] somehow lost my j's: www.erikbethke.com/Python/screenshot02.jpg www.erikbethke.com/Python/screenshot03.jpg www.erikbethke.com/Python/screenshot04.jpg www.erikbethke.com/Python/screenshot05.jpg -- http://mail.python.org/mailman/listinfo/python-list
Re: screen clear question
On Mon, 03 Jan 2005 02:15:23 +1000, Nick Coghlan Alan Gauld wrote: But the bottom line is that there is no builtin command because the mechanism is different on each platform. I'd have said it was because the inpreter is line-oriented rather than screen-oriented, but YMMV. Yeah, that might be a reason as well :-) But then the early PC GW-Basic or BASICA interpreters were line based too but both provided a CLS command because the *programs* that were written were usually screen based... But they ran on a single OS so a CLS was easily possible. Alan G. Author of the Learn to Program website http://www.freenetpages.co.uk/hp/alan.gauld -- http://mail.python.org/mailman/listinfo/python-list
Re: Python! Is! Truly! Amazing!
In article [EMAIL PROTECTED], Erik Bethke [EMAIL PROTECTED] wrote: I have NEVER experienced this kind of programming joy. Just wait until you discover Lisp! ;-) rg -- http://mail.python.org/mailman/listinfo/python-list
Re: The Industry choice
In article [EMAIL PROTECTED], Mark Carter [EMAIL PROTECTED] wrote: . [tale of *very* typical experience with non-software engineers] . . use something like Python. I didn't get a reaction from that at the time, but no doubt they'll be telling me that I'll have to make Excel work through the internet, or something. I do that, by the way--work with Excel through the 'Net. I use Python, of course. -- http://mail.python.org/mailman/listinfo/python-list
Re: Speed ain't bad
On Sat, 1 Jan 2005 14:20:06 +0100, Anders J. Munch [EMAIL PROTECTED] wrote: One of the posters inspired me to do profiling on my newbie script (pasted below). After measurements I have found that the speed of Python, at least in the area where my script works, is surprisingly high. Pretty good code for someone who calls himself a newbie. blush One line that puzzles me: sfile=open(sfpath,'rb') You never use sfile again. Right! It's a leftover from a previous implementation (that used bzip2). Forgot to delete it, thanks. Another way is the strategy of it's easier to ask forgiveness than to ask permission. If you replace: if(not os.path.isdir(zfdir)): os.makedirs(zfdir) with: try: os.makedirs(zfdir) except EnvironmentError: pass then not only will your script become a micron more robust, but assuming zfdir typically does not exist, you will have saved the call to os.path.isdir. Yes, this is the kind of habit that low-level languages like C missing features like exceptions ingrain in a mind of a programmer... Getting out of this straitjacket is kind of hard - it would not cross my mind to try smth like what you showed me, thanks! Exceptions in Python are a GODSEND. I strongly recommend to any former C programmer wanting to get rid of a straightjacket to read the following to get an idea how not to write C code in Python and instead exploit the better side of VHLL: http://gnosis.cx/TPiP/appendix_a.txt -- It's a man's life in a Python Programming Association. -- http://mail.python.org/mailman/listinfo/python-list
Re: The Industry choice
[EMAIL PROTECTED] (Cameron Laird) wrote: Let me add a cautionary note, though: Big Companies, including Oracle, Software AG, IBM, Cisco, and so on, have adopted Tcl over and over. All of them still rely on Tcl for crucial products. All of them also have employees who sincerely wonder, Tcl? Isn't that dead? A lot of people laugh at Tcl, but it's really a very useful tool. In my last job, we did a major component of our product (SNMP-based network management package) in Tcl, probably on the order of 10 kloc. It has its limitations, but it's very easy to learn, very easy to embed and extend, and reasonably fast. It certainly blows away shell scripting. Around here, AOL/Moviephone has been trolling for years for Tcl people; I guess that counts as a big company. -- http://mail.python.org/mailman/listinfo/python-list
Re: The Industry choice
Roy Smith wrote: I think you've hit the nail on the head. In awk (and perl, and most shells, and IIRC, FORTRAN), using an undefined variable silently gets you a default value (empty string or zero). This tends to propagate errors and make them very difficult to track down. You may recall correctly, but Fortran compilers have improved. The following Fortran 90 program integer, parameter :: n = 1 real :: x,y=2.0,z(n) print*,dog print*,x z(n+1) = 1.0 print*,z end has 3 errors, all detected at compile time by the Lahey/Fujitsu Fortran 95 compiler, with the proper options: 2004-I: xundef.f, line 2: 'y' is set but never used. 2005-W: xundef.f, line 4: 'x' is used but never set. 2153-W: xundef.f, line 5, column 1: Subscript out of range. At run time, the output is dog The variable (x) has an undefined value. Error occurs at or near line 4 of _MAIN__ Running Python 2.4 on the Python analog, n = 1 y = 2.0 z = range(n) print dog print x z[n] = 1.0 print z one error is caught: dog Traceback (most recent call last): File xundef.py, line 5, in ? print x NameError: name 'x' is not defined You will see the out-of-bounds error for z only after fixing the undefined-x error. No warning is ever given about y, which is set but never used. In practice, 'print dog' could be some operation taking hours. Can PyChecker find all the problems in a single run, without executing 'print dog'? If so, it would be great if it were integrated with the CPython interpreter. One reason interpreted languages like Python are recommended to beginners is to avoid the edit/compile/debug cycle. But I think it is faster and less frustrating to have many errors caught in one shot. -- http://mail.python.org/mailman/listinfo/python-list
Re: The Industry choice
Cameron Laird wrote: In article [EMAIL PROTECTED], Mark Carter [EMAIL PROTECTED] wrote: . [tale of *very* typical experience with non-software engineers] . . Don't start me! Dammit, too late ... I've noticed that they have an overwhelming obsession with GUIs, too. They design wizards for everything. Damn pretty they are, too. Albeit a bit flakey. They seem to conflate pretty interfaces with good interfaces and good software. I used to joke that since our software wasn't particularly magical, it didn't need wizards. But I think I just ended up sounding bitter. We once had a bit of software that we thought we'd like to turn into a generic application. The focus on improvements was, predictably enough, that we should design a GUI that could do anything a client would likely to want to do. It was my opinion, though, having seen the very special-cases nature required in the original software, that it was almost impossible to predict exactly how a customer might want the product tailored. I suggested that what they really needed was a library (Python would have been good for this, Lisp might have been even better) that could be extended as required. GUIs second, functionality first. But hey, what would I know. Fortunately, the whole thing's been put on the back burner. And trying to get through to them why source control makes sense, that when more than one person works on a project, some form of coordination is required, that copying and pasting code is evil, and that Excel probably isn't the hammer for every nail. Honestly, I thought (real) engineers were supposed to be clever. -- http://mail.python.org/mailman/listinfo/python-list
Re: Python! Is! Truly! Amazing!
Erik Bethke wrote: Anyways, I am now a super gushing fan-boy. I have worked my way up from a scripter working in crappy proprietary languages to a c++ programmer, to now biz guy. But when I walked away from programming I gave it a grim farewell, c++ work is good, but so much mind goes into it to make progree compared to other creative uses of the mind. But Python rocks, it makes programming very fun again and now I finding myself coming home earlier so I can get to work on Python and I have an entire heap of new projects I wanted to get done. Yeah, it is really a great language. For me, it matches my internal idea of 'pseudocode' to a T. Executable shorthand - does it get any better than that? --Kamilche -- http://mail.python.org/mailman/listinfo/python-list
Re: Continuations Based Web Framework - Seaside.
none wrote: Does Python really need yet another framework? Apart from the intellectual excersise, wouldn't it be nice if Python would get a framework for the rest of us (meaning: mere mortals) which would focus upon getting work done in a simple manner instead of creating yet another, new, hip, exciting, way of creating dynamic websites? If Python cannot deliver a PHP clone, at least you would expect a Rails lookalike. Spyce (http://spyce.sf.net) would be the superior Python-based PHP clone you are looking for. -- http://mail.python.org/mailman/listinfo/python-list
Re: The Industry choice
Quoth Paul Rubin http://[EMAIL PROTECTED]: | Donn Cave [EMAIL PROTECTED] writes: | Yes, it would be really weird if Python went that way, and the | sort of idle speculations we were reading recently from Guido | sure sounded like he knows better. But it's not like there aren't | some interesting issues farther on downstream there, in the compare | function. cmp(), and str() and so forth, play a really big role in | Python's dynamically typed polymorphism. It seems to me they are | kind of at odds with static type analysis | | I don't understand that. If I see str x = str(3), then I know that | x is a string. Sure, but the dynamically typed polymorphism in that function is about its parameters, not its result. If you see str(x), you can't infer the type of x. Of course you don't need to, in Python style programming this is the whole point, and even in say Haskell there will be a similar effect where most everything derives the Show typeclass. But this kind of polymorphism is pervasive enough in Python's primitive functions that it's an issue for static type analysis, it seems to me, especially of the type inference kind. cmp() is more of a real issue than str(), outside of the type inference question. Is (None 0) a valid expression, for example? Donn Cave, [EMAIL PROTECTED] -- http://mail.python.org/mailman/listinfo/python-list
arbitrary number of arguments in a function declaration
How do I set up a function so that it can take an arbitrary number of arguments? For example, I have a bunch of expenses which may grow or shrink depending on the client's circumstance and a function that sums them up... hard coding them is tedious. How might I make this dynamic so that it can handle any amount of expenses? def tot_expenses(self, e0, e1, e2, e3): pass -- http://mail.python.org/mailman/listinfo/python-list
Re: arbitrary number of arguments in a function declaration
rbt wrote: How do I set up a function so that it can take an arbitrary number of arguments? For example, I have a bunch of expenses which may grow or shrink depending on the client's circumstance and a function that sums them up... hard coding them is tedious. How might I make this dynamic so that it can handle any amount of expenses? def tot_expenses(self, e0, e1, e2, e3): pass The Python Tutorial is a wonderful thing. . . Anyway, you can either set up your function to take a proper list, and then discover that the sum function already exists to add up the contents of a list: def tot_expenses(self, expenses): self.total_expenses = sum(expenses) Or, have the function take a variable number of arguments, and do the same thing: def tot_expenses(self, *args): self.total_expenses = sum(args) Cheers, Nick. -- Nick Coghlan | [EMAIL PROTECTED] | Brisbane, Australia --- http://boredomandlaziness.skystorm.net -- http://mail.python.org/mailman/listinfo/python-list
Re: arbitrary number of arguments in a function declaration
rbt wrote: How do I set up a function so that it can take an arbitrary number of arguments? If you haven't already, you should check out the Tutorial: http://docs.python.org/tut/node6.html#SECTION00673 How might I make this dynamic so that it can handle any amount of expenses? def tot_expenses(self, e0, e1, e2, e3): pass py class C(object): ... def tot_expenses(self, *expenses): ... print expenses ... py C().tot_expenses(110, 24) (110, 24) py C().tot_expenses(110, 24, 2, 56) (110, 24, 2, 56) Steve -- http://mail.python.org/mailman/listinfo/python-list
Re: What can I do with Python ??
Jabaru wrote: BTW, I don't know of a way to write fullscreen games in C#... Directx, Opengl, Gdi+, win32api, SDL... the list goes on Yes, that's right, but most of those you can use in Python, too. I should have inserted the word specific at the right point in my sentence wink Reinhold -- http://mail.python.org/mailman/listinfo/python-list
Rebinding stdout (was: Re: Python! Is! Truly! Amazing!)
In article [EMAIL PROTECTED], [EMAIL PROTECTED] (Aahz) wrote: In article [EMAIL PROTECTED], Roy Smith [EMAIL PROTECTED] wrote: In article [EMAIL PROTECTED], Ron Garret [EMAIL PROTECTED] wrote: In article [EMAIL PROTECTED], Erik Bethke [EMAIL PROTECTED] wrote: I have NEVER experienced this kind of programming joy. Just wait until you discover Lisp! Taking this more seriously than it deserves, I've tried poking at Lisp a couple of times -- each time, I walk away shaking my head in disgust. Lisp just ain't as *READABLE* as Python. Readability is in the eye of the beholder, but this is not the place to argue this. But this topic does bring up a legitimate question: I have a bunch of code that generates HTML using PRINT statements. I need to convert all this code to return strings rather than actually printing them (so I can use the results to populate templates). In Lisp I could do this: (with-output-to-string (s) (let ( (*standard-output* s) ) (call-html-generating-code) s)) Is there an equivalent Python trick to capture a function call's output as a string? Thanks, rg -- http://mail.python.org/mailman/listinfo/python-list
Re: IDLE question
Ishwor [EMAIL PROTECTED] writes: On Sun, 26 Dec 2004 13:02:01 +0100, Rolf Wester [EMAIL PROTECTED] wrote: Hi, I would like to use IDLE as interactively as I can with Emacs. In Emacs I can send a marked region to the Python interpreter. Is there any way to do the same thing with IDLE? Although i don't use anything much beside IDLE, vim for coding, AFAIK IDLE can't do that. IDLE opens up python shell. Within that shell you type in your script , commands and create objects as such..The interpreter will execute your code then. Copy. Paste at shell prompt. enter. I'm thinking about adding copy and paste to right click menu. Maybe paste/exec would be cool in the shell window. -- KBK -- http://mail.python.org/mailman/listinfo/python-list
Re: Rebinding stdout
Ron Garret wrote: But this topic does bring up a legitimate question: I have a bunch of code that generates HTML using PRINT statements. I need to convert all this code to return strings rather than actually printing them (so I can use the results to populate templates). In Lisp I could do this: (with-output-to-string (s) (let ( (*standard-output* s) ) (call-html-generating-code) s)) Is there an equivalent Python trick to capture a function call's output as a string? Just to make sure I understand, I'm going to restate your question: Is there a way to capture stdout? The answer: Sure, replace it with something file-like: import sys, StringIO default = sys.stdout writer = StringIO.StringIO() sys.stdout = writer print 'Whatever' sys.stdout = default print writer.getvalue() Whatever // m -- http://mail.python.org/mailman/listinfo/python-list
How to make executable file ?
Just how to make *.exe file from python code ?? I typed this : a, b = 0, 1 while b 1000: print b, a, b = b, a+b and saved it as pyt.txt Now, how do I make pyt.exe file ??? I want to run it on windows where isn't installed python. -- http://mail.python.org/mailman/listinfo/python-list
Re: How to make executable file ?
BOOGIEMAN wrote: [...] and saved it as pyt.txt Maybe pyt.py is better :) Now, how do I make pyt.exe file ??? I want to run it on windows where isn't installed python. Have a look at py2exe: http://starship.python.net/crew/theller/py2exe/ don't be scared when you see the dimension of the files... cheers -- Gian Mario Tagliaretti PyGTK GUI programming http://www.parafernalia.org/pygtk/ -- http://mail.python.org/mailman/listinfo/python-list
ctypes NULL pointers; was: Python To Send Emails Via Outlook Express
Posted in a previous thread was some Python code for accessing Window's Simple MAPI api using the ctypes module. http://groups-beta.google.com/group/comp.lang.python/msg/56fa74cdba9b7be9 This Simple MAPI module was Ian's completed version of an example I had posted in an earlier message. In it I had to set some pointer fields in a C structure to NULL. I was not happy with the solution I used so I made an inquiry on the ctypes-users mailing list. Thanks to Thomas Heller I got some answers. The simplest way to create a NULL pointer instance in ctypes is to call the pointer class without an argument. from ctypes import POINTER, c_int INT_P = POINTER(c_int) # A pointer to a C integer p = INT_P() # An INT_P instance set to NULL When the pointer is a member of a structure things are a little different. For the ctypes primatives c_void_p, c_char_p and c_wchar_p one can simply use None to set the field NULL. from ctypes import Structure, c_void_p class STRUCT(Structure): _fields_ = [('voidptr', c_void_p)] s=STRUCT( None ) # Create an instance with voidptr field NULL This is documented in the ctypes tutorial. A problem with ctypes 0.9.2 prevents using None to initialize POINTER derived fields. This has been fixed so future releases will allow it. In the meantime the following will work. class IPSTRUCT(Structure): _fields_ [('intptr'), INT_P] s=IPSTRUCT( INT_P() ) A null pointer of the correct type is assigned to the field. I hope this clears up any confusion my Simple MAPI example may have caused regarding ctypes pointers. Lenard Lindstrom [EMAIL PROTECTED] -- http://mail.python.org/mailman/listinfo/python-list
Re: How to make executable file ?
On Sun, 02 Jan 2005 21:56:45 +0100, Gian Mario Tagliaretti wrote: don't be scared when you see the dimension of the files... 1.9 Mb for a console application ?! And is it possible to make Windows application ? I want to display results in windows message box. -- http://mail.python.org/mailman/listinfo/python-list
RE: Frameworks for Non-Content Oriented Web Apps
[EMAIL PROTECTED] wrote: Let me make an attemp at defining Non-Content Oriented Web Applications. A Non-Content Oriented Web Application: (1) will be accessed from web browser(obviously). Clear enough. (2) will be developed using 'W3C' and other open standards(STRICTLY, to ensure compatibility and portablity). This is getting better IMO. But we're still at the point where exclusively following open standards ensures in-compatibility and non-portability. Meh. (3) will expose some kind of functionality to the user, not just some document to read. If I were to rephrase that, I would say serves dynamic pages as opposed to static. (4) functionality can be very simple to very complex. Which usually means a multitude of tools, depending on how complex. The big issue with leaving this question so generic is that the answers are legion. So I'll just keep it short and make my own shameless plug: try Cation for the Web interface and Dejavu for the data layer, both developed by yours truly. ;) http://www.aminus.org/rbre/python or... svn://casadeamor.com/cation/trunk svn://casadeamor.com/dejavu/trunk Robert Brewer MIS Amor Ministries [EMAIL PROTECTED] -- http://mail.python.org/mailman/listinfo/python-list
Re: How to make executable file ?
Hi all, This may be OT but is there a way to do the same for *nix type of system? Like cast a python interpreter with scripts together? I'm running Mac OSX here. The only remote idea I have is to use jythonc to convert everything into .class files and package that as a .jar file but I can't do that with C bindings. Any suggestions? Thanks, Maurice -- http://mail.python.org/mailman/listinfo/python-list
Re: The Industry choice
Bulba! [EMAIL PROTECTED] writes: [...] The point is obviously cover your ass attitude of managers: Managers get paid for taking risk :) -- http://mail.python.org/mailman/listinfo/python-list
Re: Rebinding stdout
In article [EMAIL PROTECTED], Mark McEahern [EMAIL PROTECTED] wrote: Ron Garret wrote: But this topic does bring up a legitimate question: I have a bunch of code that generates HTML using PRINT statements. I need to convert all this code to return strings rather than actually printing them (so I can use the results to populate templates). In Lisp I could do this: (with-output-to-string (s) (let ( (*standard-output* s) ) (call-html-generating-code) s)) Is there an equivalent Python trick to capture a function call's output as a string? Just to make sure I understand, I'm going to restate your question: Is there a way to capture stdout? The answer: Sure, replace it with something file-like: import sys, StringIO default = sys.stdout writer = StringIO.StringIO() sys.stdout = writer print 'Whatever' sys.stdout = default print writer.getvalue() Whatever // m That's exactly what I was looking for. Thanks! rg -- http://mail.python.org/mailman/listinfo/python-list
Re: ctypes NULL pointers; was: Python To Send Emails Via Outlook Express
Thanks again Lenard!! -- http://mail.python.org/mailman/listinfo/python-list
Re: How to make executable file ?
Maurice LING wrote: Hi all, This may be OT but is there a way to do the same for *nix type of system? Like cast a python interpreter with scripts together? I'm running Mac OSX here. For OSX, google for py2app - for *nix in general, I believe freeze is your mman, although so many *nixen ship with Python these days it's not such an issue. -- Website: www DOT jarmania FULLSTOP com -- http://mail.python.org/mailman/listinfo/python-list
Re: The Industry choice
Peter Dembinski [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] Besides, shouldn't str be a reserved word or something? It is a name in the builtins module which is automatically searched after globals. Many experienced Pythoneers strongly advise against rebinding builtin names *unless* one is intentionally wrapping or overriding the builtin object. The latter are sometimes valid expert uses of masking builtins. Newbies are regularly warned on this list against making a habit of casual use of list, dict, int, str, etc. None has been reserved because there is no known good use for overriding it. True and False will be reserved someday. There have been proposals to turn on reserved status for all builtins on a per-module status. Terry J. Reedy -- http://mail.python.org/mailman/listinfo/python-list
Re: Python! Is! Truly! Amazing!
The way that Paul Graham sees Lisp: ()))yes!) ) Roy Smith [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] In article [EMAIL PROTECTED], Ron Garret [EMAIL PROTECTED] wrote: In article [EMAIL PROTECTED], Erik Bethke [EMAIL PROTECTED] wrote: I have NEVER experienced this kind of programming joy. Just wait until you discover Lisp! ;-) rg Shouldn't that be ;-)) ? -- http://mail.python.org/mailman/listinfo/python-list
Re: The Industry choice
Roy Smith [EMAIL PROTECTED] wrote: Stefan Axelsson [EMAIL PROTECTED] wrote: Yes, ignoring most of the debate about static vs. dynamic typing, I've also longed for 'use strict'. You can use __slots__ to get the effect you're after. Well, sort of; it only works for instance variables, not locals. And the gurus will argue that __slots__ wasn't intended for that, so you shouldn't do it. There's a simple, excellent recipe by Michele Simionato, on both the online and forthcoming 2nd edition printed Cookbook, showing how to do that the right way -- with __setattr__ -- rather than with __slots__ . Alex -- http://mail.python.org/mailman/listinfo/python-list
Re: The Industry choice
[EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] 2004-I: xundef.f, line 2: 'y' is set but never used. 2005-W: xundef.f, line 4: 'x' is used but never set. 2153-W: xundef.f, line 5, column 1: Subscript out of range. None of these are syntax errors. The first two of these would be caught by lint or pychecker (I am presuming). One reason interpreted languages like Python are recommended to beginners is to avoid the edit/compile/debug cycle. But I think it is faster and less frustrating to have many errors caught in one shot. True syntax errors often result in such a cascade of bogus errors that it may often be best to fix the first reported error and then recompile. Of course, compilers vary in their recovery efforts. Terry J. Reedy -- http://mail.python.org/mailman/listinfo/python-list
Re: The Industry choice
Bulba! [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] On Sat, 01 Jan 2005 15:08:01 -0500, Steve Holden whereas when a company goes bust there's no guarantee the software IP will ever be extricated from the resulting mess. There is a good _chance_ here: money. Somebody has poured a lot of money into this thing. It's not going to get dropped bc of that. From what I have read, the amount of proprietary code which *did* get effectively shredded after the dot-com bust is enough to make one cry. There were a few companies that would buy code at bankruptcy sales for maybe 1% of its development cost, but even then, with the original programmers long gone, it could be hard to make anything from it. Terry J. Reedy -- http://mail.python.org/mailman/listinfo/python-list
Re: The Industry choice
Steve Holden [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] Well clearly there's a spectrum. However, I have previously written that the number of open source projects that appear to get stuck somewhere between release 0.1 and release 0.9 is amazingly large, and does imply some dissipation of effort. And how do the failure and effort dissipation rates of open source code compare to those of closed source code? Of course, we have only anecdotal evidence that the latter is also 'amazingly large'. And, to be fair, the latter should include the one-programmer proprietary projects that correspond to the one-programmer open projects. Also, what is 'amazing' to one depends on one's expectations ;-). It is known, for instance, that some large fraction of visible retail business fail within a year. And that natural selection is based on that fact that failure is normal. Terry J. Reedy -- http://mail.python.org/mailman/listinfo/python-list
? about file() and open()
Was wondering if there was any difference between these two functions. I have read some text that said file() wasn't introduced until 2.2 and that it was synonymous with open(). Does this mean that I should be using file() where I used open() before? Sean Morris -- http://mail.python.org/mailman/listinfo/python-list
Re: The Industry choice
Terry Reedy [EMAIL PROTECTED] wrote: None has been reserved because there is no known good use for overriding it. Should I infer from the above that there's a known bad use? True and False will be reserved someday. I remember a lisp I used many years ago. If you tried to rebind nil, you got an error message -- in latin! -- http://mail.python.org/mailman/listinfo/python-list
Re: HTTP GET request with basic authorization?
Christopher J. wrote: I tried this, but it didn't work: conn.request(GET, /somepage.html, None, {AUTHORIZATION: Basic username:password}) Hmm, try this: import re, base64 userpass = base64.encodestring('user:pass').replace('\n', '') authd = {'Authorization':'Basic %s' % userpass} conn.request('GET', '/uri', None, authd) Or this: import re, base64, urllib2 userpass = ('user', 'pass') url = 'http://somewhere' request = urllib2.Request(url) authstring = base64.encodestring('%s:%s' % userpass) authstring = authstring.replace('\n', '') request.add_header(Authorization, Basic %s % authstring) content = urllib2.urlopen(request).read() -- http://mail.python.org/mailman/listinfo/python-list
Re: The Industry choice
Bulba! [EMAIL PROTECTED] wrote: True. I have a bit of interest in economics, so I've seen e.g. this example - why is it that foreign branches of companies tend to cluster themselves in one city or country (e.g. It's not just _foreign_ companies -- regional clustering of all kinds of business activities is a much more widespread phenomenon. Although I'm not sure he was the first to research the subject, Tjalling Koopmans, as part of his lifework on normative economics for which he won the Nobel Prize 30 years ago, published a crucial essay on the subject about 50 years ago (sorry, can't recall the exact date!) focusing on _indivisibilities_, leading for example to transportation costs, and to increasing returns with increasing scale. Today, Paul Krugman is probably the best-known name in this specific field (he's also a well-known popularizer and polemist, but his specifically-scientific work in economics has mostly remained in this field). China right now)? According to standard economics it should not happen - what's the point of getting into this overpriced city if elsewhere in this country you can find just as good conditions for business. Because you can't. Standard economics, in the sense of what you might have studied in college 25 years ago if that was your major, is quite able to account for that if you treat spatial variables as exogenous to the model; Krugman's breakthroughs (and most following work, from what I can tell -- but economics is just a hobby for me, so I hardly have time to keep up with the literature, sigh!) have to do with making them endogenous. Exogenous is fine if you're looking at the decision a single firm, the N+1 - th to set up shop in (say) a city, faces, given decisions already taken by other N firms in the same sector. The firm's production processes have inputs and outputs, coming from other firms and (generally, with the exception of the last layer of retailers etc) going to other firms. Say that the main potential buyers for your firm's products are firms X, Y and Z, whose locations all happen to be (that's the exogenous part) in the Q quarter of town. So, all your competitors have their locations in or near Q, too. Where are you going to set up your location? Rents are higher in Q than somewhere out in the boondocks -- but being in Q has obvious advantages: your salespeople will be very well-placed to shuttle between X, Y, Z and your offices, often with your designers along so they can impress the buyers or get their specs for competitive bidding, etc, etc. At some points, the competition for rents in quarter Q will start driving some experimenters elsewhere, but they may not necessarily thrive in those other locations. If, whatever industry you're in, you can strongly benefit from working closely with customers, then quarter Q will be where many firms making the same products end up (supply-side clustering). Now consider a new company Z set up to compete with X, Y and Z. Where will THEY set up shop? Quarter Q has the strong advantage of offering many experienced suppliers nearby -- and in many industries there are benefits in working closely with suppliers, too (even just to easily have them compete hard for your business...). So, there are easily appreciated exogenous models to explain demand-side clustering, too. That's how you end up with a Holliwood, a Silicon Valley, a Milan (for high-quality fashion and industrial design), even, say, on a lesser scale, a Valenza Po or an Arezzo for jewelry. Ancient European cities offer a zillion examples, with streets and quarters named after the trades or professions that were most clustered there -- of course, there are many other auxiliary factors related to the fact that people often _like_ to associate with others of the same trade (according to Adam Smith, generally to plot some damage to the general public;-), but supply-side and demand-side, at least for a simpler exogenous model, are plenty. Say that it's the 18th century (after the corporations' power to stop foreign competition from nearby towns had basically waned), you're a hat-maker from Firenze, and for whatever reason you need to move yourself and your business to Bologna. If all the best hat-makers' workshops and shops are clustered around Piazza dell'Orologio, where are YOU going to set up shop? Rents in that piazza are high, BUT - that's where people who want to buy new hats will come strolling to look at the displays, compare prices, and generally shop. That's close to where felt-makers are, since they sell to other hat-makers. Should your business soon flourish, so you'll need to hire a worker, that's where you can soon meet all the local workers, relaxing with a glass of wine at the local osteria after work, and start getting acquainted with everybody, etc, etc... Risk avoidance is quite a secondary issue here (except if you introduce in your model an aspect of imperfect-information, in which case, following on the
Re: ? about file() and open()
Sean [EMAIL PROTECTED] wrote: Was wondering if there was any difference between these two functions. Not today: open is file True they're two names for the same object. Which isn't a function, btw: type(open) type 'type' the object, as you see, is a type (besides calling it to instantiate it, you might inherit from it, etc). I have read some text that said file() wasn't introduced until 2.2 and that it was synonymous with open(). Does this mean that I should be using file() where I used open() before? According to Guido, you should keep _calling_ 'open' -- that's the name to which a factory function to be called may be bound in the future if and when a good way is found to return filelike objects of some other type depending on circumstances (e.g., one day it might become possible to open some kinds of URL that way). You should use 'file' when you're subclassing, or in other situations where you want to be sure you're naming a type, not a function (few good cases come to mind, but maybe isinstance is a possible case, although likely not _good_...;-). Alex -- http://mail.python.org/mailman/listinfo/python-list
Re: The Industry choice
Bulba! [EMAIL PROTECTED] writes: This free software (not so much OSS) notion but you can hire programmers to fix it doesn't really happen in practice, at least not frequently: because this company/guy remains ALONE with this technology, the costs are unacceptable. Yes, but fixing python software - even sloppily written python software - is pretty easy. I regularly see contracts to add a feature to or fix a bug in some bit of OSS Python. mike -- Mike Meyer [EMAIL PROTECTED] http://www.mired.org/home/mwm/ Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information. -- http://mail.python.org/mailman/listinfo/python-list
Re: How to make executable file ?
Maurice LING [EMAIL PROTECTED] wrote: Hi all, This may be OT but is there a way to do the same for *nix type of system? Like cast a python interpreter with scripts together? Yes, but fortunately on the Mac you don't need that. I'm running Mac OSX here. Assuming we're talking Mac OS X 10.3 or later, Python itself comes with the operating system (it's used somewhere in stuff provided with the system, such as fax handling). As I saw others suggest, google for py2app, it's probably the best way to handle this for the Mac today. Alex -- http://mail.python.org/mailman/listinfo/python-list
Re: PEP 288 ponderings
On Sun, 2 Jan 2005, Ian Bicking wrote: Steven Bethard wrote: PEP 288 was mentioned in one of the lambda threads and so I ended up reading it for the first time recently. I definitely don't like the idea of a magical __self__ variable that isn't declared anywhere. It also seemed to me like generator attributes don't really solve the problem very cleanly. An example from the PEP[1]: def mygen(): while True: print __self__.data yield None g = mygen() g.data = 1 g.next()# prints 1 g.data = 2 g.next()# prints 2 I don't get why this isn't good enough: def mygen(data): while True: print data[0] yield None It's OK, but rather limited. IMHO a nicer approach is to use decorators to decorate a generator with extra attributes. Specifically to embed the generator inside an iterator inside an anonymous class. (We're exploring this as a alternative approach to the system we currently use at work) (Hmm... Now I describe it that sounds rather hideous, but the result is nice) First of all the decorator: import copy def wrapgenerator(bases=object, **attrs): def decorate(func): class statefulgenerator(bases): __doc__ = func.__doc__ def __init__(self,*args): super(statefulgenerator, self).__init__(*args) self.func=func(self,*args) for k in attrs.keys(): self.__dict__[k] = copy.deepcopy(attrs[k]) self.next=self.__iter__().next def __iter__(self): return iter(self.func) return statefulgenerator return decorate This would be used thus: @wrapgenerator(component) def forwarder(self): # The generator, note the explicit self for local state # for this generator Simple data forwarding generator while 1: if self.dataReady(inbox): self.send(outbox,self.recv(inbox)) elif self.dataReady(control): if self.recv(control) == shutdown: break yield 1 self.send(signal,shutdown) yield 0 This clearly assumes a set of attributes, local methods etc. In this case our local methods, attribute etc are from this class: class component(object): def __init__(self, *args): # Default queues self.queues = {inbox:[],control:[],outbox:[],signal:[]} def send(self, box, object): self.queues[box].append(object) def dataReady(self,box): return len(self.queues[box])0 def recv(self, box): # NB. Exceptions aren't caught X=self.queues[box][0] del self.queues[box][0] return X This then gets used in the usual way: f = forwarder() f __main__.statefulgenerator object at 0x402d f.send(inbox, some data) f.send(inbox, some more data) f.next() 1 f.next() 1 f.recv(outbox) 'some data' f.recv(outbox) 'some more data' If you just want (arbitrary) generator attributes, then that's a lot easier (since we don't need to support an arbitrary base class): import copy def add_attrs_to_generator(**attrs): def decorate(func): class statefulgenerator: __doc__ = func.__doc__ def __init__(self,*args): self.func=func(self,*args) for k in attrs.keys(): self.__dict__[k] = copy.deepcopy(attrs[k]) self.next=self.__iter__().next def __iter__(self): return iter(self.func) return statefulgenerator return decorate @add_attrs_to_generator() def simpleGen(self): while True: print dir(self) yield None We can also add default attributes: @add_attrs_to_generator(test=1,simple=2) def simpleGen(self): while True: print dir(self) yield None g=simpleGen() g.next() ['__doc__', '__init__', '__iter__', '__module__', 'func', 'next', 'simple', 'test'] We've been using this general approach of giving generators local state for communications for a while now, and it's been rather interesting/fun to use. However we've been using explicit declaration of a class, and then a standard fixed name for the generator (main) instead. (we've been thinking about using decorators as syntactic sugar) Being able to pass exception in would be very nice, however we've used a control attribute, queue in practice, to allow for need to be able to shutdown an arbitrary generator. However, I don't think the __self__ part of the PEP is explicitly required - since you can build that onto generators using python quite happily now (@add_attrs_to_generator). The code for the stuff we're playing with (in case anyone's interested :) is at http://kamaelia.sourceforge.net/. The specific subsystem that uses this approach has been released as a separate download (Axon[1]) on the sourceforge project page[2], and the main system (obviously) uses this heavily and can be browsed via viewcvs. [3] [1] http://kamaelia.sourceforge.net/Docs/Axon.html [2] http://sourceforge.net/projects/kamaelia [3]
Re: Continuations Based Web Framework - Seaside.
Kendall Clark [EMAIL PROTECTED] writes: That was me, actually. I remain surprised that there isn't a move afoot either to implement something like Seaside or Borges in Python or to adapt one of the existing web frameworks to be modal/continuation style. Since Python doesn't have continuations, that would be a bit tricky. -- http://mail.python.org/mailman/listinfo/python-list
[ANN] ratfun-1.0 Polynomials And Rational Functions
The ratfun module provides classes for defining polynomial and rational function (ratio of two polynomials) objects. These objects can be used in arithmetic expressions and evaluated at a particular point. Home page: http://calcrpnpy.sourceforge.net/ratfun.html Note: If you are using rpncalc-1.2 or later, this module is already included. This release is for folks who don't want rpncalc. -- http://mail.python.org/mailman/listinfo/python-list
Re: The Industry choice
Roy Smith [EMAIL PROTECTED] writes: Around here, AOL/Moviephone has been trolling for years for Tcl people; I guess that counts as a big company. The AOL web server also uses tcl as a built-in dynamic content generation language (i.e. sort of like mod_python), or at least it used to. -- http://mail.python.org/mailman/listinfo/python-list
Re: Continuations Based Web Framework - Seaside.
Paul Rubin http://[EMAIL PROTECTED] wrote: Since Python doesn't have continuations, that would be a bit tricky. Since I've already said Nevow with wolf works the same as borges. The only thing that wouldn't work without continuations is the back button. With greenlet module (from Armin Rigo) also the back button will work. I've also already posted an url to the svn sandbox with a working example inside. -- Valentino Volonghi aka Dialtone Now Running MacOSX 10.3.7 Blog: http://vvolonghi.blogspot.com http://weever.berlios.de -- http://mail.python.org/mailman/listinfo/python-list
Re: Continuations Based Web Framework - Seaside.
[EMAIL PROTECTED] (Valentino Volonghi aka Dialtone) writes: Since I've already said Nevow with wolf works the same as borges. The only thing that wouldn't work without continuations is the back button. With greenlet module (from Armin Rigo) also the back button will work. Thanks, I'm not familiar with wolf, borges, or greenlet. I've also been wondering what Rails is. Maybe some configuration of PyPy can supply first-class continuations like the old Stackless did. That would be really cool for all sorts of reasons. Then again, maybe it's reasonable to just fake it all, using ordinary threads and queues. I might try coding something that way. -- http://mail.python.org/mailman/listinfo/python-list
using HTTP Digest auth with arbitrary HTTP methods?
Hello there. I've run into some missing functionality with HTTP Digest authentication in the 2.3 library and I was wondering if I'm just missing something. Missing functionality the first: urllib2 1a. You can add handlers to your opener indicating that you want to use HTTP Digest auth. This is nice way to handle it, but I don't see any way to use a custom verb in your URLOpener -- it always uses either GET or POST depending on whether you provided data. Is there any way to specify an arbitrary method? This would allow urllib2 to be used to write WebDAV clients. 1b. HTTPDigestAuthHandler is initialized with an HTTPPasswordMgr object, which unfortunately deals in cleartext passwords. Digest authentication can be computed using only a hash of username, password, and realm; it would be nice if there was an alternate version of HTTPPasswordMgr that let you deal in hashes instead of or in addition to plaintext passwords. Missing functionality the second: httplib. 2a. httplib.HTTPConnection lets you execute arbitrary HTTP methods with arbitrary headers and data; this is the missing functionality in 1a above. However, you have to deal with following redirects and authentication and so forth yourself. Is there any way to use the flexibility of HTTPConnection.request(method, url[, body[, headers]]) with the convenience of the chains of urllib2 handlers? The upshot is what I'm trying to do is write a WebDAV-using DAV client library, and I almost have everything I need to do it; the problem is I can't find an easy way to do digest authentication for arbitrary HTTP methods. WebDAV (RFC 2518), for those not familiar, is an extension to HTTP that defines some new methods and settles the semantics of some existing but rarely implemented HTTP methods (PUT and DELETE, for example) to define something similar to a file system. It's intended for things like letting a group of people author a web site. -- http://mail.python.org/mailman/listinfo/python-list
Calling Function Without Parentheses!
What a debug nightmare! I just spent HOURS running my script through the debugger, sprinkling in log statements, and the like, tracking down my problem. I called a function without the ending parentheses. I sure do WISH Python would trap it when I try to do the following: MyFunc instead of: MyFunc() h. -- http://mail.python.org/mailman/listinfo/python-list
Re: Calling Function Without Parentheses!
Kamilche I called a function without the ending parentheses. I sure do Kamilche WISH Python would trap it when I try to do the following: Kamilche MyFunc Kamilche instead of: Kamilche MyFunc() Google for pychecker. Skip -- http://mail.python.org/mailman/listinfo/python-list
Re: Calling Function Without Parentheses!
Kamilche wrote: What a debug nightmare! I just spent HOURS running my script through the debugger, sprinkling in log statements, and the like, tracking down my problem. I called a function without the ending parentheses. I sure do WISH Python would trap it when I try to do the following: MyFunc instead of: MyFunc() You're a former Pascal programmer, aren't you? ;-) In Python, it's not an error, because you can do things like: def simpson(f, a, b): ...Simpson's Rule approximation of the integral of f on [a, b]. ...return (b - a) * (f(a) + 4 * f((a + b) / 2.0) + f(b)) / 6.0 ... simpson(math.sin, 0.0, math.pi) # Note that math.sin is a function 2.0943951023931953 -- http://mail.python.org/mailman/listinfo/python-list
Re: Calling Function Without Parentheses!
Kamilche wrote: What a debug nightmare! I just spent HOURS running my script through the debugger, sprinkling in log statements, and the like, tracking down my problem. I called a function without the ending parentheses. I sure do WISH Python would trap it when I try to do the following: MyFunc instead of: MyFunc() h. Aaaah indeed. You must be using an extremely old version of pychecker. The version I have in my Python22 directory gave the same results as the current one; see below. C:\junktype noparens.py [bangs inserted to defeat Google's lstrip() !def bar(): ! foo !def foo(): ! alist = [] ! alist.sort C:\junkpychecker noparens.py C:\junkc:\python24\python.exe c:\python22\Lib\site-packages\pychecker\checker.py noparens.py Processing noparens... Warnings... noparens.py:2: Statement appears to have no effect noparens.py:5: Statement appears to have no effect -- http://mail.python.org/mailman/listinfo/python-list
Re: Calling Function Without Parentheses!
Dan Bishop wrote: Kamilche wrote: What a debug nightmare! I just spent HOURS running my script through the debugger, sprinkling in log statements, and the like, tracking down my problem. I called a function without the ending parentheses. I sure do WISH Python would trap it when I try to do the following: MyFunc instead of: MyFunc() You're a former Pascal programmer, aren't you? ;-) In Python, it's not an error, because you can do things like: def simpson(f, a, b): ...Simpson's Rule approximation of the integral of f on [a, b]. ...return (b - a) * (f(a) + 4 * f((a + b) / 2.0) + f(b)) / 6.0 ... simpson(math.sin, 0.0, math.pi) # Note that math.sin is a function 2.0943951023931953 In Python, it's not an error, because functions are first class citizens. The OP's problem is evaluating an expression and then doing SFA with the result. Pychecker appears to be able to make the distinction; see below: C:\junktype simpson.py import math def simpson(f, a, b): return (b - a) * (f(a) + 4 * f((a + b) / 2.0) + f(b)) / 6.0 print simpson(math.sin, 0.0, math.pi) C:\junkpython simpson.py 2.09439510239 C:\junkpychecker simpson.py C:\junkc:\python24\python.exe c:\python22\Lib\site-packages\pychecker\checker.py simpson.py Processing simpson... 2.09439510239 Warnings... None -- http://mail.python.org/mailman/listinfo/python-list
Re: Continuations Based Web Framework - Seaside.
Steve Holden wrote: I did actually do some sort-of-related work in this area, which I presented at PyCon DC 2004 - you can access the paper at http://www.python.org/pycon/dc2004/papers/18/Setting_A_Context.pdf An audience member mentioned the Smalltalk and Scheme-based work on web continuation frameworks, and I was sorry my answer at the time seemed unduly dismissive. There are some interesting similarities, and though my own implementation is decidedly clunky I like to think the paper explains some of the advantages of maintaining state and why the back button is an obnoxious anachronism :-) I think the technique you talked about is an easier way to achieve a similar goal as the continuation-based frameworks. While using continuations for web applications is an interesting idea, I don't think it's been shown to be successful. It's certainly not something I'd want to implement on Python (even given the actual features to make it possible), and from what I've read of the Ruby projects that use it (Borges and Wee?), they aren't ready to implement production applications either. The technique you present could be implemented on any framework, right now, with the expectation that it would work in a production situation. -- Ian Bicking / [EMAIL PROTECTED] / http://blog.ianbicking.org -- http://mail.python.org/mailman/listinfo/python-list
Re: Calling Function Without Parentheses!
Kamilche wrote: What a debug nightmare! I just spent HOURS running my script through the debugger, sprinkling in log statements, and the like, tracking down my problem. I called a function without the ending parentheses. I sure do WISH Python would trap it when I try to do the following: MyFunc Actually you want use a method as an ordinary variable without calling it in many cases. It is often used in a dynamic language. A simple example is: result = [] a = result.append if something: a('some result') elif something_else: a('another result') else: a('default result') -- hilsen/regards Max M, Denmark http://www.mxm.dk/ IT's Mad Science -- http://mail.python.org/mailman/listinfo/python-list
Re: File locking is impossible in Windows? SOLUTION
Sure it will do if one of the processes needs read access only. Scenario when you need shared rw acces with locking: In the file you have records say 30 bytes long, 2 processes are reading/writing these records by: lock-read-unlock or lock-write-unlock . Both processes have to open the file with rw access. But the third process can overwrite the locked file! Actually the common method to prevent file from been overwritten is: lock the region outside the file. Such feacure is added to lock/unlock namely for this purpose. You found the bug in WIN32. PS. When you copy the file (say c:\b) over file with locked region say (c:\a), the length of the file c:\b becomes the length of c:\a, and the content of c:\a is all zeroes. By the way, I would understand the logic if copy copyes bytes outside locked regions but preserves all locks. -- http://mail.python.org/mailman/listinfo/python-list
Re: using HTTP Digest auth with arbitrary HTTP methods?
In comp.lang.python, [I] wrote: Hello there. I've run into some missing functionality with HTTP Digest authentication in the 2.3 library and I was wondering if I'm just missing something. Missing functionality the first: urllib2 1a. You can add handlers to your opener indicating that you want to use HTTP Digest auth. This is nice way to handle it, but I don't see any way to use a custom verb in your URLOpener -- it always uses either GET or POST depending on whether you provided data. Is there any way to specify an arbitrary method? This would allow urllib2 to be used to write WebDAV clients. 1b. HTTPDigestAuthHandler is initialized with an HTTPPasswordMgr object, which unfortunately deals in cleartext passwords. Digest authentication can be computed using only a hash of username, password, and realm; it would be nice if there was an alternate version of HTTPPasswordMgr that let you deal in hashes instead of or in addition to plaintext passwords. Well, I figured out a workaround, but it requires changing urllib2.py since the bugs are in base classes. I instead copied it (to urllib3.py) and made the following changes: a. in AbstractDigestAuthHandler.get_authorization, call req.get_method() instead of req.has_data() and 'POST' or 'GET' (python has a ternary operator, who knew) b. in AbstractHTTPHandler.do_open, call req.get_method instead of the hard-coded if-logic which is the same as that in req.get_method Both of these seem like bugs in urllib2. Then I overrode urllib2.Request and made it possibly to set the method, and then passed an instance of my custom Request class (the one that shouldn't have to exist, since Request should allow method to be set explicitly) to OpenerDirector.open(). I'd like to see these changes make it into the standard library -- after being vetted by whoever's in charge of urllib2. Anybody know who I should talk to? -- http://mail.python.org/mailman/listinfo/python-list
Re: Problem remotely shutting down a windows computer with python
While I have no solution for the recipe you cited, it seems like alot of trouble could be avoided by simply importing the os module and running the following command using os.system: shutdown -s Daniel Bickett On 2 Jan 2005 20:13:35 -0800, EW [EMAIL PROTECTED] wrote: I have a problem when using the python script found here: http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/360649 It is a script to remotely shutdown a windows computer. When I use it, the computer shuts down, but doesn't power off like with a regular shutdown. It stays on the Safe to power off screen and I have to push the power button to actually power off. Anyone know why this happens with this script? Thanks for any help. Eric -- http://mail.python.org/mailman/listinfo/python-list -- http://mail.python.org/mailman/listinfo/python-list
Re: Problem remotely shutting down a windows computer with python
I believe that would shutdown the computer you were physically at, but it wouldn't shutdown the computer down the hall over the LAN like this script was meant to do. -- http://mail.python.org/mailman/listinfo/python-list
Re: Problem remotely shutting down a windows computer with python
Hi, According to the online docs for InitiateSystemShutdown() at http://aspn.activestate.com/ASPN/docs/ActivePython/2.2/PyWin32/win32api__InitiateSystemShutdown_meth.html bRebootAfterShutdown : int Specifies whether the computer is to restart immediately after shutting down. If this parameter is TRUE, the computer is to restart. If this parameter is FALSE, the system flushes all caches to disk, clears the screen, and displays a message indicating that it is safe to power down. Same at Microsoft for the Win32 API Call - http://msdn.microsoft.com/library/default.asp?url=/library/en-us/sysinfo/base/initiatesystemshutdown.asp Looks like this is the documented outcome. You could alternatively try setting a little XML-RPC app to invoke 'shutdown -s' on the remote PC from your PC (e.g. using Twisted Python). Thanks, --Kartic -- http://mail.python.org/mailman/listinfo/python-list
XML: Better way to accomplish this?
Hi, I'm working on creating an xml structure like the following, as effiecienty and elegantly as possible using minidom preferably: #region #population #total #0 #/total #R #0 #/R #C #0 #/C #I #0 #/I #/population #cities #city1 #cityname/ #mayor/ #morelater/ #citypopulation #R #0 #/R #C #0 #/C #I #0 #/I #/citypopulation #/city1 #city2 #cityname/ #mayor/ #morelater/ #citypopulation #R #0 #/R #C #0 #/C #I #0 #/I #/citypopulation #/city2 #city3 and so on #cityname/ #mayor/ #morelater/ #citypopulation #R #0 #/R #C #0 #/C #I #0 #/I #/citypopulation #/city3 and so on #/cities #/region (left out) The following code accomplishes that, but being a newb to xml..I'm not sure if this can be done a better (I'd like to stick with dom due to the nature of this app): (left textnode parts like mayor, cityname out to keep code concise for now) #from xml.dom.minidom import parseString ##create a new document #scoreXML= parseString(u'region/'.encode('UTF-8')) #art = scoreXML.documentElement # ##create a total population, cities and some city elements #population = scoreXML.createElementNS(None,u'population') #cities = scoreXML.createElementNS(None,u'cities') #city1 = scoreXML.createElementNS(None,u'city1') #city2 = scoreXML.createElementNS(None,u'city2') #city3 = scoreXML.createElementNS(None,u'city3 and so on') # ##add it under the region element #art.appendChild(population) #art.appendChild(cities) # ## create a total element with a population number inside ## and do this for all RCI numbers #population.appendChild(scoreXML.createElementNS(None,u'total')) #total = scoreXML.createTextNode(u'0') #population.firstChild.appendChild(total) ##will get RCI with seperate function #RCI = [scoreXML.createTextNode(u'0'), # scoreXML.createTextNode(u'0'), # scoreXML.createTextNode(u'0')] #[r,c,i] #for populationElement in [u'R',u'C',u'I']: # population.appendChild(scoreXML.createElementNS(None,populationElement)) #population.lastChild.appendChild(RCI[0]) #RCI.pop(0) # ##add the elements underneath city #allcities = [city1,city2,city3] #for city in allcities: # cities.appendChild(city) # # for cityattribute in [u'cityname',u'mayor',u'morelater']: # city.appendChild(scoreXML.createElementNS(None,cityattribute)) # # citypopulation = scoreXML.createElementNS(None,u'citypopulation') # city.appendChild(citypopulation) # #will get RCI with seperate function # RCI = [scoreXML.createTextNode(u'0'), #scoreXML.createTextNode(u'0'), #scoreXML.createTextNode(u'0')] #[r,c,i] # # for populationElement in [u'R',u'C',u'I']: #citypopulation.appendChild(scoreXML.createElementNS(None,populationElement)) # citypopulation.lastChild.appendChild(RCI[0]) # RCI.pop(0) ##write the result #print scoreXML.toprettyxml() Any ideas? -thanks in advance -- http://mail.python.org/mailman/listinfo/python-list
[Twisted-Python] Problem with Echoserver (TCP), Help!
Hi, I am new to Twisted. I use a Twisted 1.3.0 on MS Windows XP Home Edition, my python version is 2.3 I try the TCP echoserv.py and echoclient.py example. But the client always fail with following message: Unhandled error in Deferred: Traceback (most recent call last): File D:\PYTHON23\Lib\site-packages\twisted\internet\default.py, line 134, in mainLoop self.runUntilCurrent() File D:\PYTHON23\Lib\site-packages\twisted\internet\base.py, line 423, in ru nUntilCurrent call.func(*call.args, **call.kw) File D:\PYTHON23\Lib\site-packages\twisted\internet\tcp.py, line 384, in res olveAddress d.addCallbacks(self._setRealAddress, self.failIfNotConnected) File D:\PYTHON23\Lib\site-packages\twisted\internet\defer.py, line 205, in a ddCallbacks self._runCallbacks() --- exception caught here --- File D:\PYTHON23\Lib\site-packages\twisted\internet\defer.py, line 338, in _ runCallbacks self.result = callback(self.result, *args, **kw) File D:\PYTHON23\Lib\site-packages\twisted\internet\tcp.py, line 388, in _se tRealAddress self.doConnect() File D:\PYTHON23\Lib\site-packages\twisted\internet\tcp.py, line 403, in doConnect r, w, e = select.select([], [], [self.fileno()], 0.0) select.error: (10022, '') What is the matter? Thanks. -SeSe -- http://mail.python.org/mailman/listinfo/python-list
Re: thread/queue bug
[EMAIL PROTECTED] Note that python-bugs-list is a moderated list for use only by automated reports generated from SourceForge. I'm redirecting the reply to [EMAIL PROTECTED] I have a very strange bug. A thread in a .pyc stops dead. This program has many threads and queues and has worked great for months. One thread listens for UDP messages from other programs, and puts the messages in listenq. Procmsgs gets from listenq and for a certain kind of message creates another mq = Queue(0). I don't wish to distribute the source to pnetx.py so I have a short program pnet.py import it, that is pnetx.pyc. Then the procmsgs thread dies at the Queue statement. But if I run pnetx.py as the main program, all works fine. So if pnetx.py or .pyc is imported this thread dies. ??? I've tried this with 2.3.3 and 2.3.4. Anyone? Sounds like your module spawns a thread as a side effect of being imported. Don't do that -- you'll get in deadlock trouble with the import lock if you do (use Google to learn more about that). -- http://mail.python.org/mailman/listinfo/python-list
Re: [Twisted-Python] Problem with Echoserver (TCP), Help!
Hi, My experience with Twisted is also limited but let me try to help you. I tried the same combo as you and it worked well with the following responses: receive: Hello, world! receive: What a fine day it is. receive: Bye-bye! connection lost: Connection was closed cleanly. I am sure you started the server before the client. Do you have some firewall software installed that prevents the client from connecting to the server? Thanks --Kartic -- http://mail.python.org/mailman/listinfo/python-list
Re: ctypes NULL pointers; was: Python To Send Emails Via Outlook Express
Ok ; thank you. -- http://mail.python.org/mailman/listinfo/python-list