Re: [Tutor] wxPython GUI builders?
Alan Gauld wrote: > What's available and in what state of readiness? > > I tried Boa Constructor but after half a dozen code tweaks > I was still running into compatibility errors with the latest > wxPython and gave up. > > I know that Glade is out there, but what state is it in? > And PythonCard offers another approach but I haven't > looked at it for about 3 years. > > Are there any others? And which ones do people > actually use? Commercial or Freeware. > > Alan G. > > ___ > Tutor maillist - Tutor@python.org > http://mail.python.org/mailman/listinfo/tutor > Dabo is another but it's under continuing development. Colin W. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] avoid eval how???
Pujo Aji wrote: > Hello > > I have a dynamic functions which created by some algorithms during > runtime. > These functions are in string type. > When I want to use it, I can use eval command. > But can someone give me more suggestion about how to handle this > problem, I want to avoid eval. Why avoid? It seems the simplest way. Colin W. > > Example : > L = ['x+sin(x)', '1/(2.2 + pow(2,3)/sin(30)'] > > > Sincerely Yours, > pujo > > > >___ >Tutor maillist - Tutor@python.org >http://mail.python.org/mailman/listinfo/tutor > > ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] avoid eval how???
Danny Yoo wrote: >>>I have a dynamic functions which created by some algorithms during >>>runtime. These functions are in string type. When I want to use it, I >>>can use eval command. But can someone give me more suggestion about >>>how to handle this problem, I want to avoid eval. >>> >>> >>Why avoid? It seems the simplest way. >> >> > >Hi Colin, > >The problem is that an eval()-like is too powerful for most programmers to >use safely. It's danger is not a Python-specific issue, but common to any >language that provides an eval() on arbitrary strings. > >http://en.wikipedia.org/wiki/Eval#Security_risks > >This aversion to eval() isn't based on some theoretical worry; the PHP >folks got hit by exploits that targeted eval-using code just a few months >ago. Read the "Security" section of: > >http://phpxmlrpc.sourceforge.net/#security > >to see what kind of issues eval() brings when we use it. They hit the >same conceptual problem three times before they finally got humble enough >to realize that eval() was the wrong tool. > >We have to learn from their mistakes, or else we'll make them ourselves. >*grin* > > > Danny, You make some good points here but I suggest that, in the real world, the risks are small. You might consider using exec instead. It would appear that one can specify a restricted environment in which the statement is executed. Colin W. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] printing statement
bob wrote: >At 11:31 AM 11/3/2005, Johan Geldenhuys wrote: > > >>Hi all, >>Just a quick question; >> >>How do I code this output: >>""" >>files dirs >>== >>""" >> >>I want to print something a few space away from the left side or in the >>middle of the line. >> >> > >In the Python Library Reference look up 2.3.6.2 String Formatting >Operations - % interpolation > >In general you create a "template" of the desired output with %s (or other >conversion type) wherever you want a value substituted. >"%-15s%-15s" % ('files', 'dirs') will give >"files dirs " >"%-15s%-15s" % (filename, directory) will give >"funny.doc c:\root" >assuming the variabies filename, directory have the values shown. >the - means left align, 15 is field width. > >___ >Tutor maillist - Tutor@python.org >http://mail.python.org/mailman/listinfo/tutor > > > Have you considered the % formatting operator? See 2.3.6.2 String Formatting Operations in the Library Reference. Colin W. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] File IO
Michael Haft wrote: >Hello, > I tried the following code: > >def readSOMNETM(inputName): >input = open(inputName, "r") >result = [] >for line in input: >fields = line.split() >data = fields[1] + fields[2] + fields[7] >result.append(data) >input.close() >return result > > >print "Here goes" >print "Enter filename:" >filename = raw_input("Name:") >print readSOMNETM(filename) >print "might work" > >on a file that lookes like this: > >Monthly Weather Data, LAU73M.MET, converted from: >BAD LAUCHSTAEDT; DAILY METEOROLOGICAL DATA FOR 01/01/1973-31/12/1973 >VAP, DEWP CALCULATED FROM MEASURED AVTEMP AND HUMID DATA >MONTH RAINAVTEMP S10 RAD SUN WINDEVAPW >** >1 22.50.3 * 54.615.1* 11.9 >2 16.11.8 * 110 51.1* 18.1 >3 16.44.8 * 227.5 94.5* 36.8 >4 19.55.9 * 286.3 89 * 45.5 >5 36.113.2* 448.5 164.6 * 83 >6 36 16.9* 525.7 208.8 * 105.7 >7 37.718.2* 459.7 165.4 * 98.6 >8 29.318.2* 463.8 206.8 * 97.9 >9 27 14.8* 277.5 119.5 * 58.7 >10 57.67.6 * 158.7 72.2* 31.3 >11 23.43.9 * 98.375.6* 19.1 >12 14 0.7 * 55.538 * 12.5 > > >And recieved the following error: > >Traceback (most recent call last): > File "C:\Python24\INProgress.py", line 15, in -toplevel- >print readSOMNETM(filename) > File "C:\Python24\INProgress.py", line 6, in readSOMNETM >data = fields[1] + fields[2] + fields[7] >IndexError: list index out of range > >Essentially I'm trying to write a bit of code that can take any of the >fields in the above data i.e. rain temp evap for each month for a hundred >or so files like this one and spit out a file at the end that has the data >in a different format. > >Any help would be very much appreciated I need to get this done by the end >of next week > >Thanks > >Mike > >___ >Tutor maillist - Tutor@python.org >http://mail.python.org/mailman/listinfo/tutor > > > My guess is that you have a line, perhaps the last one in the file, which does not end with '\n'. You might try: def readSOMNETM(inputName): input = open(inputName, "r") result = [] for line in input: fields = line.split() try: data = fields[1] + fields[2] + fields[7] except: print repr(line) print fields raise ValueError result.append(data) input.close() return result Colin W. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] avoid eval how???
Danny Yoo wrote: >>You make some good points here but I suggest that, in the real world, >>the risks are small. >> >> > >Hi Colin, > >But that's the point I'm trying to make; eval() is appropriate only for >toy code. In real world code that's exposed to the world, using eval() is >usually the wrong thing to do, because it really is dangerous unless we >really know what we're doing. > > >eval() is more potent than it appears. We had a thread about this last >year: > >http://mail.python.org/pipermail/tutor/2004-December/033819.html >http://mail.python.org/pipermail/tutor/2004-December/033828.html > >I gave an an example that shows that it's very possible to write an >infinite loop (or at least hit Python's stack limit) with a single >expression: > >## >s = "(lambda loop: loop(loop)) (lambda self: self(self))" >eval(s) >## > >Note that there are no calls to the builtins, nor any reference to outside >free variables. It's just simple function application. > > >Beginners see eval() as an easy all-in-one tool for doing parsing and >value conversion. Those who use it indiscriminately don't understand that >Python's eval() has enough power to do bad things like infinite loops and >calls to os.system(). > > > > >>You might consider using exec instead. It would appear that one can >>specify a restricted environment in which the statement is executed. >> >> > >I think you're talking about 'rexec'. But the folks who finally wrote the >Python Standard Library eventually woke up and deprecated rexec. > >http://www.python.org/doc/lib/module-rexec.html > >They deprecated it because they could not guarantee a safe, restricted >execution environment on top of Python's eval() and exec primitives. > > > Hi Danny, No, I was thinking of exec. The given statement can be executed in a specified environment. You might say "The rogue code can dodge that with an import statement with an import". True, but it seems to me that a user specified __import__ function can protect against this. I have not tried this. >I'm not saying that eval() is useless: it does have its uses. And I >suppose that it's possible to write sandboxes if we're cautious enough >with it. My point, though, is that it is not trivial to make eval()/exec >safe. Plenty of smart people have tried it and messed it up. I'm dumb >enough not to try. *grin* > > > I accept the points you make wrt eval. Colin W. >There are plenty of other alternatives for turning a string into dynamic >"code". I'd rather we concentrate on those because such techniques are >well known and battle tested. > > >Hope this helps! > > > ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] testing: doctest and unittest
Alex Hunsley wrote: >Regards testing, I've been playing with both the unittest >(http://pyunit.sourceforge.net/pyunit.html) and doctest >(http://docs.python.org/lib/module-doctest.html). I was wondering what >peoples thoughts were on the effectiveness and convenience of one versus >the other. It seems to me that doctest is good for quicky and >straightforwards input/output tests for small units, whereas unittest >would be good for dynamic or complicated testing. > >Where do you seasoned pythonites see unittest and doctest in relation to >each other? Do you only use one or the other? > >ta, >alex > > >___ >Tutor maillist - Tutor@python.org >http://mail.python.org/mailman/listinfo/tutor > > > I looked at doctest and feel that it clutters the module text and so would prefer unittest but I haven't yet got to formalizing my tests in that way. See some of the numarray source as an example of clutter. Some argue that having the examples in the source is beneficial. I agree but feel that the clutter outweighs the benefit. Colin W. Colin W. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Who called me?
Liam Clarke-Hutchinson wrote: >I believe only by explicitly passing a reference to the parent? > >Liam Clarke-Hutchinson > >-Original Message- >From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf >Of Bill Campbell >Sent: Wednesday, 9 November 2005 7:00 a.m. >To: Tutor >Subject: [Tutor] Who called me? > > >Is there a way in python for a method to determine its parent? > >In particular, I'm working with SimpleXMLRPCServer, and would like to be >able to find the client_address in the routine that has been dispatched. I >know that client_address is an attribute of the handler class instance, but >don't know how to get to that. > >Bill >-- >INTERNET: [EMAIL PROTECTED] Bill Campbell; Celestial Software LLC >UUCP: camco!bill PO Box 820; 6641 E. Mercer Way >FAX:(206) 232-9186 Mercer Island, WA 98040-0820; (206) 236-1676 >URL: http://www.celestial.com/ > >My brother sent me a postcard the other day with this big satellite photo of >the entire earth on it. On the back it said: ``Wish you were here''. > -- Steven Wright >___ >Tutor maillist - Tutor@python.org >http://mail.python.org/mailman/listinfo/tutor > >A new monthly electronic newsletter covering all aspects of MED's work is now >available. Subscribers can choose to receive news from any or all of seven >categories, free of charge: Growth and Innovation, Strategic Directions, >Energy and Resources, Business News, ICT, Consumer Issues and Tourism. See >http://news.business.govt.nz for more details. > > > > >http://www.govt.nz - connecting you to New Zealand central & local government >services > >Any opinions expressed in this message are not necessarily those of the >Ministry of Economic Development. This message and any files transmitted with >it are confidential and solely for the use of the intended recipient. If you >are not the intended recipient or the person responsible for delivery to the >intended recipient, be advised that you have received this message in error >and that any use is strictly prohibited. Please contact the sender and delete >the message and any attachment from your computer. >___ >Tutor maillist - Tutor@python.org >http://mail.python.org/mailman/listinfo/tutor > > > You might consider the inspect module. See 3.11.4 in the Library Reference. I think that the interpreter stack contains this information but have not used te module myself. Colin W. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor