From gwright at labyrinth.net.au Mon Jan 2 10:39:31 2006 From: gwright at labyrinth.net.au (George Wright) Date: Mon, 2 Jan 2006 20:39:31 +1100 Subject: [melbourne-pug] Opening .sxi files Message-ID: Having now started to delve into Twisted with the help of Abe Fettig's nice book on the subject I downloaded Justin Warren's file of his presentation twisted.sxi I can't open .sxi files on my iMac Tiger !! Love to be able to read it. I do have Powerpoint but no other presentation thing. Can anyone help? Maybe Justin could convert to Power Point or do I have to install Open Office or something? George Wright http://users.bigpond.net.au/George.Wright/ http://www.labyrinth.net.au/~gwright From huw.davies at kerberos.davies.net.au Mon Jan 2 13:33:34 2006 From: huw.davies at kerberos.davies.net.au (Huw Davies) Date: Mon, 02 Jan 2006 23:33:34 +1100 Subject: [melbourne-pug] Opening .sxi files In-Reply-To: References: Message-ID: <3E396D73-8101-428C-8FA8-0832F4C92ECC@kerberos.davies.net.au> On 02/01/2006, at 8:39 PM, George Wright wrote: > Having now started to delve into Twisted with the help of Abe > Fettig's nice book on the subject I downloaded > Justin Warren's file of his presentation twisted.sxi > I can't open .sxi files on my iMac Tiger !! > Love to be able to read it. > I do have Powerpoint but no other presentation thing. > Can anyone help? > Maybe Justin could convert to Power Point or do I have to install > Open Office or something? Well OpenOffice is the tool to open .sxi files, but if you don't want to install it (dead easy as long as you have X11 installed on your Mac) e-mail me off list with a copy of the .sxi file and I'll convert it to pdf for you. Huw Davies | e-mail: Huw.Davies at kerberos.davies.net.au Melbourne | "If soccer was meant to be played in the Australia | air, the sky would be painted green" From gcross at fastmail.fm Tue Jan 3 11:56:34 2006 From: gcross at fastmail.fm (Graeme Cross) Date: Tue, 3 Jan 2006 21:56:34 +1100 Subject: [melbourne-pug] Opening .sxi files In-Reply-To: References: Message-ID: <860b2b0fd310085cfdf3776a06ef56fa@fastmail.fm> On 02/01/2006, at 8:39 PM, George Wright wrote: > Having now started to delve into Twisted with the help of Abe > Fettig's nice book on the subject I downloaded > Justin Warren's file of his presentation twisted.sxi > I can't open .sxi files on my iMac Tiger !! > Love to be able to read it. > I do have Powerpoint but no other presentation thing. NeoOffice/J -- a port of StarOffice to run natively on Mac OS X (ie. no need for X11). http://www.neooffice.org/ for more info and downloads. Regards, Graeme -- Graeme Cross From daedalus at eigenmagic.com Mon Jan 2 23:42:08 2006 From: daedalus at eigenmagic.com (Justin Warren) Date: Tue, 03 Jan 2006 09:42:08 +1100 Subject: [melbourne-pug] Opening .sxi files In-Reply-To: References: Message-ID: <1136241729.6532.2.camel@localhost.localdomain> On Mon, 2006-01-02 at 20:39 +1100, George Wright wrote: > Having now started to delve into Twisted with the help of Abe > Fettig's nice book on the subject I downloaded > Justin Warren's file of his presentation twisted.sxi > I can't open .sxi files on my iMac Tiger !! > Love to be able to read it. > I do have Powerpoint but no other presentation thing. > Can anyone help? > Maybe Justin could convert to Power Point or do I have to install > Open Office or something? Hey George, I've attached the presentation as a .ppt for you. Cheers, -- Justin Warren -------------- next part -------------- A non-text attachment was scrubbed... Name: OSDC-2005-twisted-presentation-v1.1.ppt Type: application/vnd.ms-powerpoint Size: 81408 bytes Desc: not available Url : http://mail.python.org/pipermail/melbourne-pug/attachments/20060103/cccbd9b2/attachment-0001.ppt From gwright at labyrinth.net.au Wed Jan 4 08:25:08 2006 From: gwright at labyrinth.net.au (George Wright) Date: Wed, 4 Jan 2006 18:25:08 +1100 Subject: [melbourne-pug] Opening .sxi files In-Reply-To: <1136241729.6532.2.camel@localhost.localdomain> References: <1136241729.6532.2.camel@localhost.localdomain> Message-ID: <369CE6D6-F224-4354-BFDB-924EF53E5484@labyrinth.net.au> Wow! thanks for all the helpful responses. I now have a PowerPoint, and a pdf and a link to non X11 Office Thanks Justin, Graeme and Huw Much appreciated. George On 03/01/2006, at 9:42 AM, Justin Warren wrote: > On Mon, 2006-01-02 at 20:39 +1100, George Wright wrote: >> Having now started to delve into Twisted with the help of Abe >> Fettig's nice book on the subject I downloaded >> Justin Warren's file of his presentation twisted.sxi >> I can't open .sxi files on my iMac Tiger !! >> Love to be able to read it. >> I do have Powerpoint but no other presentation thing. >> Can anyone help? >> Maybe Justin could convert to Power Point or do I have to install >> Open Office or something? > > Hey George, > > I've attached the presentation as a .ppt for you. > > Cheers, > > -- > Justin Warren > > _______________________________________________ > melbourne-pug mailing list > melbourne-pug at python.org > http://mail.python.org/mailman/listinfo/melbourne-pug From lemeia at bigpond.com Thu Jan 5 14:13:22 2006 From: lemeia at bigpond.com (lemeia) Date: Fri, 6 Jan 2006 0:13:22 +1100 Subject: [melbourne-pug] mapping strings to class attributes/operators etc. Message-ID: <6678821.1136466802115.JavaMail.root@web09sl> Hi all, I'm a new member so hello everyone. I'm also a very new Python programmer. I'm really impressed with how quick it was to pick up Python. I've only really explored it as an option once I moved to the Linux platform from Windows. There's several things I'd like to do with Python as an all purpose utility language, but right now I would like to ask some advice on something in particular. I've got a program I use to read in large files of data which I use to create temporary objects and apply various comparisons and criteria against the objects I create and write to different output files and increment various statistic attributes in my application object for later reporting. The problem is that this isn't a fixed operation at all. It would be much better for these comparisons and actions to be very dynamic and prevent me from constantly changing the code and rerunning it. I was thinking I would like to develop some sort of mini-query language. Very simplified and fairly specific to the objects I am creating during my run. Is there a way in Python (using Dictionaries or something) to map strings to attributes, operators, functions etc... So if I wanted to say object: dimensions condition: height < 8.4 action: writeReject(height) exception: none then the application would parse it into a statement like: if dimension.height < 8.4: self.writeReject(height) In this way, I could save various conditions and even build them into a string of conditions called a criteria system (for example). I could also use the same mechanism to design reports based on alterable (and storable) conditions that the user specifies. Can this sort of thing be done cleverly in Python? Regards Patrick From daedalus at eigenmagic.com Thu Jan 5 23:58:09 2006 From: daedalus at eigenmagic.com (Justin Warren) Date: Fri, 06 Jan 2006 09:58:09 +1100 Subject: [melbourne-pug] mapping strings to class attributes/operators etc. In-Reply-To: <6678821.1136466802115.JavaMail.root@web09sl> References: <6678821.1136466802115.JavaMail.root@web09sl> Message-ID: <1136501889.6385.22.camel@localhost.localdomain> On Fri, 2006-01-06 at 00:13 +1100, lemeia wrote: > Hi all, > > I'm a new member so hello everyone. I'm also a very new Python programmer. > I'm really impressed with how quick it was to pick up Python. I've only really explored it as an option once I moved to the Linux platform from Windows. > > There's several things I'd like to do with Python as an all purpose utility language, but right now I would like to ask some advice on something in particular. > > I've got a program I use to read in large files of data which I use to create temporary objects and apply various comparisons and criteria against the objects I create and write to different output files and increment various statistic attributes in my application object for later reporting. > > The problem is that this isn't a fixed operation at all. It would be much better for these comparisons and actions to be very dynamic and prevent me from constantly changing the code and rerunning it. > > I was thinking I would like to develop some sort of mini-query language. Very simplified and fairly specific to the objects I am creating during my run. > > Is there a way in Python (using Dictionaries or something) to map strings to attributes, operators, functions etc... > > So if I wanted to say > object: dimensions > condition: height < 8.4 action: writeReject(height) exception: none > > then the application would parse it into a statement like: > if dimension.height < 8.4: > self.writeReject(height) > > In this way, I could save various conditions and even build them into a string of conditions called a criteria system (for example). I could also use the same mechanism to design reports based on alterable (and storable) conditions that the user specifies. > Can this sort of thing be done cleverly in Python? Python can do anything. :) We do something along these lines in our seafelt software in that there's a dynamic mapping of a given object class to a specific piece of code that is executed in a semi-known way. What you'll need to do is create a kind of templating system, which is basically what you've referred to above. Using your example above, you have a dimensions object, so it would instanciate something like: def __init__(self, name, condition, success, fail): self.name = name self.condition = condition ... then you could have a function that gets called on all your template created objects: def process(self): if eval(condition): self.success() else: self.fail() Processed like this: for obj in template_objs: obj.process() If you want to pass arguments to dynamically called functions, you'll need to pass in *args or **kwargs so that the correct arguments can be looked up, as in your writeReject(height) example. Hope that helps. -- Justin Warren From cropleyb at yahoo.com.au Sat Jan 7 22:53:54 2006 From: cropleyb at yahoo.com.au (Bruce Cropley) Date: Sun, 8 Jan 2006 08:53:54 +1100 (EST) Subject: [melbourne-pug] mapping strings to class attributes/operators etc In-Reply-To: Message-ID: <20060107215354.320.qmail@web60217.mail.yahoo.com> Hi Patrick > I've got a program I use to read in large files of > data which I use to create temporary objects and > apply various comparisons and criteria against the > objects I create and write to different output files > and increment various statistic attributes in my > application object for later reporting. > > The problem is that this isn't a fixed operation at > all. It would be much better for these comparisons > and actions to be very dynamic and prevent me from > constantly changing the code and rerunning it. In compiled languages with lots of pain required to build anything, writing a mini-language makes a lot of sense. Python is comparatively quick and easy to write and modify, so you can get something working without much effort. Perhaps you're finding that it takes a long time to process the data to get to the point where you can run the queries, but you need to try a few different types of statistics. In this case, you might want to try embedding an interpreter into your application using the "cmd" module, or using "eval" like Justin suggested. Another option would be to get the app to "reload" a specific module that has this summary processing in it. The data that I've worked with in python apps like this tends to have been fairly easy to represent in a relational table or two. If you want to do Object Relational mapping, I've heard good things about a python library called SQLObject. In my experience, if your data is fairly flat, then you won't save on the runtime by using an approach like the above, because the data structures that you need to gather the summary information can change frequently. In that case you could try a Pipeline design pattern with different classes for filters, accumulators etc, with a standard interface calling from one stage to the next. Hope that helps, Bruce Send instant messages to your online friends http://au.messenger.yahoo.com From tennessee at tennessee.id.au Sun Jan 8 01:44:47 2006 From: tennessee at tennessee.id.au (Tennessee Leeuwenburg) Date: Sun, 08 Jan 2006 11:44:47 +1100 Subject: [melbourne-pug] mapping strings to class attributes/operators etc. In-Reply-To: <1136501889.6385.22.camel@localhost.localdomain> References: <6678821.1136466802115.JavaMail.root@web09sl> <1136501889.6385.22.camel@localhost.localdomain> Message-ID: <43C0607F.4060201@tennessee.id.au> One way, of course, would be with some kind of class which has a run method. You could instantiate a new instance of each class, store each in a dictionary indexed by keyword, then call BagOfInstances["keyword"].run() I don't *think* you can simply store methods directly into a dictionary, but I might be wrong. It could be possible to do BagOfInstances["keyword"] = methodName and be done with it. Cheers, -T From tennessee at tennessee.id.au Sun Jan 8 01:31:07 2006 From: tennessee at tennessee.id.au (Tennessee Leeuwenburg) Date: Sun, 08 Jan 2006 11:31:07 +1100 Subject: [melbourne-pug] mapping strings to class attributes/operators etc. In-Reply-To: <1136501889.6385.22.camel@localhost.localdomain> References: <6678821.1136466802115.JavaMail.root@web09sl> <1136501889.6385.22.camel@localhost.localdomain> Message-ID: <43C05D4B.9060205@tennessee.id.au> Justin Warren wrote: >On Fri, 2006-01-06 at 00:13 +1100, lemeia wrote: > > >>Hi all, >> >>I'm a new member so hello everyone. I'm also a very new Python programmer. >>I'm really impressed with how quick it was to pick up Python. I've only really explored it as an option once I moved to the Linux platform from Windows. >> >>There's several things I'd like to do with Python as an all purpose utility language, but right now I would like to ask some advice on something in particular. >> >>I've got a program I use to read in large files of data which I use to create temporary objects and apply various comparisons and criteria against the objects I create and write to different output files and increment various statistic attributes in my application object for later reporting. >> >>The problem is that this isn't a fixed operation at all. It would be much better for these comparisons and actions to be very dynamic and prevent me from constantly changing the code and rerunning it. >> >>I was thinking I would like to develop some sort of mini-query language. Very simplified and fairly specific to the objects I am creating during my run. >> >>Is there a way in Python (using Dictionaries or something) to map strings to attributes, operators, functions etc... >> >>So if I wanted to say >>object: dimensions >>condition: height < 8.4 action: writeReject(height) exception: none >> >>then the application would parse it into a statement like: >>if dimension.height < 8.4: >> self.writeReject(height) >> >>In this way, I could save various conditions and even build them into a string of conditions called a criteria system (for example). I could also use the same mechanism to design reports based on alterable (and storable) conditions that the user specifies. >> >> Could you please explain the actual task with a little more detail? I can think of a number of options, and have done similar things myself before using Java, but I don't know exactly what you're trying to do. Cheers, -T From lemeia at bigpond.com Sun Jan 8 11:39:42 2006 From: lemeia at bigpond.com (lemeia) Date: Sun, 8 Jan 2006 21:39:42 +1100 Subject: [melbourne-pug] mapping strings to class Message-ID: <18117635.1136716783177.JavaMail.root@web02sl> Hi all, I've got so far as to dynamically generate a string of conditions from a configuration file. However, I've run into a few problems. I've contained the whole set of conditions in one string variable which I then execute using the exec statement. My string will be similar to this: if conditionA: statement1 statement2 return True elif conditionB: statement1 statement2 return True else: return False First of all, I found out that I can't use "return" as part of an exec statement unless it is part of a funtion. So I defined the whole thing as a function (check()) and then called the function from outside of the exec statement. It sort of looks like this: def checkResults(self, criteria): exec(criteria) return criteria() But it's all falling appart by now. I don't know how the function should be defined within the exec statement so that I can call it successfully from outside of the exec statement. The fact is that checkResults() is an attribute of an object when it is being called. So that means I would need to make sure that when my dynamically generated function check() is called it needs to have access to the same object - the comparisons are based on attributes of this object. So how do I do this? Regards Patrick From tennessee at tennessee.id.au Sun Jan 8 12:10:54 2006 From: tennessee at tennessee.id.au (Tennessee Leeuwenburg) Date: Sun, 08 Jan 2006 22:10:54 +1100 Subject: [melbourne-pug] mapping strings to class In-Reply-To: <18117635.1136716783177.JavaMail.root@web02sl> References: <18117635.1136716783177.JavaMail.root@web02sl> Message-ID: <43C0F33E.8000902@tennessee.id.au> Sounds like you've fallen off the bandwagon somewhere. Could you please give some more detail on the problem? Cheers, -T From cropleyb at yahoo.com.au Mon Jan 9 12:11:18 2006 From: cropleyb at yahoo.com.au (Bruce Cropley) Date: Mon, 9 Jan 2006 22:11:18 +1100 (EST) Subject: [melbourne-pug] mapping strings to class Message-ID: <20060109111118.50334.qmail@web60216.mail.yahoo.com> Hi Patrick You can use a dictionary of functions or methods (bound to an object or not): Python 2.4.1 (#2, Mar 31 2005, 00:05:10) >>> class B: ... def meth1(self, x): ... print x ... >>> b = B() >>> b.meth1 > >>> B.meth1 >>> d = {"a":b.meth1, "whatever":B.meth1} >>> d["a"]("hello") hello >>> d["whatever"](b, "hello") hello You can also pass in a global and local scope to eval: >>> help(eval) Help on built-in function eval in module __builtin__: eval(...) eval(source[, globals[, locals]]) -> value Evaluate the source in the context of globals and locals. The source may be a string representing a Python expression or a code object as returned by compile(). The globals must be a dictionary and locals can be any mappping, defaulting to the current globals and locals. If only globals is given, locals defaults to it. And similarly for exec... >>> def blah(): ... something = {1:2, 3:4} ... exec("print something[1]", globals(), locals()) ... >>> blah() 2 Though you may prefer something along these lines: >>> def blah(): ... exec("def inner(a): print a") ... inner(4) ... >>> blah() 4 > def checkResults(self, criteria): > exec(criteria) > return criteria() You probably want to use different names for the string and the function. And perhaps you could pass in self to the criteria function so it can access whatever attributes it needs: class Whatever: ... def checkResults(self, criteriaStr): exec(criteriaStr) # Includes "def criteriaFunc(whatever):..." return criteriaFunc(self) BTW, it's probably bad to run the exec for every item in a large data set. Hope that helps, Bruce =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= Bruce Cropley Software Development Consultant 0400 147 429 (m) Melbourne, Australia brucedecoy-sig yahoo.com.au Python/Agile processes/Version control/AI/Algs./C++ http://jroller.com/comments/cropleyb/Weblog ____________________________________________________ Do you Yahoo!? Yahoo! Music: Vote 'Who's Next' and see your favourite band live http://au.music.yahoo.com/artists/whos-next/ From tennessee at tennessee.id.au Mon Jan 9 12:28:50 2006 From: tennessee at tennessee.id.au (Tennessee Leeuwenburg) Date: Mon, 09 Jan 2006 22:28:50 +1100 Subject: [melbourne-pug] mapping strings to class In-Reply-To: <20060109111118.50334.qmail@web60216.mail.yahoo.com> References: <20060109111118.50334.qmail@web60216.mail.yahoo.com> Message-ID: <43C248F2.20208@tennessee.id.au> Bruce Cropley wrote: >Hi Patrick > >You can use a dictionary of functions or methods >(bound to an object or not): > >Python 2.4.1 (#2, Mar 31 2005, 00:05:10) > > >>>>class B: >>>> >>>> >... def meth1(self, x): >... print x >... > > >>>>b = B() >>>>b.meth1 >>>> >>>> >0x57080>> > > >>>>B.meth1 >>>> >>>> > > > >>>>d = {"a":b.meth1, "whatever":B.meth1} >>>>d["a"]("hello") >>>> >>>> >hello > > Hi Bruce, Thanks for this addition -- I had thought/hoped that it worked like this, but wasn't sure -- hence my suggestion of a dictionary of instances. I suppose they are functionally equivalent, but I prefer your method for simplicity. Cheers, -T From lemeia at bigpond.com Mon Jan 9 17:56:29 2006 From: lemeia at bigpond.com (lemeia) Date: Tue, 10 Jan 2006 3:56:29 +1100 Subject: [melbourne-pug] mapping strings to class Message-ID: <22277306.1136825789441.JavaMail.root@web04sl> Actually, I ditched the exec approach. I decided it might be less problematic to only put the conditions themselves in eval statements. This is now working. Of course I am now coping with a significant slow down in the processing run but that was expected. I am going to see if compiling the conditions before the run brings about any improvement, but I think I'm probably going to have to tolerate some slow down as a price to pay for the many dynamic conditions I'm evaluating. Patrick ===== Message: 1 Date: Sun, 08 Jan 2006 22:10:54 +1100 From: Tennessee Leeuwenburg Subject: Re: [melbourne-pug] mapping strings to class To: Melbourne Python Users Group Message-ID: <43C0F33E.8000902 at tennessee.id.au> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Sounds like you've fallen off the bandwagon somewhere. Could you please give some more detail on the problem? Cheers, -T